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

dwindle

v0.1.3

Published

Fast continuous level of detail geometry simplification using the Visvalingam area approach. Provides methods for simplifying to a target point count or percentage in addition to point-area significance.

Downloads

13

Readme

Build Status License: MIT

Dwindle

dwindle ˈdwɪnd(ə)l

verb

  • diminish gradually in size, amount, or strength.

Try the demo here

This is a geometry simplification tool I've wanted to write for a while cos the Visvalingam algorithm is just cool, basically. It accepts a list of 2d coordinates, which could be the outline of a complex polygon or a line-string (like a route) and simplifies the data in the most visually pleasing and acceptable manor i.e. by retaining the important and 'significant' data where possible.

It uses the Visvalingam method which is algorithmically clearer, easier to implement and I believe more effective and consistent than the classic Douglas-Peucker approach.

Usage

Install via npm

$ npm install dwindle

Instantiate the object. Dwindle expects an array of coordinate-pair arrays as input:

var Dwindle = require('dwindle');

let points = [[0,0], [100, 0], [100,100], ... [0, 100]];
let myshape = new Dwindle(points);

There are three choices when reducing the data;

  • Specifiying a target point count
let reduced = myshape.simplify({target: 1000}); // reduce to 1000 points
  • Specifiying a percentage reduction
let reduced = myshape.simplify({percent:50}); // reduce set by half
  • Specifiying a minimum target area (not so useful in practice but it is the basis of the algorithm internally)
let reduced = myshape.simplify({area:0.01}); // by minimum area

The .simplify() method returns an array of coordinate-pair arrays, same as the input.

Note that if your points array (the one you pass to the Dwindle constructor) changes and you want the simplifcations to reflect these changes, then you will need to rebuild the index by calling:

myshape.rebuild(newpoints);

Rebuilding is fast and can be called multiple times no problem.