Polygon Class
Polygon class.
Constructor
Polygon
()
Item Index
Methods
Properties
Methods
append
-
poly
-
from
-
to
Append points "from" to "to"-1 from an other polygon "poly" onto this one.
Parameters:
-
poly
PolygonThe polygon to get points from.
-
from
NumberThe vertex index in "poly".
-
to
NumberThe end vertex index in "poly". Note that this vertex is NOT included when appending.
Returns:
at
-
i
Get a vertex at position i. It does not matter if i is out of bounds, this function will just cycle.
Parameters:
-
i
Number
Returns:
canSee
-
a
-
b
Check if two vertices in the polygon can see each other
Parameters:
-
a
NumberVertex index 1
-
b
NumberVertex index 2
Returns:
clear
()
Array
Clear the polygon data
Returns:
copy
-
i
-
j
-
[targetPoly]
Copy the polygon from vertex i to vertex j.
Parameters:
-
i
Number -
j
Number -
[targetPoly]
Polygon optionalOptional target polygon to save in.
Returns:
The resulting copy.
decomp
()
Array
Decomposes the polygon into one or more convex sub-Polygons.
Returns:
An array or Polygon objects.
first
()
Array
Get first vertex
Returns:
getCutEdges
()
Array
Decomposes the polygon into convex pieces. Returns a list of edges [[p1,p2],[p2,p3],...] that cuts the polygon. Note that this algorithm has complexity O(N^4) and will be very slow for polygons with many vertices.
Returns:
isReflex
-
i
Check if a point in the polygon is a reflex point
Parameters:
-
i
Number
Returns:
isSimple
-
path
Checks that the line segments of this polygon do not intersect each other.
Parameters:
-
path
ArrayAn array of vertices e.g. [[0,0],[0,1],...]
Returns:
last
()
Array
Get last vertex
Returns:
makeCCW
()
Make sure that the polygon vertices are ordered counter-clockwise.
quickDecomp
-
result
-
[reflexVertices]
-
[steinerPoints]
-
[delta]
-
[maxlevel]
-
[level]
Quickly decompose the Polygon into convex sub-polygons.
Parameters:
-
result
Array -
[reflexVertices]
Array optional -
[steinerPoints]
Array optional -
[delta]
Number optional -
[maxlevel]
Number optional -
[level]
Number optional
Returns:
removeCollinearPoints
-
[precision]
Remove collinear points in the polygon.
Parameters:
-
[precision]
Number optionalThe threshold angle to use when determining whether two edges are collinear. Use zero for finest precision.
Returns:
The number of points removed
reverse
()
Reverse the vertices in the polygon
slice
-
cutEdges
Slices the polygon given one or more cut edges. If given one, this function will return two polygons (false on failure). If many, an array of polygons.
Parameters:
-
cutEdges
ArrayA list of edges, as returned by .getCutEdges()
Returns:
Properties
vertices
Array
Vertices that this polygon consists of. An array of array of numbers, example: [[0,0],[1,0],..]