Skip to main content

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:
NameTypeAttributesDefaultDescription
shapePathBuilding.Path
holesArray.<PathBuilding.Path><optional>[]
Properties:
NameTypeAttributesDefaultDescription
boundsCommon.RectShape bounds
holesDirectionPathBuilding.Polygon.PointsDirection<optional>CLOCKWISEProvides 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.
verticesFloat32ArrayTriangulated geometry

Since:

  • version 3.0.5

Methods

center()

Translate shape with center (0, 0)

clone() → PathBuilding.Polygon

Clone instance

Returns:

Polygon instance

Type

PathBuilding.Polygon

containsPoint(pt) → {boolean}

Check is point part of polygon

Parameters:
NameTypeDescription
ptCommon.PointTest point
Returns:

is point part of polygon

Type

boolean

convex() → PathBuilding.Polygon

Computes the convex shell of current polygon

Returns:

Convex polygon

Type

PathBuilding.Polygon

fit(frame)

Scale shape to fit in provided frame

Parameters:
NameTypeDescription
frameCommon.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:
NameTypeDescription
polyPathBuilding.PolygonIntersect 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:
NameTypeAttributesDefaultDescription
cleanDeltafloat<optional>0.1Uses 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

PathBuilding.PolygonArray

simplifyRamerDouglasPeucker(epsilonopt) → PathBuilding.Polygon

Simplifies a polygon by reducing the number of its vertices.

Parameters:
NameTypeAttributesDefaultDescription
epsilonfloat<optional>0.1Threshold value that determines the level of simplification. Greater values result into polygons with less segments.

See:

Returns:

Simplified polygon

Type

PathBuilding.Polygon

toSVGPath() → {string}

Converts polygon geometry to SVG path data

Returns:

SVG path

Type

string

transform(matrix) → PathBuilding.Polygon

Transforms polygon data

Parameters:
NameTypeDescription
matrixCommon.MatrixTransform matrix
Returns:

poly Transformed polygon

Type

PathBuilding.Polygon

transformSelf(matrix)

Self transforms polygon data

Parameters:
NameTypeDescription
matrixCommon.MatrixTransform matrix

triangulate() → {Float32Array}

Triangulate polygon data

Returns:

Triangles vertices

Type

Float32Array

union(polygon) → PathBuilding.Polygon

Computes the convex hull of 2 polygons

Parameters:
NameTypeDescription
polygonPathBuilding.Polygon
Returns:

Convex hull polygon

Type

PathBuilding.Polygon

(static) createInstance(shape, holesopt) → PathBuilding.Polygon

Creates Polygon instance

Parameters:
NameTypeAttributesDefaultDescription
shapeArray.<float>Float32Array
holesArray.<(Array.<float>Float32Array)><optional>[]
Returns:

Polygon instance

Type

PathBuilding.Polygon

(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:
NameTypeAttributesDefaultDescription
shapeArray.<float>Float32Array
holesArray.<(Array.<float>Float32Array)><optional>[]
Returns:

Polygon instance

Type

PathBuilding.Polygon

(static) fromJSON(data) → PathBuilding.Polygon

Deserialize from JSON

Parameters:
NameTypeDescription
dataJSONPloygon data
Returns:

Polygon instance

Type

PathBuilding.Polygon

Type Definitions

PointsDirection

Enumeration of points direction in path which represents hole in polygon

Properties:
NameTypeDescription
CLOCKWISEobject
COUNTERCLOCKWISEobject

Home