Infrastructure module¶
-
class
Infrastructure.Infrastructure(regions, graph, bounding_box)¶ Bases:
src.Backend.Polygon.PolygonThis class represents the Infrastructure using a Polygon, Pathfinder, and a Graph
- Attributes
- gatesList of Points
The location of the gates along the city wall
- roadsList of Lists of Points
Each list represents the points along a path which represents the main roads of the city
Methods
area()Finds the area of the polygon
cut(p1, p2)Cuts a polygon along two points
cut_gap(p1, p2, gap)Cuts a polygon along two points
cut_out(interior_polygon)Cuts a larger polygon into parts without an interior polygon part
cut_out_2(interior_polygon)Cuts out a shape from a larger polygon if the interior polygon is a scaled down version of the larger polygon
cut_out_gap_2(interior_polygon, scalar)Cuts out a shape from a larger polygon if the interior polygon is a scaled down version of the larger polygon with a gap
easy_cut(p, ang, gap)Cuts a polygon into two parts based on a point and an angle, with a gap for the width of the cut
find_ext_point(furthest_point, ang, initial_p)Find an extreme point given a furthest_point, an angle, and an initial point
find_intersecting_edge(p, ang)Given a line segment this method returns an edge that that line segment intersects
find_intersecting_edges(p, ext_p)Given a line segment this method returns edges that that line segment intersects, this is used because of an edge case in the find_intersecting_edges
furthest_conglomerate_point(p)Finds a point that has the furthest x value among all points in the polygon and has the furthest y value among all points in the polygon
furthest_point(point)Finds the furthest point in this polygon from a give point
get_center()Finds the centroid of the polygon.
Returns the List of Points that defines the Gates
get_perimeter()Finds the perimeter of the polygon
Returns the List of Lists of Points that defines the main roads in the city
get_vertices()Gets the vertices of the polygon
in_segment(p1, p2, p3)Returns true if p3 is in the line segment from p1 to p2.
inside(larger_polygon)Checks a given polygon to see if it is in a larger polygon
intersection(p1, p2, p3, p4)Finds the point of intersection given twp line segments
is_bordering(other)Checks to see if a given polygon borders this polygon.
is_contained(point)Returns true if Point point is located on the edge of or in this Polygon.
is_convex()Returns true if the polygon is convex and has no intersecting lines.
is_rectangle()Check a given polygon to see if it is a rectangle
longest_side_and_length()Finds the longest side and length
move_center_to(p)Moves a polygon’s center to a given point p
move_polygon_by_center(left_right_distance, …)Moves a polygon’s center by left_right_distance left or right, and up_down_distance up or down.
on_edge(p)Checks to see if a given point p is on any edge of the polygon
rectangle_inside(p1, p2)Finds a rectangle given an edge of the polygon
scale_of_polygon(scalar)Scales a polygon by a scalar and returns a new scaled polygon centered on the original polygon’s center
set_vertices(vertices[, reorder])Sets the vertices of the polygon
split(p, ang, gap)splits a polygon along a point and an angle relative to edge of p
to_points(polygons)Takes a list of polygons and converts it to a list of points
to_polygon(vertices)Returns a polygon given a list of lists, i.e. [[1, 2], [3, 4], [5, 6]] => polygon with those vertices.
-
get_gates()¶ Returns the List of Points that defines the Gates
- Returns
- List of Points
The List of Points that defines the Gates of the Wall
-
get_roads()¶ Returns the List of Lists of Points that defines the main roads in the city
- Returns
- List of List of Points
The List of Lists of Points that defines the main roads in the city
-
Infrastructure.bfs_path(G, source, destination)¶ Use a breadth first search to find the path from vertex source to vertex destination.
- Parameters
- Gnx.Graph
The graph to search
- sourcePoint
Origin point
- destinationPoint
Destination point
- Returns
- deque
A queue with the path from source to destination already enqueued.
-
Infrastructure.move_vertex(region, vertex, new_vertex, vert_dict)¶ Move the vertex in the region, and update that same vertex in the neighbours of the region
- Parameters
- regionRegion
The region whose vertex is being updated
- vertexPoint
Vertex of the region to be changed, which will also be updated in the neighbouring regions
- new_vertexPoint
The new location of the vertex
- vert_dictDict
A dictionary which will be used to move the nodes in the graph
-
Infrastructure.print_dict(dict_name, points)¶
-
Infrastructure.print_list(list_name, points)¶
-
Infrastructure.project_vector(u, v)¶ Project vector u onto vector v
Convert the Points into np.array and then use
\[ext\{proj\}_{\vec{v}}(\vec{u}) = \frac{\vec{u} \cdot \vec{v}}{||\vec{v}||^2} \times \vec{v}\]- Parameters
- uPoint
Vector
- vPoint
Vector
- Returns
- Point
The result of projecting u onto v