Path Util
segment-start
segment-start() -> vector
Returns the first position vector of a path segment.
segment-end
segment-end() -> vector
Returns the last position vector of a path segment
bounds
bounds() -> array
Calculates the bounding points for a list of path segments
length
length() -> float
Calculates the length of a path
segment-at-t
segment-at-t() -> dictionary
Finds the segment that contains a point that is distance t
from the start of a path.
The distance to find the segment with. A float will be in absolute distance along the path. A ratio will be relative to the length of the path. Will panic if the distance is greater than the length of the path.
When true the path will be reversed, effectively looking for the segment from the end of the path.
The number of samples to use when calculating the length of a cubic segment.
Clamps the distance to the length of the path, so the function won't panic.
Returns a dictionary with the folloing key-value pairs:
point-on-path
point-on-path() -> none or vector
Finds the position of a point a distance from the start of a path. If the path is empty none will be returned.
Absolute position on the path if given an float or integer, or relative position if given a ratio from 0% to 100%. When this value is negative, the point will be found from the end of the path instaed of the start.
If true, use linear extrapolation if distance is outsides the path's range
direction
direction() -> array
Finds the position and direction of a point a distance along from the start of a path. Returns an array of two vectors where the first is the position, and the second is the direction.
Absolute position on the path if given an float or integer, or relative position if given a ratio from 0% to 100%. When this value is negative, the point will be found from the end of the path instaed of the start.
line-segment
line-segment() -> segment
Creates a line segment with points
cubic-segment
cubic-segment() -> segment
Creates a cubic bezier segment
normalize
normalize() -> array
Normalize segments by connecting gaps via straight line segments and merging multiple line segments into a single one.
shorten-segment
shorten-segment() -> segment
Shortens a segment by a given distance.
The distance to move the start of the segment towards the end of the segment. If this value is negative, the end of the segment will be moved towards the start.
Shortening bezier curves suffers from rounding and precision errors so a position can be given to "snap" a curve's start/end point to.
How cubic segments should be shortned. Can be "LINEAR"
to use bezier.cubic-shorten-linear
or "CURVED"
to use bezier.cubic-shorten
.
shorten-path
shorten-path() -> segments Segments of the path that have been shortened
Shortens a path's segments by the given distances. The start of the path is shortened first by moving the point along the path towards the end. The end of the path is then shortened in the same way. When a distance is 0 no other calculations are made.