winding-polygon 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/winding-polygon.rb +3 -1
- data/lib/winding-polygon/version.rb +1 -1
- data/spec/winding-polygon_spec.rb +33 -0
- 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: d44f05e5f4d9feb93c0f33ae9bb149db8cce5161
|
4
|
+
data.tar.gz: 0226aa7e2ef617527e886511380e0994dd43494c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f28db5bbd6bd7c2588f59e4fa80e8476fc36c404c70b08d8dd1026ca179ff8f0fcd1ea77847a008762cc787b19f0f881fcee10348fd332df64c6f71679edde31
|
7
|
+
data.tar.gz: a1525f67badaac5b6921aaf1dab8a2f1d583ed24cbf5faae804570d4088159545d0479c10b955252c53951d0095cceb3d5c17ad428638fa8bcff5df7fe81d14b
|
data/lib/winding-polygon.rb
CHANGED
@@ -11,8 +11,10 @@ module WindingPolygon
|
|
11
11
|
|
12
12
|
def self.decompose(input_polygon)
|
13
13
|
|
14
|
+
raise Exception.new("The input polygon is invalid") if input_polygon.nil? || input_polygon.vertices.nil? || input_polygon.vertices.size<4 || input_polygon.vertices.first != input_polygon.vertices.last
|
15
|
+
|
14
16
|
intersection_points = input_polygon.get_intersection_points
|
15
|
-
return [input_polygon] if intersection_points.nil? || intersection_points.size==0
|
17
|
+
return [input_polygon.vertices] if intersection_points.nil? || intersection_points.size==0
|
16
18
|
|
17
19
|
input_polygon.simple_segments.sort_by!{|seg| [seg.left_point] }
|
18
20
|
simple_polygons = Array.new
|
@@ -36,6 +36,7 @@ describe WindingPolygon do
|
|
36
36
|
|
37
37
|
end
|
38
38
|
|
39
|
+
#TODO: need to be fixed for this case.
|
39
40
|
it 'should decompose a production complex polygon3 into 2 simple polygons' do
|
40
41
|
puts 'should decompose a production complex polygon3 into 2 simple polygons'
|
41
42
|
points = JSON.parse("[["+"-117.24925876095165 33.91178188651025,-117.23665 33.92297,-117.23454 33.88265,-117.2329768082223 33.876156994994965,-117.22880432048471 33.858825798560716,-117.21764 33.82916,-117.19441 33.78354,-117.18500627102398 33.76125512143704,-117.17963 33.75808,-117.1822623691137 33.75475264555591,-117.17329 33.73349,-117.1469 33.68342,-117.15323 33.72559,-117.16379 33.7651,-117.17963 33.81249,-117.19969 33.86073,-117.21209151500123 33.88704,-117.21342 33.88704,-117.22240964169768 33.89151566678272,-117.22187 33.8923,-117.24357401835415 33.907738274960245,-117.2451 33.90719,-117.24429633564073 33.90241238017341,-117.25423918087715 33.90736261775205,-117.24925876095165 33.91178188651025".gsub(',','],[').gsub(' ',',')+"]]")
|
@@ -95,4 +96,36 @@ describe WindingPolygon do
|
|
95
96
|
|
96
97
|
end
|
97
98
|
|
99
|
+
|
100
|
+
it 'should decompose a non-closed complex polygon into two simple ones, one of them is non-closed too.' do
|
101
|
+
puts 'should decompose a non-closed complex polygon into two simple ones, one of them is non-closed too.'
|
102
|
+
points = JSON.parse("[["+"48.38589399615689 -121.67504882813289,48.34940025288681 -118.35717773438792,46.11179728878453 -121.97167968751148,46.438325724662185 -117.81884765625605,48.07119285609636 -121.64208984375948".gsub(',','],[').gsub(' ',',')+"]]")
|
103
|
+
polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[1].to_f,item[0].to_f)})
|
104
|
+
|
105
|
+
t1 = Time.now
|
106
|
+
begin
|
107
|
+
multi_polygons = WindingPolygon.decompose(polygon)
|
108
|
+
rescue Exception=>e
|
109
|
+
e.message.should == "The input polygon is invalid"
|
110
|
+
end
|
111
|
+
t2 = Time.now
|
112
|
+
puts "elapsed time: #{(t2-t1)*1000.to_i} ms"
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'jason example 1 should work' do
|
117
|
+
puts 'should decompose a non-closed complex polygon into two simple ones, one of them is non-closed too.'
|
118
|
+
points = JSON.parse("[["+"48.80007546725736 -124.3227539062524,45.63756276917531 -123.795410156251,46.06608048393649 -116.76416015625323,48.94459805806026 -117.07177734375331,48.80007546725736 -124.3227539062524".gsub(',','],[').gsub(' ',',')+"]]")
|
119
|
+
polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[1].to_f,item[0].to_f)})
|
120
|
+
|
121
|
+
t1 = Time.now
|
122
|
+
multi_polygons = WindingPolygon.decompose(polygon)
|
123
|
+
t2 = Time.now
|
124
|
+
puts "elapsed time: #{(t2-t1)*1000.to_i} ms"
|
125
|
+
multi_polygons.should_not be_nil
|
126
|
+
|
127
|
+
multi_polygons.size.should == 1
|
128
|
+
|
129
|
+
end
|
130
|
+
|
98
131
|
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.14
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|