winding-polygon 0.0.10 → 0.0.11
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 +35 -0
- data/lib/winding-polygon/version.rb +1 -1
- data/spec/winding-polygon_spec.rb +18 -3
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7095ba948d2e8c743100374bee8bf0811a9bcbde
|
4
|
+
data.tar.gz: 281b4e3a1957120e521020b3c27d397410b01405
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a67c3cc375d9fda3337279cad8f86c19fb2230ab215b24292be81fa4c7bf85844a48896a5d2bd3b676531797bf59792add7b91e11d289f9bbd9bdc8ecc42090
|
7
|
+
data.tar.gz: 967d1b5a71fc803b7659ff182e51c1ec660974aa6f16fc7106fc3e9c7d1fed8af1ed67d351e0386c3f1b16f8ce9812c63a0e14db46ff8f4bbc520ec3e89a9bc0
|
data/lib/winding-polygon.rb
CHANGED
@@ -16,6 +16,41 @@ module WindingPolygon
|
|
16
16
|
end
|
17
17
|
simple_polygons
|
18
18
|
|
19
|
+
#make sure they're real simple
|
20
|
+
final_simple_polygons = Array.new
|
21
|
+
simple_polygons.each do |polylgon|
|
22
|
+
final_decompose(final_simple_polygons, polylgon)
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
final_simple_polygons
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.final_decompose(final_simple_polygons, polygon)
|
31
|
+
first_duplicate = polygon.detect { |p| polygon.count(p)>1 && p!=polygon.first }
|
32
|
+
|
33
|
+
if first_duplicate.nil?
|
34
|
+
final_simple_polygons << polygon
|
35
|
+
return
|
36
|
+
end
|
37
|
+
|
38
|
+
index1 = polygon.index(first_duplicate)
|
39
|
+
index2 = polygon.rindex(first_duplicate)
|
40
|
+
|
41
|
+
polygon1 = polygon[0..index1].concat(polygon[index2+1..polygon.length-1])
|
42
|
+
if !polygon1.detect { |p| polygon1.count(p)>1 && p!=polygon1.first }.nil?
|
43
|
+
self.final_decompose(final_simple_polygons, polygon1)
|
44
|
+
else
|
45
|
+
final_simple_polygons << polygon1
|
46
|
+
end
|
47
|
+
|
48
|
+
polygon2 = polygon[index1..index2]
|
49
|
+
if !polygon2.detect { |p| polygon2.count(p)>1 && p!=polygon2.first }.nil?
|
50
|
+
self.final_decompose(final_simple_polygons, polygon2)
|
51
|
+
else
|
52
|
+
final_simple_polygons << polygon2
|
53
|
+
end
|
19
54
|
end
|
20
55
|
|
21
56
|
def self.get_one_simple_polygon(first_segment, input_polygon)
|
@@ -6,8 +6,23 @@ describe WindingPolygon do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
|
9
|
-
it 'should decompose a production complex polygon
|
10
|
-
puts 'should decompose a production complex polygon 2
|
9
|
+
it 'should decompose a production complex polygon into 2 simple polygons' do
|
10
|
+
puts 'should decompose a production complex polygon into 2 simple polygons'
|
11
|
+
points = JSON.parse("[["+"-87.78842 41.85362,-87.78739 41.85208,-87.78619 41.85029,-87.78722 41.8352,-87.78894 41.83354,-87.79014 41.83264,-87.79168 41.83175,-87.7934 41.83098,-87.79546 41.83021,-87.79752 41.82957,-87.79992 41.82893,-87.80198 41.82842,-87.80387 41.82804,-87.8061 41.82778,-87.80833 41.82778,-87.81022 41.82778,-87.81245 41.82778,-87.81417 41.82804,-87.81537 41.82855,-87.81657 41.82906,-87.81812 41.83021,-87.81932 41.83175,-87.82052 41.83341,-87.82189 41.83763,-87.82086 41.85605,-87.81949 41.85771,-87.81795 41.85911,-87.81589 41.86078,-87.81365 41.86231,-87.81159 41.86333,-87.80953 41.86423,-87.80713 41.86487,-87.80524 41.86487,-87.80301 41.86487,-87.8013 41.86474,-87.79958 41.86461,-87.79803 41.86436,-87.79666 41.86397,-87.79546 41.86359,-87.79409 41.86321,-87.79288 41.86269,-87.79185 41.86205,-87.79031 41.86103,-87.78928 41.86014,-87.79048 41.85886,-87.79151 41.85796,-87.79288 41.85668,-87.7946 41.85528,-87.79615 41.854,-87.79752 41.85272,-87.79906 41.85131,-87.80078 41.84952,-87.80198 41.84837,-87.80301 41.84748,-87.80473 41.84722,-87.78842 41.85362".gsub(',','],[').gsub(' ',',')+"]]")
|
12
|
+
polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0].to_f,item[1].to_f)})
|
13
|
+
|
14
|
+
t1 = Time.now
|
15
|
+
multi_polygons = WindingPolygon.decompose(polygon)
|
16
|
+
t2 = Time.now
|
17
|
+
puts "elapsed time: #{(t2-t1)*1000.to_i} ms"
|
18
|
+
multi_polygons.should_not be_nil
|
19
|
+
|
20
|
+
multi_polygons.size.should == 2
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should decompose a production complex polygon into 20 simple polygons' do
|
25
|
+
puts 'should decompose a production complex polygon into 20 simple polygons'
|
11
26
|
points = JSON.parse("[["+"34.09522 -82.77396,34.09522 -82.76984,34.0901 -82.76022,34.08555 -82.75542,34.081 -82.74512,34.081 -82.74031,34.08157 -82.72933,34.08442 -82.7204,34.0992 -82.70667,34.11285 -82.70186,34.11 -82.69774,34.10148 -82.68607,34.10091 -82.68126,34.10148 -82.67096,34.10546 -82.66478,34.10887 -82.65997,34.11853 -82.65173,34.15661 -82.66409,34.16002 -82.67165,34.16627 -82.69293,34.17138 -82.70667,34.1782 -82.7204,34.19297 -82.73963,34.19751 -82.73413,34.19751 -82.72246,34.19694 -82.71422,34.19524 -82.69431,34.19297 -82.68263,34.18558 -82.66066,34.18047 -82.65311,34.17024 -82.6483,34.1549 -82.65929,34.15093 -82.66478,34.14183 -82.68057,34.13672 -82.69225,34.12876 -82.71697,34.12933 -82.73757,34.16002 -82.76022,34.1674 -82.75199,34.1674 -82.74718,34.1674 -82.74306,34.16627 -82.73276,34.164 -82.72795,34.15831 -82.71971,34.14695 -82.71353,34.12422 -82.72246,34.12422 -82.72727,34.12422 -82.73345,34.12706 -82.74855,34.13104 -82.75542,34.14127 -82.76572,34.14979 -82.7719,34.15831 -82.77808,34.18899 -82.77121,34.18899 -82.76709,34.18842 -82.7561,34.18729 -82.74993,34.18558 -82.74375,34.17933 -82.7307,34.17479 -82.72452,34.1674 -82.71628,34.15093 -82.70873,34.13445 -82.71491,34.12876 -82.72452,34.12592 -82.7307,34.12365 -82.73757,34.12024 -82.75473,34.11853 -82.76503,34.12024 -82.77327,34.12422 -82.78426,34.12933 -82.78906,34.13786 -82.79456,34.15263 -82.80348,34.16172 -82.8076,34.18217 -82.8028,34.18104 -82.79662,34.17479 -82.79181,34.16968 -82.787,34.16343 -82.78151,34.15718 -82.77533,34.15206 -82.77052,34.1532 -82.7664,34.18274 -82.7719,34.18274 -82.77808,34.17877 -82.78838,34.17365 -82.79318,34.14297 -82.78838,34.1424 -82.78014,34.14354 -82.77396,34.14979 -82.76503,34.15661 -82.75885,34.16627 -82.74924,34.17252 -82.74169,34.17536 -82.73688,34.1782 -82.72589,34.1782 -82.71903,34.17763 -82.71285,34.17649 -82.70667,34.17479 -82.70049,34.16797 -82.69087,34.16286 -82.68675,34.13104 -82.69431,34.13047 -82.6998,34.13047 -82.70529,34.1316 -82.71147,34.13331 -82.71628,34.13729 -82.72109,34.14183 -82.72589,34.14865 -82.73139,34.15547 -82.73551,34.17081 -82.73139,34.17081 -82.72727,34.17081 -82.71765,34.16968 -82.71216,34.16797 -82.70598,34.1657 -82.70186,34.15945 -82.69568,34.14297 -82.70117,34.14183 -82.70598,34.14183 -82.71147,34.14183 -82.71765,34.14297 -82.72177,34.14865 -82.73139,34.15263 -82.73551,34.15775 -82.741,34.1657 -82.74718,34.17252 -82.75199,34.18274 -82.75679,34.19183 -82.76366,34.19126 -82.76778,34.18899 -82.77258,34.1657 -82.76778,34.1657 -82.76366,34.16627 -82.75885,34.16968 -82.75405,34.17365 -82.74993,34.18047 -82.74443,34.18445 -82.73825,34.18672 -82.73413,34.18842 -82.73001,34.18842 -82.72521,34.18842 -82.71971,34.18842 -82.71559,34.18785 -82.71147,34.18615 -82.70667,34.18047 -82.69843,34.17593 -82.69293,34.17024 -82.68744,34.16456 -82.68263,34.14865 -82.67577,34.13501 -82.68057,34.1316 -82.68744,34.12933 -82.69293,34.12592 -82.69843,34.12365 -82.70323,34.12024 -82.71147,34.11683 -82.71971,34.11341 -82.72795,34.11285 -82.73688,34.11285 -82.74443,34.11341 -82.74993,34.11569 -82.75542,34.12365 -82.76366,34.13104 -82.76846,34.14127 -82.77327,34.14695 -82.76915,34.14411 -82.76434,34.13956 -82.76022,34.13445 -82.7561,34.12308 -82.7513,34.10943 -82.74649,34.09806 -82.741,34.0884 -82.73345,34.08555 -82.72795,34.08442 -82.72246,34.08442 -82.71765,34.08669 -82.71147,34.09295 -82.70529,34.10091 -82.70049,34.11171 -82.69568,34.1191 -82.70049,34.11796 -82.70667,34.11796 -82.71285,34.11796 -82.71903,34.11853 -82.72383,34.11967 -82.73001,34.12194 -82.73688,34.12422 -82.74169,34.13104 -82.74787,34.14922 -82.74169,34.15149 -82.73757,34.15206 -82.73276,34.15206 -82.72658,34.15206 -82.7204,34.15206 -82.71422,34.15093 -82.70941,34.14809 -82.70392,34.14013 -82.6998,34.12024 -82.70804,34.11626 -82.71285,34.11398 -82.71903,34.11398 -82.72383,34.11455 -82.73001,34.11512 -82.73482,34.11796 -82.74031,34.12024 -82.74649,34.12365 -82.75267,34.12706 -82.76022,34.13047 -82.76778,34.13388 -82.77602,34.13672 -82.78426,34.13729 -82.79044,34.13729 -82.79593,34.13729 -82.80005,34.13445 -82.80554,34.12024 -82.80005,34.12592 -82.79456,34.13786 -82.78975,34.22193 -82.79387,34.09522 -82.77396".gsub(',','],[').gsub(' ',',')+"]]")
|
12
27
|
polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[1].to_f,item[0].to_f)})
|
13
28
|
|
@@ -17,7 +32,7 @@ describe WindingPolygon do
|
|
17
32
|
puts "elapsed time: #{(t2-t1)*1000.to_i} ms"
|
18
33
|
multi_polygons.should_not be_nil
|
19
34
|
|
20
|
-
multi_polygons.size.should ==
|
35
|
+
multi_polygons.size.should == 23
|
21
36
|
|
22
37
|
end
|
23
38
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Xu
|
@@ -28,31 +28,31 @@ dependencies:
|
|
28
28
|
name: test-unit
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description:
|
55
|
+
description: 'Use Bentley-Ottmann algorithm to solve self-intersecting polygon issue '
|
56
56
|
email:
|
57
57
|
- mxu2008@gmail.com
|
58
58
|
executables: []
|
@@ -99,17 +99,17 @@ require_paths:
|
|
99
99
|
- lib
|
100
100
|
required_ruby_version: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- -
|
102
|
+
- - '>='
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
|
-
- -
|
107
|
+
- - '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
111
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.0.
|
112
|
+
rubygems_version: 2.0.0
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: Detect intersecting points and decompose it into multi-polygons
|