@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
| Parameter | Type |
|---|---|
seg | Segment |
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
| Parameter | Type |
|---|---|
seg | Segment |
loc | SegmentLocation |
Returns
number
derivative()
derivative(
seg,loc):vec2
Defined in: Segment.ts:51
Returns the derivative of the segment at the given location.
Parameters
| Parameter | Type |
|---|---|
seg | Segment |
loc | SegmentLocation |
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
| Parameter | Type |
|---|---|
seg | Segment |
times | Iterable<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
| Parameter | Type | Default value | Description |
|---|---|---|---|
seg | Segment | undefined | - |
tolerance | number | 0 | When 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
| Parameter | Type |
|---|---|
seg | Segment |
Returns
boolean
length()
length(
seg):number
Defined in: Segment.ts:12
Returns the length of the segment.
Parameters
| Parameter | Type |
|---|---|
seg | Segment |
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
| Parameter | Type |
|---|---|
seg | Segment |
loc | SegmentLocation |
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
| Parameter | Type | Default value |
|---|---|---|
seg | Segment | undefined |
distance | number | undefined |
tolerance | number | 0.05 |
Returns
orientation()
orientation(
seg,loc):mat2d
Defined in: Segment.ts:79
Returns the orientation matrix of the segment at the given location.
Parameters
| Parameter | Type |
|---|---|
seg | Segment |
loc | SegmentLocation |
Returns
mat2d
point()
point(
seg,loc):vec2
Defined in: Segment.ts:38
Returns the point of the segment at the given location.
Parameters
| Parameter | Type |
|---|---|
seg | Segment |
loc | SegmentLocation |
Returns
vec2
reverse()
reverse(
seg):Segment
Defined in: Segment.ts:197
Returns the segment traversed in the opposite direction.
Parameters
| Parameter | Type |
|---|---|
seg | Segment |
Returns
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 Parameter | Default type |
|---|---|
V extends Vertex | Vertex |
Parameters
| Parameter | Type |
|---|---|
start | vec2 |
vertices | readonly 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
| Parameter | Type |
|---|---|
seg | Segment |
loc | SegmentLocation |
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
| Parameter | Type | Description |
|---|---|---|
seg | Segment | - |
direction | vec2 | The 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
| Parameter | Type | Description |
|---|---|---|
seg | Segment | - |
origin | vec2 | The 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
| Parameter | Type |
|---|---|
seg | Segment |
loc | SegmentLocation |
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
| Parameter | Type |
|---|---|
seg | Segment |
from | SegmentLocation |
to | SegmentLocation |
attrDefs? | Readonly<Record<string, AttributeDef>> |