vis-why 1.2.3 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +20 -33
  2. package/package.json +10 -7
package/index.js CHANGED
@@ -1,37 +1,30 @@
1
- var heap = require('sterta');
2
-
3
- module.exports = simplify;
1
+ import heap from 'sterta';
4
2
 
5
3
  function areaLL(a, b, c) {
6
- return Math.abs(
7
- (a[0] - c[0]) * (b[1] - a[1]) -
8
- (a[0] - b[0]) * (c[1] - a[1])
9
- );
4
+ return Math.abs((a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]));
10
5
  }
11
6
 
12
-
13
7
  function areaCompare(p, q) {
14
8
  return p.area - q.area;
15
9
  }
16
10
 
17
-
18
11
  function calculate(poly, area) {
19
- var i,
20
- ts = { heap: heap(areaCompare, true) },
21
- triangle,
22
- trianglePrev,
23
- a = poly[0],
24
- b, c = poly[1],
25
- list = [];
12
+ const ts = { heap: heap(areaCompare, true) };
13
+ let triangle;
14
+ let trianglePrev;
15
+ let a = poly[0];
16
+ let b;
17
+ let c = poly[1];
18
+ const list = [];
26
19
 
27
20
  // calculate areas
28
- for (i = 2; i < poly.length; i++) {
21
+ for (let i = 2; i < poly.length; i++) {
29
22
  b = c;
30
23
  c = poly[i];
31
24
  triangle = {
32
- a: a,
33
- b: b,
34
- c: c,
25
+ a,
26
+ b,
27
+ c,
35
28
  area: area(a, b, c),
36
29
  next: null,
37
30
  prev: trianglePrev,
@@ -56,12 +49,11 @@ function calculate(poly, area) {
56
49
  return ts;
57
50
  }
58
51
 
59
-
60
52
  function eliminate(ts, limit, area) {
61
- var triangle,
62
- prevTriangle,
63
- nextTriangle,
64
- counter = ts.heap.size() - limit;
53
+ let triangle;
54
+ let prevTriangle;
55
+ let nextTriangle;
56
+ let counter = ts.heap.size() - limit;
65
57
 
66
58
  while (counter-- > 0) {
67
59
  triangle = ts.heap.pop();
@@ -88,9 +80,8 @@ function eliminate(ts, limit, area) {
88
80
  }
89
81
  }
90
82
 
91
-
92
83
  function collect(triangle) {
93
- var poly = [triangle.a];
84
+ const poly = [triangle.a];
94
85
 
95
86
  while (true) {
96
87
  poly.push(triangle.b);
@@ -105,8 +96,7 @@ function collect(triangle) {
105
96
  return poly;
106
97
  }
107
98
 
108
-
109
- function simplify(poly, limit, area) {
99
+ export default function simplify(poly, limit, area = areaLL) {
110
100
  if (poly.length < 3) {
111
101
  return poly;
112
102
  }
@@ -119,10 +109,7 @@ function simplify(poly, limit, area) {
119
109
  return poly;
120
110
  }
121
111
 
122
- // default area function
123
- area = area || areaLL;
124
-
125
- var ts = calculate(poly, area);
112
+ const ts = calculate(poly, area);
126
113
  if (!ts.first) {
127
114
  // empty heap - straight line with all triangles empty
128
115
  return [poly[0], poly[poly.length - 1]];
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "vis-why",
3
- "version": "1.2.3",
3
+ "version": "2.0.1",
4
4
  "description": "M Visvalingam and J D Whyatt line simplification algorithm",
5
5
  "main": "index.js",
6
+ "type": "module",
6
7
  "scripts": {
7
8
  "test": "make check"
8
9
  },
9
- "repository": "pirxpilot/vis-why",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/pirxpilot/vis-why.git"
13
+ },
10
14
  "keywords": [
11
15
  "line",
12
16
  "simplification"
@@ -15,13 +19,12 @@
15
19
  "license": "MIT",
16
20
  "homepage": "https://github.com/pirxpilot/vis-why",
17
21
  "devDependencies": {
18
- "@pirxpilot/jshint": "~3",
19
- "@pirxpilot/matcha": "~1",
20
- "polyline-encoded": "^0.0.8",
21
- "should": "~13"
22
+ "@biomejs/biome": "2.4.3",
23
+ "@pirxpilot/google-polyline": "~4",
24
+ "@pirxpilot/matcha": "~1"
22
25
  },
23
26
  "dependencies": {
24
- "sterta": "^2.2.1"
27
+ "sterta": "~3"
25
28
  },
26
29
  "files": [
27
30
  "index.js"