winding-polygon 0.0.5 → 0.0.6
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/event_queue.rb +3 -9
- data/lib/winding-polygon/point.rb +14 -0
- data/lib/winding-polygon/version.rb +1 -1
- data/spec/winding-polygon_spec.rb +41 -0
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81637ec0ec7f02d00c10a2e683c31ec31a2de7cb
|
4
|
+
data.tar.gz: 94db42e23f1df32e82af4e3353e69356e239a75c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a661b1dbe28627aaa6638365b4065cc43b7f77f39a0dd7ebbbe8b649050bd71b7c9943ee68124e7f37663540ddc5565009164f29dd2578194faf4f2aaf1cc5b
|
7
|
+
data.tar.gz: 58debae2b8874308c7df1ecf6aa38a6643044a07f33fc878948ac3e42ebf511eced0feda11e355109e865241eb5c6d4543806c83908154dce446dc2eb2f59cff
|
@@ -26,19 +26,13 @@ module WindingPolygon
|
|
26
26
|
@events[a][:type] = 'right'
|
27
27
|
@events[b][:type] = 'left'
|
28
28
|
end
|
29
|
-
end
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
for i in 1..@events.size-1
|
34
|
-
if @events[i][:type]=='left' && left_y == @events[i][:vertex].y
|
35
|
-
@events[i][:vertex].y += 0.000000000000001
|
36
|
-
left_y = @events[i][:vertex].y
|
37
|
-
end
|
30
|
+
@events[a][:other_y]=@events[b][:vertex].y
|
31
|
+
@events[b][:other_y]=@events[a][:vertex].y
|
38
32
|
end
|
39
33
|
|
40
34
|
# sort events lexicographically
|
41
|
-
@events.sort!{|a,b| a[:vertex].compare(b[:vertex])}
|
35
|
+
@events.sort!{|a,b| a[:vertex].compare(b[:vertex]).nonzero? || a[:type]<=>b[:type] || a[:other_y]<=>b[:other_y] }
|
42
36
|
|
43
37
|
end
|
44
38
|
|
@@ -24,6 +24,20 @@ module WindingPolygon
|
|
24
24
|
return 0
|
25
25
|
end
|
26
26
|
|
27
|
+
def <=> other_point
|
28
|
+
raise Exception.new("Self is x=#{@x},y=#{@y}, the other_point is nil") if other_point.nil?
|
29
|
+
# x-coord first
|
30
|
+
return 1 if @x > other_point.x
|
31
|
+
return -1 if @x < other_point.x
|
32
|
+
|
33
|
+
# y-coord second
|
34
|
+
return 1 if @y > other_point.y
|
35
|
+
return -1 if @y < other_point.y
|
36
|
+
|
37
|
+
# they are the same point
|
38
|
+
return 0
|
39
|
+
end
|
40
|
+
|
27
41
|
def == (other_point)
|
28
42
|
@x==other_point.x && @y==other_point.y
|
29
43
|
end
|
@@ -24,4 +24,45 @@ describe WindingPolygon do
|
|
24
24
|
|
25
25
|
end
|
26
26
|
|
27
|
+
|
28
|
+
it 'should decompose a practical complex polygon into four simple polygons' do
|
29
|
+
|
30
|
+
points = JSON.parse("[[-98.4609375000036,40.3051841980949],[-98.4609375000036,38.057277897745],[-96.0878906250017,40.1038062719331],[-96.6152343750031,37.9880405545487],[-97.6152343750031,40.9880405545487],[-98.0152343750031,37.9880405545487],[-98.4609375000036,40.3051841980949]]")
|
31
|
+
polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
|
32
|
+
|
33
|
+
multi_polygons = []
|
34
|
+
WindingPolygon.decompose(polygon,multi_polygons)
|
35
|
+
multi_polygons.should_not be_nil
|
36
|
+
|
37
|
+
multi_polygons.size.should == 4
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should decompose a production complex polygon 2 into two simple polygons' do
|
42
|
+
|
43
|
+
points = JSON.parse("[[-95.6968,29.93101],[-95.6992,29.93101],[-95.7016,29.9319],[-95.70401,29.93309],[-95.7071,29.93428],[-95.7095,29.93488],[-95.7119,29.93547],[-95.71431,29.93607],[-95.7174,29.93666],[-95.72014,29.93726],[-95.72255,29.93785],[-95.72564,29.93875],[-95.72804,29.93994],[-95.72598,29.95094],[-95.72358,29.95303],[-95.72152,29.95481],[-95.71877,29.95659],[-95.71637,29.95778],[-95.71362,29.95838],[-95.71122,29.95838],[-95.70847,29.95838],[-95.70538,29.95808],[-95.70195,29.95778],[-95.69851,29.95719],[-95.69405,29.956],[-95.69165,29.9554],[-95.6889,29.95451],[-95.68615,29.95332],[-95.68307,29.95184],[-95.68066,29.95124],[-95.67723,29.94856],[-95.67483,29.94648],[-95.67242,29.9438],[-95.67448,29.93607],[-95.67689,29.93339],[-95.67895,29.93161],[-95.68101,29.93131],[-95.68341,29.93131],[-95.68615,29.93131],[-95.6889,29.93101],[-95.69165,29.93101],[-95.69439,29.93101],[-95.69748,29.93161],[-95.70023,29.9322],[-95.70435,29.93339],[-95.70641,29.93428],[-95.70984,29.93458],[-95.6968,29.93101]]")
|
44
|
+
polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0].to_f,item[1].to_f)})
|
45
|
+
|
46
|
+
multi_polygons = []
|
47
|
+
WindingPolygon.decompose(polygon,multi_polygons)
|
48
|
+
multi_polygons.should_not be_nil
|
49
|
+
|
50
|
+
multi_polygons.size.should == 3
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should decompose a production complex polygon 3 into two simple polygons' do
|
55
|
+
|
56
|
+
points = JSON.parse("[[-95.6968,29.93101],[-95.6992,29.93101],[-95.7016,29.9319],[-95.70401,29.93309],[-95.7071,29.93428],[-95.70747130044843,29.934372825112106],[-95.70984,29.93458],[-95.6968,29.93101]]")
|
57
|
+
polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0].to_f,item[1].to_f)})
|
58
|
+
|
59
|
+
multi_polygons = []
|
60
|
+
WindingPolygon.decompose(polygon,multi_polygons)
|
61
|
+
multi_polygons.should_not be_nil
|
62
|
+
|
63
|
+
multi_polygons.size.should == 2
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
27
68
|
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.6
|
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-05-
|
11
|
+
date: 2013-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -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: []
|
@@ -92,17 +92,17 @@ require_paths:
|
|
92
92
|
- lib
|
93
93
|
required_ruby_version: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- -
|
95
|
+
- - '>='
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
|
-
- -
|
100
|
+
- - '>='
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
103
|
requirements: []
|
104
104
|
rubyforge_project:
|
105
|
-
rubygems_version: 2.0.
|
105
|
+
rubygems_version: 2.0.0
|
106
106
|
signing_key:
|
107
107
|
specification_version: 4
|
108
108
|
summary: Detect intersecting points and decompose it into multi-polygons
|