Skip to content

Commit

Permalink
Merge pull request #361 from rgeo/fix/capi-no-z
Browse files Browse the repository at this point in the history
fix(capi): Compatibility with GEOS 3.12
  • Loading branch information
keithdoggett committed Aug 24, 2023
2 parents b58faa4 + 18e22c5 commit 8f61123
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 10 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ on:
branches:
- main
pull_request:
workflow_dispatch:

# This allows a subsequently queued workflow run to interrupt previous runs.
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true

jobs:
Test:
Expand Down Expand Up @@ -49,7 +55,7 @@ jobs:
run: bundle install
- name: Set Maintainer Mode
if: ${{ github.event.pull_request }}
run: export MAINTAINER_MODE=1
run: export MAINTAINER_MODE='-Wold-style-definition'
- name: Test
run: bundle exec rake
Memcheck:
Expand Down
4 changes: 4 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* Fix Lint/MissingSuper from rubocop_todos. (@haroon26) #352
* Drop support for Ruby 2.6. (@seuros) #353

**Bug Fixes**

* Support GEOS 3.12 #361

### 3.0.0 / 2023-01-25

**Breaking Changes**
Expand Down
2 changes: 2 additions & 0 deletions ext/geos_c_impl/factory.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ method_factory_write_for_marshal(VALUE self, VALUE obj)
wkb_writer = self_data->marshal_wkb_writer;
if (!wkb_writer) {
wkb_writer = GEOSWKBWriter_create();
GEOSWKBWriter_setOutputDimension(wkb_writer, 2);
if (has_3d) {
GEOSWKBWriter_setOutputDimension(wkb_writer, 3);
}
Expand Down Expand Up @@ -427,6 +428,7 @@ method_factory_write_for_psych(VALUE self, VALUE obj)
wkt_writer = self_data->psych_wkt_writer;
if (!wkt_writer) {
wkt_writer = GEOSWKTWriter_create();
GEOSWKTWriter_setOutputDimension(wkt_writer, 2);
GEOSWKTWriter_setTrim(wkt_writer, 1);
if (has_3d) {
GEOSWKTWriter_setOutputDimension(wkt_writer, 3);
Expand Down
2 changes: 2 additions & 0 deletions ext/geos_c_impl/geometry.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ method_geometry_as_text(VALUE self)
wkt_writer = factory_data->wkt_writer;
if (!wkt_writer) {
wkt_writer = GEOSWKTWriter_create();
GEOSWKTWriter_setOutputDimension(wkt_writer, 2);
GEOSWKTWriter_setTrim(wkt_writer, 1);
factory_data->wkt_writer = wkt_writer;
}
Expand Down Expand Up @@ -304,6 +305,7 @@ method_geometry_as_binary(VALUE self)

if (!wkb_writer) {
wkb_writer = GEOSWKBWriter_create();
GEOSWKBWriter_setOutputDimension(wkb_writer, 2);
factory_data->wkb_writer = wkb_writer;
}
str = (char*)GEOSWKBWriter_write(wkb_writer, self_geom, &size);
Expand Down
4 changes: 4 additions & 0 deletions lib/rgeo/geos/ffi_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def initialize(opts = {})
@wkt_writer = nil
else
@wkt_writer = ::Geos::WktWriter.new
@wkt_writer.output_dimensions = 2
@wkt_writer.trim = true
@wkt_generator = nil
end
Expand All @@ -66,6 +67,7 @@ def initialize(opts = {})
@wkb_writer = nil
else
@wkb_writer = ::Geos::WkbWriter.new
@wkb_writer.output_dimensions = 2
@wkb_generator = nil
end

Expand Down Expand Up @@ -447,6 +449,7 @@ def generate_wkb(geom)
def write_for_marshal(geom)
if Utils.ffi_supports_set_output_dimension || !@_has_3d
wkb_writer = ::Geos::WkbWriter.new
wkb_writer.output_dimensions = 2
wkb_writer.output_dimensions = 3 if @_has_3d
wkb_writer.write(geom.fg_geom)
else
Expand All @@ -461,6 +464,7 @@ def read_for_marshal(str)
def write_for_psych(geom)
if Utils.ffi_supports_set_output_dimension || !@_has_3d
wkt_writer = ::Geos::WktWriter.new
wkt_writer.output_dimensions = 2
wkt_writer.trim = true
wkt_writer.output_dimensions = 3 if @_has_3d
wkt_writer.write(geom.fg_geom)
Expand Down
2 changes: 1 addition & 1 deletion test/docs/documentation_links_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

require_relative "../test_helper"

class DocumentationLinksTest < MiniTest::Test # :nodoc:
class DocumentationLinksTest < Minitest::Test # :nodoc:
def test_every_markdown_documents_linked
root_path = File.join(__dir__, "..", "..")
by_files = Dir[File.join(root_path, "doc", "*.md")]
Expand Down
2 changes: 1 addition & 1 deletion test/docs/examples_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# If this test raises an error, then the Examples.md file should
# be updated.

class ExamplesTest < MiniTest::Test
class ExamplesTest < Minitest::Test
def test_examples
unless RGeo::Geos.ffi_supported? && RGeo::Geos.capi_supported?
skip "Examples can only be run with FFI and CAPI support"
Expand Down
2 changes: 1 addition & 1 deletion test/docs/factory_compatibility_table_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Ensure that compatiblity table stays up to date. If this test fails
# and your diff shows a checkmark instead of a red X, thanks for adding
# that feature ! Otherwise, please take a look at your contribution.
class FactoryCompatibilityTableTest < MiniTest::Test # :nodoc:
class FactoryCompatibilityTableTest < Minitest::Test # :nodoc:
def test_table_ok
unless RGeo::Geos.ffi_supported? && RGeo::Geos.capi_supported?
skip "Factory Compatibility table can only be generated with FFI and CAPI support"
Expand Down
15 changes: 12 additions & 3 deletions test/geos_capi/analysis_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@ def test_ccw_p_raises_if_not_a_geos_object
assert_raises(RGeo::Error::RGeoError) { RGeo::Geos::Analysis.ccw?(ring) }
end

def test_ccw_p_raises_if_no_coordseq
def test_ccw_p_false_if_not_enough
skip "Needs GEOS 3.7+" unless RGeo::Geos::Analysis.ccw_supported?
factory = RGeo::Geos.factory(native_interface: :capi)
point = factory.point(1, 2)
assert_raises(RGeo::Error::InvalidGeometry) { RGeo::Geos::Analysis.ccw?(point) }
pt1 = factory.point(1, 2)
pt2 = factory.point(2, 0)
seq = factory.line_string([pt1, pt2])
# https://github.com/libgeos/geos/pull/878
if geos_version_match(">= 3.12.0")
assert_equal(false, RGeo::Geos::Analysis.ccw?(pt1))
assert_equal(false, RGeo::Geos::Analysis.ccw?(seq))
else
assert_raises(RGeo::Error::InvalidGeometry) { RGeo::Geos::Analysis.ccw?(pt1) }
assert_raises(RGeo::Error::InvalidGeometry) { RGeo::Geos::Analysis.ccw?(seq) }
end
end

def test_ccw_p_returns_true_if_ccw
Expand Down
2 changes: 1 addition & 1 deletion test/geos_capi/multi_line_string_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
# -----------------------------------------------------------------------------

require "test_helper"
require_relative "../test_helper"
require_relative "skip_capi"

class GeosMultiLineStringTest < Minitest::Test # :nodoc:
Expand Down
7 changes: 6 additions & 1 deletion test/geos_capi/polygon_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ def test_simplify_preserve_topology
simplified = poly.simplify_preserve_topology(1)
interior_points = simplified.interior_rings[0].points

assert_equal 5, interior_points.length
# https://github.com/libgeos/geos/pull/784
if geos_version_match(">= 3.12.0")
assert_equal 4, interior_points.length
else
assert_equal 5, interior_points.length
end
end

def test_buffer_with_style
Expand Down
2 changes: 1 addition & 1 deletion test/geos_ffi/misc_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_unary_union_mixed_collection
def test_casting_dumb_objects
test_struct = Struct.new(:factory, :fg_geom)
assert_raises(RGeo::Error::InvalidGeometry) do
@factory.point(1, 1).contains?(test_struct.new(factory: @factory))
@factory.point(1, 1).contains?(test_struct.new({ factory: @factory }))
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def psych_load(*args)
end
end

# Check if GEOS version match requirement, this will
# be either the CAPI or FFI depending on installation.
def geos_version_match(requirement)
Gem::Requirement.new(requirement).satisfied_by? Gem::Version.new(RGeo::Geos.version)
end

require_relative "common/factory_tests"
require_relative "common/geometry_collection_tests"
require_relative "common/line_string_tests"
Expand Down
File renamed without changes.

0 comments on commit 8f61123

Please sign in to comment.