Module: polygon

Methods

(static) area(pts, nopt) → {Number}

Signed area of a polygon. For 3d polygons a signed area can only be computed when the optional polygon normal n is passed in.

Parameters:
Name Type Attributes Default Description
pts Array

Polygon points

n Array <optional>
null

Optional polygon normal, needed to compute the signed area for 3d polygons

Source:
See:
Returns:
Type
Number

(static) bounds(pts) → {PolygonBounds}

Polygon bounds

Parameters:
Name Type Description
pts Array
Source:
Returns:
Type
PolygonBounds

(static) centroid(pts) → {Array}

Polygon centroid (2d)

Parameters:
Name Type Description
pts Array
Source:
Returns:
Type
Array

(static) ensure_ccw(pts, nopt) → {Array}

Ensures CCW winding

Parameters:
Name Type Attributes Default Description
pts Array
n Array <optional>
null

Optional polygon normal, needed for 3d polygons

Source:
Returns:
Type
Array

(static) ensure_cw(pts, nopt) → {Array}

Ensures CW winding

Parameters:
Name Type Attributes Default Description
pts Array
n Array <optional>
null

Optional polygon normal, needed for 3d polygons

Source:
Returns:
Type
Array

(static) intersection(a, b) → {Array}

Intersection of a set of polygons

Parameters:
Name Type Description
a Array

First polygon

b Array

Second polygon

Source:
Returns:
Type
Array

(static) is_ccw(pts, nopt) → {Boolean}

Tests wether the polygon winding is counter clockwise

Parameters:
Name Type Attributes Default Description
pts Array
n Array <optional>
null

Optional polygon normal, needed for 3d polygons

Source:
Returns:
Type
Boolean

(static) is_cw(pts, nopt) → {Boolean}

Tests wether the polygon winding is clockwise

Parameters:
Name Type Attributes Default Description
pts Array
n Array <optional>
null

Optional polygon normal, needed for 3d polygons

Source:
Returns:
Type
Boolean

(static) normal(pts, forceNewellopt) → {Array}

Polygon normal (2d / 3d)

Parameters:
Name Type Attributes Default Description
pts Array

Points of the polygon

forceNewell Boolean <optional>
false

Whether to force Newell's method

Source:
Returns:

Polygon normal or null if the polygon is degenerate

Type
Array

(static) subtract(polygons) → {Array}

Subtract polygons

Parameters:
Name Type Description
polygons Array
Source:
Returns:
Type
Array

(static) triangulate(polygon, holes)

Triangulates a polygon

Parameters:
Name Type Description
polygon Array
holes Array.<Array>
Source:
Returns:

triangles

(static) union(polygons) → {Array}

Union of a set of polygons

Parameters:
Name Type Description
polygons Array
Source:
Returns:
Type
Array

(static) winding(pts, nopt) → {Number}

Polygon winding (2d only)

Parameters:
Name Type Attributes Default Description
pts Array
n Array <optional>
null

Optional polygon normal, needed for 3d polygons

Source:
Returns:
Type
Number

Type Definitions

PolygonBounds

Polygon bounds.

Type:
  • Object
Properties:
Name Type Description
xMin Number
yMin Number
xMax Number
yMax Number
Source: