vis-why 1.2.3 → 2.0.0

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 -31
  2. package/package.json +10 -7
package/index.js CHANGED
@@ -1,37 +1,32 @@
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
4
  return Math.abs(
7
- (a[0] - c[0]) * (b[1] - a[1]) -
8
- (a[0] - b[0]) * (c[1] - a[1])
5
+ (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1])
9
6
  );
10
7
  }
11
8
 
12
-
13
9
  function areaCompare(p, q) {
14
10
  return p.area - q.area;
15
11
  }
16
12
 
17
-
18
13
  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 = [];
14
+ const ts = { heap: heap(areaCompare, true) };
15
+ let triangle;
16
+ let trianglePrev;
17
+ let a = poly[0];
18
+ let b;
19
+ let c = poly[1];
20
+ const list = [];
26
21
 
27
22
  // calculate areas
28
- for (i = 2; i < poly.length; i++) {
23
+ for (let i = 2; i < poly.length; i++) {
29
24
  b = c;
30
25
  c = poly[i];
31
26
  triangle = {
32
- a: a,
33
- b: b,
34
- c: c,
27
+ a,
28
+ b,
29
+ c,
35
30
  area: area(a, b, c),
36
31
  next: null,
37
32
  prev: trianglePrev,
@@ -56,12 +51,11 @@ function calculate(poly, area) {
56
51
  return ts;
57
52
  }
58
53
 
59
-
60
54
  function eliminate(ts, limit, area) {
61
- var triangle,
62
- prevTriangle,
63
- nextTriangle,
64
- counter = ts.heap.size() - limit;
55
+ let triangle;
56
+ let prevTriangle;
57
+ let nextTriangle;
58
+ let counter = ts.heap.size() - limit;
65
59
 
66
60
  while (counter-- > 0) {
67
61
  triangle = ts.heap.pop();
@@ -88,9 +82,8 @@ function eliminate(ts, limit, area) {
88
82
  }
89
83
  }
90
84
 
91
-
92
85
  function collect(triangle) {
93
- var poly = [triangle.a];
86
+ const poly = [triangle.a];
94
87
 
95
88
  while (true) {
96
89
  poly.push(triangle.b);
@@ -105,8 +98,7 @@ function collect(triangle) {
105
98
  return poly;
106
99
  }
107
100
 
108
-
109
- function simplify(poly, limit, area) {
101
+ export default function simplify(poly, limit, area = areaLL) {
110
102
  if (poly.length < 3) {
111
103
  return poly;
112
104
  }
@@ -119,10 +111,7 @@ function simplify(poly, limit, area) {
119
111
  return poly;
120
112
  }
121
113
 
122
- // default area function
123
- area = area || areaLL;
124
-
125
- var ts = calculate(poly, area);
114
+ const ts = calculate(poly, area);
126
115
  if (!ts.first) {
127
116
  // empty heap - straight line with all triangles empty
128
117
  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.0",
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": "^1.9.4",
23
+ "@pirxpilot/google-polyline": "^3.0.2",
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"