@sumisonic/bezier-kit-core
v0.2.0
Published
Zero-dependency 2D/3D cubic-bezier geometry library (morph, split, arc-length)
Maintainers
Readme
@sumisonic/bezier-kit-core
Zero-dependency TypeScript cubic-bezier library (geometry layer). Works with both 2D and 3D.
See the repository README for full usage, type hierarchy, non-goals, rendering examples, and comparisons with other libraries.
Installation
pnpm add @sumisonic/bezier-kit-coreMinimal example (2D)
import { createPathInterpolator, fromCatmullRom, type Point2D } from '@sumisonic/bezier-kit-core'
const a = fromCatmullRom<Point2D>([
{ x: 0, y: 0 },
{ x: 100, y: 50 },
{ x: 200, y: 0 },
])
const b = fromCatmullRom<Point2D>([
{ x: 0, y: 0 },
{ x: 100, y: -50 },
{ x: 200, y: 0 },
])
const interp = createPathInterpolator(a, b)
const morphed = interp(0.5) // BezierPath<Point2D>Switching to 3D is just changing the type parameter to Point3D (mixing 2D and 3D is a compile-time error).
Features
- Path-level:
createPathInterpolator/createPathInterpolatorStrict/createPathSplitter/matchSegmentCount - Arc-length queries:
pointAtLength/tangentAtLength - Segment-level:
pointAt/tangentAt/splitSegmentAt/arcLengthTo/segmentLength - Arc-length index:
createArcLengthIndex/arcLengthToParam - Bounding box:
bbox(returnsBBox2DorBBox3Ddepending on input) - Construction from points:
fromCatmullRom/fromPolyline - Functor:
mapPoints(2D ↔ 3D conversion, translation, scale, etc.) - Math utilities:
lerp/clamp/lerpPoint/distance/scan/binarySearchIndex - Types:
Point2D/Point3D/Point,BezierSegment<P>,BezierPath<P>,BBox2D/BBox3D/BBox<P>,ArcLengthIndex<P>,ArcLengthLocation
See the repository README for API details.
License
MIT © sumisonic
