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

adaptive-bezier-subdivider

v0.1.0

Published

adaptive subdivider for 2D quadratic and cubic bezier curves

Readme

adaptive-bezier-subdivider

Flattens a 2D bezier curve into a sequence of line segments adaptively, meaning it will use less points for the segments that are not curved very much and more points for the highly curved parts. It achivies this by recursively subdividing the curve until it is indistinguishable from a line segment.

It is a cleaned up version of Matt DesLauries port (quadratic, cubic) of Anti-Grain-Geometry's bezier subdivision algorithm, it is updated to use the more modern class and module features of javascript. You can find the original algorithm and implementation here.

Red dots are the computed points and the green/cyan segments are drawn with straight line segments.

Installation

This library can be used on both node and browser.

For browsers just put the index.js file in a suitable place then import it in your script normally:

import { AdaptiveQuadraticBezierBuilder, AdaptiveCubicBezierBuilder } from "./path-to-index.js"

In node applications, install it via npm

npm install adaptive-bezier-subdivider

then import it normally:

import { AdaptiveQuadraticBezierBuilder, AdaptiveCubicBezierBuilder } from "adaptive-bezier-subdivider"

Example

The library contains two classes, one for dealing with quadratic bezier curves:

import { AdaptiveQuadraticBezierBuilder as QBuilder } from "adaptive-bezier-subdivider";

const quadCurve = {
  P0: [-300, 0],  //curve start point
  P1: [0, 500],   //control point
  P2: [300, 200], //curve end point
};

const qb = new QBuilder();

//the method flatten returns a flat array of x and y coordinates
const quadPoints = qb.flatten(quadCurve.P0, quadCurve.P1, quadCurve.P2);

console.log(quadPoints);
//[x0, y0, x1, y1, ...]

You can also provide a scale argument to the flatten method, it will apply a finer subdivision interval so that the curve can be used in a scaled context without loosing detail for the cost of more processing time and storage:

const quadPoints = qb.flatten(quadCurve.P0, quadCurve.P1, quadCurve.P2, 3);

Here is a comparison image when using the scale factor:

Scale comparison

You can also provide and array to the flatten method and it will append the resultant points to that array

//returns the same arr appended to its end the computed points
const quadPoints = qb.flatten(quadCurve.P0, quadCurve.P1, quadCurve.P2, 3, arr);

There is also another class for dealing with cubic curves and the API is basically the same as above:

import { AdaptiveCubicBezierBuilder as CBuilder } from "adaptive-bezier-subdivider";

const cubicCurve = {
  P0: [-300, 0],   //curve start point
  P1: [400, 300],  //first control point
  P2: [-100, 60],  //second control point
  P3: [300, 10],   //curve end point
};

const cb = new CBuilder();

const cubicPoints = cb.flatten(
  cubicCurve.P0,
  cubicCurve.P1,
  cubicCurve.P2,
  cubicCurve.P3,
  3,  //scale
  arr //your array, if not provided will create and return a new one 
);

console.log(cubicPoints)
//[x0, y0, x1, y1, ...]

Usage

All the class constructor parameters and method parameters are annotated with JSDoc. you can find the usage there.

Note: the constrcutor and methods of these classes don't have input validation, you have to provide the correct parameters or only god knows what will happen (probably will just throw an error).

TODO

Add input validation