winding-polygon 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f09f3e08429b83b14f827767c614a710c744d00
4
- data.tar.gz: 3a2490fe74d30ffccb353b72dad90df6d381950f
3
+ metadata.gz: 85c02cb1aaf6a6c9f5a9e06f4731dbf064138e3c
4
+ data.tar.gz: 27b0ebb85854fdf76e29ffd49a23d87bae4526f2
5
5
  SHA512:
6
- metadata.gz: adde2609596a7b83a81a234cb4a1d66fde5cade1663f28aeece7361147490a48a61f9d29d164ac7382a20df5ee54361b4ed0b732043f654607321e193b2d8cf0
7
- data.tar.gz: 13babb54197e2582cc71fed07e3aa08a2c13f8ced36c70c51e5bd528e2a1f4e61309cd741533140759c60e453891465bb44b378dc0c1f16a9b039224ce22a5af
6
+ metadata.gz: 3c86d59427916f6f208c1d1a076aca97cb9d8df6477db51029d05bb73f12aa5030f37c3bcdc5e84af2174d4abc8c229caf539ce1a99a7d3ec59ec826795cb86a
7
+ data.tar.gz: 5bd346c94dba56d354e47631c7fc61edb00757c693ba44ece95da9b20d4041acc95b720f9d8fc469cbb08a454da9a614d7881bb4145676349c73e0e309b8bb47
@@ -28,8 +28,18 @@ module WindingPolygon
28
28
  end
29
29
  end
30
30
 
31
+ @events.sort_by! {|event| event[:vertex].y}
32
+ left_y = @events.select{|event| event[:type]=='left'}[0][:vertex].y
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
38
+ end
39
+
31
40
  # sort events lexicographically
32
41
  @events.sort!{|a,b| a[:vertex].compare(b[:vertex])}
42
+
33
43
  end
34
44
 
35
45
  end
@@ -1,8 +1,8 @@
1
1
  module WindingPolygon
2
2
  class Point
3
3
 
4
- attr_reader :x
5
- attr_reader :y
4
+ attr_accessor :x
5
+ attr_accessor :y
6
6
 
7
7
  def initialize(x,y)
8
8
  @x=x
@@ -14,17 +14,17 @@ module WindingPolygon
14
14
  end
15
15
 
16
16
  def <(other_segment)
17
- return true if @edge<other_segment.edge
17
+ return true if @left_point.y < other_segment.left_point.y
18
18
  return false
19
19
  end
20
20
 
21
21
  def >(other_segment)
22
- return true if @edge>other_segment.edge
22
+ return true if @left_point.y > other_segment.left_point.y
23
23
  return false
24
24
  end
25
25
 
26
26
  def == (other_segment)
27
- @edge == other_segment.edge && @left_point == other_segment.left_point && @right_point == other_segment.right_point
27
+ return true if @left_point.y == other_segment.left_point.y
28
28
  end
29
29
 
30
30
  def to_s
@@ -1,3 +1,3 @@
1
1
  module WindingPolygon
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/spec/polygon_spec.rb CHANGED
@@ -115,7 +115,7 @@ describe "Polygon" do
115
115
 
116
116
  it 'test is complex polygon 2' do
117
117
 
118
- points = JSON.parse("[[2.0, 2.0], [3.0, 2.0], [3.0, 3.0], [4.0, 2.0], [2.0, 2.0]]")
118
+ points = JSON.parse("[[2.0, 2.0], [3.0, 2.0], [3.0, 3.0], [4.0, 1.0],[2.0, 3.0], [2.0, 2.0]]")
119
119
  polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
120
120
 
121
121
  polygon.is_simple.should == false
@@ -141,6 +141,16 @@ describe "Polygon" do
141
141
 
142
142
  end
143
143
 
144
+ it 'test is production complex polygon 1' do
145
+
146
+ #points = JSON.parse("[[41.96514,-87.80356],[41.96182,-87.80115],[41.96156,-87.79909],[41.96131,-87.79635],[41.96105,-87.79394],[41.9608,-87.79188],[41.95978,-87.78914],[41.95876,-87.78708],[41.95722,-87.78467],[41.95544,-87.78193],[41.95339,-87.77987],[41.9511,-87.77781],[41.94803,-87.77541],[41.94446,-87.773],[41.94063,-87.7706],[41.9368,-87.76785],[41.93271,-87.76545],[41.92658,-87.76339],[41.91687,-87.76133],[41.87522,-87.76373],[41.87445,-87.76579],[41.87394,-87.76854],[41.87368,-87.7706],[41.87343,-87.77335],[41.87266,-87.77575],[41.8724,-87.77815],[41.87215,-87.78021],[41.87164,-87.78296],[41.87113,-87.78536],[41.87113,-87.78776],[41.87113,-87.78982],[41.87113,-87.79223],[41.87113,-87.79463],[41.87113,-87.79703],[41.87138,-87.79978],[41.87189,-87.80184],[41.8724,-87.8039],[41.87317,-87.8063],[41.87419,-87.80871],[41.87471,-87.81077],[41.87547,-87.81283],[41.87649,-87.81523],[41.87726,-87.81729],[41.87752,-87.81935],[41.87777,-87.82141],[41.87803,-87.82347],[41.87828,-87.82622],[41.87854,-87.82862],[41.87854,-87.83171],[41.8788,-87.83377],[41.87931,-87.83652],[41.88007,-87.83926],[41.88058,-87.84132],[41.88135,-87.84373],[41.88237,-87.84613],[41.88365,-87.84888],[41.88493,-87.85094],[41.88697,-87.85334],[41.89055,-87.8554],[41.89515,-87.85746],[41.90026,-87.85952],[41.90435,-87.86158],[41.92913,-87.85952],[41.93373,-87.85746],[41.94139,-87.8554],[41.94573,-87.85334],[41.94778,-87.85094],[41.94905,-87.84888],[41.95059,-87.84647],[41.95263,-87.84304],[41.95365,-87.84098],[41.95442,-87.83892],[41.95671,-87.83514],[41.95773,-87.83308],[41.95901,-87.83102],[41.96003,-87.82862],[41.96207,-87.82484],[41.9631,-87.82107],[41.9631,-87.81901],[41.9631,-87.81695],[41.9631,-87.81351],[41.96284,-87.81042],[41.96233,-87.80699],[41.96207,-87.80424],[41.96156,-87.80184],[41.96105,-87.79978],[41.95901,-87.79703],[41.96514,-87.80356]]")
147
+ points = JSON.parse("[[-87.80356,41.96514],[-87.80115,41.96182],[-87.79909,41.96156],[-87.79635,41.96131],[-87.79394,41.96105],[-87.79188,41.9608],[-87.78914,41.95978],[-87.78708,41.95876],[-87.78467,41.95722],[-87.78193,41.95544],[-87.77987,41.95339],[-87.77781,41.9511],[-87.77541,41.94803],[-87.773,41.94446],[-87.7706,41.94063],[-87.76785,41.9368],[-87.76545,41.93271],[-87.76339,41.92658],[-87.76133,41.91687],[-87.76373,41.87522],[-87.76579,41.87445],[-87.76854,41.87394],[-87.7706,41.87368],[-87.77335,41.87343],[-87.77575,41.87266],[-87.77815,41.8724],[-87.78021,41.87215],[-87.78296,41.87164],[-87.78536,41.87113],[-87.78776,41.87113],[-87.78982,41.87113],[-87.79223,41.87113],[-87.79463,41.87113],[-87.79703,41.87113],[-87.79978,41.87138],[-87.80184,41.87189],[-87.8039,41.8724],[-87.8063,41.87317],[-87.80871,41.87419],[-87.81077,41.87471],[-87.81283,41.87547],[-87.81523,41.87649],[-87.81729,41.87726],[-87.81935,41.87752],[-87.82141,41.87777],[-87.82347,41.87803],[-87.82622,41.87828],[-87.82862,41.87854],[-87.83171,41.87854],[-87.83377,41.8788],[-87.83652,41.87931],[-87.83926,41.88007],[-87.84132,41.88058],[-87.84373,41.88135],[-87.84613,41.88237],[-87.84888,41.88365],[-87.85094,41.88493],[-87.85334,41.88697],[-87.8554,41.89055],[-87.85746,41.89515],[-87.85952,41.90026],[-87.86158,41.90435],[-87.85952,41.92913],[-87.85746,41.93373],[-87.8554,41.94139],[-87.85334,41.94573],[-87.85094,41.94778],[-87.84888,41.94905],[-87.84647,41.95059],[-87.84304,41.95263],[-87.84098,41.95365],[-87.83892,41.95442],[-87.83514,41.95671],[-87.83308,41.95773],[-87.83102,41.95901],[-87.82862,41.96003],[-87.82484,41.96207],[-87.82107,41.9631],[-87.81901,41.9631],[-87.81695,41.9631],[-87.81351,41.9631],[-87.81042,41.96284],[-87.80699,41.96233],[-87.80424,41.96207],[-87.80184,41.96156],[-87.79978,41.96105],[-87.79703,41.95901],[-87.80356,41.96514]]")
148
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0],item[1])})
149
+
150
+ polygon.is_simple.should == false
151
+
152
+ end
153
+
144
154
  it 'get complex polygon 3 intersection points' do
145
155
 
146
156
  points = JSON.parse("[[0.0, 0.0], [3.0, 3.0], [0.0, 3.0], [3.0, 0.0], [0.0, 0.0]]")
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
4
+ version: 0.0.5
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-13 00:00:00.000000000 Z
11
+ date: 2013-05-14 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: '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.0
105
+ rubygems_version: 2.0.3
106
106
  signing_key:
107
107
  specification_version: 4
108
108
  summary: Detect intersecting points and decompose it into multi-polygons