Creates a polyline from a set of corner points.
The points defining the corners of the polyline.
If true, checks whether the resulting polyline isClosed and if it isn't, adds another point ensuring the polyline ends the same place it starts.
Gets the area enclosed by the polyline. If the polyline isn't closed, returns 0.
Gets the smallest bounding box that contains the polyline.
Gets the number of points in the polyline.
Gets the starting point of the polyline.
Gets the length of the polyline.
Gets the points that define the corners of the polyline.
Gets the number of segments in the polyline.
Gets the segments (or edges) of the polyline.
Gets the end of the polyline.
Checks whether a point is inside, outside, or on the edge of a polyline.
The point to test for containment.
The distance the point can be from the edge of the polyline and still considered coincident.
Returns a copy of the polyline with a given CurveOrientation. If the polyline already has that orientation, returns self.
The desired orientation of the new polyline.
Creates a polyline from a list of corner coordinates (in the GeoJSON format).
List of points in the format [[x1,y1],[x2,y2],[x3,y3],...]
If true, checks whether the resulting polyline isClosed and if it isn't, adds another point ensuring the polyline ends the same place it starts.
Gets the polyline in the GeoJSON format: [[x1,y1],[x2,y2],...]
.
Calculates the weighted average of all segments and returns the result.
Finds the closest point on the polyline and returns the point.
Target to get closest to.
If false, the closest point must lie on a segment of the polyline. If true, the closest point can also be a point on the polyline's interior (if it is closed and has an interior).
Shortest allowable segment.
Checks whether another polyline has the same points. Returns true if it does.
Polyline to compare against.
The amount the points can differ and still be considered equal.
Calculates where the polyline intersects other geometry and returns the parameters for these points of intersection.
The geometry to intersect.
The parameters of the intersection points. The array is always sorted from the smallest to largest parameter. Entering the parameter into pointAt will return the intersection point.
Creates a copy of the polyline with colinear segments merged together. This is achieved by traveling along the polyline and merging any segments that travel in the same direction.
The minimum angle at which segments are no longer colinear (in radians).
Calculates the normal to the polyline at a given parameter.
If the polyline is closed, it will always return the normal that points towards the inside. If the polyline is open, the vector will be on the left side of the segment (which is the right side if the environment's y-axis points downwards).
Position on the polyline to calculate the normal (see pointAt for explanation)
A unit vector
Calculates whether a polyline is in a clockwise or counter-clockwise orientation and returns the result. If the polyline is not closed, it can't have an orientation, so the function returns CurveOrientation.undefined.
The function assumes that the environment's y-axis points upwards.
In environments where the y-axis points downwards, isYDown
should be set to true
.
This inverts clockwise and counter-clockwise to ensure that
they are in the correct orientation for how you're viewing them.
Finds the point a normalized parameter along the polyline. Returns the point.
Each segment of the polyline is parameterized from 0 to 1 (like Line.pointAt).
So 0
is the start of the first segment, and 1
is the end.
0.5
is the mid point of the first segment, and 1.5
is the mid point of the second segment.
const triangle = new Polyline([new Point(0, 0), new Point(1, 1), new Point(2, 0)], true);
// The start of first segment
console.log(triangle.pointAt(0).toString());
// => (0,0)
// Mid point of first segment
console.log(triangle.pointAt(0.5).toString());
// => (0.5,0.5)
// The end of first segment / start of second segment
console.log(triangle.pointAt(1).toString());
// => (1,1)
// Mid point of second segment
console.log(triangle.pointAt(1.5).toString());
// => (1.5,0.5)
The normalized parameter.
Creates a copy of the polyline with the points in reverse order.
Gets a segment of the polyline.
The index of the segment.
Gets the polyline as a string in the format: [(x1,y1),(x2,y2),(x3,y3)]
.
Extracts a section of the polyline. Returns the resulting polyline.
The section of the polyline to extract. The domain contains
two numbers, the min
, which is the parameter for the start of the new polyline.
And the max
, which will be the end. Everything between these two points is included
in the new polyline. The position of the domain is calculated using the same method as pointAt.
Translates the geometry from one coordinate system to another while keeping
the geometry in the same position. In other words, if the geometry is currently
described relative to planeFrom
, after changeBasis,
it will be in the same position but described relative to planeTo
.
The coordinate system the geometry is currently described relative to.
The coordinate system to describe the geometry relative to.
The geometry in the new coordinate system.
Rotates the geometry about (0,0).
Angle to rotate the geometry (in radians). The direction is counter-clockwise.
Rotates the geometry about a point.
Angle to rotate the geometry (in radians). If the environment's y-axis points upwards, the direction is counter-clockwise.
Point to pivot the geometry about.
Scales the geometry and returns the resized geometry. The geometry will be scaled about (0,0), meaning everything will shrink or expand away from this point.
Magnitude to scale in x- and y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Scales the geometry and returns the resized geometry. The geometry will be scaled about (0,0), meaning everything will shrink or expand away from this point.
Magnitude to scale in x-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Magnitude to scale in y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Scales the geometry about a point and returns the resized geometry.
Magnitude to scale in x-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Magnitude to scale in y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Center of scaling. Everything will shrink or expand away from this point.
Transforms the polyline by a transform matrix and returns the result.
import { Point, Polyline. Transform, Vector } from 'shapetypes';
// Create a new polyline
const triangle = new Polyline([new Point(0, 0), new Point(1, 1), new Point(2, 0)], true);
// Check start position of the polyline
console.log(shifted.from.toString());
// => (0,0)
// Translate polyline using a transform matrix
const matrix = Transform.translate(new Vector(3,4));
const shifted = triangle.transform(matrix);
console.log(shifted.from.toString());
// => (3,4)
// Translate polyline using the direct method
const otherShifted = triangle.translate(new Vector(3, 4));
console.log(otherShifted.from.toString());
// => (3,4)
Moves the geometry along a vector and returns the moved geometry. The translation is always linear.
The direction and distance to move the geometry.
Moves the geometry along a vector and returns the moved geometry. The translation is always linear.
The direction to move the geometry.
The distance to move the geometry.
Generated using TypeDoc
A continuous line made from a series of straight segments. An array of points defines the corners of the polyline.
If the polyline's start and end point are the same, it is considered closed. This can be checked with isClosed. Some operations, such as contains, only work with closed polylines.
Example
import { Point, Polyline, Vector } from 'shapetypes' // Create a new polyline const triangle = new Polyline([new Point(0, 0), new Point(1, 1), new Point(2, 0)], true); // Get properties of the polyline console.log(triangle.area); // => 1 console.log(triangle.length); // => 4.82842712474619 // Check whether a point is inside the closed polyline console.log(triangle.contains(new Point(1, 0.5))); // => True // Move the polyline and check whether the point is inside const shifted = triangle.translate(new Vector(3, 4)); console.log(shifted.contains(new Point(1, 0.5))); // => False