Geometry · class

Spline

Explained in Hello world, Meshes and geometry.

class Spline
import { Spline } from '@driftengine/core';

Constructor

new

constructor(points: readonly SplinePoint[])
ParameterTypeDescription
pointsreadonly SplinePoint[]

Accessors

NameTypeDescription
lengthMgetnumber
pointCountgetnumberControl points, for callers that need the authored shape back.

Methods

pointParamAt

pointParamAt(distanceM: number): number

Where an arc length falls in control-point terms: index + fraction.

ParameterTypeDescription
distanceMnumber
More

The inverse of distanceAtPoint, for a caller that measured something along the curve and needs to write the answer back onto the points that produced it. The fraction matters as much as the index — bank and width are blended between two control points, so attributing a measurement to one of them without knowing which one dominates there gets the wrong point by half the time.

distanceAtPoint

distanceAtPoint(index: number): number

Arc length at control point index.

ParameterTypeDescription
indexnumber
More

A generator authors in control points — "the gap runs from the sixth point to the eighth" — but everything downstream is in metres, and the conversion is only knowable once the curve exists. Without this the caller has to guess, and a guessed hole is a hole in the wrong place.

sampleAt

sampleAt(distanceM: number, out: SplineSample): void

Evaluate the curve at an arc length, clamped to its ends.

ParameterTypeDescription
distanceMnumber
outSplineSample
More

Allocation-free by contract: it is called from the simulation, from the generator and from the mesh builder, and the first of those makes it a hot path rule rather than a preference.