new Polygon( [ elements ] )

Description
Polygon Class
Parameters
Name Type Attributes Description
elements Array.<(Vector2|BezierCurve)> <optional>
Vertices, Curves of the polygon
Properties
Name Type Description
first Vector2 The first point of the polygon, follow next on first to iterate
Details

Members


<readonly> region :Array.<Array>

Description
Get region for polybooljs plugin, can be also be used for GeoJson. Return a double level array ([[x, y], [x, y], ...])
Details
Array.<Array>

<readonly> points :Array.<Vector2>

Description
Get points of the Polygon
Details
Array.<Vector2>

<readonly> lines :Array.<Line>

Description
Get lines of the Polygon
Details
Array.<Line>

<readonly> area :Number

Description
Get area of the Polygon
Details
Number

<readonly> isConvex :Boolean

Description
Did the polygon is convex
Details
Boolean

isConcave


<readonly> isConcave :Boolean

Description
Did the polygon is concave
Details
Boolean

isConvex


<readonly> hull :Polygon

Description
Convert the current polygon to a hull polygon (convert to convex)
Details

<readonly> convex :Polygon

Description
Alias of hull
Details

hull


<readonly> clone :Polygon

Description
Clonning the current polygon, usefull to not modify the current polygon
Details

Methods


pointIsInside( point ) → {boolean}

Description
Wrapper for checking if point is inside a polygon
Parameters
Name Type Description
point Vector2 Point to check
Returns
Details

pointIsInsidePolygon( point ) → {boolean}

Description
Checking if point is inside a polygon
Parameters
Name Type Description
point Vector2 Point to check
Returns
Details

setChildren( polygons ) → {Polygon}

Description
Setting all children polygons (for holes)
Parameters
Name Type Description
polygons Array.<Polygon> Children to set
Returns
Details

addChild( polygon ) → {Polygon}

Description
Adding a child polygon (for hole)
Parameters
Name Type Description
polygon Polygon Child polygon to add
Returns
Details

setVertexes( vertices ) → {Polygon}

Description
Setting vertices of the polygon
Parameters
Name Type Description
vertices Array.<Vector2> Vertices to set
Returns
Details

true


setElements( vertices ) → {Polygon}

Description
Setting elements of the polygon
Parameters
Name Type Description
vertices Array.<(Vector2|BezierCurve)> Vertices to set
Returns
Details

addVertex( vertice ) → {Polygon}

Description
Add a new vertices to the end
Parameters
Name Type Description
vertice Vector2 the vertice to add
Returns
Details

true


addElement( element ) → {Polygon}

Description
Add a new vertices to the end
Parameters
Name Type Description
element Vector2 | BezierCurve the vertice or curve to add
Returns
Details

colliding( polygon ) → {Boolean}

Description
Is the current polygon colliding with the given polygon
Parameters
Name Type Description
polygon Polygon the second polygon for the collision
Returns
Details

intersect( polygon ) → {Array.<Polygon>}

Description
Intersect boolean operation on this polygon with the given polygon
Parameters
Name Type Description
polygon Polygon the second polygon for the operation
Returns
Details

difference( polygon ) → {Array.<Polygon>}

Description
Difference boolean operation on this polygon with the given polygon
Parameters
Name Type Description
polygon Polygon the second polygon for the operation
Returns
Details

union( polygon ) → {Array.<Polygon>}

Description
Union boolean operation on this polygon with the given polygon
Parameters
Name Type Description
polygon Polygon the second polygon for the operation
Returns
Details

xor( polygon ) → {Array.<Polygon>}

Description
Xor boolean operation on this polygon with the given polygon
Parameters
Name Type Description
polygon Polygon the second polygon for the operation
Returns
Details

moveBy( value ) → {Vector2}

Description
Move all vertices of the polygon by a Vector2
Parameters
Name Type Description
value Vector2 The value to move by
Returns
Details

<static> Colliding( p1, p2 ) → {Boolean}

Description
Is the p1 polygon colliding with the p2 polygon
Parameters
Name Type Description
p1 Polygon the first polygon for the collision
p2 Polygon the second polygon for the collision
Returns
Details

<static> FromRegion( region ) → {Polygon}

Description
Convert region to polygon
Parameters
Name Type Description
region Array.<Array> the region to convert
Returns
Details

<static> Intersect( polygon, polygon ) → {Array.<Polygon>}

Description
Intersect boolean operation on the p1 polygon with the p2 polygon
Parameters
Name Type Description
polygon Polygon the first polygon for the operation
polygon Polygon the second polygon for the operation
Returns
Details

<static> Union( polygon, polygon ) → {Array.<Polygon>}

Description
Union boolean operation on the p1 polygon with the p2 polygon
Parameters
Name Type Description
polygon Polygon the first polygon for the operation
polygon Polygon the second polygon for the operation
Returns
Details

<static> Difference( polygon, polygon ) → {Array.<Polygon>}

Description
Difference boolean operation on the p1 polygon with the p2 polygon
Parameters
Name Type Description
polygon Polygon the first polygon for the operation
polygon Polygon the second polygon for the operation
Returns
Details

<static> Xor( polygon, polygon ) → {Array.<Polygon>}

Description
Xor boolean operation on the p1 polygon with the p2 polygon
Parameters
Name Type Description
polygon Polygon the first polygon for the operation
polygon Polygon the second polygon for the operation
Returns
Details