winding-polygon 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module WindingPolygon
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -5,8 +5,8 @@ describe "EventQueue" do
5
5
  it "test can create an EventQueue" do
6
6
 
7
7
  points = JSON.parse("[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]")
8
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
9
- event_queue = EventQueue.new(polygon)
8
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
9
+ event_queue = WindingPolygon::EventQueue.new(polygon)
10
10
 
11
11
  event_queue.events.length.should == 8
12
12
  event_queue.events.length.should == event_queue.number_of_events
data/spec/point_spec.rb CHANGED
@@ -3,40 +3,40 @@ require 'spec_helper'
3
3
  describe "Point" do
4
4
 
5
5
  it 'test less than comparator' do
6
- p0 = Point.new(1,1)
7
- p1 = Point.new(3,3)
6
+ p0 = WindingPolygon::Point.new(1,1)
7
+ p1 = WindingPolygon::Point.new(3,3)
8
8
  p0.compare(p1).should == -1
9
9
  end
10
10
 
11
11
  it 'test more than comparator' do
12
- p0 = Point.new(1,1)
13
- p1 = Point.new(3,3)
12
+ p0 = WindingPolygon::Point.new(1,1)
13
+ p1 = WindingPolygon::Point.new(3,3)
14
14
  p1.compare(p0).should == 1
15
15
  end
16
16
 
17
17
  it 'test equality' do
18
- p0 = Point.new(1,1)
18
+ p0 = WindingPolygon::Point.new(1,1)
19
19
  p0.compare(p0).should == 0
20
20
  end
21
21
 
22
22
  it 'test left of line' do
23
- p0 = Point.new(1,1)
24
- p1 = Point.new(3,3)
25
- p2 = Point.new(1,3)
23
+ p0 = WindingPolygon::Point.new(1,1)
24
+ p1 = WindingPolygon::Point.new(3,3)
25
+ p2 = WindingPolygon::Point.new(1,3)
26
26
  p2.is_left(p0,p1).should > 0
27
27
  end
28
28
 
29
29
  it 'test right of line' do
30
- p0 = Point.new(1,1)
31
- p1 = Point.new(3,3)
32
- p2 = Point.new(3,1)
30
+ p0 = WindingPolygon::Point.new(1,1)
31
+ p1 = WindingPolygon::Point.new(3,3)
32
+ p2 = WindingPolygon::Point.new(3,1)
33
33
  p2.is_left(p0,p1).should < 0
34
34
  end
35
35
 
36
36
  it 'test on of line' do
37
- p0 = Point.new(1,1)
38
- p1 = Point.new(3,3)
39
- p2 = Point.new(2,2)
37
+ p0 = WindingPolygon::Point.new(1,1)
38
+ p1 = WindingPolygon::Point.new(3,3)
39
+ p2 = WindingPolygon::Point.new(2,2)
40
40
  p2.is_left(p0,p1).should == 0
41
41
  end
42
42
 
data/spec/polygon_spec.rb CHANGED
@@ -5,7 +5,7 @@ describe "Polygon" do
5
5
  it 'test can build a polygon from an array of points' do
6
6
 
7
7
  points = JSON.parse("[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]")
8
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
8
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
9
9
 
10
10
  polygon.vertices.length.should == points.length
11
11
  polygon.vertices[0].x.should == points[0][0]
@@ -15,7 +15,7 @@ describe "Polygon" do
15
15
  it 'test is polygon simple 1' do
16
16
 
17
17
  points = JSON.parse("[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]")
18
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
18
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
19
19
 
20
20
  polygon.is_simple.should == true
21
21
 
@@ -24,7 +24,7 @@ describe "Polygon" do
24
24
  it 'test is polygon simple 2' do
25
25
 
26
26
  points = JSON.parse("[[2.0, 2.0], [1.0, 2.0], [1.0, 1.0], [2.0, 1.0], [3.0, 1.0], [3.0, 2.0], [2.0, 2.0]]")
27
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
27
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
28
28
 
29
29
  polygon.is_simple.should == true
30
30
 
@@ -33,7 +33,7 @@ describe "Polygon" do
33
33
  it 'test is polygon simple 3' do
34
34
 
35
35
  points = JSON.parse("[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]")
36
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
36
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
37
37
 
38
38
  polygon.is_simple.should == true
39
39
 
@@ -42,7 +42,7 @@ describe "Polygon" do
42
42
  it 'test is polygon simple 4' do
43
43
 
44
44
  points = JSON.parse("[[0.0, 0.0], [0.0, 3.0], [3.0, 3.0], [3.0, 0.0], [0.0, 0.0]]")
45
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
45
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
46
46
 
47
47
  polygon.is_simple.should == true
48
48
 
@@ -51,7 +51,7 @@ describe "Polygon" do
51
51
  it 'test is polygon simple 5' do
52
52
 
53
53
  points = JSON.parse("[[2.0, 2.0], [2.0, 3.0], [3.0, 3.0], [4.0, 3.0], [4.0, 2.0], [2.0, 2.0]]")
54
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
54
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
55
55
 
56
56
  polygon.is_simple.should == true
57
57
 
@@ -60,7 +60,7 @@ describe "Polygon" do
60
60
  it 'test is practical polygon simple 6 (clockwise)' do
61
61
 
62
62
  points = JSON.parse("[[-110.84096146619905, 32.206464264983815],[-110.8254844632264, 32.206404507969239],[-110.82564474991523, 32.2065185890533],[-110.8278203157768, 32.211149692139429],[-110.82920840010047, 32.217701622983441],[110.82990196985523,32.220975019031748],[-110.84096004697494,32.221011891029775],[-110.84096146619905,32.206464264983815]]")
63
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
63
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
64
64
 
65
65
  polygon.is_simple.should == true
66
66
 
@@ -69,7 +69,7 @@ describe "Polygon" do
69
69
  it 'test is practical polygon simple 7 (counter clockwise)' do
70
70
 
71
71
  points = JSON.parse("[[-118.845766, 34.013743],[-118.384777,34.013743],[-118.384777, 34.335579],[-118.845766, 34.335579],[-118.845766, 34.013743]]")
72
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
72
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
73
73
 
74
74
  polygon.is_simple.should == true
75
75
 
@@ -79,7 +79,7 @@ describe "Polygon" do
79
79
  it 'get_intersection_point_hash test for practical polygon simple 6 (clockwise)' do
80
80
 
81
81
  points = JSON.parse("[[-110.84096146619905, 32.206464264983815],[-110.8254844632264, 32.206404507969239],[-110.82564474991523, 32.2065185890533],[-110.8278203157768, 32.211149692139429],[-110.82920840010047, 32.217701622983441],[110.82990196985523,32.220975019031748],[-110.84096004697494,32.221011891029775],[-110.84096146619905,32.206464264983815]]")
82
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
82
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
83
83
 
84
84
  polygon.get_first_intersection_point_hash.should be_nil
85
85
 
@@ -88,7 +88,7 @@ describe "Polygon" do
88
88
  it 'get_intersection_point_hash test for practical polygon simple 6 (counter clockwise)' do
89
89
 
90
90
  points = JSON.parse("[[-118.845766, 34.013743],[-118.384777,34.013743],[-118.384777, 34.335579],[-118.845766, 34.335579],[-118.845766, 34.013743]]")
91
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
91
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
92
92
 
93
93
  polygon.get_first_intersection_point_hash.should be_nil
94
94
 
@@ -97,7 +97,7 @@ describe "Polygon" do
97
97
  it 'test is practical polygon simple 7 (counter clockwise)' do
98
98
 
99
99
  points = JSON.parse("[[-118.845766, 34.013743],[-118.384777,34.013743],[-118.384777, 34.335579],[-118.845766, 34.335579],[-118.845766, 34.013743]]")
100
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
100
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
101
101
 
102
102
  polygon.is_simple.should == true
103
103
 
@@ -107,7 +107,7 @@ describe "Polygon" do
107
107
  it 'test is complex polygon 1' do
108
108
 
109
109
  points = JSON.parse("[[100.0, 0.0],[101.0, 1.0],[100.0, 1.0],[101.0, 0.0], [100.0, 0.0]]")
110
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
110
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
111
111
 
112
112
  polygon.is_simple.should == false
113
113
 
@@ -116,7 +116,7 @@ describe "Polygon" do
116
116
  it 'test is complex polygon 2' do
117
117
 
118
118
  points = JSON.parse("[[2.0, 2.0], [3.0, 2.0], [3.0, 3.0], [4.0, 2.0], [2.0, 2.0]]")
119
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
119
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
120
120
 
121
121
  polygon.is_simple.should == false
122
122
 
@@ -125,7 +125,7 @@ describe "Polygon" do
125
125
  it 'test is complex polygon 3' do
126
126
 
127
127
  points = JSON.parse("[[0.0, 0.0], [3.0, 3.0], [0.0, 3.0], [3.0, 0.0], [0.0, 0.0]]")
128
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
128
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
129
129
 
130
130
  polygon.is_simple.should == false
131
131
 
@@ -135,7 +135,7 @@ describe "Polygon" do
135
135
  it 'test is practical complex polygon 4' do
136
136
 
137
137
  points = JSON.parse("[[-98.4609375000036,40.3051841980949],[-98.4609375000036,38.057277897745],[-96.0878906250017,40.1038062719331],[-96.6152343750031,37.9880405545487],[-98.4609375000036,40.3051841980949]]")
138
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
138
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
139
139
 
140
140
  polygon.is_simple.should == false
141
141
 
@@ -144,44 +144,44 @@ describe "Polygon" do
144
144
  it 'get complex polygon 3 intersection points' do
145
145
 
146
146
  points = JSON.parse("[[0.0, 0.0], [3.0, 3.0], [0.0, 3.0], [3.0, 0.0], [0.0, 0.0]]")
147
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
147
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
148
148
 
149
- polygon.get_intersection_points[0].should == Point.new(1.5,1.5)
149
+ polygon.get_intersection_points[0].should == WindingPolygon::Point.new(1.5,1.5)
150
150
 
151
151
  end
152
152
 
153
153
  it 'get practical complex polygon 4 intersection points' do
154
154
 
155
155
  points = JSON.parse("[[-98.4609375000036,40.3051841980949],[-98.4609375000036,38.057277897745],[-96.0878906250017,40.1038062719331],[-96.6152343750031,37.9880405545487],[-98.4609375000036,40.3051841980949]]")
156
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
156
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
157
157
 
158
- polygon.get_intersection_points[0].should == Point.new(-97.39951856124108,38.97265129300353)
158
+ polygon.get_intersection_points[0].should == WindingPolygon::Point.new(-97.39951856124108,38.97265129300353)
159
159
 
160
160
  end
161
161
 
162
162
  it 'get_intersection_point_hash test for practical complex polygon' do
163
163
 
164
164
  points = JSON.parse("[[-98.4609375000036,40.3051841980949],[-98.4609375000036,38.057277897745],[-96.0878906250017,40.1038062719331],[-96.6152343750031,37.9880405545487],[-98.4609375000036,40.3051841980949]]")
165
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
165
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
166
166
 
167
- polygon.get_first_intersection_point_hash.should == {:point=>Point.new(-97.39951856124108,38.97265129300353),:edge1=>1,:edge2=>3 }
167
+ polygon.get_first_intersection_point_hash.should == {:point=>WindingPolygon::Point.new(-97.39951856124108,38.97265129300353),:edge1=>1,:edge2=>3 }
168
168
 
169
169
  end
170
170
 
171
171
  it 'should decompose a practical complex polygon into two simple polygons' do
172
172
 
173
173
  points = JSON.parse("[[-98.4609375000036,40.3051841980949],[-98.4609375000036,38.057277897745],[-96.0878906250017,40.1038062719331],[-96.6152343750031,37.9880405545487],[-98.4609375000036,40.3051841980949]]")
174
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
174
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
175
175
 
176
176
  multi_polygons = polygon.decompose
177
177
  multi_polygons.should_not be_nil
178
178
 
179
179
  points1 = JSON.parse("[[-98.4609375000036,40.3051841980949],[-98.4609375000036,38.057277897745],[-97.39951856124108,38.97265129300353],[-98.4609375000036,40.3051841980949]]")
180
- polygon1 = Polygon.new(points1.map{|item| Point.new(item[0],item[1])})
180
+ polygon1 = WindingPolygon::Polygon.new(points1.map{|item| WindingPolygon::Point.new(item[0],item[1])})
181
181
  multi_polygons[0].should ==polygon1
182
182
 
183
183
  points2 = JSON.parse("[[-97.39951856124108,38.97265129300353],[-96.0878906250017,40.1038062719331],[-96.6152343750031,37.9880405545487],[-97.39951856124108,38.97265129300353]]")
184
- polygon2 = Polygon.new(points2.map{|item| Point.new(item[0],item[1])})
184
+ polygon2 = WindingPolygon::Polygon.new(points2.map{|item| WindingPolygon::Point.new(item[0],item[1])})
185
185
  multi_polygons[1].should ==polygon2
186
186
 
187
187
  end
data/spec/segment_spec.rb CHANGED
@@ -4,13 +4,13 @@ describe "Segment" do
4
4
 
5
5
  it "test_segments_intersect_at_the_endpoint" do
6
6
 
7
- segment1 = Segment.new({:edge=>0})
8
- segment1.left_point = Point.new(0,0)
9
- segment1.right_point = Point.new(2,2)
7
+ segment1 = WindingPolygon::Segment.new({:edge=>0})
8
+ segment1.left_point = WindingPolygon::Point.new(0,0)
9
+ segment1.right_point = WindingPolygon::Point.new(2,2)
10
10
 
11
- segment2 = Segment.new({:edge=>1})
12
- segment2.left_point = Point.new(0,2)
13
- segment2.right_point = Point.new(2,2)
11
+ segment2 = WindingPolygon::Segment.new({:edge=>1})
12
+ segment2.left_point = WindingPolygon::Point.new(0,2)
13
+ segment2.right_point = WindingPolygon::Point.new(2,2)
14
14
 
15
15
  intersection_point = segment1.intersection_point_with(segment2)
16
16
  intersection_point.x.should ==2
@@ -4,9 +4,9 @@ describe "SweepLine" do
4
4
 
5
5
  it "test can find" do
6
6
  points = JSON.parse("[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]")
7
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
8
- sweep_line = SweepLine.new(polygon)
9
- event_queue = EventQueue.new(polygon)
7
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
8
+ sweep_line = WindingPolygon::SweepLine.new(polygon)
9
+ event_queue = WindingPolygon::EventQueue.new(polygon)
10
10
 
11
11
  event = event_queue.events.pop
12
12
  while !event.nil?
@@ -8,18 +8,18 @@ describe WindingPolygon do
8
8
  it 'should decompose a practical complex polygon into two simple polygons' do
9
9
 
10
10
  points = JSON.parse("[[-98.4609375000036,40.3051841980949],[-98.4609375000036,38.057277897745],[-96.0878906250017,40.1038062719331],[-96.6152343750031,37.9880405545487],[-98.4609375000036,40.3051841980949]]")
11
- polygon = Polygon.new(points.map{|item| Point.new(item[0],item[1])})
11
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
12
12
 
13
13
  multi_polygons = []
14
14
  WindingPolygon.decompose(polygon,multi_polygons)
15
15
  multi_polygons.should_not be_nil
16
16
 
17
17
  points1 = JSON.parse("[[-98.4609375000036,40.3051841980949],[-98.4609375000036,38.057277897745],[-97.39951856124108,38.97265129300353],[-98.4609375000036,40.3051841980949]]")
18
- polygon1 = Polygon.new(points1.map{|item| Point.new(item[0],item[1])})
18
+ polygon1 = WindingPolygon::Polygon.new(points1.map{|item| WindingPolygon::Point.new(item[0],item[1])})
19
19
  multi_polygons[0].should ==polygon1
20
20
 
21
21
  points2 = JSON.parse("[[-97.39951856124108,38.97265129300353],[-96.0878906250017,40.1038062719331],[-96.6152343750031,37.9880405545487],[-97.39951856124108,38.97265129300353]]")
22
- polygon2 = Polygon.new(points2.map{|item| Point.new(item[0],item[1])})
22
+ polygon2 = WindingPolygon::Polygon.new(points2.map{|item| WindingPolygon::Point.new(item[0],item[1])})
23
23
  multi_polygons[1].should ==polygon2
24
24
 
25
25
  end
data/test/test_avltree.rb CHANGED
@@ -9,13 +9,13 @@ class TestAVLTree < Test::Unit::TestCase
9
9
  # 1 4
10
10
  # 3 5
11
11
  #
12
- @tree = AVLTree.new [1,2,5,4,3]
12
+ @tree = WindingPolygon::AVLTree.new [1,2,5,4,3]
13
13
  #
14
14
  # 4
15
15
  # 2 6
16
16
  # 1 3 5 7
17
17
  #
18
- @rot_tree = AVLTree.new [4,2,6,3,1,5,7]
18
+ @rot_tree = WindingPolygon::AVLTree.new [4,2,6,3,1,5,7]
19
19
  end
20
20
 
21
21
  def test_sort
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.3
4
+ version: 0.0.4
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: ! 'Use Bentley-Ottmann algorithm to solve self-intersecting polygon issue '
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.3
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