vis-why 1.2.2 → 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/Readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  [![NPM version][npm-image]][npm-url]
2
- [![Build Status][travis-image]][travis-url]
3
- [![Dependency Status][gemnasium-image]][gemnasium-url]
2
+ [![Build Status][build-image]][build-url]
3
+ [![Dependency Status][deps-image]][deps-url]
4
4
 
5
5
  # vis-why
6
6
 
@@ -51,11 +51,11 @@ simplify(poly, 4, area);
51
51
  [npm]: https://www.npmjs.org/
52
52
  [vis-why]: https://hydra.hull.ac.uk/resources/hull:8338
53
53
 
54
- [npm-image]: https://img.shields.io/npm/v/vis-why.svg
54
+ [npm-image]: https://img.shields.io/npm/v/vis-why
55
55
  [npm-url]: https://npmjs.org/package/vis-why
56
56
 
57
- [travis-url]: https://travis-ci.org/pirxpilot/vis-why
58
- [travis-image]: https://img.shields.io/travis/pirxpilot/vis-why.svg
57
+ [build-url]: https://github.com/pirxpilot/vis-why/actions/workflows/check.yaml
58
+ [build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/vis-why/check.yaml?branch=main
59
59
 
60
- [gemnasium-image]: https://img.shields.io/gemnasium/pirxpilot/vis-why.svg
61
- [gemnasium-url]: https://gemnasium.com/pirxpilot/vis-why
60
+ [deps-image]: https://img.shields.io/librariesio/release/npm/vis-why
61
+ [deps-url]: https://libraries.io/npm/vis-why
package/index.js CHANGED
@@ -1,36 +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], b, c = poly[1],
24
- 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 = [];
25
21
 
26
22
  // calculate areas
27
- for (i = 2; i < poly.length; i++) {
23
+ for (let i = 2; i < poly.length; i++) {
28
24
  b = c;
29
25
  c = poly[i];
30
26
  triangle = {
31
- a: a,
32
- b: b,
33
- c: c,
27
+ a,
28
+ b,
29
+ c,
34
30
  area: area(a, b, c),
35
31
  next: null,
36
32
  prev: trianglePrev,
@@ -55,14 +51,13 @@ function calculate(poly, area) {
55
51
  return ts;
56
52
  }
57
53
 
58
-
59
54
  function eliminate(ts, limit, area) {
60
- var triangle,
61
- prevTriangle,
62
- nextTriangle,
63
- counter = ts.heap.size() - limit;
55
+ let triangle;
56
+ let prevTriangle;
57
+ let nextTriangle;
58
+ let counter = ts.heap.size() - limit;
64
59
 
65
- while(counter-- > 0) {
60
+ while (counter-- > 0) {
66
61
  triangle = ts.heap.pop();
67
62
  prevTriangle = triangle.prev;
68
63
  nextTriangle = triangle.next;
@@ -87,11 +82,10 @@ function eliminate(ts, limit, area) {
87
82
  }
88
83
  }
89
84
 
90
-
91
85
  function collect(triangle) {
92
- var poly = [triangle.a];
86
+ const poly = [triangle.a];
93
87
 
94
- while(true) {
88
+ while (true) {
95
89
  poly.push(triangle.b);
96
90
  if (!triangle.next) {
97
91
  break;
@@ -104,8 +98,7 @@ function collect(triangle) {
104
98
  return poly;
105
99
  }
106
100
 
107
-
108
- function simplify(poly, limit, area) {
101
+ export default function simplify(poly, limit, area = areaLL) {
109
102
  if (poly.length < 3) {
110
103
  return poly;
111
104
  }
@@ -118,10 +111,7 @@ function simplify(poly, limit, area) {
118
111
  return poly;
119
112
  }
120
113
 
121
- // default area function
122
- area = area || areaLL;
123
-
124
- var ts = calculate(poly, area);
114
+ const ts = calculate(poly, area);
125
115
  if (!ts.first) {
126
116
  // empty heap - straight line with all triangles empty
127
117
  return [poly[0], poly[poly.length - 1]];
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "vis-why",
3
- "version": "1.2.2",
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
10
  "repository": {
10
11
  "type": "git",
11
- "url": "https://github.com/pirxpilot/vis-why.git"
12
+ "url": "git+https://github.com/pirxpilot/vis-why.git"
12
13
  },
13
14
  "keywords": [
14
15
  "line",
@@ -18,16 +19,14 @@
18
19
  "license": "MIT",
19
20
  "homepage": "https://github.com/pirxpilot/vis-why",
20
21
  "devDependencies": {
21
- "@pirxpilot/matcha": "~1",
22
- "jshint": "~2",
23
- "mocha": "~3",
24
- "polyline-encoded": "^0.0.8",
25
- "should": "~11"
22
+ "@biomejs/biome": "^1.9.4",
23
+ "@pirxpilot/google-polyline": "^3.0.2",
24
+ "@pirxpilot/matcha": "~1"
26
25
  },
27
26
  "dependencies": {
28
- "sterta": "^2.2.1"
27
+ "sterta": "~3"
29
28
  },
30
29
  "files": [
31
30
  "index.js"
32
31
  ]
33
- }
32
+ }
package/History.md DELETED
@@ -1,76 +0,0 @@
1
-
2
- 1.2.2 / 2017-04-15
3
- ==================
4
-
5
- * update deprecated dependencies
6
-
7
- 1.2.1 / 2017-02-17
8
- ==================
9
-
10
- * change name to vis-why
11
- * remove obsolete component.json
12
-
13
- 1.2.0 / 2017-02-08
14
- ==================
15
-
16
- * add support for custom area function
17
-
18
- 1.1.6 / 2017-01-12
19
- ==================
20
-
21
- * fix elimination of empty triangles
22
-
23
- 1.1.5 / 2016-12-15
24
- ==================
25
-
26
- * use @pirxpilot/matcha instead od matcha
27
- * minor adjustment to calculate loop
28
-
29
- 1.1.4 / 2016-12-10
30
- ==================
31
-
32
- * fix exception for duplicate and co-linear stops
33
-
34
- 1.1.3 / 2016-12-08
35
- ==================
36
-
37
- * make it faster - especially for polylines longer than 1k items
38
-
39
- 1.1.2 / 2016-12-06
40
- ==================
41
-
42
- * properly collect triangles
43
- * add basic benchmarks
44
- * let all test run
45
-
46
- 1.1.1 / 2016-11-18
47
- ==================
48
-
49
- * fix exception when applied to straight line case
50
-
51
- 1.1.0 / 2016-11-06
52
- ==================
53
-
54
- * fix Makefile test target
55
- * upgrade code42day-binary-heap to 2.0.0
56
- * upgrade mocha to ~3 and should to ~11
57
-
58
- 1.0.3 / 2015-11-11
59
- ==================
60
-
61
- * switch to browserify build
62
-
63
- 1.0.2 / 2014-07-30
64
- ==================
65
-
66
- * declare code42day/binary-heap dependency properly
67
-
68
- 1.0.1 / 2014-07-30
69
- ==================
70
-
71
- * optimization: rebuild triangle heap
72
-
73
- 1.0.0 / 2014-07-29
74
- ==================
75
-
76
- * Initial implementation