Skip to main content

Path Util

segment-start

segment-start() -> vector 

Returns the first position vector of a path segment.

Path segment

segment-end

segment-end() -> vector 

Returns the last position vector of a path segment

Path segment

bounds

bounds() -> array 

Calculates the bounding points for a list of path segments

segments:

List of path segments

length

length() -> float 

Calculates the length of a path

segments:

List of path segments

segment-at-t

segment-at-t() -> dictionary 

Finds the segment that contains a point that is distance t from the start of a path.

segments:

The array of segments that make up the 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.

rev:

Default: false

When true the path will be reversed, effectively looking for the segment from the end of the path.

samples:

Default: default-samples

The number of samples to use when calculating the length of a cubic segment.

clamp:

Default: false

Clamps the distance to the length of the path, so the function won't panic.


Returns a dictionary with the folloing key-value pairs:

index:

The index of the segment in the given array of segments.

segment:

The found segment.

travelled:

The absolute distance travelled along the path to find the segment.

distance:

The distance left to travel along the path.

length:

The length of the returned segment.

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.

segments:

List of path segments

t:

int or float or ratio

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.

extrapolate:

Default: false

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.

segments:

List of path segments

t:

int or float or ratio

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.

extrapolate:

If true, use linear extrapolation if distance is outsides the path's range

clamp:

Default: false

Clamps the distance between the start and end of a path.

line-segment

line-segment() -> segment 

Creates a line segment with points

points:

List of points

cubic-segment

cubic-segment() -> segment 

Creates a cubic bezier segment

Start

End

ctrl-a:

Control point a

ctrl-b:

Control point b

normalize

normalize() -> array 

Normalize segments by connecting gaps via straight line segments and merging multiple line segments into a single one.

segments:

The path segments to normalize.

shorten-segment

shorten-segment() -> segment 

Shortens a segment by a given distance.

segment:

The segment to shorten.

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.

snap-to:

Default: none

Shortening bezier curves suffers from rounding and precision errors so a position can be given to "snap" a curve's start/end point to.

mode:

Default: "CURVED"

How cubic segments should be shortned. Can be "LINEAR" to use bezier.cubic-shorten-linear or "CURVED" to use bezier.cubic-shorten.

samples:

Default: default-samples

The number of samples to use when shortening a cubic segment.

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.

segments:

The segments of the path to shorten.

start-distance:

The distance to shorten from the start of the path.

end-distance:

The distance to shorten from the end of the path

pos:

Tuple of points to "snap" the path ends to