Class: Polygon

Polygon(vertices)

Define a Polygon.

Constructor

new Polygon(vertices)

Create a polygon.

Parameters:
Name Type Description
vertices Array.<Point> | Polygon

The vertices of the polygon.

Source:

Methods

addVertex(v)

Add a vertex to the polygon.

Parameters:
Name Type Description
v Point

The vertex to add.

Source:

copy() → {Polygon}

Make a copy of the polygon.

Source:
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.

Source:
Returns:

The bounding rectangle for this polygon.

Type
Polygon

getCenter() → {Point}

Calculate the center of the polygon.

Source:
Returns:

The center.

Type
Point

getHeight() → {number}

Get the height of the bounding rectangle.

Source:
Returns:

The difference between max and min Y values.

Type
number

getOrigin() → {Point}

Get the upper left corner (origin) of the bounding rectangle.

Source:
Returns:

The upper left corner.

Type
Point

getWidth() → {number}

Get the width of the bounding rectangle.

Source:
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.

Source: