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
28
Maintainers
Readme
Dwindle
dwindle ˈdwɪnd(ə)l
verb
- diminish gradually in size, amount, or strength.
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.