Class: Polygon
PathBuilding.Polygon(shape, holesopt)
Represents polygon shape
Constructor
new Polygon(shape, holesopt)
Do not use constructor. Use createInstance or createSharedInstance method to construct polygon.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
shape | PathBuilding.Path | |||
holes | Array.<PathBuilding.Path> | <optional> | [] |
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
bounds | Common.Rect | Shape bounds | ||
holesDirection | PathBuilding.Polygon.PointsDirection | <optional> | CLOCKWISE | Provides control over holes points direction. ClipperLib provides holes clockwised. Many libraries provides COUNTERCLOCKWISE points direction in holes.This property value is significant for polygon rendering. |
vertices | Float32Array | Triangulated geometry |
Since:
- version 3.0.5
Methods
center()
Translate shape with center (0, 0)
clone() → PathBuilding.Polygon
Clone instance
Returns:
Polygon instance
Type
containsPoint(pt) → {boolean}
Check is point part of polygon
Parameters:
Name | Type | Description |
---|---|---|
pt | Common.Point | Test point |
Returns:
is point part of polygon
Type
boolean
convex() → PathBuilding.Polygon
Computes the convex shell of current polygon
Returns:
Convex polygon
Type
fit(frame)
Scale shape to fit in provided frame
Parameters:
Name | Type | Description |
---|---|---|
frame | Common.Rect |
intersects(poly) → {boolean}
Check are 2 polygons have common part.Before call of this method is a good practice to check bounds intersection: instance.bounds.intersects(poly.bounds)
Parameters:
Name | Type | Description |
---|---|---|
poly | PathBuilding.Polygon | Intersect with polygon |
Returns:
intersection availability
Type
boolean
simplify(cleanDeltaopt) → PathBuilding.PolygonArray
Removes self-intersections from the supplied polygon (by performing a boolean union operation using the nominated PolyFillType).Polygons with non-contiguous duplicate vertices (ie 'touching') will be split into two polygons.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
cleanDelta | float | <optional> | 0.1 | Uses Radial Reduction algorithm, which merges sequential vertices, if they are at or under certain distance of each other, merge also collinear vertices |
See:
Returns:
Simplified polygons
Type
simplifyRamerDouglasPeucker(epsilonopt) → PathBuilding.Polygon
Simplifies a polygon by reducing the number of its vertices.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
epsilon | float | <optional> | 0.1 | Threshold value that determines the level of simplification. Greater values result into polygons with less segments. |
See:
Returns:
Simplified polygon
Type
toSVGPath() → {string}
Converts polygon geometry to SVG path data
Returns:
SVG path
Type
string
transform(matrix) → PathBuilding.Polygon
Transforms polygon data
Parameters:
Name | Type | Description |
---|---|---|
matrix | Common.Matrix | Transform matrix |
Returns:
poly Transformed polygon
Type
transformSelf(matrix)
Self transforms polygon data
Parameters:
Name | Type | Description |
---|---|---|
matrix | Common.Matrix | Transform matrix |
triangulate() → {Float32Array}
Triangulate polygon data
Returns:
Triangles vertices
Type
Float32Array
union(polygon) → PathBuilding.Polygon
Computes the convex hull of 2 polygons
Parameters:
Name | Type | Description |
---|---|---|
polygon | PathBuilding.Polygon |
Returns:
Convex hull polygon
Type
(static) createInstance(shape, holesopt) → PathBuilding.Polygon
Creates Polygon instance
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
shape | Array.<float> | Float32Array | ||
holes | Array.<(Array.<float> | Float32Array)> | <optional> | [] |
Returns:
Polygon instance
Type
(static) createSharedInstance(shape, holesopt) → PathBuilding.Polygon
Creates Polygon instance. Difference from createInstance is when points type is Array, it is converted to TypedArray.When SharedArrayBuffer is available for underlying context TypedArray is based on shared buffer.This method also defines encoding property, applicable for JSON serialization.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
shape | Array.<float> | Float32Array | ||
holes | Array.<(Array.<float> | Float32Array)> | <optional> | [] |
Returns:
Polygon instance
Type
(static) fromJSON(data) → PathBuilding.Polygon
Deserialize from JSON
Parameters:
Name | Type | Description |
---|---|---|
data | JSON | Ploygon data |
Returns:
Polygon instance
Type
Type Definitions
PointsDirection
Enumeration of points direction in path which represents hole in polygon
Properties:
Name | Type | Description |
---|---|---|
CLOCKWISE | object | |
COUNTERCLOCKWISE | object |