npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

bezier-spline-eval

v0.1.0

Published

A lightweight, high-performance TypeScript library for evaluating cubic and quadratic Bézier splines, finding their extents, and calculating inflection points.

Downloads

24

Readme

bezier-spline-eval

A lightweight, high-performance TypeScript library for evaluating cubic and quadratic Bézier splines, finding their extents (bounding box), and calculating inflection points. Built with gl-matrix for performance and zero allocations during calculations.

Perfect for graphics applications, UI development, game development, and any other case where you need to analyze Bézier curves.

Features

  • Cubic and Quadratic Bézier Splines: Full support for both common curve types.
  • N-Dimensional: Works with points of any dimension (e.g., 2D, 3D).
  • Evaluation: Find the position on a curve at any t value.
  • Extents: Calculate the precise axis-aligned bounding box.
  • Critical Points: Find t values for maxima, minima, and inflections.
  • Performant: Uses gl-matrix under the hood.
  • TypeScript Native: Fully typed for a great developer experience.
  • Modern: Outputs ES Modules and UMD bundles.

Installation

npm install bezier-spline-eval

Usage

Here’s a quick example of how to use the library.

import { CubicSpline, QuadraticSpline } from 'bezier-spline-eval';

// --- Quadratic Example (e.g., SVG 'Q' command) ---

const quadraticPoints = [[0, 0], [100, 200], [200, 0]];
const quadSpline = new QuadraticSpline(quadraticPoints);

// Get the point at the halfway mark
const midPoint = quadSpline.evaluate(0.5); // [100, 100]

// Get the bounding box of the curve
const quadExtents = quadSpline.extents();
// quadExtents will be [[0, 0], [200, 100]]

console.log('Quadratic midpoint:', midPoint);
console.log('Quadratic extents:', quadExtents);


// --- Cubic Example (e.g., SVG 'C' command) ---

const cubicPoints = [[0, 0], [50, 200], [150, -200], [200, 0]];
const cubicSpline = new CubicSpline(cubicPoints);

// Find the t-value of the peak height
const criticalPoints = cubicSpline.curveMaximaMinimaT();
const yCriticalT = criticalPoints[1][0]; // ~0.31

// Get the peak point on the curve
const peakPoint = cubicSpline.evaluate(yCriticalT);

// Get the bounding box
const cubicExtents = cubicSpline.extents();

console.log('Cubic peak point:', peakPoint);
console.log('Cubic extents:', cubicExtents);

API

new QuadraticSpline(points: Point[])

Creates a quadratic spline instance. points must be an array of 3 points, where each point is an array of numbers (e.g., [x, y]).

new CubicSpline(points: Point[])

Creates a cubic spline instance. points must be an array of 4 points.

Instance Methods

  • .evaluate(t: number | number[]): Point | Point[] Calculates the point(s) on the curve for the given t value(s) (from 0 to 1).

  • .extents(): [Point, Point] | null Returns the bounding box of the curve as a tuple [minPoint, maxPoint].

  • .extremes(): Point[] Returns an array of all points on the curve that define its extents (i.e., the start/end points and all critical points).

  • .curveMaximaMinimaT(): Record<number, number[]> Returns a dictionary where keys are dimension indices and values are arrays of t values where that dimension's derivative is zero.

  • .curveInflectionT(): Record<number, number[]> (CubicSpline only) Returns a dictionary of t values where the curve has an inflection point in that dimension.

Development

To work on this project locally:

  1. Clone the repository
  2. Install dependencies: npm install
  3. Run tests: npm test
  4. Build the library: npm run build

This project uses Vite for building and Vitest for testing.

License

MIT