Polygon

class foronoi.graph.Polygon(tuples)

A bounding polygon that will clip the edges and fit around the Voronoi diagram.

Parameters

tuples (list[(float, float)]) – x,y-coordinates of the polygon’s vertices

finish_edges(edges, **kwargs)

Clip the edges to the bounding box/polygon, and remove edges and vertices that are fully outside. Inserts vertices at the clipped edges’ endings.

Parameters

edges (list(HalfEdge)) – A list of edges in the Voronoi diagram. Every edge should be presented only by one half edge.

Returns

clipped_edges – A list of clipped edges

Return type

list(HalfEdge)

finish_polygon(edges, existing_vertices, points)

Creates half-edges on the bounding polygon that link with Voronoi diagram’s half-edges and existing vertices.

Parameters
  • edges (list(HalfEdge)) – The list of clipped edges from the Voronoi diagram

  • existing_vertices (set(Vertex)) – The list of vertices that already exists in the clipped Voronoi diagram, and vertices

  • points (set(Point)) – The list of cell points

Returns

  • edges (list(HalfEdge)) – The list of all edges including the bounding polygon’s edges

  • vertices (list(Vertex)) – The list of all vertices including the

inside(point)

Tests whether a point is inside a polygon. Based on the Javascript implementation from https://github.com/substack/point-in-polygon

Parameters

point (Point) – The point for which to check if it it is inside the polygon

Returns

inside – Whether the point is inside or not

Return type

bool