Constructor
new Polygon(vertices)
Create a polygon.
Parameters:
Name | Type | Description |
---|---|---|
vertices |
Array.<Point> | Polygon | The vertices of the polygon. |
Methods
addVertex(v)
Add a vertex to the polygon.
Parameters:
Name | Type | Description |
---|---|---|
v |
Point | The vertex to add. |
copy() → {Polygon}
Make a copy of the polygon.
Returns:
New Polygon.
- Type
- Polygon
getBoundingRectangle() → {Polygon}
Calculates the bounding rectangle. It's worth noting that the first point in the bounding rectangle is the upper left corner, and subsequent points proceed clockwise. Certain methods rely on this ordering.
Returns:
The bounding rectangle for this polygon.
- Type
- Polygon
getCenter() → {Point}
Calculate the center of the polygon.
Returns:
The center.
- Type
- Point
getHeight() → {number}
Get the height of the bounding rectangle.
Returns:
The difference between max and min Y values.
- Type
- number
getOrigin() → {Point}
Get the upper left corner (origin) of the bounding rectangle.
Returns:
The upper left corner.
- Type
- Point
getWidth() → {number}
Get the width of the bounding rectangle.
Returns:
The difference between max and min X values.
- Type
- number
rotate(degrees, center)
Rotate the polygon around a point.
Parameters:
Name | Type | Description |
---|---|---|
degrees |
number | The number of degrees to rotate. |
center |
Point | The point around which to rotate. If not supplied, the physical center of the polygon is used. |