Class: Polygon
Polygon(vertices, isOpen)
new Polygon(vertices, isOpen)
The constructor.
Parameters:
Name | Type | Description |
---|---|---|
vertices |
Array:.<Vertex:> | An array of 2d vertices that shape the polygon. |
isOpen |
boolean | Indicates if the polygon should be rendered as an open or closed shape. |
- Source:
Methods
addVert(vert)
Add a vertex to the end of the `vertices` array.
Parameters:
Name | Type | Description |
---|---|---|
vert |
Vertex | The vertex to add. |
- Source:
containsVert(vert) → {boolean}
Check if the given vertex is inside this polygon.
Ray-casting algorithm found at
https://stackoverflow.com/questions/22521982/check-if-point-inside-a-polygon
Ray-casting algorithm found at
https://stackoverflow.com/questions/22521982/check-if-point-inside-a-polygon
Parameters:
Name | Type | Description |
---|---|---|
vert |
Vertex | The vertex to check. The new x-component. |
- Source:
Returns:
True if the passed vertex is inside this polygon. The polygon is considered closed.
- Type
- boolean
getBounds() → {Bounds}
Get the bounding box (bounds) of this polygon.
- Source:
Returns:
The rectangular bounds of this polygon.
- Type
- Bounds
getVertexAt(index) → {Vertex}
Get the polygon vertex at the given position (index).
The index may exceed the total vertex count, and will be wrapped around then (modulo).
For k >= 0:
- getVertexAt( vertices.length ) == getVertexAt( 0 )
- getVertexAt( vertices.length + k ) == getVertexAt( k )
- getVertexAt( -k ) == getVertexAt( vertices.length -k )
Parameters:
Name | Type | Description |
---|---|---|
index |
number | The index of the desired vertex. |
- Source:
Returns:
At the given index.
- Type
- Vertex
move(amount) → {Polygon}
Move the polygon's vertices by the given amount.
Parameters:
Name | Type | Description |
---|---|---|
amount |
XYCoords | The amount to move. |
- Source:
Returns:
this for chaining
- Type
- Polygon
rotate(angle, center) → {Polygon}
Rotate the polygon around the given center.
Parameters:
Name | Type | Description |
---|---|---|
angle |
number | The rotation angle. |
center |
Vertex | The center of rotation. |
- Source:
Returns:
this, for chaining.
- Type
- Polygon
scale(factor, center) → {Polygon}
Scale the polygon relative to the given center.
Parameters:
Name | Type | Description |
---|---|---|
factor |
number | The scale factor. |
center |
Vertex | The center of scaling. |
- Source:
Returns:
this, for chaining.
- Type
- Polygon
toCubicBezierData(thresholdopt) → {Array:.<Vertex:>}
Convert this polygon to a sequence of cubic Bézier curves.
The first vertex in the returned array is the start point.
The following sequence are triplets of (first-control-point, secnond-control-point, end-point):
The first vertex in the returned array is the start point.
The following sequence are triplets of (first-control-point, secnond-control-point, end-point):
startPoint, controlPoint0_0, controlPoint1_1, pathPoint1, controlPoint1_0, controlPoint1_1, ..., endPoint
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
threshold |
number |
<optional> |
An optional threshold (default=1.0) how strong the curve segments should over-/under-drive. Should be between 0.0 and 1.0 for best results but other values are allowed. |
- Source:
Returns:
An array of 2d vertices that shape the cubic Bézier curve.
- Type
- Array:.<Vertex:>
toCubicBezierPath(threshold) → {BezierPath}
Convert this polygon to a cubic bezier path instance.
Parameters:
Name | Type | Description |
---|---|---|
threshold |
number | The threshold, usually from 0.0 to 1.0. |
- Source:
Returns:
- A bezier path instance.
- Type
- BezierPath
toCubicBezierSVGString() → {string}
Convert this polygon to a cubic bezier curve, represented as an SVG data string.
- Source:
Returns:
The 'd' part for an SVG 'path' element.
- Type
- string
toQuadraticBezierData() → {Array:.<Vertex:>}
Convert this polygon to a sequence of quadratic Bézier curves.
The first vertex in the returned array is the start point.
The following sequence are pairs of control-point-and-end-point:
The first vertex in the returned array is the start point.
The following sequence are pairs of control-point-and-end-point:
startPoint, controlPoint0, pathPoint1, controlPoint1, pathPoint2, controlPoint2, ..., endPoint
- Source:
Returns:
An array of 2d vertices that shape the quadratic Bézier curve.
- Type
- Array:.<Vertex:>
toQuadraticBezierSVGString() → {string}
Convert this polygon to a quadratic bezier curve, represented as an SVG data string.
- Source:
Returns:
The 'd' part for an SVG 'path' element.
- Type
- string
toSVGString(optionsopt) → {string}
Create an SVG representation of this polygon.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
object |
<optional> |
An optional set of options, like 'className'. |
- Source:
Returns:
The SVG string.
- Type
- string