Module: modeling/geometries/path2

Represents a 2D geometry consisting of a list of ordered points.

Source:
See:
  • path2 for data structure information.
Examples
colorize([0,0,0,1], path2.fromPoints({ closed: true }, [[0,0], [4,0], [4,3]]))
{
  "points": [[0,0], [4,0], [4,3]],
  "isClosed": true,
  "transforms": [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],
  "color": [0,0,0,1]
}

Methods

(static) appendArc(options, geometry) → {path2}

Append a series of points to the given geometry that represent an arc. This implementation follows the SVG specifications.

Parameters:
Name Type Description
options Object

options for construction

Properties
Name Type Attributes Default Description
endpoint vec2

end point of arc (REQUIRED)

radius vec2 <optional>
[0,0]

radius of arc (X and Y)

xaxisrotation Number <optional>
0

rotation (RADIANS) of the X axis of the arc with respect to the X axis of the coordinate system

clockwise Boolean <optional>
false

draw an arc clockwise with respect to the center point

large Boolean <optional>
false

draw an arc longer than TAU / 2 radians

segments Number <optional>
16

number of segments per full rotation

geometry path2

the path of which to append the arc

Source:
See:
Returns:

a new path with the appended points

Type
path2
Example
let p1 = path2.fromPoints({}, [[27.5,-22.96875]]);
p1 = path2.appendPoints([[27.5,-3.28125]], p1);
p1 = path2.appendArc({endpoint: [12.5, -22.96875], radius: [15, -19.6875]}, p1);

(static) appendBezier(options, geometry) → {path2}

Append a series of points to the given geometry that represent a Bezier curve. The Bézier curve starts at the last point in the given geometry, and ends at the last control point. The other control points are intermediate control points to transition the curve from start to end points. The first control point may be null to ensure a smooth transition occurs. In this case, the second to last point of the given geometry is mirrored into the control points of the Bezier curve. In other words, the trailing gradient of the geometry matches the new gradient of the curve.

Parameters:
Name Type Description
options Object

options for construction

Properties
Name Type Attributes Default Description
controlPoints Array

list of control points (2D) for the bezier curve

segment Number <optional>
16

number of segments per 360 rotation

geometry path2

the path of which to appended points

Source:
Returns:

a new path with the appended points

Type
path2
Example
let p5 = path2.create({}, [[10,-20]])
p5 = path2.appendBezier({controlPoints: [[10,-10],[25,-10],[25,-20]]}, p5);
p5 = path2.appendBezier({controlPoints: [null, [25,-30],[40,-30],[40,-20]]}, p5)

(static) appendPoints(points, geometry) → {path2}

Append the given list of points to the end of the given geometry.

Parameters:
Name Type Description
points Array

the points (2D) to append to the given path

geometry path2

the given path

Source:
Returns:

a new path with the appended points

Type
path2
Example
let newpath = appendPoints([[3, 4], [4, 5]], oldpath)

(static) clone(geometry) → {path2}

Performs a shallow clone of the give geometry.

Parameters:
Name Type Description
geometry path2

the geometry to clone

Source:
Returns:

a new path

Type
path2

(static) close(geometry) → {path2}

Close the given geometry.

Parameters:
Name Type Description
geometry path2

the path to close

Source:
Returns:

a new path

Type
path2

(static) concat(…paths) → {path2}

Concatenate the given paths.

If both contain the same point at the junction, merge it into one. A concatenation of zero paths is an empty, open path. A concatenation of one closed path to a series of open paths produces a closed path. A concatenation of a path to a closed path is an error.

Parameters:
Name Type Attributes Description
paths path2 <repeatable>

the paths to concatenate

Source:
Returns:

a new path

Type
path2
Example
let newpath = concat(fromPoints({}, [[1, 2]]), fromPoints({}, [[3, 4]]))

(static) create() → {path2}

Create an empty, open path.

Source:
Returns:

a new path

Type
path2
Example
let newpath = create()

(static) equals(a, b) → {Boolean}

Determine if the given paths are equal. For closed paths, this includes equality under point order rotation.

Parameters:
Name Type Description
a path2

the first path to compare

b path2

the second path to compare

Source:
Returns:
Type
Boolean

(static) fromCompactBinary(data) → {path2}

Create a new path from the given compact binary data.

Parameters:
Name Type Description
data TypedArray

compact binary data

Source:
Returns:

a new path

Type
path2

(static) fromPoints(options, points) → {path2}

Create a new path from the given points. The points must be provided an array of points, where each point is an array of two numbers.

Parameters:
Name Type Description
options Object

options for construction

Properties
Name Type Attributes Default Description
closed Boolean <optional>
false

if the path should be open or closed

points Array

array of points (2D) from which to create the path

Source:
Returns:

a new path

Type
path2

(static) isA(object) → {Boolean}

Determine if the given object is a path2 geometry.

Parameters:
Name Type Description
object Object

the object to interrogate

Source:
Returns:

true if the object matches a path2

Type
Boolean

(static) reverse(geometry) → {path2}

Reverses the path so that the points are in the opposite order. This swaps the left (interior) and right (exterior) edges.

Parameters:
Name Type Description
geometry path2

the path to reverse

Source:
Returns:

a new path

Type
path2
Example
let newpath = reverse(mypath)

(static) toCompactBinary(geometry) → {TypedArray}

Produce a compact binary representation from the given path.

Parameters:
Name Type Description
geometry path2

the path geometry

Source:
Returns:

compact binary representation

Type
TypedArray

(static) toPoints(geometry) → {Array}

Produces an array of points from the given geometry. The returned array should not be modified as the data is shared with the geometry.

Parameters:
Name Type Description
geometry path2

the geometry

Source:
Returns:

an array of points

Type
Array
Example
let sharedpoints = toPoints(geometry)

(static) toString(geometry) → {String}

Create a string representing the contents of the given path.

Parameters:
Name Type Description
geometry path2

the path

Source:
Returns:

a representative string

Type
String
Example
console.out(toString(path))

(static) transform(matrix, geometry) → {path2}

Transform the given geometry using the given matrix. This is a lazy transform of the points, as this function only adjusts the transforms. The transforms are applied when accessing the points via toPoints().

Parameters:
Name Type Description
matrix mat4

the matrix to transform with

geometry path2

the geometry to transform

Source:
Returns:

a new path

Type
path2
Example
let newpath = transform(fromZRotation(TAU / 8), path)

(static) validate(object)

Determine if the given object is a valid path2. Checks for valid data points, and duplicate points.

If the geometry is not valid, an exception will be thrown with details of the geometry error.

Parameters:
Name Type Description
object Object

the object to interrogate

Source:
Throws:

error if the geometry is not valid

Type
Error