Skip to main content

geometry2d

Polygons on the plane, as lists of [x, y] points in outline order: triangulation, booleans, hulls and containment. Every answer is the same on every platform: the booleans run in fixed point and the rest is plain arithmetic.

9 functions, 0 constants. Scripts reach it as geometry2d::.

Functions

Argument kinds are the script values a call passes: node is a node handle, any a table or value of any kind, fn a callback.

functionacts onwhat it does
area(any) -> floatThe polygon's area, always positive whatever its winding.
contains(any, any) -> boolWhether a point lies inside the polygon; a point on an edge counts as inside.
convex_hull(any) -> anyThe smallest convex polygon around the points, counter-clockwise.
difference(any, any) -> anyEverything inside the first polygon and outside the second, shaped as union shapes it.
intersection(any, any) -> anyEverything inside both polygons, shaped as union shapes it.
is_clockwise(any) -> boolWhether the points run clockwise, with y up.
segments_intersect(any, any, any, any) -> anyWhere two segments cross, or nil when they do not; touching at an endpoint counts.
triangulate(any) -> anyThe polygon cut into triangles, as [i, j, k] triples indexing its points, counter-clockwise; either winding is accepted.
union(any, any) -> anyEverything inside either polygon: a list of shapes, each a list of paths whose first is the outline and the rest holes.