douglas_peucker 0.0.1

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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in douglas_peucker.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2011 Josh Clayton
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,24 @@
1
+ # Douglas-Peucker Algorithm
2
+
3
+ This algorithm simplifies a line by recursively dividing a line and removing points outside of a predefined threshold. Check out the [Wikipedia page](http://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm) to read up on it more.
4
+
5
+ ## Usage
6
+
7
+ >> require "douglas_peucker"
8
+ => true
9
+ >> line = [[0, 0], [1, 1], [2, 1], [3, 2.5], [4, 4]]
10
+ => [[0, 0], [1, 1], [2, 1], [3, 2.5], [4, 4]]
11
+ >> DouglasPeucker::LineSimplifier.new(line).threshold(1).points
12
+ => [[0, 0], [4, 4]]
13
+ >> DouglasPeucker::LineSimplifier.new(line).threshold(0.5).points
14
+ => [[0, 0], [2, 1], [4, 4]]
15
+ >> DouglasPeucker::LineSimplifier.new(line).points
16
+ => [[0, 0], [1, 1], [2, 1], [4, 4]]
17
+
18
+ ## License
19
+
20
+ See the LICENSE
21
+
22
+ ## Author
23
+
24
+ Written by Josh Clayton, although the algorithm and its various implementations have been written before.
@@ -0,0 +1,7 @@
1
+ require "bundler"
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require "rspec/core/rake_task"
5
+ RSpec::Core::RakeTask.new(:rspec)
6
+
7
+ task :default => [:rspec]
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "douglas_peucker/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "douglas_peucker"
7
+ s.version = DouglasPeucker::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Josh Clayton"]
10
+ s.email = ["joshua.clayton@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{A Ruby implementation of the Douglas–Peucker algorithm}
13
+ s.summary = %q{A Ruby implementation of the Douglas–Peucker algorithm}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_development_dependency("rspec", "~> 2.6.0")
21
+ end
@@ -0,0 +1,7 @@
1
+ module DouglasPeucker
2
+ autoload :Line, "douglas_peucker/line"
3
+ autoload :Point, "douglas_peucker/point"
4
+ autoload :OrthogonalDistance, "douglas_peucker/orthogonal_distance"
5
+ autoload :LineSimplifier, "douglas_peucker/line_simplifier"
6
+ autoload :Version, "douglas_peucker/version"
7
+ end
@@ -0,0 +1,3 @@
1
+ module DouglasPeucker
2
+ class Line < Struct.new(:start, :end); end
3
+ end
@@ -0,0 +1,50 @@
1
+ module DouglasPeucker
2
+ class LineSimplifier
3
+
4
+ def initialize(points)
5
+ @points = points
6
+ @threshold = 10e-8
7
+ end
8
+
9
+ def threshold(threshold)
10
+ @threshold = threshold
11
+ self
12
+ end
13
+
14
+ def points
15
+ calculate_points(@points)
16
+ end
17
+
18
+ private
19
+
20
+ def orthogonal_distance(point, line_start, line_end)
21
+ line = Line.new(Point.new(line_start[0], line_start[1]), Point.new(line_end[0], line_end[1]))
22
+ point = Point.new(point[0], point[1])
23
+ OrthogonalDistance.new(point, line).distance
24
+ end
25
+
26
+ def calculate_points(points)
27
+ return points if points.length < 3
28
+
29
+ maximum_distance = 0
30
+ index = 0
31
+
32
+ (1..(points.length - 1)).each do |i|
33
+ current_distance = orthogonal_distance(points[i], points.first, points.last)
34
+ if current_distance > maximum_distance
35
+ index = i
36
+ maximum_distance = current_distance
37
+ end
38
+ end
39
+
40
+ if maximum_distance >= @threshold
41
+ results_1 = calculate_points(points[0..index])
42
+ results_2 = calculate_points(points[index..-1])
43
+
44
+ results_1[0..-2] + results_2
45
+ else
46
+ [points.first, points.last]
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,18 @@
1
+ module DouglasPeucker
2
+ # From http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html
3
+ class OrthogonalDistance < Struct.new(:point, :line)
4
+ def distance
5
+ numerator.abs/denominator**0.5
6
+ end
7
+
8
+ private
9
+
10
+ def numerator
11
+ ((line.end.x - line.start.x)*(line.start.y - point.y) - (line.start.x - point.x)*(line.end.y - line.start.y))
12
+ end
13
+
14
+ def denominator
15
+ (line.end.x - line.start.x)**2 + (line.end.y - line.start.y)**2
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module DouglasPeucker
2
+ class Point < Struct.new(:x, :y); end
3
+ end
@@ -0,0 +1,3 @@
1
+ module DouglasPeucker
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,459 @@
1
+ require "spec_helper"
2
+
3
+ describe DouglasPeucker::LineSimplifier, "with two points" do
4
+ let(:line) { [[0, 0], [99, 1]] }
5
+
6
+ it "returns both points with a small threshold" do
7
+ DouglasPeucker::LineSimplifier.new(line).threshold(10e-5).points.should == line
8
+ end
9
+
10
+ it "returns both points with a big threshold" do
11
+ DouglasPeucker::LineSimplifier.new(line).threshold(99).points.should == line
12
+ end
13
+ end
14
+
15
+ describe DouglasPeucker::LineSimplifier, "with a simple line" do
16
+ let(:line) { [[0, 0], [2, 0], [4, 4]] }
17
+
18
+ it "includes all three points if threshold is zero" do
19
+ DouglasPeucker::LineSimplifier.new(line).threshold(10e-5).points.should == line
20
+ end
21
+
22
+ it "includes all three points if threshold is too small" do
23
+ DouglasPeucker::LineSimplifier.new(line).threshold(1).points.should == line
24
+ DouglasPeucker::LineSimplifier.new(line).threshold((2**0.5).round(5)).points.should == line
25
+ end
26
+
27
+ it "excludes points if threshold is big enough" do
28
+ DouglasPeucker::LineSimplifier.new(line).threshold((2**0.5) + 0.3).points.should == [[0, 0], [4, 4]]
29
+ end
30
+ end
31
+
32
+ describe DouglasPeucker::LineSimplifier, "with a bigger line" do
33
+ let(:line) do
34
+ [
35
+ [0, 0],
36
+ [1, 1],
37
+ [2, 1],
38
+ [3, 2.5],
39
+ [4, 4]
40
+ ]
41
+ end
42
+
43
+ it "oversimplifies with a large threshold" do
44
+ DouglasPeucker::LineSimplifier.new(line).threshold(2).points.should == [[0, 0], [4, 4]]
45
+ end
46
+ end
47
+
48
+ # List of points from
49
+ # http://www.phpriot.com/articles/reducing-map-path-douglas-peucker-algorithm/4
50
+ describe DouglasPeucker::LineSimplifier, "with a massive line" do
51
+ let(:line) do
52
+ [
53
+ [-33.3240789844364,115.638325287067],
54
+ [-33.3240755555556,115.638360555556],
55
+ [-33.3240722222222,115.638396666667],
56
+ [-33.3240783333333,115.638419444444],
57
+ [-33.3246238888889,115.638753333333],
58
+ [-33.3246716666667,115.638813888889],
59
+ [-33.3247216666667,115.638857777778],
60
+ [-33.3247783333333,115.638908333333],
61
+ [-33.3248188888889,115.638933333333],
62
+ [-33.3248483333333,115.638941666667],
63
+ [-33.3248366666667,115.63901],
64
+ [-33.3246905555556,115.639496666667],
65
+ [-33.3244577777778,115.639959444444],
66
+ [-33.3243933333333,115.640034444444],
67
+ [-33.3247722222222,115.64049],
68
+ [-33.3250116666667,115.640761666667],
69
+ [-33.3252088888889,115.640923888889],
70
+ [-33.3254516666667,115.641070555556],
71
+ [-33.3258016666667,115.641201666667],
72
+ [-33.3260861111111,115.641242777778],
73
+ [-33.3262483333333,115.641245555556],
74
+ [-33.3264027777778,115.641217777778],
75
+ [-33.3266022222222,115.64116],
76
+ [-33.3267394444444,115.641115555556],
77
+ [-33.3271016666667,115.640994444444],
78
+ [-33.32748,115.640953888889],
79
+ [-33.3278433333333,115.640965],
80
+ [-33.3278988888889,115.640971666667],
81
+ [-33.3280316666667,115.641007222222],
82
+ [-33.3282477777778,115.641089444444],
83
+ [-33.3284666666667,115.641213888889],
84
+ [-33.3286688888889,115.641335],
85
+ [-33.3292377777778,115.641728333333],
86
+ [-33.3297683333333,115.642054444444],
87
+ [-33.3307816666667,115.642637222222],
88
+ [-33.3316822222222,115.643195],
89
+ [-33.3317516666667,115.643238333333],
90
+ [-33.3336577777778,115.644440555556],
91
+ [-33.3339866666667,115.644631666667],
92
+ [-33.3348883333333,115.645208333333],
93
+ [-33.33618,115.646065555556],
94
+ [-33.3363022222222,115.646147777778],
95
+ [-33.3365594444444,115.646294444444],
96
+ [-33.33716,115.646660555556],
97
+ [-33.3372666666667,115.646722777778],
98
+ [-33.3375916666667,115.646892222222],
99
+ [-33.3383216666667,115.647232777778],
100
+ [-33.3385261111111,115.647322777778],
101
+ [-33.3386222222222,115.647397777778],
102
+ [-33.3389205555556,115.647555555556],
103
+ [-33.3395622222222,115.647913333333],
104
+ [-33.3399055555556,115.648169444444],
105
+ [-33.34017,115.648402777778],
106
+ [-33.3402622222222,115.648500555556],
107
+ [-33.3405927777778,115.648932777778],
108
+ [-33.3407822222222,115.649263333333],
109
+ [-33.3408994444444,115.649528888889],
110
+ [-33.3409622222222,115.64974],
111
+ [-33.3409805555556,115.649866111111],
112
+ [-33.3410077777778,115.650059444444],
113
+ [-33.3410266666667,115.650232777778],
114
+ [-33.3410333333333,115.650487222222],
115
+ [-33.3410283333333,115.650679444444],
116
+ [-33.341005,115.650836666667],
117
+ [-33.3409177777778,115.651433888889],
118
+ [-33.3408427777778,115.651975555556],
119
+ [-33.3407094444444,115.652796666667],
120
+ [-33.340705,115.652825],
121
+ [-33.34062,115.653385555556],
122
+ [-33.3405794444444,115.653650555556],
123
+ [-33.3405572222222,115.653795555556],
124
+ [-33.340415,115.654651111111],
125
+ [-33.3401177777778,115.654593333333],
126
+ [-33.3396,115.654533888889],
127
+ [-33.3392644444444,115.654541666667],
128
+ [-33.3386505555556,115.654514444444],
129
+ [-33.3384444444444,115.654475555556],
130
+ [-33.3383433333333,115.654471111111],
131
+ [-33.337535,115.654371666667],
132
+ [-33.3364127777778,115.654178888889],
133
+ [-33.336375,115.654177222222],
134
+ [-33.3363755555556,115.65417],
135
+ [-33.3363755555556,115.654162222222],
136
+ [-33.3363755555556,115.654153888889],
137
+ [-33.3363744444444,115.654145555556],
138
+ [-33.3363733333333,115.654137777778],
139
+ [-33.3363716666667,115.654129444444],
140
+ [-33.3363694444444,115.654121666667],
141
+ [-33.3363672222222,115.654114444444],
142
+ [-33.3363638888889,115.654106666667],
143
+ [-33.3363605555556,115.654099444444],
144
+ [-33.3363566666667,115.654092777778],
145
+ [-33.3363527777778,115.654086111111],
146
+ [-33.3363483333333,115.65408],
147
+ [-33.3363433333333,115.654073888889],
148
+ [-33.3363383333333,115.654068888889],
149
+ [-33.3363327777778,115.654063888889],
150
+ [-33.3363272222222,115.654058888889],
151
+ [-33.3363211111111,115.654055],
152
+ [-33.336315,115.654051666667],
153
+ [-33.3363083333333,115.654048333333],
154
+ [-33.3363022222222,115.654045555556],
155
+ [-33.3362955555556,115.654043333333],
156
+ [-33.3362883333333,115.654042222222],
157
+ [-33.3362816666667,115.654041111111],
158
+ [-33.336275,115.654040555556],
159
+ [-33.3362677777778,115.654040555556],
160
+ [-33.3362611111111,115.654041111111],
161
+ [-33.3362544444444,115.654042222222],
162
+ [-33.3362477777778,115.654044444444],
163
+ [-33.3362411111111,115.654046666667],
164
+ [-33.3362344444444,115.654049444444],
165
+ [-33.3362283333333,115.654052777778],
166
+ [-33.3362222222222,115.654056111111],
167
+ [-33.3362161111111,115.654060555556],
168
+ [-33.3362105555556,115.654065],
169
+ [-33.336205,115.654070555556],
170
+ [-33.3362,115.654076111111],
171
+ [-33.3361955555556,115.654081666667],
172
+ [-33.3361911111111,115.654088333333],
173
+ [-33.3361872222222,115.654095],
174
+ [-33.3361833333333,115.654101666667],
175
+ [-33.33618,115.654108888889],
176
+ [-33.3361772222222,115.654116666667],
177
+ [-33.336175,115.654124444444],
178
+ [-33.3361727777778,115.654132222222],
179
+ [-33.3361711111111,115.65414],
180
+ [-33.3361705555556,115.654148333333],
181
+ [-33.3361694444444,115.654156666667],
182
+ [-33.3361694444444,115.654164444444],
183
+ [-33.33617,115.654172777778],
184
+ [-33.3361705555556,115.654181111111],
185
+ [-33.3361716666667,115.654188888889],
186
+ [-33.3361733333333,115.654197222222],
187
+ [-33.3361755555556,115.654205],
188
+ [-33.3361783333333,115.654212222222],
189
+ [-33.3361811111111,115.65422],
190
+ [-33.3361844444444,115.654227222222],
191
+ [-33.3361883333333,115.654233888889],
192
+ [-33.3361922222222,115.654240555556],
193
+ [-33.3361966666667,115.654246666667],
194
+ [-33.3362016666667,115.654252222222],
195
+ [-33.3362066666667,115.654257777778],
196
+ [-33.3362122222222,115.654262777778],
197
+ [-33.3362177777778,115.654267222222],
198
+ [-33.3362238888889,115.654271666667],
199
+ [-33.33623,115.654275],
200
+ [-33.3362366666667,115.654278333333],
201
+ [-33.3362433333333,115.654281111111],
202
+ [-33.33625,115.654282777778],
203
+ [-33.3362566666667,115.654284444444],
204
+ [-33.3362633333333,115.654285555556],
205
+ [-33.3362705555556,115.654286111111],
206
+ [-33.3362594444444,115.657527222222],
207
+ [-33.3362694444444,115.658115],
208
+ [-33.3362772222222,115.661860555556],
209
+ [-33.3362666666667,115.663044444444],
210
+ [-33.3362588888889,115.663943888889],
211
+ [-33.3362666666667,115.664742777778],
212
+ [-33.3362638888889,115.664801111111],
213
+ [-33.3362094444444,115.664952777778],
214
+ [-33.3361661111111,115.665025],
215
+ [-33.3361244444444,115.665072777778],
216
+ [-33.3360622222222,115.66512],
217
+ [-33.3359894444444,115.665158333333],
218
+ [-33.3358877777778,115.665172777778],
219
+ [-33.3357855555556,115.665168333333],
220
+ [-33.335585,115.665027777778],
221
+ [-33.3350388888889,115.664572777778],
222
+ [-33.3345688888889,115.664177222222],
223
+ [-33.333825,115.663587777778],
224
+ [-33.3328094444444,115.662822222222],
225
+ [-33.3325316666667,115.662621111111],
226
+ [-33.3323305555556,115.662475],
227
+ [-33.3322338888889,115.662401111111],
228
+ [-33.3321866666667,115.662373333333],
229
+ [-33.3321555555556,115.662366111111],
230
+ [-33.3321172222222,115.662363333333],
231
+ [-33.3320261111111,115.662363333333],
232
+ [-33.3318933333333,115.662373888889],
233
+ [-33.3319111111111,115.66242],
234
+ [-33.3319816666667,115.662791666667],
235
+ [-33.3320411111111,115.663145],
236
+ [-33.3320822222222,115.663462222222],
237
+ [-33.3321,115.663766666667],
238
+ [-33.332095,115.664183333333],
239
+ [-33.3320761111111,115.664577777778],
240
+ [-33.3320144444444,115.664891666667],
241
+ [-33.3319433333333,115.665122222222],
242
+ [-33.3322855555556,115.665379444444],
243
+ [-33.3331094444444,115.666027222222],
244
+ [-33.3335483333333,115.666373888889],
245
+ [-33.3336416666667,115.666491666667],
246
+ [-33.3338494444444,115.666663333333],
247
+ [-33.334155,115.666840555556],
248
+ [-33.3348594444444,115.667103888889],
249
+ [-33.3350183333333,115.667190555556],
250
+ [-33.335155,115.667307222222],
251
+ [-33.3352505555556,115.667408333333],
252
+ [-33.3353327777778,115.667505],
253
+ [-33.335585,115.667743333333],
254
+ [-33.3358294444444,115.668190555556],
255
+ [-33.3359744444444,115.66853],
256
+ [-33.3360222222222,115.668892777778],
257
+ [-33.3360344444444,115.669116666667],
258
+ [-33.3360388888889,115.669197222222],
259
+ [-33.33605,115.670768888889],
260
+ [-33.3360455555556,115.672128888889],
261
+ [-33.3360255555556,115.674903888889],
262
+ [-33.3360227777778,115.676181111111],
263
+ [-33.3360094444444,115.677107777778],
264
+ [-33.3359277777778,115.678325],
265
+ [-33.3357772222222,115.679310555556],
266
+ [-33.3354888888889,115.680615],
267
+ [-33.3353194444444,115.681237222222],
268
+ [-33.3349355555556,115.682392222222],
269
+ [-33.3346111111111,115.683531666667],
270
+ [-33.3343683333333,115.684342222222],
271
+ [-33.3340466666667,115.685418888889],
272
+ [-33.3336411111111,115.686831111111],
273
+ [-33.3335783333333,115.687009444444],
274
+ [-33.3335166666667,115.687186111111],
275
+ [-33.3333222222222,115.687761111111],
276
+ [-33.3330883333333,115.688365555556],
277
+ [-33.3327988888889,115.689008333333],
278
+ [-33.3325322222222,115.689537222222],
279
+ [-33.3322255555556,115.690066111111],
280
+ [-33.3319261111111,115.690547222222],
281
+ [-33.3315672222222,115.69107],
282
+ [-33.3314077777778,115.691283888889],
283
+ [-33.3310461111111,115.691757222222],
284
+ [-33.3298994444444,115.693195],
285
+ [-33.3291927777778,115.694116111111],
286
+ [-33.3287655555556,115.694647222222],
287
+ [-33.3280827777778,115.695564444444],
288
+ [-33.3276688888889,115.696246111111],
289
+ [-33.3276005555556,115.696347777778],
290
+ [-33.3274927777778,115.696505],
291
+ [-33.3274327777778,115.696578333333],
292
+ [-33.3273633333333,115.696640555556],
293
+ [-33.3273061111111,115.696677777778],
294
+ [-33.3272094444444,115.696726111111],
295
+ [-33.3271427777778,115.696745555556],
296
+ [-33.3270638888889,115.696761111111],
297
+ [-33.3268266666667,115.696790555556],
298
+ [-33.3266177777778,115.6968],
299
+ [-33.3265144444444,115.696808888889],
300
+ [-33.3263777777778,115.696821666667],
301
+ [-33.3262744444444,115.696834444444],
302
+ [-33.3261411111111,115.696861666667],
303
+ [-33.3258988888889,115.696919444444],
304
+ [-33.3257561111111,115.696950555556],
305
+ [-33.3255227777778,115.69699],
306
+ [-33.325365,115.697006666667],
307
+ [-33.3251983333333,115.69702],
308
+ [-33.3250888888889,115.697021666667],
309
+ [-33.3249761111111,115.69702],
310
+ [-33.3247816666667,115.697001111111],
311
+ [-33.3245933333333,115.696989444444],
312
+ [-33.3244227777778,115.696955555556],
313
+ [-33.324355,115.696985],
314
+ [-33.3240672222222,115.696919444444],
315
+ [-33.3230883333333,115.696683333333],
316
+ [-33.32234,115.696469444444],
317
+ [-33.3217983333333,115.696355],
318
+ [-33.321045,115.696186111111],
319
+ [-33.3208144444444,115.696146111111],
320
+ [-33.3191055555556,115.695857777778],
321
+ [-33.3173294444444,115.695498333333],
322
+ [-33.3168344444444,115.695422777778],
323
+ [-33.3160822222222,115.695284444444],
324
+ [-33.3158644444444,115.695241666667],
325
+ [-33.3152672222222,115.695123888889],
326
+ [-33.3152677777778,115.695121111111],
327
+ [-33.3152688888889,115.695108888889],
328
+ [-33.31527,115.695096666667],
329
+ [-33.3152705555556,115.695085],
330
+ [-33.3152705555556,115.695072777778],
331
+ [-33.3152705555556,115.695060555556],
332
+ [-33.3152694444444,115.695048333333],
333
+ [-33.3152683333333,115.695036666667],
334
+ [-33.3152666666667,115.695024444444],
335
+ [-33.3152644444444,115.695012777778],
336
+ [-33.3152616666667,115.695001111111],
337
+ [-33.3152588888889,115.694989444444],
338
+ [-33.315255,115.694978333333],
339
+ [-33.3152511111111,115.694967222222],
340
+ [-33.3152466666667,115.694956111111],
341
+ [-33.3152422222222,115.694945555556],
342
+ [-33.3152366666667,115.694935],
343
+ [-33.3152311111111,115.694925],
344
+ [-33.3152255555556,115.694915],
345
+ [-33.3152188888889,115.694905555556],
346
+ [-33.3152122222222,115.694896111111],
347
+ [-33.3152055555556,115.694887777778],
348
+ [-33.3151983333333,115.694879444444],
349
+ [-33.3151905555556,115.694871111111],
350
+ [-33.3151827777778,115.694863888889],
351
+ [-33.3151744444444,115.694856666667],
352
+ [-33.3151661111111,115.69485],
353
+ [-33.3151572222222,115.694843888889],
354
+ [-33.3151483333333,115.694837777778],
355
+ [-33.3151388888889,115.694832777778],
356
+ [-33.3151294444444,115.694827777778],
357
+ [-33.31512,115.694823888889],
358
+ [-33.3151105555556,115.69482],
359
+ [-33.3151005555556,115.694816666667],
360
+ [-33.3150905555556,115.694813888889],
361
+ [-33.3150805555556,115.694811666667],
362
+ [-33.3150705555556,115.69481],
363
+ [-33.3150638888889,115.694809444444],
364
+ [-33.3150605555556,115.694809444444],
365
+ [-33.3150505555556,115.694808888889],
366
+ [-33.3150405555556,115.694808888889],
367
+ [-33.31503,115.694809444444],
368
+ [-33.31502,115.694810555556],
369
+ [-33.31501,115.694812222222],
370
+ [-33.315,115.694814444444],
371
+ [-33.31499,115.694817222222],
372
+ [-33.3149805555556,115.694820555556],
373
+ [-33.3149705555556,115.694823888889],
374
+ [-33.3149611111111,115.694828333333],
375
+ [-33.3149516666667,115.694833333333],
376
+ [-33.3149427777778,115.694838333333],
377
+ [-33.3149338888889,115.694844444444],
378
+ [-33.314925,115.694850555556],
379
+ [-33.3149166666667,115.694857222222],
380
+ [-33.3149083333333,115.694864444444],
381
+ [-33.3149005555556,115.694872222222],
382
+ [-33.3148927777778,115.69488],
383
+ [-33.3148855555556,115.694888333333],
384
+ [-33.3148788888889,115.694897222222],
385
+ [-33.3148722222222,115.694906666667],
386
+ [-33.3148661111111,115.694916111111],
387
+ [-33.31486,115.694926111111],
388
+ [-33.3148544444444,115.694936111111],
389
+ [-33.3148494444444,115.694946666667],
390
+ [-33.3148444444444,115.694957222222],
391
+ [-33.31484,115.694968333333],
392
+ [-33.3148361111111,115.694979444444],
393
+ [-33.3148327777778,115.694991111111],
394
+ [-33.31483,115.695002222222],
395
+ [-33.3148272222222,115.695013888889],
396
+ [-33.314825,115.695026111111],
397
+ [-33.3148233333333,115.695037777778],
398
+ [-33.3148222222222,115.69505],
399
+ [-33.3148216666667,115.695062222222],
400
+ [-33.3148211111111,115.695073888889],
401
+ [-33.3147438888889,115.695072222222],
402
+ [-33.3145216666667,115.695077222222],
403
+ [-33.3142655555556,115.695102222222],
404
+ [-33.3138061111111,115.695135555556],
405
+ [-33.31346,115.695201666667],
406
+ [-33.3130127777778,115.695333888889],
407
+ [-33.3125211111111,115.695484444444],
408
+ [-33.3123194444444,115.695587222222],
409
+ [-33.3120872222222,115.695690555556],
410
+ [-33.3118622222222,115.695798333333],
411
+ [-33.31175,115.695856666667],
412
+ [-33.3115977777778,115.69595],
413
+ [-33.3114672222222,115.696025555556],
414
+ [-33.3113183333333,115.696106111111],
415
+ [-33.3111855555556,115.696187777778],
416
+ [-33.31112,115.696235555556],
417
+ [-33.3109944444444,115.696335],
418
+ [-33.3108894444444,115.696411666667],
419
+ [-33.3107816666667,115.696497222222],
420
+ [-33.3106561111111,115.696602777778],
421
+ [-33.3098788888889,115.697270555556],
422
+ [-33.3097755555556,115.697339444444],
423
+ [-33.3097555555556,115.697353333333],
424
+ [-33.3097444444444,115.697361111111],
425
+ [-33.3093833333333,115.697713333333],
426
+ [-33.3090761111111,115.697967777778],
427
+ [-33.3087366666667,115.698245555556],
428
+ [-33.3085644444444,115.698388888889],
429
+ [-33.3083677777778,115.698551666667],
430
+ [-33.30808,115.698808888889],
431
+ [-33.3076816666667,115.699201111111],
432
+ [-33.3071077777778,115.699707777778],
433
+ [-33.30673,115.700068333333],
434
+ [-33.3063894444444,115.700397777778],
435
+ [-33.30606,115.700706666667],
436
+ [-33.3057366666667,115.700995],
437
+ [-33.3054838888889,115.701237777778],
438
+ [-33.3055772222222,115.701379444444],
439
+ [-33.30561,115.701519444444],
440
+ [-33.3056127777778,115.701662777778],
441
+ [-33.3056261111111,115.702640555556],
442
+ [-33.3056266666667,115.702681111111],
443
+ [-33.3056583333333,115.702921111111],
444
+ [-33.3057144444444,115.703187222222],
445
+ [-33.3057894444444,115.703453888889],
446
+ [-33.3059144444444,115.703747222222],
447
+ [-33.30613,115.704095],
448
+ [-33.3063644444444,115.704267222222],
449
+ [-33.3068955555556,115.704573888889],
450
+ [-33.3077883333333,115.704722777778],
451
+ [-33.30797,115.704753333333],
452
+ [-33.3082938888889,115.704819444444]
453
+ ]
454
+ end
455
+
456
+ it "simplifies the line correctly" do
457
+ DouglasPeucker::LineSimplifier.new(line).threshold(0.00005).points.length.should == 70
458
+ end
459
+ end
@@ -0,0 +1,42 @@
1
+ require "spec_helper"
2
+
3
+ describe DouglasPeucker::OrthogonalDistance do
4
+ context "with a horizontal line" do
5
+ let(:line) do
6
+ DouglasPeucker::Line.new(DouglasPeucker::Point.new(0,0), DouglasPeucker::Point.new(4,0))
7
+ end
8
+
9
+ it "calculates distance correctly" do
10
+ DouglasPeucker::OrthogonalDistance.new(DouglasPeucker::Point.new(2, 0), line).distance.should == 0
11
+ DouglasPeucker::OrthogonalDistance.new(DouglasPeucker::Point.new(2, 2), line).distance.should == 2
12
+ DouglasPeucker::OrthogonalDistance.new(DouglasPeucker::Point.new(4, 4), line).distance.should == 4
13
+ DouglasPeucker::OrthogonalDistance.new(DouglasPeucker::Point.new(2, -2), line).distance.should == 2
14
+ end
15
+ end
16
+
17
+ context "with a vertical line" do
18
+ let(:line) do
19
+ DouglasPeucker::Line.new(DouglasPeucker::Point.new(0,0), DouglasPeucker::Point.new(0,4))
20
+ end
21
+
22
+ it "calculates distance correctly" do
23
+ DouglasPeucker::OrthogonalDistance.new(DouglasPeucker::Point.new(2, 0), line).distance.should == 2
24
+ DouglasPeucker::OrthogonalDistance.new(DouglasPeucker::Point.new(2, 2), line).distance.should == 2
25
+ DouglasPeucker::OrthogonalDistance.new(DouglasPeucker::Point.new(4, 4), line).distance.should == 4
26
+ DouglasPeucker::OrthogonalDistance.new(DouglasPeucker::Point.new(-2, 2), line).distance.should == 2
27
+ end
28
+ end
29
+
30
+ context "with a sloped line" do
31
+ let(:line) do
32
+ DouglasPeucker::Line.new(DouglasPeucker::Point.new(0,0), DouglasPeucker::Point.new(4,4))
33
+ end
34
+
35
+ it "calculates distance correctly" do
36
+ DouglasPeucker::OrthogonalDistance.new(DouglasPeucker::Point.new(1, 1), line).distance.should == 0
37
+ DouglasPeucker::OrthogonalDistance.new(DouglasPeucker::Point.new(2, 2), line).distance.should == 0
38
+ DouglasPeucker::OrthogonalDistance.new(DouglasPeucker::Point.new(4, 0), line).distance.should be_within(1e-9).of(2*2**0.5)
39
+ DouglasPeucker::OrthogonalDistance.new(DouglasPeucker::Point.new(2, 0), line).distance.should be_within(1e-9).of(2**0.5)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ require "douglas_peucker"
2
+ require "bundler/setup"
3
+ Bundler.require(:development)
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: douglas_peucker
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Josh Clayton
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-09-04 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: 2.6.0
25
+ type: :development
26
+ version_requirements: *id001
27
+ description:
28
+ email:
29
+ - joshua.clayton@gmail.com
30
+ executables: []
31
+
32
+ extensions: []
33
+
34
+ extra_rdoc_files: []
35
+
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - douglas_peucker.gemspec
43
+ - lib/douglas_peucker.rb
44
+ - lib/douglas_peucker/line.rb
45
+ - lib/douglas_peucker/line_simplifier.rb
46
+ - lib/douglas_peucker/orthogonal_distance.rb
47
+ - lib/douglas_peucker/point.rb
48
+ - lib/douglas_peucker/version.rb
49
+ - spec/douglas_peucker/line_simplifier_spec.rb
50
+ - spec/douglas_peucker/orthogonal_distance_spec.rb
51
+ - spec/spec_helper.rb
52
+ has_rdoc: true
53
+ homepage: ""
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options: []
58
+
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.6.2
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: "A Ruby implementation of the Douglas\xE2\x80\x93Peucker algorithm"
80
+ test_files:
81
+ - spec/douglas_peucker/line_simplifier_spec.rb
82
+ - spec/douglas_peucker/orthogonal_distance_spec.rb
83
+ - spec/spec_helper.rb