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

spherical-delaunay

v0.2.0

Published

Spherical Delaunay triangulation via 3D convex hull, with O(sqrt(N)) nearest-neighbor queries

Readme

spherical-delaunay

Spherical Delaunay triangulation via 3D convex hull, with O(√N) nearest-neighbor queries.

Install

npm install spherical-delaunay

Usage

Convert lat/lon points to Cartesian coordinates, build a triangulation, then query it for the nearest point to any location:

import {
  toCartesian,
  convexHull,
  buildTriangulation,
  flattenTriangulation,
  createQueryContext,
  findNearestVertices,
  vertexLatLon,
} from "spherical-delaunay";

// Points on the sphere, as lat/lon in degrees.
const cities = [
  { lat: 48.8566, lon: 2.3522 }, // Paris
  { lat: 51.5074, lon: -0.1278 }, // London
  { lat: 52.52, lon: 13.405 }, // Berlin
  { lat: 41.9028, lon: 12.4964 }, // Rome
  { lat: 40.4168, lon: -3.7038 }, // Madrid
  { lat: 59.3293, lon: 18.0686 }, // Stockholm
];

// Build the triangulation once...
const hull = convexHull(cities.map(toCartesian));
const triangulation = buildTriangulation(hull);

// ...then query it as often as you like.
const fd = flattenTriangulation(triangulation);
const ctx = createQueryContext(fd);

const query = toCartesian({ lat: 45, lon: 5 }); // somewhere in the Alps
const { nearestVertex } = findNearestVertices(ctx, query);

console.log(vertexLatLon(fd, nearestVertex)); // { lat, lon } of the nearest city

findNearestVertices also accepts a k for k-nearest queries, a filter predicate to restrict matches, and a startTriangle to warm-start the search from a previous result — useful for a sequence of nearby queries. Triangulations can be persisted or sent over the wire with toJson/fromJson, or the compact serializeBinary/deserializeBinary binary format.

How it works

A spherical Delaunay triangulation is exactly the set of faces of the 3D convex hull of its points on the unit sphere. convexHull builds that hull incrementally, and buildTriangulation turns it into a navigable triangle mesh. Nearest-neighbor queries then reduce to a triangle walk — crossing from triangle to triangle toward the query point — followed by a greedy walk over Delaunay-adjacent vertices, both O(√N) for uniformly distributed points. See docs/nearest-neighbor.md for the full theory, including how the implementation stays correct for partial-sphere (regional) datasets and under floating-point coordinate quantization.

Vendored dependencies

The package has zero runtime npm dependencies. The exact-arithmetic geometric predicate (orient3D) it relies on for robustness against near-degenerate input is vendored from mourner/robust-predicates under src/vendor/robust-predicates/. That code is public domain and carries its own LICENSE file.

License

ISC © Chris Steinbach. See LICENSE.