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

voronoijs

v1.0.0

Published

A TypeScript implementation of Steven J. Fortune's algorithm to efficiently compute Voronoi diagrams. The Voronoi object's purpose is to solely compute a Voronoi diagram, it is completely standalone, with no dependency on external code: it contains no ren

Downloads

1,258

Readme

TypeScript-Voronoi

A TypeScript implementation of Steven J. Fortune's algorithm to efficiently compute Voronoi diagrams, forked from Javascript-Voronoi. The Voronoi object's purpose is to solely compute a Voronoi diagram, it is completely standalone, with no dependency on external code: it contains no rendering code: that is left to the user of the library.

Main object: Voronoi

A TypeScript object which allows to compute a Voronoi diagram. The Voronoi object doesn't render the resulting Voronoi diagram, the user is responsible for rendering the diagram.

Usage

Roughly:

import { Voronoi, BoundingBox, Site, Diagram } from 'voronoijs';

let voronoi = new Voronoi();
let bbox: BoundingBox = {xl: 0, xr: 800, yt: 0, yb: 600}; // xl is x-left, xr is x-right, yt is y-top, and yb is y-bottom
let sites: Site[] = [ {x: 200, y: 200}, {x: 50, y: 250}, {x: 400, y: 100} /* , ... */ ];

// a 'vertex' is an object exhibiting 'x' and 'y' properties. The
// Voronoi object will add a unique 'voronoiId' property to all
// sites. The 'voronoiId' can be used as a key to lookup the associated cell
// in diagram.cells.

let diagram: Diagram = voronoi.compute(sites, bbox);

The returned 'diagram' variable is a Javascript object with the following properties:

diagram.vertices

An array of unordered, unique Voronoi.Vertex objects making up the Voronoi diagram. Each Voronoi.Vertex object in the list is shared by many Voronoi.Edge objects.

diagram.edges

An array of unordered, unique Voronoi.Edge objects making up the Voronoi diagram. Voronoi.Edges are defined by two vertices, va and vb, which vertices are shared by connected edges. This mean that if you change one vertex belonging to an edge, other connected edges will also be changed.

diagram.cells

An array of Voronoi.Cell objects making up the Voronoi diagram. A Voronoi.Cell object might have an empty array of halfedges, meaning no Voronoi cell could be computed for a particular cell.

diagram.execTime

The time it took to compute the Voronoi diagram, in milliseconds.

Added on October 12, 2013: In order to help improve performance, Voronoi.recycle() has been added to allow the recycling of a returned Voronoi diagram. Usage:

let diagram;
...

// some kind of loop starting here (whether outright or through a timer)
...

voronoi.recycle(diagram);
// diagram.vertices, diagram.edges and diagram.cells can no longer be used!
diagram = voronoi.compute(sites, bbox);

// do stuff with content of `diagram`
...

This new method helps performance significantly when re-computing a Voronoi diagram, as it saves on memory allocation, and associated garbage collection.

Public objects

Voronoi

The Voronoi object which computes a Voronoi diagram.

Voronoi.Vertex
  • x: no explanation required.

  • y: no explanation required.

Voronoi.Edge
  • lSite: the Voronoi site object at the left of this Voronoi.Edge object. The site object is just a reference to a site in the array of sites supplied by the user when Voronoi.compute() was called.

  • rSite: the Voronoi site object at the right of this Voronoi.Edge object (can be null, when this is a border edge). The site object is just a reference to a site in the array of sites supplied by the user when Voronoi.compute() was called.

  • va: a Voronoi.Vertex object with an x and a y property defining the start point (relative to the Voronoi site on the left) of this Voronoi.Edge object.

  • vb: a Voronoi.Vertex object with an x and a y property defining the end point (relative to Voronoi site on the left) of this Voronoi.Edge object.

Voronoi.Cell
  • site: the Voronoi site object associated with the Voronoi cell.

  • halfedges: an array of Voronoi.Halfedge objects, ordered counterclockwise, defining the polygon for this Voronoi cell.

Voronoi.Halfedge
  • site: the Voronoi site object owning this Voronoi.Halfedge object.

  • edge: a reference to the unique Voronoi.Edge object underlying this Voronoi.Halfedge object.

  • getStartpoint(): a method returning a Voronoi.Vertex of the start point of this halfedge. Keep in mind halfedges are always counterclockwise.

  • getEndpoint(): a method returning a Voronoi.Vertex object with an x and a y property for the end point of this halfedge. Keep in mind halfedges are always counterclockwise.

License

Copyright (c) 2018 Chisato Hasegawa https://github.com/chase0213/TypeScript-Voronoi

Licensed under The MIT License http://en.wikipedia.org/wiki/MIT_License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.