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:

Members

isOpen :boolean

Type:
  • boolean
Source:

vertices :Array.<Vertex>

Type:
Source:

Methods

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
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

rotate(angle, center) → {Polygon}

Rotatee 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):
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:
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