-
Notifications
You must be signed in to change notification settings - Fork 1
Poly.lua
Warning: Poly.lua is entirely new and still WIP. Precise documentation will not be included until a baseline functionality is achieved - however, the library will be accessible and will almost always at least compile during this time, though nothing is guaranteed.
Poly.lua is a polygon class library designed in the fashion of Vec and Line. It requires Vec and Line to work, in the same fashion as Line and Rec. Poly is designed to provide basic utilities for general shapes, such as intersection, combination, subtraction, rotation, and even some raycasting utilities. It should be noted that polygon is designed primarily for 2d convex polygons, though it will include functions for decomposing concave 2d polygons. Complex or composite polygons, however - i.e. those with holes punched in the middle - are unlikely to be well-supported.
It is instantiated more or less as standard:
local poly = Poly(0,0,10,10,0,10)
local poly = Line(Vec(0,0),Vec(10,10),Vec(0,10))Either of these methods will produce a right 45-degree triangle with leg lengths of 10.
The polygon supports the following properties, similarly to the rectangle:
poly.typereturns "polygon" (set)poly.xreturns the minimum x coordinate of the polygon (set)poly.x1alias of xpoly.yreturns the minimum y coordinate of the polygon (set)poly.y1alias of ypoly.x2returns the maximum x coordinate of the polygon (set)poly.y2returns the maximum y coordinate of the polygon (set)
The following methods are also supported:
>* poly:order() sorts the vertices in clockwise order for convex polygons.
badly broken, working on a fix.
poly:add(...)Adds a vertex (or vertices) to the polygon - identical behavior to construction.poly:rem(i)Removes a vertex from the polygon and returns it; without an index, removes last.
poly:del()recycles the polygon as above.