An abstract around an Array of Points that define a polygonal shape that can be collision-tested against.
See also:
Static variables
Static methods
staticcentroid(this:Array<Point>):Point
Calculates a centroid of the Polygon and returns its position.
staticcontains(this:Array<Point>, p:Point, isConvex:Bool = false):Bool
Tests if Point p is inside this Polygon.
Parameters:
p | The point to test against. |
|---|---|
isConvex | Use simplified collision test suited for convex polygons. Results are undefined if polygon is concave. |
staticconvexHull(this:Array<Point>):Array<Point>
Returns a new Polygon containing a convex hull of this Polygon. See Monotone chain algorithm for more details.
staticdistance(this:Array<Point>, pt:Point, ?outside:Bool):Float
Return the distance of pt to the closest edge.
If outside is true, only return a positive value if pt is outside the polygon, zero otherwise
If outside is false, only return a positive value if pt is inside the polygon, zero otherwise
staticdistanceSq(this:Array<Point>, pt:Point, ?outside:Bool):Float
Same as distance but returns the squared value
staticfastTriangulate(this:Array<Point>):Array<Int>
Uses EarCut algorithm to quickly triangulate the polygon. This will not create the best triangulation possible but is quite solid wrt self-intersections and merged points. Returns the points indexes
staticfindClosestPoint(this:Array<Point>, pt:Point, maxDist:Float):Null<Point>
Returns closest Polygon vertex to Point pt within set maximum distance.
Parameters:
pt | The point to test against. |
|---|---|
maxDist | Maximum distance vertex can be away from |
Returns:
A Point instance in the Polygon representing closest vertex (not the copy). null if no vertices were found near the pt within maxDist.
staticgetBounds(this:Array<Point>, ?b:Bounds):Null<Bounds>
Returns bounding box of the Polygon.
Parameters:
b | Optional Bounds instance to be filled. Returns new Bounds instance if |
|---|
staticgetCollider(this:Array<Point>, isConvex:Bool = false):PolygonCollider
Returns new PolygonCollider instance containing this Polygon.
Parameters:
isConvex | Use simplified collision test suited for convex polygons. Results are undefined if polygon is concave. |
|---|
staticoptimize(this:Array<Point>, epsilon:Float):Polygon
Creates a new optimized polygon by eliminating almost colinear edges according to epsilon distance.
staticprojectPoint(this:Array<Point>, pt:Point):Null<Point>
Return the closest point on the edges of the polygon
staticreverse(this:Array<Point>):Void
Reverses the Polygon points ordering. Can be used to change polygon from anti-clockwise to clockwise.
statictoIPolygon(this:Array<Point>, scale:Float = 1.):IPolygon
Converts Polygon to Int-based IPolygon.
