PavePave
Home
Guide
API
Sandbox
  • English
  • 日本語
GitHub
Home
Guide
API
Sandbox
  • English
  • 日本語
GitHub
  • Segment

@baku89/pave v1.0.1


@baku89/pave / Segment

Segment

A collection of functions to handle Segment.

Functions

bounds()

bounds(seg): Rect

Defined in: Segment.ts:25

Returns the bounding box of the segment.

Parameters

ParameterType
segSegment

Returns

Rect


curvature()

curvature(seg, loc): number

Defined in: Segment.ts:143

Returns the signed curvature at the given location. Positive when the segment turns towards its normal side.

Parameters

ParameterType
segSegment
locSegmentLocation

Returns

number


derivative()

derivative(seg, loc): vec2

Defined in: Segment.ts:51

Returns the derivative of the segment at the given location.

Parameters

ParameterType
segSegment
locSegmentLocation

Returns

vec2


divideAtTimes()

divideAtTimes(seg, times, attrDefs?): Vertex[]

Defined in: Segment.ts:228

Returns a new vertex array with the segment divided at the given times.

Parameters

ParameterType
segSegment
timesIterable<number>
attrDefs?Readonly<Record<string, AttributeDef>>

Returns

Vertex[]


isStraight()

isStraight(seg, tolerance): boolean

Defined in: Segment.ts:130

Returns true if the segment is a straight line. Also returns true for zero-length segments.

Parameters

ParameterTypeDefault valueDescription
segSegmentundefined-
tolerancenumber0When positive, the segment only has to stay within this distance of its chord

Returns

boolean


isZero()

isZero(seg): boolean

Defined in: Segment.ts:116

Returns true if the segment is a zero-length segment.

Parameters

ParameterType
segSegment

Returns

boolean


length()

length(seg): number

Defined in: Segment.ts:12

Returns the length of the segment.

Parameters

ParameterType
segSegment

Returns

number


normal()

normal(seg, loc): vec2

Defined in: Segment.ts:72

Returns the normal vector of the segment at the given location., which is normally rotated 90 degrees clockwise in Y-down coordinate.

Parameters

ParameterType
segSegment
locSegmentLocation

Returns

vec2


offset()

offset(seg, distance, tolerance): Path

Defined in: Segment.ts:184

Returns the raw parallel curve of the segment at the given signed distance along its normal, as an open path. Lines and circular arcs are offset exactly; cubic Béziers and elliptic arcs are approximated by cubic Béziers within tolerance. Where the distance exceeds the radius of curvature, the parallel curve folds back on itself; use Path.offset for a trimmed result.

Parameters

ParameterTypeDefault value
segSegmentundefined
distancenumberundefined
tolerancenumber0.05

Returns

Path


orientation()

orientation(seg, loc): mat2d

Defined in: Segment.ts:79

Returns the orientation matrix of the segment at the given location.

Parameters

ParameterType
segSegment
locSegmentLocation

Returns

mat2d


point()

point(seg, loc): vec2

Defined in: Segment.ts:38

Returns the point of the segment at the given location.

Parameters

ParameterType
segSegment
locSegmentLocation

Returns

vec2


reverse()

reverse(seg): Segment

Defined in: Segment.ts:197

Returns the segment traversed in the opposite direction.

Parameters

ParameterType
segSegment

Returns

Segment


reverseVertexChain()

reverseVertexChain<V>(start, vertices, startAttrs?): V[]

Defined in: Segment.ts:266

Reverses a vertex chain: start is the pen position before vertices[0], and each vertex draws to its point from the previous position.

Type Parameters

Type ParameterDefault type
V extends VertexVertex

Parameters

ParameterType
startvec2
verticesreadonly V[]
startAttrs?Readonly<Record<string, AttributeValue>>

Returns

V[]


tangent()

tangent(seg, loc): vec2

Defined in: Segment.ts:64

Returns the tangent vector of the segment at the given location.

Parameters

ParameterType
segSegment
locSegmentLocation

Returns

vec2


tangentTimes()

tangentTimes(seg, direction): number[]

Defined in: Segment.ts:157

Sorted t values in (0, 1) where the tangent of the segment is parallel to direction. Lines never report any, since their tangent is constant.

Parameters

ParameterTypeDescription
segSegment-
directionvec2The direction to compare the tangent with. Its length does not matter.

Returns

number[]


tangentTimesFrom()

tangentTimesFrom(seg, origin): number[]

Defined in: Segment.ts:171

Sorted t values in (0, 1) where the line from origin to the segment is tangent to it. Lines never report any.

Parameters

ParameterTypeDescription
segSegment-
originvec2The point the tangents pass through

Returns

number[]


toTime()

toTime(seg, loc): number

Defined in: Segment.ts:252

Returns the time of the segment at the given location.

Parameters

ParameterType
segSegment
locSegmentLocation

Returns

number


trim()

trim(seg, from, to, attrDefs?): Segment

Defined in: Segment.ts:89

Returns a new segment that is the result of trimming the given segment from the start to the end.

Parameters

ParameterType
segSegment
fromSegmentLocation
toSegmentLocation
attrDefs?Readonly<Record<string, AttributeDef>>

Returns

Segment

Edit this page