Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize Validation #228

Merged
merged 6 commits into from Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 60 additions & 4 deletions .travis.yml
@@ -1,11 +1,67 @@
dist: trusty
language: ruby

os:
- linux
dist: xenial

addons:
apt:
packages:
- libgeos-3.4.2
language: ruby
- libgeos-dev
- libgeos-3.5.0

jobs:
include:
- os: linux
dist: trusty
addons:
apt:
packages:
- libgeos-dev
- libgeos-3.4.2

- os: linux
dist: xenial
addons:
apt:
packages:
- libgeos-dev
- libgeos-3.5.0

- os: linux
dist: bionic
addons:
apt:
packages:
- libgeos-dev
- libgeos-3.6.2

- os: linux
dist: eoan
addons:
apt:
packages:
- libgeos-dev
- libgeos-3.7.2

- os: linux
dist: focal
addons:
apt:
packages:
- libgeos-dev
- libgeos-3.8.0

- os: osx
addons:
homebrew:
packages:
- geos
update: true

rvm:
- 2.7
- 2.6
- 2.5
- 2.4
- jruby-9.2.6.0
- jruby-9.2.13.0
2 changes: 2 additions & 0 deletions History.md
@@ -1,7 +1,9 @@
### Current

* Add SphericalPolygonMethods#centroid #208 (allknowingfrog)
* Expand gemspec
* Drop Ruby 2.3 support
* Change ProjectedLinearRing #is_simple? method to be uniform across geos versions #228

### 2.1.1 / 2019-8-26

Expand Down
1 change: 1 addition & 0 deletions lib/rgeo/geographic/projected_feature_classes.rb
Expand Up @@ -33,6 +33,7 @@ class ProjectedLinearRingImpl # :nodoc:
include ProjectedGeometryMethods
include ProjectedNCurveMethods
include ProjectedLineStringMethods
include ProjectedLinearRingMethods
end

class ProjectedLineImpl # :nodoc:
Expand Down
6 changes: 6 additions & 0 deletions lib/rgeo/geographic/projected_feature_methods.rb
Expand Up @@ -166,6 +166,12 @@ def validate_geometry
end
end

module ProjectedLinearRingMethods # :nodoc:
def is_simple?
projection.valid?
end
end

module ProjectedNSurfaceMethods # :nodoc:
def area
projection.area
Expand Down
4 changes: 4 additions & 0 deletions lib/rgeo/geos/ffi_feature_methods.rb
Expand Up @@ -121,6 +121,10 @@ def is_simple?
@fg_geom.simple?
end

def valid?
@fg_geom.valid?
end

def equals?(rhs)
return false unless rhs.is_a?(RGeo::Feature::Instance)
fg = factory.convert_to_fg_geometry(rhs)
Expand Down
2 changes: 1 addition & 1 deletion test/common/multi_polygon_tests.rb
Expand Up @@ -200,7 +200,7 @@ def test_boundary
parsed_coordinates.zip(boundary_coordinates).each do |parsed_line, boundary_line|
parsed_line.zip(boundary_line).each do |p_coord, b_coord|
p_coord.zip(b_coord).each do |p_val, b_val|
assert_in_delta(p_val, b_val, 0.00000000000001)
assert_in_delta(p_val, b_val, 1e-13)
end
end
end
Expand Down
12 changes: 11 additions & 1 deletion test/geos_capi/polygon_test.rb
Expand Up @@ -109,7 +109,17 @@ def test_buffer_with_style
buffered_line_string =
line_string.buffer_with_style(0.3, RGeo::Geos::CAP_SQUARE, RGeo::Geos::JOIN_MITRE, 5)

assert_equal polygon, buffered_line_string
# having issues with floating point errors on some systems
# 4.3 -> 4.29999999999999, for example, and throws an error
# iterating through points and using assert_in_delta instead
# of assert_equal
b_coords = buffered_line_string.exterior_ring.coordinates
p_coords = polygon.exterior_ring.coordinates
p_coords.zip(b_coords).each do |p_coord, b_coord|
p_coord.zip(b_coord).each do |pt1, pt2|
assert_in_delta(pt1, pt2, 1e-7)
end
end
Comment on lines +112 to +122
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is not satisfying, but this PR is not the place to fix floating point errors!

end

def test_is_valid_polygon
Expand Down
16 changes: 16 additions & 0 deletions test/geos_ffi/polygon_test.rb
Expand Up @@ -36,4 +36,20 @@ def test_union
poly3 = poly1.union(poly2)
assert_equal(poly1, poly3)
end

def test_is_valid_polygon
polygon_coordinates = [[0, 0], [0, 5], [5, 5], [5, 0], [0, 0]]
points_arr = polygon_coordinates.map { |v| @factory.point(v[0], v[1]) }
outer_ring = @factory.linear_ring(points_arr)
polygon = @factory.polygon(outer_ring)

assert_equal(polygon.valid?, true)

polygon_coordinates = [[-1, -1], [-1, 0], [1, 0], [1, 1], [0, 1], [0, -1], [-1, -1]]
points_arr = polygon_coordinates.map { |v| @factory.point(v[0], v[1]) }
outer_ring = @factory.linear_ring(points_arr)
polygon = @factory.polygon(outer_ring)

assert_equal(polygon.valid?, false)
end
end if RGeo::Geos.ffi_supported?
8 changes: 8 additions & 0 deletions test/simple_mercator/polygon_test.rb
Expand Up @@ -15,6 +15,14 @@ def setup
@factory = RGeo::Geographic.simple_mercator_factory
end

def test_is_simple_validation_behavior
# See https://github.com/rgeo/rgeo/issues/218
assert_raises RGeo::Error::InvalidGeometry do
wkt = "POLYGON((0 0, 1 1, 1 0, 0 1, 0 0))"
@factory.parse_wkt(wkt)
end
end

# These tests suffer from floating point issues
undef_method :test_point_on_surface
undef_method :test_boundary_one_hole
Expand Down