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