winding-polygon 0.0.6 → 0.0.7

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: 81637ec0ec7f02d00c10a2e683c31ec31a2de7cb
4
- data.tar.gz: 94db42e23f1df32e82af4e3353e69356e239a75c
3
+ metadata.gz: f8c0df6f0765c7a2a1a8a060d1bb6c78510ecef9
4
+ data.tar.gz: 6a0d538f3f4b56cf79c1445953da99f363130b27
5
5
  SHA512:
6
- metadata.gz: 9a661b1dbe28627aaa6638365b4065cc43b7f77f39a0dd7ebbbe8b649050bd71b7c9943ee68124e7f37663540ddc5565009164f29dd2578194faf4f2aaf1cc5b
7
- data.tar.gz: 58debae2b8874308c7df1ecf6aa38a6643044a07f33fc878948ac3e42ebf511eced0feda11e355109e865241eb5c6d4543806c83908154dce446dc2eb2f59cff
6
+ metadata.gz: 77e7991c609942476f78bf67c2944ccdde34d88f99e17cbc51823f98634ce6000bae5aa47635dc811b24cc125da188b011fc2d2bef2b2f1bd1fd1aed8b9a656e
7
+ data.tar.gz: 42958476e6918e4794eaa881c2c54624baf0aa41521865af4887341a36bdcb7d960c0abeaf326a0d54ba23614e87ebf4e2fc63c9d630b1ff09abc8de1d4410e1
@@ -25,6 +25,7 @@ module WindingPolygon
25
25
 
26
26
  def == (other_segment)
27
27
  return true if @left_point.y == other_segment.left_point.y
28
+ return false
28
29
  end
29
30
 
30
31
  def to_s
@@ -38,6 +39,8 @@ module WindingPolygon
38
39
  denominator = (@right_point.y - @left_point.y) * (other_segment.left_point.x - other_segment.right_point.x) -
39
40
  (other_segment.left_point.y - other_segment.right_point.y) * (@right_point.x - @left_point.x)
40
41
 
42
+ return nil if denominator==0
43
+
41
44
  t = numerator.to_f / denominator
42
45
 
43
46
  x = @left_point.x + t * (@right_point.x - @left_point.x)
@@ -134,7 +134,9 @@ module WindingPolygon
134
134
  return nil if (lsign * rsign > 0)
135
135
 
136
136
  #segments s1 and s2 straddle. Intersect exists.
137
- s1.intersection_point_with(s2)
137
+ intersection_point = s1.intersection_point_with(s2)
138
+ return nil if intersection_point.nil?
139
+ intersection_point
138
140
  end
139
141
  end
140
142
  end
@@ -1,3 +1,3 @@
1
1
  module WindingPolygon
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -64,5 +64,19 @@ describe WindingPolygon do
64
64
 
65
65
  end
66
66
 
67
+ it 'should decompose a production complex polygon 4 into two simple polygons' do
68
+
69
+ 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]]")
70
+ polygon = WindingPolygon::Polygon.new(points.map{|item| WindingPolygon::Point.new(item[0].to_f,item[1].to_f)})
71
+
72
+ multi_polygons = []
73
+ WindingPolygon.decompose(polygon,multi_polygons)
74
+ multi_polygons.should_not be_nil
75
+
76
+ multi_polygons.size.should == 2
77
+
78
+ end
79
+
80
+
67
81
 
68
82
  end
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.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Xu