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

webgl-dm-voronoi

v1.0.1

Published

Voronoi diagrams on the GPU using distance-meshes.

Downloads

6

Readme

Bower version Build Status Built with Grunt

What is this?

A live demo is worth a thousand words, so here it is. This is a voronoi diagram plotting library that takes advantage of the GPU pipeline in order to convert meshes into voronoi diagrams. A paper explaining the method used can be viewed here.

Currently, we support point and line-segment voronoi sites. In the future we intend to add on line-strips, polygons and general curves.

Installation

Install via bower: bower install webgl-dm-voronoi

The dist/ directory contains both a normal (voronoi.js) as well as a minified version of the library (voronoi.min.js). Include in the browser using <script src="path/to/voronoi.min.js"></script>

Usage

Create

var voronoi = new Voronoi.Diagram(options);

options is an object with (optionally) the following properties:

|Name|Default|Description| |:--:|:-----------:|:----------| | canvas | null | If you want to draw onto an existing canvas, supply its dom element in this option. | width | 500 | In case canvas option was null, the diagram will create its own canvas element as wide as this. | height | 500 | Analogous to the width option above. | precision | 16 | Positive integer which controls the level of detail of the distance mesh. The higher, the more detailed will the mesh be, producing a better rendering at the cost of performance. | markers | true | Boolean indicating whether site markers are initially visible.

If you use an existing canvas, just pass its DOM element in the canvas option. Otherwise, you will need to add the canvas the voronoi diagram created to the DOM yourself:

document.appendChild(voronoi.canvas);

Populate

Currently, we support two voronoi site types: points and line segments.

Something that is common to all site instantiation methods is that the returned value is a reference to the created site object. You can use it to dynamically change the site's properties (i.e. position in the case of a point-site or the position of the endpoints of a line-site).

Each instantiation method will also take a color parameter, this will be the color of the rendered voronoi cell of the created site. The value passed can be either a css color string or an object {r:, g:, b:} with channel values in the interval [0, 1].

Every site gives you read access to its unique id via site.id (integer), its associated color site.color ({r:, g:, b:}) and its type site.type (SiteType.point or SiteType.line).

Points

Instantiate points like so:

var p = voronoi.point(x, y, color);

You may change the position of a point site:

p.x = ...  // new x;
p.y = ...  // new y;

Line segments

Instantiate a line segment like so:

var line = voronoi.line(a = {x:, y:}, b = {x:, y:}, color)

You may change the position of the endpoints:

// Individual axis
line.a.x = ... // new x for endpoint A
line.b.y = ... // new y for endpoint B

// Simultaneously
line.a.set(x, y);

Removing sites

You may remove a site from the diagram by invoking remove() in one of two ways:

voronoi.remove(site);  // pass in the site object itself
voronoi.remove(site.id);  // pass in the site's ID

Render

voronoi.render();

Canvas resizing

If the canvas' width or height has changed, you should call

voronoi.resize()

This will read the new size of the canvas and adjust the GL viewport and camera projection matrix accordingly.

Site visualization

If you wish to render simple markers visualizing where the voronoi site shapes (e.g. points or line segments) are, you can control their visibility by setting:

voronoi.markers.visible = true;

Demo

Under test/integration you can view some basic usage cases. A more complex demo can be seen live here.

License

This software is licensed under the MIT License. See the LICENSE file for more information.