An abstract around an Array of IPoints that define a polygonal shape that can be collision-tested against.

See also:

Variables

@:implread onlylength:Int

The amount of vertices in the polygon.

@:implread onlypoints:Array<IPoint>

The underlying Array of vertices.

Methods

@:implarea():Float

Calculates total area of the IPolygon.

@:value({ isConvex : false })@:implcontains(p:Point, isConvex:Bool = false):Bool

Tests if Point p is inside this IPolygon.

Parameters:

p

The point to test against.

isConvex

Use simplified collision test suited for convex polygons. Results are undefined if polygon is concave.

@:implconvexHull():Array<IPoint>

Returns a new IPolygon containing a convex hull of this IPolygon. See Monotone chain algorithm for more details.

@:implgetBounds(?b:IBounds):IBounds

Returns the bounding box of the IPolygon.

@:value({ withHoles : true })@:implinlineintersection(p:IPolygon, withHoles:Bool = true):IPolygons

Calculates an intersection areas between this IPolygon and a given IPolygon p and returns the resulting IPolygons.

Parameters:

p

The IPolygon to intersect with.

withHoles

When enabled, keeps the holes in resulting polygons as a separate IPolygon.

@:implisClockwise():Bool

Tests if polygon points are in the clockwise order.

@:implisConvex():Bool

Tests if the polygon is convex or concave.

@:value({ withHoles : true })@:imploffset(delta:Float, kind:OffsetKind, withHoles:Bool = true):IPolygons

Offsets the polygon edges by specified amount and returns the resulting IPolygons.

Parameters:

delta

The offset amount.

kind

The corner rounding method.

withHoles

When enabled, keeps the holes in resulting polygons as a separate IPolygon.

@:imploptimize(epsilon:Float):IPolygon

Creates a new optimized polygon by eliminating almost colinear edges according to the epsilon distance.

@:implreverse():Void

Reverses the IPolygon points ordering. Can be used to change polygon from anti-clockwise to clockwise.

@:value({ withHoles : true })@:implinlinesubtraction(p:IPolygon, withHoles:Bool = true):IPolygons

Subtracts the area of a given IPolygon p from this IPolygon and returns the resulting IPolygons.

Parameters:

p

The IPolygon to subtract with.

withHoles

When enabled, keeps the holes in resulting polygons as a separate IPolygon.

@:value({ scale : 1. })@:impltoPolygon(scale:Float = 1.):Polygon

Converts this IPolygon into a floating point-based Polygon.

@:value({ withHoles : true })@:implunion(p:IPolygon, withHoles:Bool = true):IPolygons

Combines this IPolygon and a given IPolygon p and returns the resulting IPolygons.

Parameters:

p

The IPolygon to union with.

withHoles

When enabled, keeps the holes in resulting polygons as a separate IPolygon.