Skip to content

Commit e6ea3a7

Browse files
committedFeb 7, 2024
format sources
1 parent c7fab28 commit e6ea3a7

File tree

3 files changed

+86
-41
lines changed

3 files changed

+86
-41
lines changed
 

‎benchmark/index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ suite('vis-why', function () {
1919
// or switch to fixed number of iterations
2020
// set('iterations', 500);
2121

22-
before(function() {
22+
before(function () {
2323
this.shortPolyline = require('../test/fixtures/short.json');
2424
this.longPolyline = require('../test/fixtures/long.json');
2525
});
2626

27-
bench('short', function() {
27+
bench('short', function () {
2828
simplify(this.shortPolyline, 5);
2929
});
3030

31-
bench('long', function() {
31+
bench('long', function () {
3232
simplify(this.longPolyline, 10);
3333
});
3434

35-
[1000, 5000, 10000, 30000].forEach(function(len) {
35+
[1000, 5000, 10000, 30000].forEach(function (len) {
3636
var polyline = usa.slice(-len);
37-
bench('huge ' + len, function() {
37+
bench('huge ' + len, function () {
3838
simplify(polyline, len / 100);
3939
});
4040
});

‎index.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ function calculate(poly, area) {
2020
ts = { heap: heap(areaCompare, true) },
2121
triangle,
2222
trianglePrev,
23-
a = poly[0], b, c = poly[1],
23+
a = poly[0],
24+
b, c = poly[1],
2425
list = [];
2526

2627
// calculate areas
@@ -62,7 +63,7 @@ function eliminate(ts, limit, area) {
6263
nextTriangle,
6364
counter = ts.heap.size() - limit;
6465

65-
while(counter-- > 0) {
66+
while (counter-- > 0) {
6667
triangle = ts.heap.pop();
6768
prevTriangle = triangle.prev;
6869
nextTriangle = triangle.next;
@@ -91,7 +92,7 @@ function eliminate(ts, limit, area) {
9192
function collect(triangle) {
9293
var poly = [triangle.a];
9394

94-
while(true) {
95+
while (true) {
9596
poly.push(triangle.b);
9697
if (!triangle.next) {
9798
break;

‎test/simplify.js

+77-33
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,43 @@
11
var { describe, it } = require('node:test');
22
var simplify = require('..');
33

4-
describe('simplify', function() {
5-
it('should not change short polylines', function() {
4+
describe('simplify', function () {
5+
it('should not change short polylines', function () {
66
simplify([]).should.have.length(0);
7-
simplify([[0, 0], [1, 1]]).should.eql([[0, 0], [1, 1]]);
7+
simplify([
8+
[0, 0],
9+
[1, 1]
10+
]).should.eql([
11+
[0, 0],
12+
[1, 1]
13+
]);
814
});
915

10-
it('should work with small limits', function() {
11-
simplify([[0, 0], [1, 1.5], [2, 2]], 2).should.eql([[0, 0], [2, 2]]);
16+
it('should work with small limits', function () {
17+
simplify([
18+
[0, 0],
19+
[1, 1.5],
20+
[2, 2]
21+
], 2).should.eql([
22+
[0, 0],
23+
[2, 2]
24+
]);
1225
});
1326

14-
it('should not change anything if limit is larger than poly length', function() {
15-
simplify([[0, 0], [1, 1], [2, 2]], 4).should.eql([[0, 0], [1, 1], [2, 2]]);
27+
it('should not change anything if limit is larger than poly length', function () {
28+
simplify([
29+
[0, 0],
30+
[1, 1],
31+
[2, 2]
32+
], 4).should.eql([
33+
[0, 0],
34+
[1, 1],
35+
[2, 2]
36+
]);
1637
});
1738

1839

19-
it('should simplify longer polylines', function() {
40+
it('should simplify longer polylines', function () {
2041

2142
var poly = [
2243
[0, 0],
@@ -31,12 +52,17 @@ describe('simplify', function() {
3152
[9, 9]
3253
];
3354

34-
simplify(poly, 4).should.eql([[ 0, 0 ], [ 3, 3 ], [ 8, 5 ], [ 9, 9 ]]);
55+
simplify(poly, 4).should.eql([
56+
[0, 0],
57+
[3, 3],
58+
[8, 5],
59+
[9, 9]
60+
]);
3561

3662
});
3763

3864

39-
it('should simplify longer polylines using custom properties', function() {
65+
it('should simplify longer polylines using custom properties', function () {
4066

4167
function area(a, b, c) {
4268
return Math.abs(
@@ -46,29 +72,29 @@ describe('simplify', function() {
4672
}
4773

4874
var poly = [
49-
{x: 0, y: 0, label: 'a'},
50-
{x: 1, y: 0, label: 'b'},
51-
{x: 1, y: 1, label: 'c'},
52-
{x: 3, y: 1, label: 'd'},
53-
{x: 3, y: 3, label: 'e'},
54-
{x: 4, y: 4, label: 'f'},
55-
{x: 5, y: 4, label: 'g'},
56-
{x: 8, y: 5, label: 'h'},
57-
{x: 8, y: 7, label: 'i'},
58-
{x: 9, y: 9, label: 'j'}
75+
{ x: 0, y: 0, label: 'a' },
76+
{ x: 1, y: 0, label: 'b' },
77+
{ x: 1, y: 1, label: 'c' },
78+
{ x: 3, y: 1, label: 'd' },
79+
{ x: 3, y: 3, label: 'e' },
80+
{ x: 4, y: 4, label: 'f' },
81+
{ x: 5, y: 4, label: 'g' },
82+
{ x: 8, y: 5, label: 'h' },
83+
{ x: 8, y: 7, label: 'i' },
84+
{ x: 9, y: 9, label: 'j' }
5985
];
6086

6187
simplify(poly, 4, area).should.eql([
62-
{x: 0, y: 0, label: 'a'},
63-
{x: 3, y: 3, label: 'e'},
64-
{x: 8, y: 5, label: 'h'},
65-
{x: 9, y: 9, label: 'j'}
88+
{ x: 0, y: 0, label: 'a' },
89+
{ x: 3, y: 3, label: 'e' },
90+
{ x: 8, y: 5, label: 'h' },
91+
{ x: 9, y: 9, label: 'j' }
6692
]);
6793

6894
});
6995

7096

71-
it('should keep the ends of the straight line', function() {
97+
it('should keep the ends of the straight line', function () {
7298

7399
var poly = [
74100
[-3, -3],
@@ -78,14 +104,20 @@ describe('simplify', function() {
78104
[5, 5]
79105
];
80106

81-
simplify(poly, 2).should.eql([[ -3, -3 ], [ 5, 5 ]]);
82-
simplify(poly, 3).should.eql([[ -3, -3 ], [ 5, 5 ]]);
107+
simplify(poly, 2).should.eql([
108+
[-3, -3],
109+
[5, 5]
110+
]);
111+
simplify(poly, 3).should.eql([
112+
[-3, -3],
113+
[5, 5]
114+
]);
83115
});
84116

85117
it('should remove duplicate stops', function () {
86118
var poly = [
87-
[-91.9655, 39.55001],
88-
[-91.9655, 39.55001],
119+
[-91.9655, 39.55001],
120+
[-91.9655, 39.55001],
89121
[-91.96581, 39.55024],
90122
[-91.96596, 39.55041],
91123
[-91.96599, 39.55053],
@@ -97,7 +129,7 @@ describe('simplify', function() {
97129
];
98130

99131
simplify(poly, 9).should.eql([
100-
[-91.9655, 39.55001],
132+
[-91.9655, 39.55001],
101133
[-91.96581, 39.55024],
102134
[-91.96596, 39.55041],
103135
[-91.96599, 39.55053],
@@ -109,15 +141,27 @@ describe('simplify', function() {
109141
});
110142

111143

112-
it('should simplify longer polyline', function() {
144+
it('should simplify longer polyline', function () {
113145
var poly = require('./fixtures/long.json');
114146
var simplified = require('./fixtures/simplified-long.json');
115147

116148
simplify(poly, 40).should.eql(simplified);
117149
});
118150

119151
it('should keep the first point', function () {
120-
var poly = [[0, 0], [1, 0], [2, 0], [3, 1], [4, 2], [4, 4]];
121-
simplify(poly, 4).should.eql([[0, 0], [2, 0], [4, 2], [4, 4]]);
152+
var poly = [
153+
[0, 0],
154+
[1, 0],
155+
[2, 0],
156+
[3, 1],
157+
[4, 2],
158+
[4, 4]
159+
];
160+
simplify(poly, 4).should.eql([
161+
[0, 0],
162+
[2, 0],
163+
[4, 2],
164+
[4, 4]
165+
]);
122166
});
123167
});

0 commit comments

Comments
 (0)