diff --git a/lib/coordinate_sequence.rb b/lib/coordinate_sequence.rb index 12a0b39..6e78340 100644 --- a/lib/coordinate_sequence.rb +++ b/lib/coordinate_sequence.rb @@ -31,6 +31,13 @@ def initialize(*args) ) end + def initialize_copy(source) + @ptr = FFI::AutoPointer.new( + FFIGeos.GEOSCoordSeq_clone_r(Geos.current_handle, source.ptr), + self.class.method(:release) + ) + end + def self.no_release(ptr) #:nodoc: end @@ -38,10 +45,6 @@ def self.release(ptr) #:nodoc: FFIGeos.GEOSCoordSeq_destroy_r(Geos.current_handle, ptr) end - def clone - self.class.new(FFIGeos.GEOSCoordSeq_clone_r(Geos.current_handle, self.ptr)) - end - # Yields coordinates as [ x, y, z ]. The z coordinate may be omitted for # 2-dimensional CoordinateSequences. def each diff --git a/lib/geometry.rb b/lib/geometry.rb index 2ff63b3..64bb354 100644 --- a/lib/geometry.rb +++ b/lib/geometry.rb @@ -14,6 +14,13 @@ def initialize(ptr, auto_free = true) ) end + def initialize_copy(source) + @ptr = FFI::AutoPointer.new( + FFIGeos.GEOSGeom_clone_r(Geos.current_handle, source.ptr), + self.class.method(:release) + ) + end + def self.no_release(ptr) #:nodoc: end @@ -21,10 +28,6 @@ def self.release(ptr) #:nodoc: FFIGeos.GEOSGeom_destroy_r(Geos.current_handle, ptr) end - def clone - cast_geometry_ptr(FFIGeos.GEOSGeom_clone_r(Geos.current_handle, ptr)) - end - # Returns the name of the Geometry type, i.e. "Point", "Polygon", etc. def geom_type FFIGeos.GEOSGeomType_r(Geos.current_handle, self.ptr) diff --git a/test/coordinate_sequence_tests.rb b/test/coordinate_sequence_tests.rb index 09da798..94006c7 100644 --- a/test/coordinate_sequence_tests.rb +++ b/test/coordinate_sequence_tests.rb @@ -67,4 +67,26 @@ def test_check_bounds assert_raise(RuntimeError) { @cs.get_ordinate(10, 0) } assert_raise(RuntimeError) { @cs.get_ordinate(-1, 0) } end + + def test_clone + @cs.set_x(0, 1) + @cs.set_y(0, 2) + + cs_b = @cs.clone + + assert_equal(@cs.get_x(0), cs_b.get_x(0)) + assert_equal(@cs.get_y(0), cs_b.get_y(0)) + assert_equal(@cs.dimensions, cs_b.dimensions) + end + + def test_dup + @cs.set_x(0, 1) + @cs.set_y(0, 2) + + cs_b = @cs.dup + + assert_equal(@cs.get_x(0), cs_b.get_x(0)) + assert_equal(@cs.get_y(0), cs_b.get_y(0)) + assert_equal(@cs.dimensions, cs_b.dimensions) + end end diff --git a/test/geometry_tests.rb b/test/geometry_tests.rb index c5daba3..a567b8f 100644 --- a/test/geometry_tests.rb +++ b/test/geometry_tests.rb @@ -1516,4 +1516,18 @@ def test_geometry_collection_array ], geom[1..2].collect { |g| write(g) }) end end + + def test_clone + geom_a = read('POINT(0 0)') + geom_b = geom_a.clone + + assert(geom_a.eql?(geom_b)) + end + + def test_dup + geom_a = read('POINT(0 0)') + geom_b = geom_a.dup + + assert(geom_a.eql?(geom_b)) + end end