d4_polygon library

This package provides a few basic geometric operations for two-dimensional polygons.

Each polygon is represented as an list of two-element list [​[x0, y0], [x1, y1], …], and may either be closed (wherein the first and last point are the same) or open (wherein they are not). Typically polygons are in counterclockwise order, assuming a coordinate system where the origin is in the top-left corner.

Functions

polygonArea(List<List<num>> polygon) num
Returns the signed area of the specified polygon.
polygonCentroid(List<List<num>> polygon) List<num>
Returns the centroid of the specified polygon.
polygonContains(List<List<num>> polygon, List<num> point) bool
Returns true if and only if the specified point is inside the specified polygon.
polygonHull(List<List<num>> points) List<List<num>>?
Returns the convex hull of the specified points using Andrew’s monotone chain algorithm.
polygonLength(List<List<num>> polygon) num
Returns the length of the perimeter of the specified polygon.