bfoz / geometry

Geometric primitives for Ruby
https://rubygems.org/gems/geometry
BSD 2-Clause "Simplified" License
47 stars 18 forks source link

[Bug] Specific Polygons That Won't Union #78

Open sdubinsky opened 4 years ago

sdubinsky commented 4 years ago

Hi, I have two polygons:

geo1 = Geometry::Polygon.new(Geometry::Point[1691, 957], Geometry::Point[1677, 1175], Geometry::Point[1635, 1173], Geometry::Point[1649, 951])
geo2 = Geometry::Polygon.new(Geometry::Point[1690, 1033], Geometry::Point[1687, 1139], Geometry::Point[1670, 1138], Geometry::Point[1673, 1030])

When I call geo1.union(geo2) it throws an error:

Error:
TestBox#test_broken_box:
NoMethodError: undefined method `first' for nil:NilClass
    /home/deus-ex/.gem/ruby/2.7.1/gems/geometry-6.5/lib/geometry/polyline.rb:143:in `close!'
    /home/deus-ex/.gem/ruby/2.7.1/gems/geometry-6.5/lib/geometry/polygon.rb:32:in `initialize'
    /home/deus-ex/.gem/ruby/2.7.1/gems/geometry-6.5/lib/geometry/polygon.rb:174:in `new'
    /home/deus-ex/.gem/ruby/2.7.1/gems/geometry-6.5/lib/geometry/polygon.rb:174:in `union'
    /home/deus-ex/code/title_reader/test/test_box.rb:147:in `test_broken_box'

However, if I call geo2.union(geo1) it works fine. It also works if I change the first point in geo2 to Geometry::Point[1695, 1033]. I don't know enough about geometry to debug this further.

Thanks!

sdubinsky commented 4 years ago

This is geometry version 6.5.