simplify_rb 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -2
- data/Rakefile +1 -1
- data/example/example.rb +10 -0
- data/lib/simplify_rb.rb +72 -69
- data/lib/simplify_rb/symbolizer.rb +1 -1
- data/lib/simplify_rb/version.rb +2 -2
- data/spec/fixtures/all-points.yml +200 -0
- data/spec/fixtures/result-fast.yml +66 -0
- data/spec/fixtures/result-high-quality.yml +66 -0
- data/spec/simplify_rb_spec.rb +19 -14
- data/spec/symbolizer_spec.rb +1 -1
- metadata +8 -3
- data/spec/fixtures/simplify_test_data.rb +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25ddf7e1fd393b6bcfe5c5f13a07fe3d01de5077
|
4
|
+
data.tar.gz: 2f46c665b134257da7bb0f0a205386d7e7c72a57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87e8a58fa61d2afcc0d3b769e9f2713639b980a180efc7382430dbf38521a6edc09e2442751c5d6b11fc8dd38a867b49ca3c073db1915b8c697a87add825571f
|
7
|
+
data.tar.gz: be9911eedb076f6fc15b4e6ff03587c785b654e6a51e668f2f8785bfa77a3612b1ae807039d2c0b19f0782f1223f0cba33ee763232d54f1580b2ae2d8d042f3f
|
data/README.md
CHANGED
@@ -25,11 +25,14 @@ Or install it yourself as:
|
|
25
25
|
```ruby
|
26
26
|
require 'simplify_rb'
|
27
27
|
|
28
|
-
points = [
|
28
|
+
points = [
|
29
|
+
{ x: 51.5256, y: -0.0875 },
|
30
|
+
{ x: 51.7823, y: -0.0912 }
|
31
|
+
]
|
29
32
|
tolerance = 1
|
30
33
|
high_quality = true
|
31
34
|
|
32
|
-
SimplifyRb.
|
35
|
+
SimplifyRb::Simplifier.new.process(points, tolerance, high_quality)
|
33
36
|
```
|
34
37
|
|
35
38
|
```points```: An array of hashes, containing x,y coordinates.
|
data/Rakefile
CHANGED
data/example/example.rb
ADDED
data/lib/simplify_rb.rb
CHANGED
@@ -1,104 +1,107 @@
|
|
1
1
|
require 'simplify_rb/version'
|
2
2
|
require 'simplify_rb/symbolizer'
|
3
3
|
|
4
|
-
|
4
|
+
module SimplifyRb
|
5
|
+
class Simplifier
|
6
|
+
def process(points, tolerance = 1, highest_quality = false)
|
7
|
+
raise ArgumentError.new('Points must be an array') unless points.is_a? Array
|
5
8
|
|
6
|
-
|
7
|
-
raise ArgumentError.new('Points must be an array') unless points.is_a? Array
|
9
|
+
return points if points.length <= 1
|
8
10
|
|
9
|
-
|
11
|
+
symbolizer = Symbolizer.new
|
10
12
|
|
11
|
-
|
13
|
+
points = symbolizer.symbolize_keys(points) unless points.all? { |p| symbolizer.keys_are_symbols?(p.keys) }
|
12
14
|
|
13
|
-
|
15
|
+
sq_tolerance = tolerance * tolerance
|
14
16
|
|
15
|
-
|
17
|
+
# Optimisation step 1
|
18
|
+
points = simplify_radial_dist(points, sq_tolerance) unless highest_quality
|
16
19
|
|
17
|
-
|
18
|
-
|
20
|
+
# Optimisation step 2
|
21
|
+
simplify_douglas_peucker(points, sq_tolerance)
|
22
|
+
end
|
19
23
|
|
20
|
-
|
21
|
-
simplify_douglas_peucker(points, sq_tolerance)
|
22
|
-
end
|
24
|
+
private
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
# Basic distance-based simplification
|
27
|
+
def simplify_radial_dist(points, sq_tolerance)
|
28
|
+
new_points = [points.first]
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
points.each do |point|
|
31
|
+
new_points << point if (get_sq_dist(point, new_points.last) > sq_tolerance)
|
32
|
+
end
|
31
33
|
|
32
|
-
|
34
|
+
new_points << points.last unless new_points.last == points.last
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
+
new_points
|
37
|
+
end
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
# Simplification using optimized Douglas-Peucker algorithm with recursion elimination
|
40
|
+
def simplify_douglas_peucker(points, sq_tolerance)
|
41
|
+
first = 0
|
42
|
+
last = points.length - 1
|
43
|
+
index = nil
|
44
|
+
stack = []
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
+
points.first[:keep] = true
|
47
|
+
points.last[:keep] = true
|
46
48
|
|
47
|
-
|
48
|
-
|
49
|
+
while last
|
50
|
+
max_sq_dist = 0
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
+
((first + 1)...last).each do |i|
|
53
|
+
sq_dist = get_sq_seg_dist(points[i], points[first], points[last])
|
52
54
|
|
53
|
-
|
54
|
-
|
55
|
-
|
55
|
+
if sq_dist > max_sq_dist
|
56
|
+
index = i
|
57
|
+
max_sq_dist = sq_dist
|
58
|
+
end
|
56
59
|
end
|
57
|
-
end
|
58
60
|
|
59
|
-
|
60
|
-
|
61
|
+
if max_sq_dist > sq_tolerance
|
62
|
+
points[index][:keep] = true
|
61
63
|
|
62
|
-
|
63
|
-
|
64
|
+
stack.push(first, index, index, last)
|
65
|
+
end
|
64
66
|
|
65
|
-
|
66
|
-
|
67
|
+
first, last = stack.pop(2)
|
68
|
+
end # end while
|
67
69
|
|
68
|
-
|
69
|
-
|
70
|
+
points.select { |p| p[:keep] && p.delete(:keep) }
|
71
|
+
end
|
70
72
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
73
|
+
# Square distance between two points
|
74
|
+
def get_sq_dist(point_1, point_2)
|
75
|
+
dx = point_1[:x] - point_2[:x]
|
76
|
+
dy = point_1[:y] - point_2[:y]
|
75
77
|
|
76
|
-
|
77
|
-
|
78
|
+
dx * dx + dy * dy
|
79
|
+
end
|
78
80
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
81
|
+
# Square distance from a point to a segment
|
82
|
+
def get_sq_seg_dist(point, point_1, point_2)
|
83
|
+
x = point_1[:x]
|
84
|
+
y = point_1[:y]
|
85
|
+
dx = point_2[:x] - x
|
86
|
+
dy = point_2[:y] - y
|
85
87
|
|
86
|
-
|
87
|
-
|
88
|
+
if dx != 0 || dy != 0
|
89
|
+
t = ((point[:x] - x) * dx + (point[:y] - y) * dy) / (dx * dx + dy * dy)
|
88
90
|
|
89
|
-
|
90
|
-
|
91
|
-
|
91
|
+
if t > 1
|
92
|
+
x = point_2[:x]
|
93
|
+
y = point_2[:y]
|
92
94
|
|
93
|
-
|
94
|
-
|
95
|
-
|
95
|
+
elsif t > 0
|
96
|
+
x += dx * t
|
97
|
+
y += dy * t
|
98
|
+
end
|
96
99
|
end
|
97
|
-
end
|
98
100
|
|
99
|
-
|
100
|
-
|
101
|
+
dx = point[:x] - x
|
102
|
+
dy = point[:y] - y
|
101
103
|
|
102
|
-
|
104
|
+
dx * dx + dy * dy
|
105
|
+
end
|
103
106
|
end
|
104
107
|
end
|
data/lib/simplify_rb/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.
|
1
|
+
module SimplifyRb
|
2
|
+
VERSION = "0.2.0"
|
3
3
|
end
|
@@ -0,0 +1,200 @@
|
|
1
|
+
- :x: 224.55
|
2
|
+
:y: 250.15
|
3
|
+
- :x: 226.91
|
4
|
+
:y: 244.19
|
5
|
+
- :x: 233.31
|
6
|
+
:y: 241.45
|
7
|
+
- :x: 234.98
|
8
|
+
:y: 236.06
|
9
|
+
- :x: 244.21
|
10
|
+
:y: 232.76
|
11
|
+
- :x: 262.59
|
12
|
+
:y: 215.31
|
13
|
+
- :x: 267.76
|
14
|
+
:y: 213.81
|
15
|
+
- :x: 273.57
|
16
|
+
:y: 201.84
|
17
|
+
- :x: 273.12
|
18
|
+
:y: 192.16
|
19
|
+
- :x: 277.62
|
20
|
+
:y: 189.03
|
21
|
+
- :x: 280.36
|
22
|
+
:y: 181.41
|
23
|
+
- :x: 286.51
|
24
|
+
:y: 177.74
|
25
|
+
- :x: 292.41
|
26
|
+
:y: 159.37
|
27
|
+
- :x: 296.91
|
28
|
+
:y: 155.64
|
29
|
+
- :x: 314.95
|
30
|
+
:y: 151.37
|
31
|
+
- :x: 319.75
|
32
|
+
:y: 145.16
|
33
|
+
- :x: 330.33
|
34
|
+
:y: 137.57
|
35
|
+
- :x: 341.48
|
36
|
+
:y: 139.96
|
37
|
+
- :x: 369.98
|
38
|
+
:y: 137.89
|
39
|
+
- :x: 387.39
|
40
|
+
:y: 142.51
|
41
|
+
- :x: 391.28
|
42
|
+
:y: 139.39
|
43
|
+
- :x: 409.52
|
44
|
+
:y: 141.14
|
45
|
+
- :x: 414.82
|
46
|
+
:y: 139.75
|
47
|
+
- :x: 427.72
|
48
|
+
:y: 127.30
|
49
|
+
- :x: 439.60
|
50
|
+
:y: 119.74
|
51
|
+
- :x: 474.93
|
52
|
+
:y: 107.87
|
53
|
+
- :x: 486.51
|
54
|
+
:y: 106.75
|
55
|
+
- :x: 489.20
|
56
|
+
:y: 109.45
|
57
|
+
- :x: 493.79
|
58
|
+
:y: 108.63
|
59
|
+
- :x: 504.74
|
60
|
+
:y: 119.66
|
61
|
+
- :x: 512.96
|
62
|
+
:y: 122.35
|
63
|
+
- :x: 518.63
|
64
|
+
:y: 120.89
|
65
|
+
- :x: 524.09
|
66
|
+
:y: 126.88
|
67
|
+
- :x: 529.57
|
68
|
+
:y: 127.86
|
69
|
+
- :x: 534.21
|
70
|
+
:y: 140.93
|
71
|
+
- :x: 539.27
|
72
|
+
:y: 147.24
|
73
|
+
- :x: 567.69
|
74
|
+
:y: 148.91
|
75
|
+
- :x: 575.25
|
76
|
+
:y: 157.26
|
77
|
+
- :x: 580.62
|
78
|
+
:y: 158.15
|
79
|
+
- :x: 601.53
|
80
|
+
:y: 156.85
|
81
|
+
- :x: 617.74
|
82
|
+
:y: 159.86
|
83
|
+
- :x: 622.00
|
84
|
+
:y: 167.04
|
85
|
+
- :x: 629.55
|
86
|
+
:y: 194.60
|
87
|
+
- :x: 638.90
|
88
|
+
:y: 195.61
|
89
|
+
- :x: 641.26
|
90
|
+
:y: 200.81
|
91
|
+
- :x: 651.77
|
92
|
+
:y: 204.56
|
93
|
+
- :x: 671.55
|
94
|
+
:y: 222.55
|
95
|
+
- :x: 683.68
|
96
|
+
:y: 217.45
|
97
|
+
- :x: 695.25
|
98
|
+
:y: 219.15
|
99
|
+
- :x: 700.64
|
100
|
+
:y: 217.98
|
101
|
+
- :x: 703.12
|
102
|
+
:y: 214.36
|
103
|
+
- :x: 712.26
|
104
|
+
:y: 215.87
|
105
|
+
- :x: 721.49
|
106
|
+
:y: 212.81
|
107
|
+
- :x: 727.81
|
108
|
+
:y: 213.36
|
109
|
+
- :x: 729.98
|
110
|
+
:y: 208.73
|
111
|
+
- :x: 735.32
|
112
|
+
:y: 208.20
|
113
|
+
- :x: 739.94
|
114
|
+
:y: 204.77
|
115
|
+
- :x: 769.98
|
116
|
+
:y: 208.42
|
117
|
+
- :x: 779.60
|
118
|
+
:y: 216.87
|
119
|
+
- :x: 784.20
|
120
|
+
:y: 218.16
|
121
|
+
- :x: 800.24
|
122
|
+
:y: 214.62
|
123
|
+
- :x: 810.53
|
124
|
+
:y: 219.73
|
125
|
+
- :x: 817.19
|
126
|
+
:y: 226.82
|
127
|
+
- :x: 820.77
|
128
|
+
:y: 236.17
|
129
|
+
- :x: 827.23
|
130
|
+
:y: 236.16
|
131
|
+
- :x: 829.89
|
132
|
+
:y: 239.89
|
133
|
+
- :x: 851.00
|
134
|
+
:y: 248.94
|
135
|
+
- :x: 859.88
|
136
|
+
:y: 255.49
|
137
|
+
- :x: 865.21
|
138
|
+
:y: 268.53
|
139
|
+
- :x: 857.95
|
140
|
+
:y: 280.30
|
141
|
+
- :x: 865.48
|
142
|
+
:y: 291.45
|
143
|
+
- :x: 866.81
|
144
|
+
:y: 298.66
|
145
|
+
- :x: 864.68
|
146
|
+
:y: 302.71
|
147
|
+
- :x: 867.79
|
148
|
+
:y: 306.17
|
149
|
+
- :x: 859.87
|
150
|
+
:y: 311.37
|
151
|
+
- :x: 860.08
|
152
|
+
:y: 314.35
|
153
|
+
- :x: 858.29
|
154
|
+
:y: 314.94
|
155
|
+
- :x: 858.10
|
156
|
+
:y: 327.60
|
157
|
+
- :x: 854.54
|
158
|
+
:y: 335.40
|
159
|
+
- :x: 860.92
|
160
|
+
:y: 343.00
|
161
|
+
- :x: 856.43
|
162
|
+
:y: 350.15
|
163
|
+
- :x: 851.42
|
164
|
+
:y: 352.96
|
165
|
+
- :x: 849.84
|
166
|
+
:y: 359.59
|
167
|
+
- :x: 854.56
|
168
|
+
:y: 365.53
|
169
|
+
- :x: 849.74
|
170
|
+
:y: 370.38
|
171
|
+
- :x: 844.09
|
172
|
+
:y: 371.89
|
173
|
+
- :x: 844.75
|
174
|
+
:y: 380.44
|
175
|
+
- :x: 841.52
|
176
|
+
:y: 383.67
|
177
|
+
- :x: 839.57
|
178
|
+
:y: 390.40
|
179
|
+
- :x: 845.59
|
180
|
+
:y: 399.05
|
181
|
+
- :x: 848.40
|
182
|
+
:y: 407.55
|
183
|
+
- :x: 843.71
|
184
|
+
:y: 411.30
|
185
|
+
- :x: 844.09
|
186
|
+
:y: 419.88
|
187
|
+
- :x: 839.51
|
188
|
+
:y: 432.76
|
189
|
+
- :x: 841.33
|
190
|
+
:y: 441.04
|
191
|
+
- :x: 847.62
|
192
|
+
:y: 449.22
|
193
|
+
- :x: 847.16
|
194
|
+
:y: 458.44
|
195
|
+
- :x: 851.38
|
196
|
+
:y: 462.79
|
197
|
+
- :x: 853.97
|
198
|
+
:y: 471.15
|
199
|
+
- :x: 866.36
|
200
|
+
:y: 480.77
|
@@ -0,0 +1,66 @@
|
|
1
|
+
- :x: 224.55
|
2
|
+
:y: 250.15
|
3
|
+
- :x: 267.76
|
4
|
+
:y: 213.81
|
5
|
+
- :x: 296.91
|
6
|
+
:y: 155.64
|
7
|
+
- :x: 330.33
|
8
|
+
:y: 137.57
|
9
|
+
- :x: 409.52
|
10
|
+
:y: 141.14
|
11
|
+
- :x: 439.6
|
12
|
+
:y: 119.74
|
13
|
+
- :x: 486.51
|
14
|
+
:y: 106.75
|
15
|
+
- :x: 529.57
|
16
|
+
:y: 127.86
|
17
|
+
- :x: 539.27
|
18
|
+
:y: 147.24
|
19
|
+
- :x: 617.74
|
20
|
+
:y: 159.86
|
21
|
+
- :x: 629.55
|
22
|
+
:y: 194.6
|
23
|
+
- :x: 671.55
|
24
|
+
:y: 222.55
|
25
|
+
- :x: 727.81
|
26
|
+
:y: 213.36
|
27
|
+
- :x: 739.94
|
28
|
+
:y: 204.77
|
29
|
+
- :x: 769.98
|
30
|
+
:y: 208.42
|
31
|
+
- :x: 779.6
|
32
|
+
:y: 216.87
|
33
|
+
- :x: 800.24
|
34
|
+
:y: 214.62
|
35
|
+
- :x: 820.77
|
36
|
+
:y: 236.17
|
37
|
+
- :x: 859.88
|
38
|
+
:y: 255.49
|
39
|
+
- :x: 865.21
|
40
|
+
:y: 268.53
|
41
|
+
- :x: 857.95
|
42
|
+
:y: 280.3
|
43
|
+
- :x: 867.79
|
44
|
+
:y: 306.17
|
45
|
+
- :x: 859.87
|
46
|
+
:y: 311.37
|
47
|
+
- :x: 854.54
|
48
|
+
:y: 335.4
|
49
|
+
- :x: 860.92
|
50
|
+
:y: 343
|
51
|
+
- :x: 849.84
|
52
|
+
:y: 359.59
|
53
|
+
- :x: 854.56
|
54
|
+
:y: 365.53
|
55
|
+
- :x: 844.09
|
56
|
+
:y: 371.89
|
57
|
+
- :x: 839.57
|
58
|
+
:y: 390.4
|
59
|
+
- :x: 848.4
|
60
|
+
:y: 407.55
|
61
|
+
- :x: 839.51
|
62
|
+
:y: 432.76
|
63
|
+
- :x: 853.97
|
64
|
+
:y: 471.15
|
65
|
+
- :x: 866.36
|
66
|
+
:y: 480.77
|
@@ -0,0 +1,66 @@
|
|
1
|
+
- :x: 224.55
|
2
|
+
:y: 250.15
|
3
|
+
- :x: 267.76
|
4
|
+
:y: 213.81
|
5
|
+
- :x: 296.91
|
6
|
+
:y: 155.64
|
7
|
+
- :x: 330.33
|
8
|
+
:y: 137.57
|
9
|
+
- :x: 409.52
|
10
|
+
:y: 141.14
|
11
|
+
- :x: 439.6
|
12
|
+
:y: 119.74
|
13
|
+
- :x: 486.51
|
14
|
+
:y: 106.75
|
15
|
+
- :x: 529.57
|
16
|
+
:y: 127.86
|
17
|
+
- :x: 539.27
|
18
|
+
:y: 147.24
|
19
|
+
- :x: 617.74
|
20
|
+
:y: 159.86
|
21
|
+
- :x: 629.55
|
22
|
+
:y: 194.6
|
23
|
+
- :x: 671.55
|
24
|
+
:y: 222.55
|
25
|
+
- :x: 727.81
|
26
|
+
:y: 213.36
|
27
|
+
- :x: 739.94
|
28
|
+
:y: 204.77
|
29
|
+
- :x: 769.98
|
30
|
+
:y: 208.42
|
31
|
+
- :x: 784.2
|
32
|
+
:y: 218.16
|
33
|
+
- :x: 800.24
|
34
|
+
:y: 214.62
|
35
|
+
- :x: 820.77
|
36
|
+
:y: 236.17
|
37
|
+
- :x: 859.88
|
38
|
+
:y: 255.49
|
39
|
+
- :x: 865.21
|
40
|
+
:y: 268.53
|
41
|
+
- :x: 857.95
|
42
|
+
:y: 280.3
|
43
|
+
- :x: 867.79
|
44
|
+
:y: 306.17
|
45
|
+
- :x: 858.29
|
46
|
+
:y: 314.94
|
47
|
+
- :x: 854.54
|
48
|
+
:y: 335.4
|
49
|
+
- :x: 860.92
|
50
|
+
:y: 343
|
51
|
+
- :x: 849.84
|
52
|
+
:y: 359.59
|
53
|
+
- :x: 854.56
|
54
|
+
:y: 365.53
|
55
|
+
- :x: 844.09
|
56
|
+
:y: 371.89
|
57
|
+
- :x: 839.57
|
58
|
+
:y: 390.4
|
59
|
+
- :x: 848.4
|
60
|
+
:y: 407.55
|
61
|
+
- :x: 839.51
|
62
|
+
:y: 432.76
|
63
|
+
- :x: 853.97
|
64
|
+
:y: 471.15
|
65
|
+
- :x: 866.36
|
66
|
+
:y: 480.77
|
data/spec/simplify_rb_spec.rb
CHANGED
@@ -1,43 +1,48 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'simplify_rb'
|
3
|
-
require
|
3
|
+
require 'yaml'
|
4
4
|
|
5
|
-
describe SimplifyRb do
|
6
|
-
describe '#
|
5
|
+
describe SimplifyRb::Simplifier do
|
6
|
+
describe '#process' do
|
7
7
|
context 'simplifies points correctly with the given tolerance' do
|
8
|
-
let(:test_data) {
|
9
|
-
let(:
|
10
|
-
let(:
|
8
|
+
let(:test_data) { fixture_file('all-points.yml') }
|
9
|
+
let(:expected_result_fast) { fixture_file('result-fast.yml') }
|
10
|
+
let(:expected_result_high_quality) { fixture_file('result-high-quality.yml') }
|
11
11
|
|
12
|
-
it 'uses the fast strategy by default' do
|
13
|
-
result =
|
14
|
-
expect(result).to eq(
|
12
|
+
it 'uses the fast strategy by default', focus: true do
|
13
|
+
result = subject.process(test_data, 5)
|
14
|
+
expect(result).to eq(expected_result_fast)
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'uses the high quality strategy when the flag is passed' do
|
18
|
-
result =
|
19
|
-
expect(result).to eq(
|
18
|
+
result = subject.process(test_data, 5, true)
|
19
|
+
expect(result).to eq(expected_result_high_quality)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
context 'only one point' do
|
24
24
|
it 'returns a list with one point' do
|
25
25
|
data = [{ x: 1, y: 2 }]
|
26
|
-
expect(
|
26
|
+
expect(subject.process(data)).to eq(data)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
context 'no points' do
|
31
31
|
it 'returns an empty list of points' do
|
32
|
-
expect(
|
32
|
+
expect(subject.process([])).to be_empty
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
describe 'unexpected argument' do
|
37
37
|
it 'raises an error if the points are not passsed as an array' do
|
38
38
|
data = { x: 1, y: 2 }
|
39
|
-
expect {
|
39
|
+
expect { subject.process(data) }.to raise_error(ArgumentError, 'Points must be an array')
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
43
|
+
|
44
|
+
def fixture_file(name)
|
45
|
+
path = File.expand_path("../fixtures/#{name}", __FILE__)
|
46
|
+
YAML.load_file(path)
|
47
|
+
end
|
43
48
|
end
|
data/spec/symbolizer_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'simplify_rb/symbolizer'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe SimplifyRb::Symbolizer do
|
5
5
|
describe '#keys_are_symbols?' do
|
6
6
|
it 'returns false if any key is not a Symbol' do
|
7
7
|
expect(subject.keys_are_symbols?([:a, 'b', :c])).to equal(false)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplify_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- odlp
|
@@ -67,11 +67,14 @@ files:
|
|
67
67
|
- LICENSE.txt
|
68
68
|
- README.md
|
69
69
|
- Rakefile
|
70
|
+
- example/example.rb
|
70
71
|
- lib/simplify_rb.rb
|
71
72
|
- lib/simplify_rb/symbolizer.rb
|
72
73
|
- lib/simplify_rb/version.rb
|
73
74
|
- simplify_rb.gemspec
|
74
|
-
- spec/fixtures/
|
75
|
+
- spec/fixtures/all-points.yml
|
76
|
+
- spec/fixtures/result-fast.yml
|
77
|
+
- spec/fixtures/result-high-quality.yml
|
75
78
|
- spec/simplify_rb_spec.rb
|
76
79
|
- spec/spec_helper.rb
|
77
80
|
- spec/symbolizer_spec.rb
|
@@ -100,7 +103,9 @@ signing_key:
|
|
100
103
|
specification_version: 4
|
101
104
|
summary: Polyline simplification library. Ruby port of Simplify.js.
|
102
105
|
test_files:
|
103
|
-
- spec/fixtures/
|
106
|
+
- spec/fixtures/all-points.yml
|
107
|
+
- spec/fixtures/result-fast.yml
|
108
|
+
- spec/fixtures/result-high-quality.yml
|
104
109
|
- spec/simplify_rb_spec.rb
|
105
110
|
- spec/spec_helper.rb
|
106
111
|
- spec/symbolizer_spec.rb
|
@@ -1,57 +0,0 @@
|
|
1
|
-
module SimplifyTestData
|
2
|
-
def self.points
|
3
|
-
[
|
4
|
-
{x:224.55,y:250.15},{x:226.91,y:244.19},{x:233.31,y:241.45},{x:234.98,y:236.06},
|
5
|
-
{x:244.21,y:232.76},{x:262.59,y:215.31},{x:267.76,y:213.81},{x:273.57,y:201.84},
|
6
|
-
{x:273.12,y:192.16},{x:277.62,y:189.03},{x:280.36,y:181.41},{x:286.51,y:177.74},
|
7
|
-
{x:292.41,y:159.37},{x:296.91,y:155.64},{x:314.95,y:151.37},{x:319.75,y:145.16},
|
8
|
-
{x:330.33,y:137.57},{x:341.48,y:139.96},{x:369.98,y:137.89},{x:387.39,y:142.51},
|
9
|
-
{x:391.28,y:139.39},{x:409.52,y:141.14},{x:414.82,y:139.75},{x:427.72,y:127.30},
|
10
|
-
{x:439.60,y:119.74},{x:474.93,y:107.87},{x:486.51,y:106.75},{x:489.20,y:109.45},
|
11
|
-
{x:493.79,y:108.63},{x:504.74,y:119.66},{x:512.96,y:122.35},{x:518.63,y:120.89},
|
12
|
-
{x:524.09,y:126.88},{x:529.57,y:127.86},{x:534.21,y:140.93},{x:539.27,y:147.24},
|
13
|
-
{x:567.69,y:148.91},{x:575.25,y:157.26},{x:580.62,y:158.15},{x:601.53,y:156.85},
|
14
|
-
{x:617.74,y:159.86},{x:622.00,y:167.04},{x:629.55,y:194.60},{x:638.90,y:195.61},
|
15
|
-
{x:641.26,y:200.81},{x:651.77,y:204.56},{x:671.55,y:222.55},{x:683.68,y:217.45},
|
16
|
-
{x:695.25,y:219.15},{x:700.64,y:217.98},{x:703.12,y:214.36},{x:712.26,y:215.87},
|
17
|
-
{x:721.49,y:212.81},{x:727.81,y:213.36},{x:729.98,y:208.73},{x:735.32,y:208.20},
|
18
|
-
{x:739.94,y:204.77},{x:769.98,y:208.42},{x:779.60,y:216.87},{x:784.20,y:218.16},
|
19
|
-
{x:800.24,y:214.62},{x:810.53,y:219.73},{x:817.19,y:226.82},{x:820.77,y:236.17},
|
20
|
-
{x:827.23,y:236.16},{x:829.89,y:239.89},{x:851.00,y:248.94},{x:859.88,y:255.49},
|
21
|
-
{x:865.21,y:268.53},{x:857.95,y:280.30},{x:865.48,y:291.45},{x:866.81,y:298.66},
|
22
|
-
{x:864.68,y:302.71},{x:867.79,y:306.17},{x:859.87,y:311.37},{x:860.08,y:314.35},
|
23
|
-
{x:858.29,y:314.94},{x:858.10,y:327.60},{x:854.54,y:335.40},{x:860.92,y:343.00},
|
24
|
-
{x:856.43,y:350.15},{x:851.42,y:352.96},{x:849.84,y:359.59},{x:854.56,y:365.53},
|
25
|
-
{x:849.74,y:370.38},{x:844.09,y:371.89},{x:844.75,y:380.44},{x:841.52,y:383.67},
|
26
|
-
{x:839.57,y:390.40},{x:845.59,y:399.05},{x:848.40,y:407.55},{x:843.71,y:411.30},
|
27
|
-
{x:844.09,y:419.88},{x:839.51,y:432.76},{x:841.33,y:441.04},{x:847.62,y:449.22},
|
28
|
-
{x:847.16,y:458.44},{x:851.38,y:462.79},{x:853.97,y:471.15},{x:866.36,y:480.77}
|
29
|
-
]
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.result_fast
|
33
|
-
[
|
34
|
-
{x:224.55,y:250.15},{x:267.76,y:213.81},{x:296.91,y:155.64},{x:330.33,y:137.57},
|
35
|
-
{x:409.52,y:141.14},{x:439.6,y:119.74},{x:486.51,y:106.75},{x:529.57,y:127.86},
|
36
|
-
{x:539.27,y:147.24},{x:617.74,y:159.86},{x:629.55,y:194.6},{x:671.55,y:222.55},
|
37
|
-
{x:727.81,y:213.36},{x:739.94,y:204.77},{x:769.98,y:208.42},{x:779.6,y:216.87},
|
38
|
-
{x:800.24,y:214.62},{x:820.77,y:236.17},{x:859.88,y:255.49},{x:865.21,y:268.53},
|
39
|
-
{x:857.95,y:280.3},{x:867.79,y:306.17},{x:859.87,y:311.37},{x:854.54,y:335.4},
|
40
|
-
{x:860.92,y:343},{x:849.84,y:359.59},{x:854.56,y:365.53},{x:844.09,y:371.89},
|
41
|
-
{x:839.57,y:390.4},{x:848.4,y:407.55},{x:839.51,y:432.76},{x:853.97,y:471.15},
|
42
|
-
{x:866.36,y:480.77}]
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.result_high_quality
|
46
|
-
[{x:224.55,y:250.15},{x:267.76,y:213.81},{x:296.91,y:155.64},{x:330.33,y:137.57},
|
47
|
-
{x:409.52,y:141.14},{x:439.6,y:119.74},{x:486.51,y:106.75},{x:529.57,y:127.86},
|
48
|
-
{x:539.27,y:147.24},{x:617.74,y:159.86},{x:629.55,y:194.6},{x:671.55,y:222.55},
|
49
|
-
{x:727.81,y:213.36},{x:739.94,y:204.77},{x:769.98,y:208.42},{x:784.2,y:218.16},
|
50
|
-
{x:800.24,y:214.62},{x:820.77,y:236.17},{x:859.88,y:255.49},{x:865.21,y:268.53},
|
51
|
-
{x:857.95,y:280.3},{x:867.79,y:306.17},{x:858.29,y:314.94},{x:854.54,y:335.4},
|
52
|
-
{x:860.92,y:343},{x:849.84,y:359.59},{x:854.56,y:365.53},{x:844.09,y:371.89},
|
53
|
-
{x:839.57,y:390.4},{x:848.4,y:407.55},{x:839.51,y:432.76},{x:853.97,y:471.15},
|
54
|
-
{x:866.36,y:480.77}
|
55
|
-
]
|
56
|
-
end
|
57
|
-
end
|