winding-polygon 0.0.8 → 0.0.9
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.
- checksums.yaml +4 -4
- data/lib/winding-polygon/polygon.rb +2 -2
- data/lib/winding-polygon/version.rb +1 -1
- data/spec/winding-polygon_spec.rb +26 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4e1dcc7540bc157730c91e6f845ae55d397706a
|
4
|
+
data.tar.gz: 689f63d73ce0917f4e3ca7dc2e87415560cca055
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be27e7576bc9f6240e1ff171e4f641c7f56af9282e6f54812cddddd93a76af1a7d98d93070cbd8f2fe2fe82746c61cddd5ec779b85cd438d9632bddf2762880e
|
7
|
+
data.tar.gz: b3267a598ce0141d23520eb8e79dbed8214af48003ffdb95e113832e183e4bf2de6756495a261203f8fe86fcb57587f72a6b622040bc2534844b9a372417b0c3
|
@@ -74,7 +74,7 @@ module WindingPolygon
|
|
74
74
|
if e[:type] == 'right'
|
75
75
|
s = sweep_line.find_segment(@segments[e[:edge]])
|
76
76
|
point = sweep_line.intersect(s.above, s.below)
|
77
|
-
event_queue.insert(point_hash_with_edge_info(point, s.above, s.below)) if !point.nil? && !event_queue.exist(point)
|
77
|
+
event_queue.insert(point_hash_with_edge_info(point, s.above, s.below)) if !point.nil? && !event_queue.exist(point) && !@intersection_points.any?{|p| p==point}
|
78
78
|
sweep_line.remove(s)
|
79
79
|
@simple_segments << s
|
80
80
|
end
|
@@ -113,7 +113,7 @@ module WindingPolygon
|
|
113
113
|
|
114
114
|
def find_intersection_point_between_segments(s1,s2, event_queue, sweep_line)
|
115
115
|
point =sweep_line.intersect(s1, s2)
|
116
|
-
event_queue.insert(point_hash_with_edge_info(point, s1, s2)) if !point.nil? && !event_queue.exist(point)
|
116
|
+
event_queue.insert(point_hash_with_edge_info(point, s1, s2)) if !point.nil? && !event_queue.exist(point) && !@intersection_points.any?{|p| p==point}
|
117
117
|
end
|
118
118
|
|
119
119
|
def add_to_intersection_point_collection(point)
|
@@ -171,11 +171,36 @@ describe WindingPolygon do
|
|
171
171
|
t2 = Time.now
|
172
172
|
puts "elapsed time: #{(t2-t1)*1000.to_i} ms"
|
173
173
|
|
174
|
-
|
175
174
|
multi_polygons.size.should == 7
|
176
175
|
|
176
|
+
multi_polygons[0].map{|p| "#{p.x} #{p.y}"}.join(',').should == "-119.818359375002 45.45290147989422,-115.86328125000495 34.15328996737699,-102.52676351947564 36.81219275411459,-104.17382812500229 40.17099871188528,-115.07226562500733 41.63237589430056,-109.95811865270818 42.77494310443354,-119.818359375002 45.45290147989422"
|
177
|
+
multi_polygons[1].map{|p| "#{p.x} #{p.y}"}.join(',').should == "-110.50195312500117 46.97322061018078,-103.69099150583577 44.1751011402773,-100.33100481371673 44.925766039368476,-110.50195312500117 46.97322061018078"
|
178
|
+
multi_polygons[2].map{|p| "#{p.x} #{p.y}"}.join(',').should == "-109.95811865270818 42.77494310443354,-94.15143902809056 38.48198198095287,-91.2441372988624 39.06161099850639,-103.69099150583577 44.1751011402773,-109.95811865270818 42.77494310443354"
|
179
|
+
multi_polygons[3].map{|p| "#{p.x} #{p.y}"}.join(',').should == "-102.52676351947564 36.81219275411459,-100.3945312500027 32.46399995947513,-95.82421875000551 37.08201838643584,-88.52929687500257 35.95188058401679,-84.31054687500303 33.64262887366194,-83.16796875000327 34.51617009551454,-82.37695312500296 32.538125275571225,-83.22015254748098 35.513136593728035,-94.15143902809056 38.48198198095287,-102.52676351947564 36.81219275411459"
|
180
|
+
multi_polygons[4].map{|p| "#{p.x} #{p.y}"}.join(',').should == "-100.33100481371673 44.925766039368476,-92.66015625000608 43.38159203778072,-94.68164062500398 46.18790776409503,-100.33100481371673 44.925766039368476"
|
181
|
+
multi_polygons[5].map{|p| "#{p.x} #{p.y}"}.join(',').should == "-91.2441372988624 39.06161099850639,-83.30099309938232 35.7983615956211,-84.31054687500303 39.36031127050692,-72.79687500000323 42.739443407624286,-91.2441372988624 39.06161099850639"
|
182
|
+
multi_polygons[6].map{|p| "#{p.x} #{p.y}"}.join(',').should == "-83.30099309938232 35.7983615956211,-83.22015254748098 35.513136593728035,-81.4101562500034 35.021556836103684,-83.30099309938232 35.7983615956211"
|
177
183
|
end
|
178
184
|
|
179
185
|
|
186
|
+
it 'should decompose a production complex polygon 8 into four simple polygons' do
|
187
|
+
puts 'should decompose a production complex polygon 8 into four simple polygons'
|
188
|
+
points = JSON.parse("[["+"-88.69626 32.36626,-88.69697 32.36713,-88.69706 32.36722,-88.69713 32.3673,-88.69719 32.36738,-88.69729 32.36747,-88.69743 32.36758,-88.69749 32.36765,-88.69759 32.36777,-88.69767 32.36791,-88.69769 32.36798,-88.69626 32.36626".gsub(',','],[').gsub(' ',',')+"]]")
|
189
|
+
polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0].to_f,item[1].to_f)})
|
190
|
+
|
191
|
+
t1 = Time.now
|
192
|
+
multi_polygons = WindingPolygon.decompose(polygon)
|
193
|
+
t2 = Time.now
|
194
|
+
puts "elapsed time: #{(t2-t1)*1000.to_i} ms"
|
195
|
+
multi_polygons.should_not be_nil
|
196
|
+
|
197
|
+
multi_polygons.size.should == 4
|
198
|
+
|
199
|
+
multi_polygons[0].map{|p| "#{p.x} #{p.y}"}.join(',').should == "-88.69769 32.36798,-88.69767 32.36791,-88.69759 32.36777,-88.69749 32.36765,-88.69743 32.36758,-88.69729 32.36747,-88.6971946189376 32.36738415704383,-88.69769 32.36798"
|
200
|
+
multi_polygons[1].map{|p| "#{p.x} #{p.y}"}.join(',').should == "-88.6971946189376 32.36738415704383,-88.69717928571437 32.36736571428582,-88.69719 32.36738,-88.6971946189376 32.36738415704383"
|
201
|
+
multi_polygons[2].map{|p| "#{p.x} #{p.y}"}.join(',').should == "-88.69717928571437 32.36736571428582,-88.69713 32.3673,-88.69706 32.36722,-88.69704896551728 32.367208965517285,-88.69717928571437 32.36736571428582"
|
202
|
+
multi_polygons[3].map{|p| "#{p.x} #{p.y}"}.join(',').should == "-88.69704896551728 32.367208965517285,-88.69626 32.36626,-88.69697 32.36713,-88.69704896551728 32.367208965517285"
|
203
|
+
|
204
|
+
end
|
180
205
|
|
181
206
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: winding-polygon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Xu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|