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.
- package/index.js +20 -33
- package/package.json +10 -7
package/index.js
CHANGED
|
@@ -1,37 +1,30 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
|
33
|
-
b
|
|
34
|
-
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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": "
|
|
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":
|
|
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
|
-
"@
|
|
19
|
-
"@pirxpilot/
|
|
20
|
-
"
|
|
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": "
|
|
27
|
+
"sterta": "~3"
|
|
25
28
|
},
|
|
26
29
|
"files": [
|
|
27
30
|
"index.js"
|