ffi-geos 0.0.1.beta2 → 0.0.1.beta3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1.beta2
1
+ 0.0.1.beta3
data/ffi-geos.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ffi-geos}
8
- s.version = "0.0.1.beta2"
8
+ s.version = "0.0.1.beta3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["J Smith"]
12
- s.date = %q{2011-05-11}
12
+ s.date = %q{2011-05-20}
13
13
  s.description = %q{An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS).}
14
14
  s.email = %q{dark.panda@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -21,26 +21,26 @@ Gem::Specification.new do |s|
21
21
  "Rakefile",
22
22
  "VERSION",
23
23
  "ffi-geos.gemspec",
24
- "lib/buffer_params.rb",
25
- "lib/coordinate_sequence.rb",
26
24
  "lib/ffi-geos.rb",
27
- "lib/geometry.rb",
28
- "lib/geometry_collection.rb",
29
- "lib/line_string.rb",
30
- "lib/linear_ring.rb",
31
- "lib/multi_line_string.rb",
32
- "lib/multi_point.rb",
33
- "lib/multi_polygon.rb",
34
- "lib/point.rb",
35
- "lib/polygon.rb",
36
- "lib/prepared_geometry.rb",
37
- "lib/strtree.rb",
38
- "lib/tools.rb",
39
- "lib/utils.rb",
40
- "lib/wkb_reader.rb",
41
- "lib/wkb_writer.rb",
42
- "lib/wkt_reader.rb",
43
- "lib/wkt_writer.rb",
25
+ "lib/ffi-geos/buffer_params.rb",
26
+ "lib/ffi-geos/coordinate_sequence.rb",
27
+ "lib/ffi-geos/geometry.rb",
28
+ "lib/ffi-geos/geometry_collection.rb",
29
+ "lib/ffi-geos/line_string.rb",
30
+ "lib/ffi-geos/linear_ring.rb",
31
+ "lib/ffi-geos/multi_line_string.rb",
32
+ "lib/ffi-geos/multi_point.rb",
33
+ "lib/ffi-geos/multi_polygon.rb",
34
+ "lib/ffi-geos/point.rb",
35
+ "lib/ffi-geos/polygon.rb",
36
+ "lib/ffi-geos/prepared_geometry.rb",
37
+ "lib/ffi-geos/strtree.rb",
38
+ "lib/ffi-geos/tools.rb",
39
+ "lib/ffi-geos/utils.rb",
40
+ "lib/ffi-geos/wkb_reader.rb",
41
+ "lib/ffi-geos/wkb_writer.rb",
42
+ "lib/ffi-geos/wkt_reader.rb",
43
+ "lib/ffi-geos/wkt_writer.rb",
44
44
  "test/coordinate_sequence_tests.rb",
45
45
  "test/geometry_tests.rb",
46
46
  "test/misc_tests.rb",
@@ -58,20 +58,6 @@ Gem::Specification.new do |s|
58
58
  s.require_paths = ["lib"]
59
59
  s.rubygems_version = %q{1.7.2}
60
60
  s.summary = %q{An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS).}
61
- s.test_files = [
62
- "test/coordinate_sequence_tests.rb",
63
- "test/geometry_tests.rb",
64
- "test/misc_tests.rb",
65
- "test/point_tests.rb",
66
- "test/prepared_geometry_tests.rb",
67
- "test/strtree_tests.rb",
68
- "test/test_helper.rb",
69
- "test/utils_tests.rb",
70
- "test/wkb_reader_tests.rb",
71
- "test/wkb_writer_tests.rb",
72
- "test/wkt_reader_tests.rb",
73
- "test/wkt_writer_tests.rb"
74
- ]
75
61
 
76
62
  if s.respond_to? :specification_version then
77
63
  s.specification_version = 3
data/lib/ffi-geos.rb CHANGED
@@ -3,7 +3,7 @@ require 'ffi'
3
3
  require 'rbconfig'
4
4
 
5
5
  module Geos
6
- GEOS_BASE = File.dirname(__FILE__)
6
+ GEOS_BASE = File.join(File.dirname(__FILE__), 'ffi-geos')
7
7
 
8
8
  autoload :WktReader,
9
9
  File.join(GEOS_BASE, 'wkt_reader')
@@ -1023,7 +1023,7 @@ module Geos
1023
1023
  end
1024
1024
 
1025
1025
  module VersionConstants
1026
- VERSION = File.read(File.join(GEOS_BASE, %w{ .. VERSION })).strip
1026
+ VERSION = File.read(File.join(GEOS_BASE, %w{ .. .. VERSION })).strip
1027
1027
  GEOS_JTS_PORT = Geos.jts_port
1028
1028
  GEOS_VERSION,
1029
1029
  GEOS_VERSION_MAJOR, GEOS_VERSION_MINOR, GEOS_VERISON_PATCH, GEOS_VERSION_PRERELEASE,
@@ -9,6 +9,8 @@ module Geos
9
9
  :quad_segs, :endcap, :join, :mitre_limit, :single_sided
10
10
  ].freeze
11
11
 
12
+ undef :clone, :dup
13
+
12
14
  # The defaults for the params according to GEOS are as found in
13
15
  # Geos::Constants::BUFFER_PARAMS_DEFAULTS. Note that when setting the
14
16
  # :quad_segs value that you should set it before setting other values like
@@ -29,6 +29,17 @@ module Geos
29
29
  ptr,
30
30
  auto_free ? self.class.method(:release) : self.class.method(:no_release)
31
31
  )
32
+
33
+ if !auto_free
34
+ @ptr.autorelease = false
35
+ end
36
+ end
37
+
38
+ def initialize_copy(source)
39
+ @ptr = FFI::AutoPointer.new(
40
+ FFIGeos.GEOSCoordSeq_clone_r(Geos.current_handle, source.ptr),
41
+ self.class.method(:release)
42
+ )
32
43
  end
33
44
 
34
45
  def self.no_release(ptr) #:nodoc:
@@ -38,10 +49,6 @@ module Geos
38
49
  FFIGeos.GEOSCoordSeq_destroy_r(Geos.current_handle, ptr)
39
50
  end
40
51
 
41
- def clone
42
- self.class.new(FFIGeos.GEOSCoordSeq_clone_r(Geos.current_handle, self.ptr))
43
- end
44
-
45
52
  # Yields coordinates as [ x, y, z ]. The z coordinate may be omitted for
46
53
  # 2-dimensional CoordinateSequences.
47
54
  def each
@@ -12,6 +12,17 @@ module Geos
12
12
  ptr,
13
13
  auto_free ? self.class.method(:release) : self.class.method(:no_release)
14
14
  )
15
+
16
+ if !auto_free
17
+ @ptr.autorelease = false
18
+ end
19
+ end
20
+
21
+ def initialize_copy(source)
22
+ @ptr = FFI::AutoPointer.new(
23
+ FFIGeos.GEOSGeom_clone_r(Geos.current_handle, source.ptr),
24
+ self.class.method(:release)
25
+ )
15
26
  end
16
27
 
17
28
  def self.no_release(ptr) #:nodoc:
@@ -21,10 +32,6 @@ module Geos
21
32
  FFIGeos.GEOSGeom_destroy_r(Geos.current_handle, ptr)
22
33
  end
23
34
 
24
- def clone
25
- cast_geometry_ptr(FFIGeos.GEOSGeom_clone_r(Geos.current_handle, ptr))
26
- end
27
-
28
35
  # Returns the name of the Geometry type, i.e. "Point", "Polygon", etc.
29
36
  def geom_type
30
37
  FFIGeos.GEOSGeomType_r(Geos.current_handle, self.ptr)
@@ -18,6 +18,7 @@ module Geos
18
18
  cast_geometry_ptr(FFIGeos.GEOSGetGeometryN_r(Geos.current_handle, self.ptr, n), false)
19
19
  end
20
20
  end
21
+ alias :geometry_n :get_geometry_n
21
22
 
22
23
  def [](*args)
23
24
  self.to_a[*args]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -5,11 +5,17 @@ module Geos
5
5
 
6
6
  attr_reader :ptr
7
7
 
8
+ undef :clone, :dup
9
+
8
10
  def initialize(ptr, auto_free = true)
9
11
  @ptr = FFI::AutoPointer.new(
10
12
  ptr,
11
13
  auto_free ? self.class.method(:release) : self.class.method(:no_release)
12
14
  )
15
+
16
+ if !auto_free
17
+ @ptr.autorelease = false
18
+ end
13
19
  end
14
20
 
15
21
  def self.no_release(ptr) #:nodoc:
@@ -6,6 +6,8 @@ module Geos
6
6
 
7
7
  attr_reader :ptr
8
8
 
9
+ undef :clone, :dup
10
+
9
11
  def initialize(capacity)
10
12
  ptr = FFIGeos.GEOSSTRtree_create_r(Geos.current_handle, capacity)
11
13
 
File without changes
@@ -31,8 +31,10 @@ module Geos
31
31
  raise RuntimeError.new("IllegalArgumentException: Point coordinate list must contain a single element")
32
32
  end
33
33
 
34
- cast_geometry_ptr(FFIGeos.GEOSGeom_createPoint_r(Geos.current_handle, cs.ptr)).tap {
35
- cs.ptr.autorelease = false
34
+ cs_clone = cs.clone
35
+
36
+ cast_geometry_ptr(FFIGeos.GEOSGeom_createPoint_r(Geos.current_handle, cs_clone.ptr)).tap {
37
+ cs_clone.ptr.autorelease = false
36
38
  }
37
39
  end
38
40
 
@@ -41,8 +43,10 @@ module Geos
41
43
  raise RuntimeError.new("IllegalArgumentException: point array must contain 0 or >1 elements")
42
44
  end
43
45
 
44
- cast_geometry_ptr(FFIGeos.GEOSGeom_createLineString_r(Geos.current_handle, cs.ptr)).tap {
45
- cs.ptr.autorelease = false
46
+ cs_clone = cs.clone
47
+
48
+ cast_geometry_ptr(FFIGeos.GEOSGeom_createLineString_r(Geos.current_handle, cs_clone.ptr)).tap {
49
+ cs_clone.ptr.autorelease = false
46
50
  }
47
51
  end
48
52
 
@@ -51,8 +55,10 @@ module Geos
51
55
  raise RuntimeError.new("IllegalArgumentException: point array must contain 0 or >1 elements")
52
56
  end
53
57
 
54
- cast_geometry_ptr(FFIGeos.GEOSGeom_createLinearRing_r(Geos.current_handle, cs.ptr)).tap {
55
- cs.ptr.autorelease = false
58
+ cs_clone = cs.clone
59
+
60
+ cast_geometry_ptr(FFIGeos.GEOSGeom_createLinearRing_r(Geos.current_handle, cs_clone.ptr)).tap {
61
+ cs_clone.ptr.autorelease = false
56
62
  }
57
63
  end
58
64
 
@@ -63,12 +69,15 @@ module Geos
63
69
  end
64
70
  }
65
71
 
72
+ outer_clone = outer.clone
73
+ inner_clones = inner.map(&:clone)
74
+
66
75
  ary = FFI::MemoryPointer.new(:pointer, inner.length)
67
- ary.write_array_of_pointer(inner.map(&:ptr))
76
+ ary.write_array_of_pointer(inner_clones.map(&:ptr))
68
77
 
69
- cast_geometry_ptr(FFIGeos.GEOSGeom_createPolygon_r(Geos.current_handle, outer.ptr, ary, inner.length)).tap {
70
- outer.ptr.autorelease = false
71
- inner.each { |i| i.ptr.autorelease = false }
78
+ cast_geometry_ptr(FFIGeos.GEOSGeom_createPolygon_r(Geos.current_handle, outer_clone.ptr, ary, inner_clones.length)).tap {
79
+ outer_clone.ptr.autorelease = false
80
+ inner_clones.each { |i| i.ptr.autorelease = false }
72
81
  }
73
82
  end
74
83
 
@@ -125,11 +134,15 @@ module Geos
125
134
  end
126
135
  }
127
136
 
137
+ geoms_clones = geoms.map(&:clone)
138
+
128
139
  ary = FFI::MemoryPointer.new(:pointer, geoms.length)
129
- ary.write_array_of_pointer(geoms.map(&:ptr))
140
+ ary.write_array_of_pointer(geoms_clones.map(&:ptr))
130
141
 
131
- cast_geometry_ptr(FFIGeos.GEOSGeom_createCollection_r(Geos.current_handle, t, ary, geoms.length)).tap {
132
- geoms.each { |i| i.ptr.autorelease = false }
142
+ cast_geometry_ptr(FFIGeos.GEOSGeom_createCollection_r(Geos.current_handle, t, ary, geoms_clones.length)).tap {
143
+ geoms_clones.each { |i|
144
+ i.ptr.autorelease = false
145
+ }
133
146
  }
134
147
  end
135
148
 
File without changes
File without changes
File without changes
File without changes
@@ -67,4 +67,26 @@ class CoordinateSequenceTests < Test::Unit::TestCase
67
67
  assert_raise(RuntimeError) { @cs.get_ordinate(10, 0) }
68
68
  assert_raise(RuntimeError) { @cs.get_ordinate(-1, 0) }
69
69
  end
70
+
71
+ def test_clone
72
+ @cs.set_x(0, 1)
73
+ @cs.set_y(0, 2)
74
+
75
+ cs_b = @cs.clone
76
+
77
+ assert_equal(@cs.get_x(0), cs_b.get_x(0))
78
+ assert_equal(@cs.get_y(0), cs_b.get_y(0))
79
+ assert_equal(@cs.dimensions, cs_b.dimensions)
80
+ end
81
+
82
+ def test_dup
83
+ @cs.set_x(0, 1)
84
+ @cs.set_y(0, 2)
85
+
86
+ cs_b = @cs.dup
87
+
88
+ assert_equal(@cs.get_x(0), cs_b.get_x(0))
89
+ assert_equal(@cs.get_y(0), cs_b.get_y(0))
90
+ assert_equal(@cs.dimensions, cs_b.dimensions)
91
+ end
70
92
  end
@@ -1516,4 +1516,18 @@ class GeometryTests < Test::Unit::TestCase
1516
1516
  ], geom[1..2].collect { |g| write(g) })
1517
1517
  end
1518
1518
  end
1519
+
1520
+ def test_clone
1521
+ geom_a = read('POINT(0 0)')
1522
+ geom_b = geom_a.clone
1523
+
1524
+ assert(geom_a.eql?(geom_b))
1525
+ end
1526
+
1527
+ def test_dup
1528
+ geom_a = read('POINT(0 0)')
1529
+ geom_b = geom_a.dup
1530
+
1531
+ assert(geom_a.eql?(geom_b))
1532
+ end
1519
1533
  end
data/test/misc_tests.rb CHANGED
@@ -50,4 +50,49 @@ class MiscTests < Test::Unit::TestCase
50
50
  "t2: [false]"
51
51
  ], @messages.sort)
52
52
  end
53
+
54
+ def test_segfault_on_cs_ownership
55
+ cs = Geos::CoordinateSequence.new(1, 2)
56
+ cs.set_x(0, 1)
57
+ cs.set_y(0, 2)
58
+
59
+ point = Geos.create_point(cs)
60
+ collection_a = Geos.create_geometry_collection(point)
61
+ collection_b = Geos.create_geometry_collection(point)
62
+
63
+ GC.start
64
+
65
+ writer.rounding_precision = 0
66
+
67
+ assert_equal('POINT (1 2)', write(point))
68
+ assert_equal(collection_a[0], point)
69
+ assert_equal(collection_a[0], collection_b[0])
70
+ end
71
+
72
+ def test_segfault_on_geom_ownership
73
+ point = read('POINT (10 20)')
74
+
75
+ collection_a = Geos.create_geometry_collection(point)
76
+ collection_b = Geos.create_geometry_collection(collection_a[0])
77
+
78
+ GC.start
79
+
80
+ writer.rounding_precision = 0
81
+
82
+ assert_equal('POINT (10 20)', write(point))
83
+ assert_equal(collection_a[0], point)
84
+ assert_equal(collection_a[0], collection_b[0])
85
+ end
86
+
87
+ def test_cant_clone_buffer_params
88
+ assert_raise(NoMethodError) do
89
+ Geos::BufferParams.new.clone
90
+ end
91
+ end
92
+
93
+ def test_cant_dup_buffer_params
94
+ assert_raise(NoMethodError) do
95
+ Geos::BufferParams.new.dup
96
+ end
97
+ end
53
98
  end
@@ -70,5 +70,17 @@ if defined?(Geos::PreparedGeometry)
70
70
  def test_covered_by
71
71
  relationship_tester(:covered_by?, true, true, true, false, false, true, false, false)
72
72
  end
73
+
74
+ def test_cant_clone
75
+ assert_raise(NoMethodError) do
76
+ read(POINT_A).to_prepared.clone
77
+ end
78
+ end
79
+
80
+ def test_cant_dup
81
+ assert_raise(NoMethodError) do
82
+ read(POINT_A).to_prepared.dup
83
+ end
84
+ end
73
85
  end
74
86
  end
@@ -50,5 +50,17 @@ if defined?(Geos::STRtree)
50
50
  assert_equal(2, @tree.query(read('LINESTRING(25 25, 26 26)')).length)
51
51
  assert_equal(2, @tree.query(read('LINESTRING(0 0, 100 100)')).length)
52
52
  end
53
+
54
+ def test_cant_clone
55
+ assert_raise(NoMethodError) do
56
+ Geos::STRtree.new(3).clone
57
+ end
58
+ end
59
+
60
+ def test_cant_dup
61
+ assert_raise(NoMethodError) do
62
+ Geos::STRtree.new(3).dup
63
+ end
64
+ end
53
65
  end
54
66
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-geos
3
3
  version: !ruby/object:Gem::Version
4
- hash: 62196399
4
+ hash: 62196397
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
9
  - 1
10
10
  - beta
11
- - 2
12
- version: 0.0.1.beta2
11
+ - 3
12
+ version: 0.0.1.beta3
13
13
  platform: ruby
14
14
  authors:
15
15
  - J Smith
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-05-11 00:00:00 Z
20
+ date: 2011-05-20 00:00:00 Z
21
21
  dependencies: []
22
22
 
23
23
  description: An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS).
@@ -34,26 +34,26 @@ files:
34
34
  - Rakefile
35
35
  - VERSION
36
36
  - ffi-geos.gemspec
37
- - lib/buffer_params.rb
38
- - lib/coordinate_sequence.rb
39
37
  - lib/ffi-geos.rb
40
- - lib/geometry.rb
41
- - lib/geometry_collection.rb
42
- - lib/line_string.rb
43
- - lib/linear_ring.rb
44
- - lib/multi_line_string.rb
45
- - lib/multi_point.rb
46
- - lib/multi_polygon.rb
47
- - lib/point.rb
48
- - lib/polygon.rb
49
- - lib/prepared_geometry.rb
50
- - lib/strtree.rb
51
- - lib/tools.rb
52
- - lib/utils.rb
53
- - lib/wkb_reader.rb
54
- - lib/wkb_writer.rb
55
- - lib/wkt_reader.rb
56
- - lib/wkt_writer.rb
38
+ - lib/ffi-geos/buffer_params.rb
39
+ - lib/ffi-geos/coordinate_sequence.rb
40
+ - lib/ffi-geos/geometry.rb
41
+ - lib/ffi-geos/geometry_collection.rb
42
+ - lib/ffi-geos/line_string.rb
43
+ - lib/ffi-geos/linear_ring.rb
44
+ - lib/ffi-geos/multi_line_string.rb
45
+ - lib/ffi-geos/multi_point.rb
46
+ - lib/ffi-geos/multi_polygon.rb
47
+ - lib/ffi-geos/point.rb
48
+ - lib/ffi-geos/polygon.rb
49
+ - lib/ffi-geos/prepared_geometry.rb
50
+ - lib/ffi-geos/strtree.rb
51
+ - lib/ffi-geos/tools.rb
52
+ - lib/ffi-geos/utils.rb
53
+ - lib/ffi-geos/wkb_reader.rb
54
+ - lib/ffi-geos/wkb_writer.rb
55
+ - lib/ffi-geos/wkt_reader.rb
56
+ - lib/ffi-geos/wkt_writer.rb
57
57
  - test/coordinate_sequence_tests.rb
58
58
  - test/geometry_tests.rb
59
59
  - test/misc_tests.rb
@@ -101,16 +101,5 @@ rubygems_version: 1.7.2
101
101
  signing_key:
102
102
  specification_version: 3
103
103
  summary: An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS).
104
- test_files:
105
- - test/coordinate_sequence_tests.rb
106
- - test/geometry_tests.rb
107
- - test/misc_tests.rb
108
- - test/point_tests.rb
109
- - test/prepared_geometry_tests.rb
110
- - test/strtree_tests.rb
111
- - test/test_helper.rb
112
- - test/utils_tests.rb
113
- - test/wkb_reader_tests.rb
114
- - test/wkb_writer_tests.rb
115
- - test/wkt_reader_tests.rb
116
- - test/wkt_writer_tests.rb
104
+ test_files: []
105
+