An abstract around an Array of Point
s that define a polygonal shape that can be collision-tested against.
See also:
Variables
Methods
contains(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. |
convexHull():Array<Point>
Returns a new Polygon containing a convex hull of this Polygon. See Monotone chain algorithm for more details.
distance(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
fastTriangulate():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
findClosestPoint(pt:Point, maxDist:Float):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
.
getBounds(?b:Bounds):Null<Bounds>
Returns bounding box of the Polygon.
Parameters:
b | Optional Bounds instance to be filled. Returns new Bounds instance if |
---|
getCollider(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. |
---|
optimize(epsilon:Float):Polygon
Creates a new optimized polygon by eliminating almost colinear edges according to epsilon distance.
reverse():Void
Reverses the Polygon points ordering. Can be used to change polygon from anti-clockwise to clockwise.