modeling/geometries/path2

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

Source:
See:
  • path2 for data structure information.

Methods

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

Source:
See:

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

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);
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 PI radians

segments Number <optional>
16

number of segments per full rotation

geometry path2

the path of which to append the arc

Returns:

a new path with the appended points

Type
path2

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

Source:

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.

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

Returns:

a new path with the appended points

Type
path2

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

Source:

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

Example
let newpath = appendPoints([[3, 4], [4, 5]], oldpath)
Parameters:
Name Type Description
points Array

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

geometry path2

the given path

Returns:

a new path with the appended points

Type
path2

(static) clone(geometry) → {path2}

Source:

Performs a deep clone of the give geometry.

Parameters:
Name Type Description
geometry path2

the geometry to clone

Returns:

a new path

Type
path2

(static) close(geometry) → {path2}

Source:

Close the given geometry.

Parameters:
Name Type Description
geometry path2

the path to close

Returns:

a new path

Type
path2

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

Source:

Concatenate the given paths. 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.

Example
let newpath = concat(fromPoints({}, [[1, 2]]), fromPoints({}, [[3, 4]]))
Parameters:
Name Type Attributes Description
paths path2 <repeatable>

the paths to concatenate

Returns:

a new path

Type
path2

(static) create() → {path2}

Source:

Create an empty, open path.

Example
let newpath = create()
Returns:

a new path

Type
path2

(static) eachPoint(options, thunk, geometry)

Source:

Calls a function for each point in the geometry.

Example
eachPoint({}, accumulate, geometry)
Parameters:
Name Type Description
options Object

options

thunk function

the function to call

geometry path2

the geometry to traverse

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

Source:

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

Returns:
Type
Boolean

(static) fromCompactBinary(data) → {path2}

Source:

Create a new path from the given compact binary data.

Parameters:
Name Type Description
data TypedArray

compact binary data

Returns:

a new path

Type
path2

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

Source:

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

Returns:

a new path

Type
path2

(static) isA(object) → {Boolean}

Source:

Determin if the given object is a path2 geometry.

Parameters:
Name Type Description
object Object

the object to interogate

Returns:

true if the object matches a path2

Type
Boolean

(static) reverse(geometry) → {path2}

Source:

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

Example
let newpath = reverse(mypath)
Parameters:
Name Type Description
geometry path2

the geometry to reverse

Returns:

a new path

Type
path2

(static) toCompactBinary(geometry) → {TypedArray}

Source:

Produce a compact binary representation from the given path.

Parameters:
Name Type Description
geometry path2

the path

Returns:

compact binary representation

Type
TypedArray

(static) toPoints(geometry) → {Array}

Source:

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

Example
let sharedpoints = toPoints(geometry)
Parameters:
Name Type Description
geometry path2

the geometry

Returns:

an array of points

Type
Array

(static) toString(geometry) → {String}

Source:

Create a string representing the contents of the given path.

Example
console.out(toString(path))
Parameters:
Name Type Description
geometry path2

the path

Returns:

a representive string

Type
String

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

Source:

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().

Example
let newpath = transform(fromZRotation(Math.PI / 4), path)
Parameters:
Name Type Description
matrix mat4

the matrix to transform with

geometry path2

the geometry to transform

Returns:

a new path

Type
path2