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 🙏

© 2024 – Pkg Stats / Ryan Hefner

smallest-circle

v0.1.0

Published

Iterative and recursive two-dimensional implementations of Welzl's algorithm for solving the smallest circle problem.

Downloads

3

Readme

Smallest Circle (Typescript)

Iterative and recursive two-dimensional implementations of Welzl's algorithm for computing the smallest circle that encloses a set of points.

This problem is also known as the smallest enclosing circle problem, minimum covering circle problem, or bounding circle problem. The implementation is based on the following work(s):

Welzl, E. (1991). Smallest enclosing disks (balls and ellipsoids).
In New results and new trends in computer science (pp. 359-370).
Springer, Berlin, Heidelberg.

Welzl's algorithm solves this problem in expected O(n) runtime. The original algorithm was formulated as recursive program, leading to a call stack overflow for a moderately large amount of points. Thus, the iterative implementation in this crate should be preferred. However, the recursive version is provided for demonstration purposes.

Please note that the expected runtime only holds for randomized inputs (i.e., you may want to shuffle your input stream in advance).

This is a port of the corresponding Rust implementation rust-smallest-enclosing-circle.

Install

npm install smallest-circle

Usage Examples

The smallestCircle function takes an array of points and returns an object specifying the smallest enclosing circle for the given input. You can use the provided circleCenter and circleRadius methods to determine the circle's center point and radius. Optionally randomize your input data with the provided in-place shuffle function.

import { circleCenter, circleRadius, smallestCircle, shuffle } from 'smallest-circle'

const points = [[0, 0], [8, 0], [2.5, 3], [1.5, -2], [4, 1], [7, -1]]
shuffle(points)
const circle = smallestCircle(points)
const center = circleCenter(circle)
const radius = circleRadius(circle)

console.log(center) // [ 4, 0 ]
console.log(radius) // 4

The API for the recursive version is identical (however it is discouraged to be used in real-world applications for its tendency to exceed call stack size):

import { circleCenter, circleRadius, shuffle, smallestCircleRecursive } from 'smallest-circle'

const points = [[0, 0], [8, 0], [2.5, 3], [1.5, -2], [4, 1], [7, -1]]
shuffle(points)
const circle = smallestCircleRecursive(points)
const center = circleCenter(circle)
const radius = circleRadius(circle)

console.log(center) // [ 4, 0 ]
console.log(radius) // 4