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

pointille

v1.0.1

Published

Distribute N points approximately evenly inside a polygon, deterministically, via Lloyd's algorithm on a centroidal Voronoi tessellation.

Readme

pointille

Distribute n points approximately evenly inside a polygon — deterministically — via Lloyd's algorithm on a centroidal Voronoi tessellation (CVT). Named after the Pointillist painters, who were solving much the same problem by hand.

| | Triangle | Square | Pentagon | | --- | :---: | :---: | :---: | | n = 4 | | | | | n = 5 | | | | | n = 6 | | | | | n = 7 | | | |

Faint cells show each point's Voronoi region clipped to the polygon. Regenerate with npm run test:demo.

Install

npm install pointille

Usage

import { pointille } from 'pointille'

const unitSquare = [
  [0, 0], [1, 0], [1, 1], [0, 1],
] as const

const points = pointille(unitSquare, 25)
// => 25 [x, y] tuples, all inside the square, roughly evenly spaced.

A Point is a readonly [number, number] tuple. A Polygon is an ordered ring of points (no need to close it — the first vertex is implicitly connected to the last).

Options

pointille(polygon, n, {
  iterations: 30,    // Lloyd relaxation steps. Default: 30.
  seed: 1,           // Starting index into the Halton seed sequence. Default: 1.
})

Changing seed is the canonical way to get a different — but still deterministic — layout for the same (polygon, n) pair.

Algorithm

  1. Seed. Generate n candidate points inside the polygon's bounding box using a 2D Halton sequence (pairing Van der Corput sequences in bases 2 and 3) and reject any falling outside the polygon. Halton is a low-discrepancy quasi-random sequence: no PRNG state, fully deterministic, well-spread.
  2. Relax. Iterate Lloyd's algorithm:
    • Compute a Voronoi diagram of the current sites with d3-delaunay.
    • Clip each Voronoi cell to the polygon via polygon-clipping so that we handle concave polygons.
    • Move each site to the area-weighted centroid of its clipped cell.
  3. Stop after iterations steps (default 30). The result is a centroidal Voronoi tessellation: each cell's site is at its own centroid, which gives the visual "even distribution" property.

The function is pure and deterministic: same inputs → byte-identical outputs.

Development

npm install
npm test         # node --test on src/__tests__/*.test.ts via tsx
npm run build    # tsup (ESM + CJS + .d.ts)
npm run test:demo

License

MIT