1
1
var { describe, it } = require ( 'node:test' ) ;
2
2
var simplify = require ( '..' ) ;
3
3
4
- describe ( 'simplify' , function ( ) {
5
- it ( 'should not change short polylines' , function ( ) {
4
+ describe ( 'simplify' , function ( ) {
5
+ it ( 'should not change short polylines' , function ( ) {
6
6
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
+ ] ) ;
8
14
} ) ;
9
15
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
+ ] ) ;
12
25
} ) ;
13
26
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
+ ] ) ;
16
37
} ) ;
17
38
18
39
19
- it ( 'should simplify longer polylines' , function ( ) {
40
+ it ( 'should simplify longer polylines' , function ( ) {
20
41
21
42
var poly = [
22
43
[ 0 , 0 ] ,
@@ -31,12 +52,17 @@ describe('simplify', function() {
31
52
[ 9 , 9 ]
32
53
] ;
33
54
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
+ ] ) ;
35
61
36
62
} ) ;
37
63
38
64
39
- it ( 'should simplify longer polylines using custom properties' , function ( ) {
65
+ it ( 'should simplify longer polylines using custom properties' , function ( ) {
40
66
41
67
function area ( a , b , c ) {
42
68
return Math . abs (
@@ -46,29 +72,29 @@ describe('simplify', function() {
46
72
}
47
73
48
74
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' }
59
85
] ;
60
86
61
87
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' }
66
92
] ) ;
67
93
68
94
} ) ;
69
95
70
96
71
- it ( 'should keep the ends of the straight line' , function ( ) {
97
+ it ( 'should keep the ends of the straight line' , function ( ) {
72
98
73
99
var poly = [
74
100
[ - 3 , - 3 ] ,
@@ -78,14 +104,20 @@ describe('simplify', function() {
78
104
[ 5 , 5 ]
79
105
] ;
80
106
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
+ ] ) ;
83
115
} ) ;
84
116
85
117
it ( 'should remove duplicate stops' , function ( ) {
86
118
var poly = [
87
- [ - 91.9655 , 39.55001 ] ,
88
- [ - 91.9655 , 39.55001 ] ,
119
+ [ - 91.9655 , 39.55001 ] ,
120
+ [ - 91.9655 , 39.55001 ] ,
89
121
[ - 91.96581 , 39.55024 ] ,
90
122
[ - 91.96596 , 39.55041 ] ,
91
123
[ - 91.96599 , 39.55053 ] ,
@@ -97,7 +129,7 @@ describe('simplify', function() {
97
129
] ;
98
130
99
131
simplify ( poly , 9 ) . should . eql ( [
100
- [ - 91.9655 , 39.55001 ] ,
132
+ [ - 91.9655 , 39.55001 ] ,
101
133
[ - 91.96581 , 39.55024 ] ,
102
134
[ - 91.96596 , 39.55041 ] ,
103
135
[ - 91.96599 , 39.55053 ] ,
@@ -109,15 +141,27 @@ describe('simplify', function() {
109
141
} ) ;
110
142
111
143
112
- it ( 'should simplify longer polyline' , function ( ) {
144
+ it ( 'should simplify longer polyline' , function ( ) {
113
145
var poly = require ( './fixtures/long.json' ) ;
114
146
var simplified = require ( './fixtures/simplified-long.json' ) ;
115
147
116
148
simplify ( poly , 40 ) . should . eql ( simplified ) ;
117
149
} ) ;
118
150
119
151
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
+ ] ) ;
122
166
} ) ;
123
167
} ) ;
0 commit comments