Creates a new Path that starts at startPoint and is made up of the path commands,
parts.
See also fromString
ReadonlybboxA rough estimate of the bounding box of the path. A slight overestimate. See getExactBBox
ReadonlypartsThe individual shapes that make up this path.
ReadonlystartLazy-loads and returns this path's geometry
Returns a list of intersections with this path. If strokeRadius is given,
intersections are approximated with the surface strokeRadius away from this.
If strokeRadius > 0, the resultant parameterValue has no defined value.
Note: strokeRadius is half of a stroke's width.
OptionalstrokeRadius: numberthe nearest point on this path to the given point.
Approximates this path with a group of line segments.
Like closedRoughlyIntersects except takes stroke width into account.
This is intended to be a very fast and rough approximation. Use intersection and signedDistance for more accurate (but much slower) intersection calculations.
Note: Unlike other methods, this accepts strokeWidth (and not strokeRadius).
strokeRadius is half of strokeWidth.
Returns the signed distance between point and a curve strokeRadius units
away from this path.
This returns the signed distance, which means that points inside this shape have their distance negated. For example,
import {Path, Vec2} from '@js-draw/math';
console.log(Path.fromString('m0,0 L100,0').signedDistance(Vec2.zero, 1));
would print -1 because (0,0) is on m0,0 L100,0 and thus one unit away from its boundary.
Note: strokeRadius = strokeWidth / 2
Returns a copy of this path with deleteFrom until deleteUntil replaced with insert.
This method is analogous to Array.toSpliced.
Optionaloptions: PathSplitOptionsSplits this path in two near the given point.
Optionaloptions: PathSplitOptionsConvert to an SVG path representation.
If useNonAbsCommands is given, relative path commands (e.g. l10,0) are to be used instead of
absolute commands (e.g. L10,0).
See also fromString.
OptionaluseNonAbsCommands: booleanCreates a new path by joining [other] to the end of this path
allowReverse: true iff reversing other or this is permitted if it means no moveTo command is necessary when unioning the paths.
StaticcomputeBBoxStaticfromStaticfromStaticfromCreate a Path from a subset of the SVG path specification.
Currently, this does not support elliptical arcs or s and t command
shorthands. See https://github.com/personalizedrefrigerator/js-draw/pull/19.
StatictoOptionalonlyAbsCommands: booleanTrue if we should avoid converting absolute coordinates to relative offsets -- such conversions can lead to smaller output strings, but also take time.
Represents a union of lines and curves.
To create a path from a string, see fromString.
Example
import {Path, Mat33, Vec2, LineSegment2} from '@js-draw/math'; // Creates a path from an SVG path string. // In this case, // 1. Move to (0,0) // 2. Line to (100,0) const path = Path.fromString('M0,0 L100,0'); // Logs the distance from (10,0) to the curve 1 unit // away from path. This curve forms a stroke with the path at // its center. const strokeRadius = 1; console.log(path.signedDistance(Vec2.of(10,0), strokeRadius)); // Log a version of the path that's scaled by a factor of 4. console.log(path.transformedBy(Mat33.scaling2D(4)).toString()); // Log all intersections of a stroked version of the path with // a vertical line segment. // (Try removing the `strokeRadius` parameter). const segment = new LineSegment2(Vec2.of(5, -100), Vec2.of(5, 100)); console.log(path.intersection(segment, strokeRadius).map(i => i.point));