New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

dwindle

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dwindle

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.

latest
Source
npmnpm
Version
0.1.3
Version published
Maintainers
1
Created
Source

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.

Keywords

geometry

FAQs

Package last updated on 19 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts