ffi-geos 0.5.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Geos
4
- VERSION = "0.5.0"
4
+ VERSION = "1.0.0"
5
5
  end
6
6
 
@@ -6,6 +6,9 @@ module Geos
6
6
 
7
7
  attr_reader :ptr
8
8
 
9
+ class ParseError < Geos::ParseError
10
+ end
11
+
9
12
  def initialize(*args)
10
13
  ptr = if args.first.is_a?(FFI::Pointer)
11
14
  args.first
@@ -23,12 +26,16 @@ module Geos
23
26
  cast_geometry_ptr(FFIGeos.GEOSWKBReader_read_r(Geos.current_handle, self.ptr, wkb, wkb.bytesize), {
24
27
  :srid => options[:srid]
25
28
  })
29
+ rescue Geos::GEOSException => e
30
+ raise ParseError.new(e)
26
31
  end
27
32
 
28
33
  def read_hex(wkb, options = {})
29
34
  cast_geometry_ptr(FFIGeos.GEOSWKBReader_readHEX_r(Geos.current_handle, self.ptr, wkb, wkb.bytesize), {
30
35
  :srid => options[:srid]
31
36
  })
37
+ rescue Geos::GEOSException => e
38
+ raise ParseError.new(e)
32
39
  end
33
40
 
34
41
  def self.release(ptr) #:nodoc:
@@ -58,7 +58,7 @@ module Geos
58
58
 
59
59
  def output_dimensions=(dim)
60
60
  if dim < 2 || dim > 3
61
- raise RuntimeError.new("Output dimensions must be either 2 or 3")
61
+ raise ArgumentError.new("Output dimensions must be either 2 or 3")
62
62
  end
63
63
  FFIGeos.GEOSWKBWriter_setOutputDimension_r(Geos.current_handle, self.ptr, dim)
64
64
  end
@@ -6,6 +6,9 @@ module Geos
6
6
 
7
7
  attr_reader :ptr
8
8
 
9
+ class ParseError < Geos::ParseError
10
+ end
11
+
9
12
  def initialize(*args)
10
13
  ptr = if args.first.is_a?(FFI::Pointer)
11
14
  args.first
@@ -23,6 +26,8 @@ module Geos
23
26
  cast_geometry_ptr(FFIGeos.GEOSWKTReader_read_r(Geos.current_handle, self.ptr, wkt), {
24
27
  :srid => options[:srid]
25
28
  })
29
+ rescue Geos::GEOSException => e
30
+ raise ParseError.new(e)
26
31
  end
27
32
 
28
33
  def self.release(ptr) #:nodoc:
@@ -70,7 +70,7 @@ module Geos
70
70
  def rounding_precision=(r)
71
71
  r = r.to_i
72
72
  if r > 255
73
- raise RuntimeError.new("Rounding precision cannot be greater than 255")
73
+ raise ArgumentError.new("Rounding precision cannot be greater than 255")
74
74
  end
75
75
 
76
76
  @rounding_precision = r
@@ -93,7 +93,7 @@ module Geos
93
93
  def output_dimensions=(dim)
94
94
  dim = dim.to_i
95
95
  if dim < 2 || dim > 3
96
- raise RuntimeError.new("Output dimensions must be either 2 or 3")
96
+ raise ArgumentError.new("Output dimensions must be either 2 or 3")
97
97
  end
98
98
  FFIGeos.GEOSWKTWriter_setOutputDimension_r(Geos.current_handle, self.ptr, dim)
99
99
  end
@@ -3,7 +3,7 @@
3
3
  $: << File.dirname(__FILE__)
4
4
  require 'test_helper'
5
5
 
6
- class CoordinateSequenceTests < MiniTest::Unit::TestCase
6
+ class CoordinateSequenceTests < Minitest::Test
7
7
  include TestHelper
8
8
 
9
9
  def setup
@@ -45,29 +45,29 @@ class CoordinateSequenceTests < MiniTest::Unit::TestCase
45
45
  end
46
46
 
47
47
  def test_check_bounds
48
- assert_raises(RuntimeError) { @cs.set_x(10, 0.1) }
49
- assert_raises(RuntimeError) { @cs.set_x(-1, 0.1) }
48
+ assert_raises(Geos::IndexBoundsError) { @cs.set_x(10, 0.1) }
49
+ assert_raises(Geos::IndexBoundsError) { @cs.set_x(-1, 0.1) }
50
50
 
51
- assert_raises(RuntimeError) { @cs.set_y(10, 0.1) }
52
- assert_raises(RuntimeError) { @cs.set_y(-1, 0.1) }
51
+ assert_raises(Geos::IndexBoundsError) { @cs.set_y(10, 0.1) }
52
+ assert_raises(Geos::IndexBoundsError) { @cs.set_y(-1, 0.1) }
53
53
 
54
- assert_raises(RuntimeError) { @cs.set_z(10, 0.1) }
55
- assert_raises(RuntimeError) { @cs.set_z(-1, 0.1) }
54
+ assert_raises(Geos::IndexBoundsError) { @cs.set_z(10, 0.1) }
55
+ assert_raises(Geos::IndexBoundsError) { @cs.set_z(-1, 0.1) }
56
56
 
57
- assert_raises(RuntimeError) { @cs.set_ordinate(10, 0, 0.1) }
58
- assert_raises(RuntimeError) { @cs.set_ordinate(-1, 0, 0.1) }
57
+ assert_raises(Geos::IndexBoundsError) { @cs.set_ordinate(10, 0, 0.1) }
58
+ assert_raises(Geos::IndexBoundsError) { @cs.set_ordinate(-1, 0, 0.1) }
59
59
 
60
- assert_raises(RuntimeError) { @cs.get_x(10) }
61
- assert_raises(RuntimeError) { @cs.get_x(-1) }
60
+ assert_raises(Geos::IndexBoundsError) { @cs.get_x(10) }
61
+ assert_raises(Geos::IndexBoundsError) { @cs.get_x(-1) }
62
62
 
63
- assert_raises(RuntimeError) { @cs.get_y(10) }
64
- assert_raises(RuntimeError) { @cs.get_y(-1) }
63
+ assert_raises(Geos::IndexBoundsError) { @cs.get_y(10) }
64
+ assert_raises(Geos::IndexBoundsError) { @cs.get_y(-1) }
65
65
 
66
- assert_raises(RuntimeError) { @cs.get_z(10) }
67
- assert_raises(RuntimeError) { @cs.get_z(-1) }
66
+ assert_raises(Geos::IndexBoundsError) { @cs.get_z(10) }
67
+ assert_raises(Geos::IndexBoundsError) { @cs.get_z(-1) }
68
68
 
69
- assert_raises(RuntimeError) { @cs.get_ordinate(10, 0) }
70
- assert_raises(RuntimeError) { @cs.get_ordinate(-1, 0) }
69
+ assert_raises(Geos::IndexBoundsError) { @cs.get_ordinate(10, 0) }
70
+ assert_raises(Geos::IndexBoundsError) { @cs.get_ordinate(-1, 0) }
71
71
  end
72
72
 
73
73
  def test_clone
@@ -216,15 +216,15 @@ class CoordinateSequenceTests < MiniTest::Unit::TestCase
216
216
  assert_equal('NaN', cs.z[0].to_s)
217
217
  assert_equal('NaN', cs.z[1].to_s)
218
218
 
219
- assert_raises(RuntimeError) do
219
+ assert_raises(Geos::IndexBoundsError) do
220
220
  cs.x[100]
221
221
  end
222
222
 
223
- assert_raises(RuntimeError) do
223
+ assert_raises(Geos::IndexBoundsError) do
224
224
  cs.y[100]
225
225
  end
226
226
 
227
- assert_raises(RuntimeError) do
227
+ assert_raises(Geos::IndexBoundsError) do
228
228
  cs.z[100]
229
229
  end
230
230
  end
@@ -243,15 +243,15 @@ class CoordinateSequenceTests < MiniTest::Unit::TestCase
243
243
  assert_equal(2, cs.get_y(0))
244
244
  assert_equal(11, cs.get_y(1))
245
245
 
246
- assert_raises(RuntimeError) do
246
+ assert_raises(Geos::IndexBoundsError) do
247
247
  cs.x[100] = 10
248
248
  end
249
249
 
250
- assert_raises(RuntimeError) do
250
+ assert_raises(Geos::IndexBoundsError) do
251
251
  cs.y[100] = 10
252
252
  end
253
253
 
254
- assert_raises(RuntimeError) do
254
+ assert_raises(Geos::IndexBoundsError) do
255
255
  cs.z[100] = 10
256
256
  end
257
257
  end
@@ -3,9 +3,14 @@
3
3
  $: << File.dirname(__FILE__)
4
4
  require 'test_helper'
5
5
 
6
- class GeometryCollectionTests < MiniTest::Unit::TestCase
6
+ class GeometryCollectionTests < Minitest::Test
7
7
  include TestHelper
8
8
 
9
+ def setup
10
+ super
11
+ writer.trim = true
12
+ end
13
+
9
14
  def test_geometry_collection_enumerator
10
15
  skip unless ENV['FORCE_TESTS'] || Geos::GeometryCollection.method_defined?(:[])
11
16
 
@@ -3,125 +3,123 @@
3
3
  $: << File.dirname(__FILE__)
4
4
  require 'test_helper'
5
5
 
6
- class GeometryTests < MiniTest::Unit::TestCase
6
+ class GeometryTests < Minitest::Test
7
7
  include TestHelper
8
8
 
9
- def comparison_tester(method_with_args, geom_a, geom_b, expected)
10
- method_with_args = Array(method_with_args)
11
- method = method_with_args.shift
12
- args = method_with_args
13
-
14
- geom_1 = read(geom_a)
15
- geom_b = read(geom_b)
16
- result = geom_1.send(method, geom_b, *args)
17
- assert_geom_eql_exact(read(expected), result)
18
- end
19
-
20
- def self_tester(method_with_args, g, expected)
21
- method_with_args = Array(method_with_args)
22
- geom = read(g)
23
- result = geom.send(*method_with_args)
24
- assert_geom_eql_exact(read(expected), result)
9
+ def setup
10
+ super
11
+ writer.trim = true
25
12
  end
26
13
 
27
14
  def test_intersection
28
15
  comparison_tester(
29
16
  :intersection,
30
- 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
31
- 'POLYGON((5 5, 15 5, 15 15, 5 15, 5 5))',
32
- 'POLYGON((5 10, 10 10, 10 5, 5 5, 5 10))'
17
+ 'POLYGON ((5 10, 10 10, 10 5, 5 5, 5 10))',
18
+ 'POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))',
19
+ 'POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))'
33
20
  )
34
21
  end
35
22
 
36
23
  def test_buffer
37
- tester = lambda { |expected, geom, *args|
38
- width, params = args
39
- assert_equal(expected, write(read(geom).buffer(width, params)))
40
- }
24
+ writer.rounding_precision = 2
41
25
 
42
- writer.rounding_precision = 0
43
-
44
- tester['POLYGON EMPTY', 'POINT(0 0)', 0]
26
+ simple_tester(
27
+ :buffer,
28
+ 'POLYGON EMPTY',
29
+ 'POINT(0 0)',
30
+ 0
31
+ )
45
32
 
46
- tester[
47
- 'POLYGON ((10 0, 10 -2, 9 -4, 8 -6, 7 -7, 6 -8, 4 -9, 2 -10, 0 -10, -2 -10, -4 -9, -6 -8, -7 -7, -8 -6, -9 -4, -10 -2, -10 -0, -10 2, -9 4, -8 6, -7 7, -6 8, -4 9, -2 10, -0 10, 2 10, 4 9, 6 8, 7 7, 8 6, 9 4, 10 2, 10 0))',
33
+ simple_tester(
34
+ :buffer,
35
+ 'POLYGON ((10 0, 9.8 -2, 9.2 -3.8, 8.3 -5.6, 7.1 -7.1, 5.6 -8.3, 3.8 -9.2, 2 -9.8, 1.6e-14 -10, -2 -9.8, -3.8 -9.2, -5.6 -8.3, -7.1 -7.1, -8.3 -5.6, -9.2 -3.8, -9.8 -2, -10 -3.2e-14, -9.8 2, -9.2 3.8, -8.3 5.6, -7.1 7.1, -5.6 8.3, -3.8 9.2, -2 9.8, -3.7e-14 10, 2 9.8, 3.8 9.2, 5.6 8.3, 7.1 7.1, 8.3 5.6, 9.2 3.8, 9.8 2, 10 0))',
48
36
  'POINT(0 0)',
49
37
  10
50
- ]
38
+ )
51
39
 
52
40
  # One segment per quadrant
53
- tester[
54
- 'POLYGON ((10 0, 0 -10, -10 -0, -0 10, 10 0))',
41
+ simple_tester(
42
+ :buffer,
43
+ 'POLYGON ((10 0, 1.6e-14 -10, -10 -3.2e-14, -4.6e-14 10, 10 0))',
55
44
  'POINT(0 0)',
56
45
  10,
57
46
  { :quad_segs => 1 }
58
- ]
47
+ )
59
48
 
60
49
  # End cap styles
61
- tester[
62
- 'POLYGON ((100 10, 110 0, 100 -10, 0 -10, -10 0, 0 10, 100 10))',
50
+ simple_tester(
51
+ :buffer,
52
+ 'POLYGON ((1e+02 10, 1.1e+02 0, 1e+02 -10, 0 -10, -10 1.2e-15, 0 10, 1e+02 10))',
63
53
  'LINESTRING(0 0, 100 0)',
64
54
  10,
65
55
  { :quad_segs => 1, :endcap => :round }
66
- ]
56
+ )
67
57
 
68
- tester[
69
- 'POLYGON ((100 10, 100 -10, 0 -10, 0 10, 100 10))',
58
+ simple_tester(
59
+ :buffer,
60
+ 'POLYGON ((1e+02 10, 1e+02 -10, 0 -10, 0 10, 1e+02 10))',
70
61
  'LINESTRING(0 0, 100 0)',
71
62
  10,
72
63
  { :quad_segs => 1, :endcap => :flat }
73
- ]
64
+ )
74
65
 
75
- tester[
76
- 'POLYGON ((100 10, 110 10, 110 -10, 0 -10, -10 -10, -10 10, 100 10))',
66
+ simple_tester(
67
+ :buffer,
68
+ 'POLYGON ((1e+02 10, 1.1e+02 10, 1.1e+02 -10, 0 -10, -10 -10, -10 10, 1e+02 10))',
77
69
  'LINESTRING(0 0, 100 0)',
78
70
  10,
79
71
  { :quad_segs => 1, :endcap => :square }
80
- ]
72
+ )
81
73
 
82
74
  # Join styles
83
- tester[
84
- 'POLYGON ((90 10, 90 100, 93 107, 100 110, 107 107, 110 100, 110 0, 107 -7, 100 -10, 0 -10, -7 -7, -10 0, -7 7, 0 10, 90 10))',
75
+ simple_tester(
76
+ :buffer,
77
+ 'POLYGON ((90 10, 90 1e+02, 93 1.1e+02, 1e+02 1.1e+02, 1.1e+02 1.1e+02, 1.1e+02 1e+02, 1.1e+02 0, 1.1e+02 -7.1, 1e+02 -10, 0 -10, -7.1 -7.1, -10 1.2e-15, -7.1 7.1, 0 10, 90 10))',
85
78
  'LINESTRING(0 0, 100 0, 100 100)',
86
79
  10,
87
80
  { :quad_segs => 2, :join => :round }
88
- ]
81
+ )
89
82
 
90
- tester[
91
- 'POLYGON ((90 10, 90 100, 93 107, 100 110, 107 107, 110 100, 110 0, 100 -10, 0 -10, -7 -7, -10 0, -7 7, 0 10, 90 10))',
83
+ simple_tester(
84
+ :buffer,
85
+ 'POLYGON ((90 10, 90 1e+02, 93 1.1e+02, 1e+02 1.1e+02, 1.1e+02 1.1e+02, 1.1e+02 1e+02, 1.1e+02 0, 1e+02 -10, 0 -10, -7.1 -7.1, -10 1.2e-15, -7.1 7.1, 0 10, 90 10))',
92
86
  'LINESTRING(0 0, 100 0, 100 100)',
93
87
  10,
94
88
  { :quad_segs => 2, :join => :bevel }
95
- ]
89
+ )
96
90
 
97
- tester[
98
- 'POLYGON ((90 10, 90 100, 93 107, 100 110, 107 107, 110 100, 110 -10, 0 -10, -7 -7, -10 0, -7 7, 0 10, 90 10))',
91
+ simple_tester(
92
+ :buffer,
93
+ 'POLYGON ((90 10, 90 1e+02, 93 1.1e+02, 1e+02 1.1e+02, 1.1e+02 1.1e+02, 1.1e+02 1e+02, 1.1e+02 -10, 0 -10, -7.1 -7.1, -10 1.2e-15, -7.1 7.1, 0 10, 90 10))',
99
94
  'LINESTRING(0 0, 100 0, 100 100)',
100
95
  10,
101
96
  { :quad_segs => 2, :join => :mitre }
102
- ]
97
+ )
103
98
 
104
- tester[
105
- 'POLYGON ((90 10, 90 100, 93 107, 100 110, 107 107, 110 100, 109 -5, 105 -9, 0 -10, -7 -7, -10 0, -7 7, 0 10, 90 10))',
99
+ simple_tester(
100
+ :buffer,
101
+ 'POLYGON ((90 10, 90 1e+02, 93 1.1e+02, 1e+02 1.1e+02, 1.1e+02 1.1e+02, 1.1e+02 1e+02, 1.1e+02 -5, 1e+02 -9.1, 0 -10, -7.1 -7.1, -10 1.2e-15, -7.1 7.1, 0 10, 90 10))',
106
102
  'LINESTRING(0 0, 100 0, 100 100)',
107
103
  10,
108
104
  { :quad_segs => 2, :join => :mitre, :mitre_limit => 1.0 }
109
- ]
105
+ )
110
106
 
111
107
  # Single-sided buffering
112
- tester[
113
- 'POLYGON ((100 0, 0 0, 0 10, 100 10, 100 0))',
108
+ simple_tester(
109
+ :buffer,
110
+ 'POLYGON ((1e+02 0, 0 0, 0 10, 1e+02 10, 1e+02 0))',
114
111
  'LINESTRING(0 0, 100 0)',
115
112
  10,
116
113
  { :single_sided => true }
117
- ]
114
+ )
118
115
 
119
- tester[
120
- 'POLYGON ((0 0, 100 0, 100 -10, 0 -10, 0 0))',
116
+ simple_tester(
117
+ :buffer,
118
+ 'POLYGON ((0 0, 1e+02 0, 1e+02 -10, 0 -10, 0 0))',
121
119
  'LINESTRING(0 0, 100 0)',
122
120
  -10,
123
121
  { :single_sided => true }
124
- ]
122
+ )
125
123
  end
126
124
 
127
125
  def test_convex_hull
@@ -138,447 +136,358 @@ class GeometryTests < MiniTest::Unit::TestCase
138
136
  def test_difference
139
137
  comparison_tester(
140
138
  :difference,
139
+ 'GEOMETRYCOLLECTION EMPTY',
141
140
  'POINT(0 0)',
142
- 'POINT(0 0)',
143
- 'GEOMETRYCOLLECTION EMPTY'
141
+ 'POINT(0 0)'
144
142
  )
145
143
 
146
144
  comparison_tester(
147
145
  :difference,
146
+ 'POINT (0 0)',
148
147
  'POINT(0 0)',
149
- 'POINT(1 0)',
150
- 'POINT (0 0)'
148
+ 'POINT(1 0)'
151
149
  )
152
150
 
153
151
  comparison_tester(
154
152
  :difference,
153
+ 'LINESTRING (0 0, 10 0)',
155
154
  'LINESTRING(0 0, 10 0)',
156
- 'POINT(5 0)',
157
- 'LINESTRING (0 0, 10 0)'
155
+ 'POINT(5 0)'
158
156
  )
159
157
 
160
158
  comparison_tester(
161
159
  :difference,
160
+ 'GEOMETRYCOLLECTION EMPTY',
162
161
  'POINT(5 0)',
163
- 'LINESTRING(0 0, 10 0)',
164
- 'GEOMETRYCOLLECTION EMPTY'
162
+ 'LINESTRING(0 0, 10 0)'
165
163
  )
166
164
 
167
165
  comparison_tester(
168
166
  :difference,
167
+ 'POINT (5 0)',
169
168
  'POINT(5 0)',
170
- 'LINESTRING(0 1, 10 1)',
171
- 'POINT (5 0)'
169
+ 'LINESTRING(0 1, 10 1)'
172
170
  )
173
171
 
174
172
  comparison_tester(
175
173
  :difference,
174
+ 'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0))',
176
175
  'LINESTRING(0 0, 10 0)',
177
- 'LINESTRING(5 -10, 5 10)',
178
- 'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0))'
176
+ 'LINESTRING(5 -10, 5 10)'
179
177
  )
180
178
 
181
179
  comparison_tester(
182
180
  :difference,
181
+ 'LINESTRING (0 0, 5 0)',
183
182
  'LINESTRING(0 0, 10 0)',
184
- 'LINESTRING(5 0, 20 0)',
185
- 'LINESTRING (0 0, 5 0)'
183
+ 'LINESTRING(5 0, 20 0)'
186
184
  )
187
185
 
188
186
  comparison_tester(
189
187
  :difference,
188
+ 'POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0))',
190
189
  'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
191
- 'LINESTRING(5 -10, 5 10)',
192
- 'POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0))'
190
+ 'LINESTRING(5 -10, 5 10)'
193
191
  )
194
192
 
195
193
  comparison_tester(
196
194
  :difference,
195
+ 'POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0))',
197
196
  'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
198
- 'LINESTRING(10 0, 20 0)',
199
- 'POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0))'
197
+ 'LINESTRING(10 0, 20 0)'
200
198
  )
201
199
 
202
200
  comparison_tester(
203
201
  :difference,
202
+ 'POLYGON ((5 0, 0 0, 0 10, 10 10, 10 5, 5 5, 5 0))',
204
203
  'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
205
- 'POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))',
206
- 'POLYGON ((5 0, 0 0, 0 10, 10 10, 10 5, 5 5, 5 0))'
204
+ 'POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'
207
205
  )
208
206
  end
209
207
 
210
208
  def test_sym_difference
211
- comparison_tester(
212
- :sym_difference,
213
- 'POINT(0 0)',
214
- 'POINT(0 0)',
215
- 'GEOMETRYCOLLECTION EMPTY'
216
- )
217
-
218
- comparison_tester(
219
- :sym_difference,
220
- 'POINT(0 0)',
221
- 'POINT(1 0)',
222
- 'MULTIPOINT (0 0, 1 0)'
223
- )
224
-
225
- comparison_tester(
226
- :sym_difference,
227
- 'LINESTRING(0 0, 10 0)',
228
- 'POINT(5 0)',
229
- 'LINESTRING (0 0, 10 0)'
230
- )
231
-
232
- comparison_tester(
233
- :sym_difference,
234
- 'POINT(5 0)',
235
- 'LINESTRING(0 0, 10 0)',
236
- 'LINESTRING (0 0, 10 0)'
237
- )
238
-
239
- comparison_tester(
240
- :sym_difference,
241
- 'POINT(5 0)',
242
- 'LINESTRING(0 1, 10 1)',
243
- 'GEOMETRYCOLLECTION (POINT (5 0), LINESTRING (0 1, 10 1))'
244
- )
245
-
246
- comparison_tester(
247
- :sym_difference,
248
- 'LINESTRING(0 0, 10 0)',
249
- 'LINESTRING(5 -10, 5 10)',
250
- 'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0), (5 -10, 5 0), (5 0, 5 10))'
251
- )
252
-
253
- comparison_tester(
254
- :sym_difference,
255
- 'LINESTRING(0 0, 10 0)',
256
- 'LINESTRING(5 0, 20 0)',
257
- 'MULTILINESTRING ((0 0, 5 0), (10 0, 20 0))'
258
- )
259
-
260
- comparison_tester(
261
- :sym_difference,
262
- 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
263
- 'LINESTRING(5 -10, 5 10)',
264
- 'GEOMETRYCOLLECTION (LINESTRING (5 -10, 5 0), POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0)))'
265
- )
266
-
267
- comparison_tester(
268
- :sym_difference,
269
- 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
270
- 'LINESTRING(10 0, 20 0)',
271
- 'GEOMETRYCOLLECTION (LINESTRING (10 0, 20 0), POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0)))'
272
- )
273
-
274
- comparison_tester(
275
- :sym_difference,
276
- 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
277
- 'POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))',
278
- 'MULTIPOLYGON (((5 0, 0 0, 0 10, 10 10, 10 5, 5 5, 5 0)), ((5 0, 10 0, 10 5, 15 5, 15 -5, 5 -5, 5 0)))'
279
- )
280
- end
281
-
282
- def test_symmetric_difference
283
- comparison_tester(
284
- :symmetric_difference,
285
- 'POINT(0 0)',
286
- 'POINT(0 0)',
287
- 'GEOMETRYCOLLECTION EMPTY'
288
- )
289
-
290
- comparison_tester(
291
- :symmetric_difference,
292
- 'POINT(0 0)',
293
- 'POINT(1 0)',
294
- 'MULTIPOINT (0 0, 1 0)'
295
- )
296
-
297
- comparison_tester(
298
- :symmetric_difference,
299
- 'LINESTRING(0 0, 10 0)',
300
- 'POINT(5 0)',
301
- 'LINESTRING (0 0, 10 0)'
302
- )
303
-
304
- comparison_tester(
305
- :symmetric_difference,
306
- 'POINT(5 0)',
307
- 'LINESTRING(0 0, 10 0)',
308
- 'LINESTRING (0 0, 10 0)'
309
- )
310
-
311
- comparison_tester(
312
- :symmetric_difference,
313
- 'POINT(5 0)',
314
- 'LINESTRING(0 1, 10 1)',
315
- 'GEOMETRYCOLLECTION (POINT (5 0), LINESTRING (0 1, 10 1))'
316
- )
317
-
318
- comparison_tester(
319
- :symmetric_difference,
320
- 'LINESTRING(0 0, 10 0)',
321
- 'LINESTRING(5 -10, 5 10)',
322
- 'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0), (5 -10, 5 0), (5 0, 5 10))'
323
- )
324
-
325
- comparison_tester(
326
- :symmetric_difference,
327
- 'LINESTRING(0 0, 10 0)',
328
- 'LINESTRING(5 0, 20 0)',
329
- 'MULTILINESTRING ((0 0, 5 0), (10 0, 20 0))'
330
- )
331
-
332
- comparison_tester(
333
- :symmetric_difference,
334
- 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
335
- 'LINESTRING(5 -10, 5 10)',
336
- 'GEOMETRYCOLLECTION (LINESTRING (5 -10, 5 0), POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0)))'
337
- )
338
-
339
- comparison_tester(
340
- :symmetric_difference,
341
- 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
342
- 'LINESTRING(10 0, 20 0)',
343
- 'GEOMETRYCOLLECTION (LINESTRING (10 0, 20 0), POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0)))'
344
- )
345
-
346
- comparison_tester(
347
- :symmetric_difference,
348
- 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
349
- 'POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))',
350
- 'MULTIPOLYGON (((5 0, 0 0, 0 10, 10 10, 10 5, 5 5, 5 0)), ((5 0, 10 0, 10 5, 15 5, 15 -5, 5 -5, 5 0)))'
351
- )
209
+ %w{ sym_difference symmetric_difference }.each do |method|
210
+ comparison_tester(
211
+ method,
212
+ 'GEOMETRYCOLLECTION EMPTY',
213
+ 'POINT(0 0)',
214
+ 'POINT(0 0)'
215
+ )
216
+
217
+ comparison_tester(
218
+ method,
219
+ 'MULTIPOINT (0 0, 1 0)',
220
+ 'POINT(0 0)',
221
+ 'POINT(1 0)'
222
+ )
223
+
224
+ comparison_tester(
225
+ method,
226
+ 'LINESTRING (0 0, 10 0)',
227
+ 'LINESTRING(0 0, 10 0)',
228
+ 'POINT(5 0)'
229
+ )
230
+
231
+ comparison_tester(
232
+ method,
233
+ 'LINESTRING (0 0, 10 0)',
234
+ 'POINT(5 0)',
235
+ 'LINESTRING(0 0, 10 0)'
236
+ )
237
+
238
+ comparison_tester(
239
+ method,
240
+ 'GEOMETRYCOLLECTION (POINT (5 0), LINESTRING (0 1, 10 1))',
241
+ 'POINT(5 0)',
242
+ 'LINESTRING(0 1, 10 1)'
243
+ )
244
+
245
+ comparison_tester(
246
+ method,
247
+ 'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0), (5 -10, 5 0), (5 0, 5 10))',
248
+ 'LINESTRING(0 0, 10 0)',
249
+ 'LINESTRING(5 -10, 5 10)'
250
+ )
251
+
252
+ comparison_tester(
253
+ method,
254
+ 'MULTILINESTRING ((0 0, 5 0), (10 0, 20 0))',
255
+ 'LINESTRING(0 0, 10 0)',
256
+ 'LINESTRING(5 0, 20 0)'
257
+ )
258
+
259
+ comparison_tester(
260
+ method,
261
+ 'GEOMETRYCOLLECTION (LINESTRING (5 -10, 5 0), POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0)))',
262
+ 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
263
+ 'LINESTRING(5 -10, 5 10)'
264
+ )
265
+
266
+ comparison_tester(
267
+ method,
268
+ 'GEOMETRYCOLLECTION (LINESTRING (10 0, 20 0), POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0)))',
269
+ 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
270
+ 'LINESTRING(10 0, 20 0)'
271
+ )
272
+
273
+ comparison_tester(
274
+ method,
275
+ 'MULTIPOLYGON (((5 0, 0 0, 0 10, 10 10, 10 5, 5 5, 5 0)), ((5 0, 10 0, 10 5, 15 5, 15 -5, 5 -5, 5 0)))',
276
+ 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
277
+ 'POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'
278
+ )
279
+ end
352
280
  end
353
281
 
354
282
  def test_boundary
355
- self_tester(
283
+ simple_tester(
356
284
  :boundary,
357
- 'POINT(0 0)',
358
- 'GEOMETRYCOLLECTION EMPTY'
285
+ 'GEOMETRYCOLLECTION EMPTY',
286
+ 'POINT(0 0)'
359
287
  )
360
288
 
361
- self_tester(
289
+ simple_tester(
362
290
  :boundary,
363
- 'LINESTRING(0 0, 10 10)',
364
- 'MULTIPOINT (0 0, 10 10)'
291
+ 'MULTIPOINT (0 0, 10 10)',
292
+ 'LINESTRING(0 0, 10 10)'
365
293
  )
366
294
 
367
- self_tester(
295
+ simple_tester(
368
296
  :boundary,
369
- 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0),( 5 5, 5 6, 6 6, 6 5, 5 5))',
370
- 'MULTILINESTRING ((0 0, 10 0, 10 10, 0 10, 0 0), (5 5, 5 6, 6 6, 6 5, 5 5))'
297
+ 'MULTILINESTRING ((0 0, 10 0, 10 10, 0 10, 0 0), (5 5, 5 6, 6 6, 6 5, 5 5))',
298
+ 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0),( 5 5, 5 6, 6 6, 6 5, 5 5))'
371
299
  )
372
300
  end
373
301
 
374
302
  def test_union
375
303
  comparison_tester(
376
304
  :union,
305
+ 'POINT (0 0)',
377
306
  'POINT(0 0)',
378
- 'POINT(0 0)',
379
- 'POINT (0 0)'
307
+ 'POINT(0 0)'
380
308
  )
381
309
 
382
310
  comparison_tester(
383
311
  :union,
312
+ 'MULTIPOINT (0 0, 1 0)',
384
313
  'POINT(0 0)',
385
- 'POINT(1 0)',
386
- 'MULTIPOINT (0 0, 1 0)'
314
+ 'POINT(1 0)'
387
315
  )
388
316
 
389
317
  comparison_tester(
390
318
  :union,
319
+ 'LINESTRING (0 0, 10 0)',
391
320
  'LINESTRING(0 0, 10 0)',
392
- 'POINT(5 0)',
393
- 'LINESTRING (0 0, 10 0)'
321
+ 'POINT(5 0)'
394
322
  )
395
323
 
396
324
  comparison_tester(
397
325
  :union,
326
+ 'LINESTRING (0 0, 10 0)',
398
327
  'POINT(5 0)',
399
- 'LINESTRING(0 0, 10 0)',
400
- 'LINESTRING (0 0, 10 0)'
328
+ 'LINESTRING(0 0, 10 0)'
401
329
  )
402
330
 
403
331
  comparison_tester(
404
332
  :union,
333
+ 'GEOMETRYCOLLECTION (POINT (5 0), LINESTRING (0 1, 10 1))',
405
334
  'POINT(5 0)',
406
- 'LINESTRING(0 1, 10 1)',
407
- 'GEOMETRYCOLLECTION (POINT (5 0), LINESTRING (0 1, 10 1))'
335
+ 'LINESTRING(0 1, 10 1)'
408
336
  )
409
337
 
410
338
  comparison_tester(
411
339
  :union,
340
+ 'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0), (5 -10, 5 0), (5 0, 5 10))',
412
341
  'LINESTRING(0 0, 10 0)',
413
- 'LINESTRING(5 -10, 5 10)',
414
- 'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0), (5 -10, 5 0), (5 0, 5 10))'
342
+ 'LINESTRING(5 -10, 5 10)'
415
343
  )
416
344
 
417
345
  comparison_tester(
418
346
  :union,
347
+ 'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0), (10 0, 20 0))',
419
348
  'LINESTRING(0 0, 10 0)',
420
- 'LINESTRING(5 0, 20 0)',
421
- 'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0), (10 0, 20 0))'
349
+ 'LINESTRING(5 0, 20 0)'
422
350
  )
423
351
 
424
352
  comparison_tester(
425
353
  :union,
354
+ 'GEOMETRYCOLLECTION (LINESTRING (5 -10, 5 0), POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0)))',
426
355
  'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
427
- 'LINESTRING(5 -10, 5 10)',
428
- 'GEOMETRYCOLLECTION (LINESTRING (5 -10, 5 0), POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0)))'
356
+ 'LINESTRING(5 -10, 5 10)'
429
357
  )
430
358
 
431
359
  comparison_tester(
432
360
  :union,
361
+ 'GEOMETRYCOLLECTION (LINESTRING (10 0, 20 0), POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0)))',
433
362
  'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
434
- 'LINESTRING(10 0, 20 0)',
435
- 'GEOMETRYCOLLECTION (LINESTRING (10 0, 20 0), POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0)))'
363
+ 'LINESTRING(10 0, 20 0)'
436
364
  )
437
365
 
438
366
  comparison_tester(
439
367
  :union,
368
+ 'POLYGON ((5 0, 0 0, 0 10, 10 10, 10 5, 15 5, 15 -5, 5 -5, 5 0))',
440
369
  'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
441
- 'POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))',
442
- 'POLYGON ((5 0, 0 0, 0 10, 10 10, 10 5, 15 5, 15 -5, 5 -5, 5 0))'
370
+ 'POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'
443
371
  )
444
372
  end
445
373
 
446
374
  def test_union_cascaded
447
375
  skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:union_cascaded)
448
376
 
449
- self_tester(
377
+ simple_tester(
450
378
  :union_cascaded,
379
+ 'POLYGON ((1 0, 0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0), (11 11, 12 11, 12 12, 11 12, 11 11))',
451
380
  'MULTIPOLYGON(
452
381
  ((0 0, 1 0, 1 1, 0 1, 0 0)),
453
382
  ((10 10, 10 14, 14 14, 14 10, 10 10),
454
383
  (11 11, 11 12, 12 12, 12 11, 11 11)),
455
384
  ((0 0, 11 0, 11 11, 0 11, 0 0))
456
- ))',
457
- 'POLYGON ((
458
- 1 0, 0 0, 0 1, 0 11, 10 11,
459
- 10 14, 14 14, 14 10, 11 10,
460
- 11 0, 1 0
461
- ), (11 11, 12 11, 12 12, 11 12, 11 11))'
385
+ ))'
462
386
  )
463
387
  end
464
388
 
465
389
  def test_unary_union
466
390
  skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:unary_union)
467
391
 
468
- self_tester(
392
+ simple_tester(
469
393
  :unary_union,
394
+ 'POLYGON ((1 0, 0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0), (11 11, 12 11, 12 12, 11 12, 11 11))',
470
395
  'MULTIPOLYGON(
471
396
  ((0 0, 1 0, 1 1, 0 1, 0 0)),
472
397
  ((10 10, 10 14, 14 14, 14 10, 10 10),
473
398
  (11 11, 11 12, 12 12, 12 11, 11 11)),
474
399
  ((0 0, 11 0, 11 11, 0 11, 0 0))
475
- ))',
476
- 'POLYGON ((
477
- 1 0, 0 0, 0 1, 0 11, 10 11,
478
- 10 14, 14 14, 14 10, 11 10,
479
- 11 0, 1 0
480
- ), (11 11, 12 11, 12 12, 11 12, 11 11))'
400
+ ))'
481
401
  )
482
402
  end
483
403
 
484
404
  def test_node
485
405
  skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:node)
486
406
 
487
- self_tester(
407
+ simple_tester(
488
408
  :node,
489
- 'LINESTRING(0 0, 10 0, 5 -5, 5 5)',
490
- 'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0, 5 -5, 5 0), (5 0, 5 5))'
409
+ 'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0, 5 -5, 5 0), (5 0, 5 5))',
410
+ 'LINESTRING(0 0, 10 0, 5 -5, 5 5)'
491
411
  )
492
412
  end
493
413
 
494
414
  def test_union_without_arguments
495
- self_tester(
415
+ simple_tester(
496
416
  :union,
417
+ 'POLYGON ((1 0, 0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0), (11 11, 12 11, 12 12, 11 12, 11 11))',
497
418
  'MULTIPOLYGON(
498
419
  ((0 0, 1 0, 1 1, 0 1, 0 0)),
499
420
  ((10 10, 10 14, 14 14, 14 10, 10 10),
500
421
  (11 11, 11 12, 12 12, 12 11, 11 11)),
501
422
  ((0 0, 11 0, 11 11, 0 11, 0 0))
502
- ))',
503
- 'POLYGON ((
504
- 1 0, 0 0, 0 1, 0 11, 10 11,
505
- 10 14, 14 14, 14 10, 11 10,
506
- 11 0, 1 0
507
- ), (11 11, 12 11, 12 12, 11 12, 11 11))'
423
+ ))'
508
424
  )
509
425
  end
510
426
 
511
- def test_point_on_surface
512
- self_tester(
513
- :point_on_surface,
514
- 'POINT(0 0)',
515
- 'POINT(0 0)'
516
- )
517
-
518
- self_tester(
519
- :point_on_surface,
520
- 'LINESTRING(0 0, 5 5, 10 10)',
521
- 'POINT (5 5)'
522
- )
523
-
524
- self_tester(
525
- :point_on_surface,
526
- 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
527
- 'POINT (5 5)'
528
- )
529
- end
530
-
531
- def test_representative_point
532
- self_tester(
533
- :representative_point,
534
- 'POINT(0 0)',
535
- 'POINT(0 0)'
536
- )
537
-
538
- self_tester(
539
- :representative_point,
540
- 'LINESTRING(0 0, 5 0, 10 0)',
541
- 'POINT (5 0)'
542
- )
543
-
544
- self_tester(
545
- :representative_point,
546
- 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
547
- 'POINT (5 5)'
548
- )
427
+ def test_point_on_surface_and_representative_point
428
+ %w{
429
+ point_on_surface
430
+ representative_point
431
+ }.each do |method|
432
+ simple_tester(
433
+ method,
434
+ 'POINT (0 0)',
435
+ 'POINT (0 0)'
436
+ )
437
+
438
+ simple_tester(
439
+ method,
440
+ 'POINT (5 0)',
441
+ 'LINESTRING(0 0, 5 0, 10 0)'
442
+ )
443
+
444
+ simple_tester(
445
+ method,
446
+ 'POINT (5 5)',
447
+ 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'
448
+ )
449
+ end
549
450
  end
550
451
 
551
- def test_centroid
552
- self_tester(
553
- :centroid,
554
- 'POINT(0 0)',
555
- 'POINT (0 0)'
556
- )
557
-
558
- self_tester(
559
- :centroid,
560
- 'LINESTRING(0 0, 10 10)',
561
- 'POINT (5 5)'
562
- )
563
-
564
- self_tester(
565
- :centroid,
566
- 'POLYGON((0 0, 0 10, 5 5, 10 10, 10 0, 0 0))',
567
- 'POINT (5 3.888888888888888888)'
568
- )
452
+ def test_centroid_and_center
453
+ %w{
454
+ centroid
455
+ center
456
+ }.each do |method|
457
+ simple_tester(
458
+ method,
459
+ 'POINT (0 0)',
460
+ 'POINT(0 0)'
461
+ )
462
+
463
+ simple_tester(
464
+ method,
465
+ 'POINT (5 5)',
466
+ 'LINESTRING(0 0, 10 10)'
467
+ )
468
+
469
+ writer.trim = true
470
+ writer.rounding_precision = 0
471
+
472
+ simple_tester(
473
+ method,
474
+ 'POINT (5 4)',
475
+ 'POLYGON((0 0, 0 10, 5 5, 10 10, 10 0, 0 0))'
476
+ )
477
+ end
569
478
  end
570
479
 
571
480
  def test_envelope
572
- self_tester(
481
+ simple_tester(
573
482
  :envelope,
574
- 'POINT(0 0)',
575
- 'POINT (0 0)'
483
+ 'POINT (0 0)',
484
+ 'POINT(0 0)'
576
485
  )
577
486
 
578
- self_tester(
487
+ simple_tester(
579
488
  :envelope,
580
- 'LINESTRING(0 0, 10 10)',
581
- 'POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))'
489
+ 'POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))',
490
+ 'LINESTRING(0 0, 10 10)'
582
491
  )
583
492
  end
584
493
 
@@ -642,39 +551,39 @@ class GeometryTests < MiniTest::Unit::TestCase
642
551
  end
643
552
 
644
553
  def test_line_merge
645
- self_tester(
554
+ simple_tester(
646
555
  :line_merge,
556
+ 'LINESTRING (0 0, 10 10, 10 0, 5 0, 5 -5)',
647
557
  'MULTILINESTRING(
648
558
  (0 0, 10 10),
649
559
  (10 10, 10 0),
650
560
  (5 0, 10 0),
651
561
  (5 -5, 5 0)
652
- )',
653
- 'LINESTRING (0 0, 10 10, 10 0, 5 0, 5 -5)'
562
+ )'
654
563
  )
655
564
  end
656
565
 
657
566
  def test_simplify
658
- self_tester(
659
- [ :simplify, 2 ],
567
+ simple_tester(
568
+ :simplify,
569
+ 'LINESTRING (0 0, 5 10, 10 0, 10 9, 0 9)',
660
570
  'LINESTRING(0 0, 3 4, 5 10, 10 0, 10 9, 5 11, 0 9)',
661
- 'LINESTRING (0 0, 5 10, 10 0, 10 9, 0 9)'
571
+ 2
662
572
  )
663
573
  end
664
574
 
665
575
  def test_topology_preserve_simplify
666
- self_tester(
667
- [ :topology_preserve_simplify, 2 ],
576
+ simple_tester(
577
+ :topology_preserve_simplify,
578
+ 'LINESTRING (0 0, 5 10, 10 0, 10 9, 5 11, 0 9)',
668
579
  'LINESTRING(0 0, 3 4, 5 10, 10 0, 10 9, 5 11, 0 9)',
669
- 'LINESTRING (0 0, 5 10, 10 0, 10 9, 5 11, 0 9)'
580
+ 2
670
581
  )
671
582
  end
672
583
 
673
584
  def test_extract_unique_points
674
585
  skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:extract_unique_points)
675
586
 
676
- writer.rounding_precision = 0
677
-
678
587
  geom = read('GEOMETRYCOLLECTION (
679
588
  MULTIPOLYGON (
680
589
  ((0 0, 1 0, 1 1, 0 1, 0 0)),
@@ -690,9 +599,10 @@ class GeometryTests < MiniTest::Unit::TestCase
690
599
  LINESTRING EMPTY
691
600
  ')
692
601
 
693
- assert_equal(
602
+ simple_tester(
603
+ :extract_unique_points,
694
604
  'MULTIPOINT (0 0, 1 0, 1 1, 0 1, 10 10, 10 14, 14 14, 14 10, 11 11, 11 12, 12 12, 12 11, 2 3, 3 4, 9 0)',
695
- write(geom.extract_unique_points)
605
+ geom.extract_unique_points
696
606
  )
697
607
  end
698
608
 
@@ -855,11 +765,9 @@ class GeometryTests < MiniTest::Unit::TestCase
855
765
  assert_equal(location, write(ret[:location]))
856
766
  }
857
767
 
858
- writer.rounding_precision = 0
859
-
860
768
  assert_nil(read('POINT(0 0)').valid_detail)
861
769
  tester["Invalid Coordinate", 'POINT (0 nan)', 'POINT(0 NaN)', 0]
862
- tester["Self-intersection", 'POINT (2 5)', 'POLYGON((0 0, 0 5, 5 5, 5 10, 0 0))', 0]
770
+ tester["Self-intersection", 'POINT (2.5 5)', 'POLYGON((0 0, 0 5, 5 5, 5 10, 0 0))', 0]
863
771
 
864
772
  tester["Ring Self-intersection", 'POINT (0 0)', 'POLYGON((0 0, -10 10, 10 10, 0 0, 4 5, -4 5, 0 0)))', 0]
865
773
 
@@ -886,22 +794,17 @@ class GeometryTests < MiniTest::Unit::TestCase
886
794
  end
887
795
 
888
796
  def test_num_geometries
889
- tester = lambda { |expected, g|
890
- geom = read(g)
891
- assert_equal(expected, geom.num_geometries)
892
- }
893
-
894
- tester[1, 'POINT(0 0)']
895
- tester[2, 'MULTIPOINT (0 1, 2 3)']
896
- tester[1, 'LINESTRING (0 0, 2 3)']
897
- tester[2, 'MULTILINESTRING ((0 1, 2 3), (10 10, 3 4))']
898
- tester[1, 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))']
899
- tester[2, 'MULTIPOLYGON(
797
+ simple_tester(:num_geometries, 1, 'POINT(0 0)')
798
+ simple_tester(:num_geometries, 2, 'MULTIPOINT (0 1, 2 3)')
799
+ simple_tester(:num_geometries, 1, 'LINESTRING (0 0, 2 3)')
800
+ simple_tester(:num_geometries, 2, 'MULTILINESTRING ((0 1, 2 3), (10 10, 3 4))')
801
+ simple_tester(:num_geometries, 1, 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
802
+ simple_tester(:num_geometries, 2, 'MULTIPOLYGON(
900
803
  ((0 0, 1 0, 1 1, 0 1, 0 0)),
901
804
  ((10 10, 10 14, 14 14, 14 10, 10 10),
902
805
  (11 11, 11 12, 12 12, 12 11, 11 11)))'
903
- ]
904
- tester[6, 'GEOMETRYCOLLECTION (
806
+ )
807
+ simple_tester(:num_geometries, 6, 'GEOMETRYCOLLECTION (
905
808
  MULTIPOLYGON (
906
809
  ((0 0, 1 0, 1 1, 0 1, 0 0)),
907
810
  ((10 10, 10 14, 14 14, 14 10, 10 10),
@@ -912,73 +815,48 @@ class GeometryTests < MiniTest::Unit::TestCase
912
815
  LINESTRING (0 0, 2 3),
913
816
  MULTIPOINT (0 0, 2 3),
914
817
  POINT (9 0))'
915
- ]
818
+ )
916
819
  end
917
820
 
918
821
  # get_geometry_n is segfaulting in the binary GEOS build
919
822
  def test_get_geometry_n
920
823
  skip unless defined?(Geos::FFIGeos)
921
824
 
922
- tester = lambda { |expected, g, n|
923
- geom = read(g)
924
- result = geom.get_geometry_n(n)
925
-
926
- if expected.nil?
927
- assert_nil(result)
928
- else
929
- assert_geom_eql_exact(result, read(expected))
930
- end
931
- }
932
-
933
- tester['POINT(0 1)', 'MULTIPOINT (0 1, 2 3)', 0]
934
- tester['POINT(2 3)', 'MULTIPOINT (0 1, 2 3)', 1]
935
- tester[nil, 'MULTIPOINT (0 1, 2 3)', 2]
825
+ simple_tester(:get_geometry_n, 'POINT (0 1)', 'MULTIPOINT (0 1, 2 3)', 0)
826
+ simple_tester(:get_geometry_n, 'POINT (2 3)', 'MULTIPOINT (0 1, 2 3)', 1)
827
+ simple_tester(:get_geometry_n, nil, 'MULTIPOINT (0 1, 2 3)', 2)
936
828
  end
937
829
 
938
830
  def test_num_interior_rings
939
- tester = lambda { |expected, g|
940
- geom = read(g)
941
- assert_equal(expected, geom.num_interior_rings)
942
- }
943
-
944
- tester[0, 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))']
945
- tester[1, 'POLYGON (
831
+ simple_tester(:num_interior_rings, 0, 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
832
+ simple_tester(:num_interior_rings, 1, 'POLYGON (
946
833
  (10 10, 10 14, 14 14, 14 10, 10 10),
947
834
  (11 11, 11 12, 12 12, 12 11, 11 11)
948
- )']
949
- tester[2, 'POLYGON (
835
+ )')
836
+ simple_tester(:num_interior_rings, 2, 'POLYGON (
950
837
  (10 10, 10 14, 14 14, 14 10, 10 10),
951
838
  (11 11, 11 12, 12 12, 12 11, 11 11),
952
839
  (13 11, 13 12, 13.5 12, 13.5 11, 13 11))'
953
- ]
840
+ )
954
841
 
955
842
  assert_raises(NoMethodError) do
956
- tester[0, 'POINT (0 0)']
843
+ read('POINT (0 0)').num_interior_rings
957
844
  end
958
845
  end
959
846
 
960
847
  def test_interior_ring_n
961
- tester = lambda { |expected, g, n|
962
- geom = read(g)
963
- result = geom.interior_ring_n(n)
964
-
965
- if expected.nil?
966
- assert_nil(result)
967
- else
968
- assert_geom_eql_exact(result, read(expected))
969
- end
970
- }
971
-
972
- tester[
973
- 'LINEARRING(11 11, 11 12, 12 12, 12 11, 11 11)',
848
+ simple_tester(
849
+ :interior_ring_n,
850
+ 'LINEARRING (11 11, 11 12, 12 12, 12 11, 11 11)',
974
851
  'POLYGON(
975
852
  (10 10, 10 14, 14 14, 14 10, 10 10),
976
853
  (11 11, 11 12, 12 12, 12 11, 11 11)
977
854
  )',
978
855
  0
979
- ]
856
+ )
980
857
 
981
- tester[
858
+ simple_tester(
859
+ :interior_ring_n,
982
860
  'LINEARRING (11 11, 11 12, 12 12, 12 11, 11 11)',
983
861
  'POLYGON (
984
862
  (10 10, 10 14, 14 14, 14 10, 10 10),
@@ -986,9 +864,10 @@ class GeometryTests < MiniTest::Unit::TestCase
986
864
  (13 11, 13 12, 13.5 12, 13.5 11, 13 11)
987
865
  )',
988
866
  0
989
- ]
867
+ )
990
868
 
991
- tester[
869
+ simple_tester(
870
+ :interior_ring_n,
992
871
  'LINEARRING (13 11, 13 12, 13.5 12, 13.5 11, 13 11)',
993
872
  'POLYGON (
994
873
  (10 10, 10 14, 14 14, 14 10, 10 10),
@@ -996,76 +875,54 @@ class GeometryTests < MiniTest::Unit::TestCase
996
875
  (13 11, 13 12, 13.5 12, 13.5 11, 13 11)
997
876
  )',
998
877
  1
999
- ]
878
+ )
1000
879
 
1001
- assert_raises(RuntimeError) do
1002
- tester[
880
+ assert_raises(Geos::IndexBoundsError) do
881
+ simple_tester(
882
+ :interior_ring_n,
1003
883
  nil,
1004
884
  'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))',
1005
885
  0
1006
- ]
886
+ )
1007
887
  end
1008
888
 
1009
889
  assert_raises(NoMethodError) do
1010
- tester[
890
+ simple_tester(
891
+ :interior_ring_n,
1011
892
  nil,
1012
893
  'POINT (0 0)',
1013
894
  0
1014
- ]
895
+ )
1015
896
  end
1016
897
  end
1017
898
 
1018
899
  def test_exterior_ring
1019
- tester = lambda { |expected, g|
1020
- geom = read(g)
1021
- result = geom.exterior_ring
1022
-
1023
- if expected.nil?
1024
- assert_nil(result)
1025
- else
1026
- assert_geom_eql_exact(result, read(expected))
1027
- end
1028
- }
1029
-
1030
- tester[
900
+ simple_tester(
901
+ :exterior_ring,
1031
902
  'LINEARRING (10 10, 10 14, 14 14, 14 10, 10 10)',
1032
903
  'POLYGON (
1033
904
  (10 10, 10 14, 14 14, 14 10, 10 10),
1034
905
  (11 11, 11 12, 12 12, 12 11, 11 11)
1035
906
  )'
1036
- ]
907
+ )
1037
908
 
1038
909
  assert_raises(NoMethodError) do
1039
- tester[
1040
- nil,
1041
- 'POINT (0 0)'
1042
- ]
910
+ read('POINT (0 0)').exterior_ring
1043
911
  end
1044
912
  end
1045
913
 
1046
914
  def test_interior_rings
1047
- tester = lambda { |expected, g|
1048
- geom = read(g)
1049
- result = geom.interior_rings
1050
-
1051
- if expected.nil?
1052
- assert_nil(result)
1053
- else
1054
- assert_equal(expected, result.collect { |r| write(r) } )
1055
- end
1056
- }
1057
-
1058
- writer.trim = true
1059
-
1060
- tester[
915
+ array_tester(
916
+ :interior_rings,
1061
917
  [ 'LINEARRING (11 11, 11 12, 12 12, 12 11, 11 11)' ],
1062
918
  'POLYGON(
1063
919
  (10 10, 10 14, 14 14, 14 10, 10 10),
1064
920
  (11 11, 11 12, 12 12, 12 11, 11 11)
1065
921
  )'
1066
- ]
922
+ )
1067
923
 
1068
- tester[
924
+ array_tester(
925
+ :interior_rings,
1069
926
  [
1070
927
  'LINEARRING (11 11, 11 12, 12 12, 12 11, 11 11)',
1071
928
  'LINEARRING (13 11, 13 12, 13.5 12, 13.5 11, 13 11)'
@@ -1075,30 +932,23 @@ class GeometryTests < MiniTest::Unit::TestCase
1075
932
  (11 11, 11 12, 12 12, 12 11, 11 11),
1076
933
  (13 11, 13 12, 13.5 12, 13.5 11, 13 11)
1077
934
  )'
1078
- ]
935
+ )
1079
936
  end
1080
937
 
1081
938
  def test_num_coordinates
1082
939
  skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:num_coordinates)
1083
940
 
1084
- tester = lambda { |expected, g|
1085
- geom = read(g)
1086
- result = geom.num_coordinates
1087
-
1088
- assert_equal(expected, result)
1089
- }
1090
-
1091
- tester[1, 'POINT(0 0)']
1092
- tester[2, 'MULTIPOINT (0 1, 2 3)']
1093
- tester[2, 'LINESTRING (0 0, 2 3)']
1094
- tester[4, 'MULTILINESTRING ((0 1, 2 3), (10 10, 3 4))']
1095
- tester[5, 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))']
1096
- tester[15, 'MULTIPOLYGON (
941
+ simple_tester(:num_coordinates, 1, 'POINT(0 0)')
942
+ simple_tester(:num_coordinates, 2, 'MULTIPOINT (0 1, 2 3)')
943
+ simple_tester(:num_coordinates, 2, 'LINESTRING (0 0, 2 3)')
944
+ simple_tester(:num_coordinates, 4, 'MULTILINESTRING ((0 1, 2 3), (10 10, 3 4))')
945
+ simple_tester(:num_coordinates, 5, 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
946
+ simple_tester(:num_coordinates, 15, 'MULTIPOLYGON (
1097
947
  ((0 0, 1 0, 1 1, 0 1, 0 0)),
1098
948
  ((10 10, 10 14, 14 14, 14 10, 10 10),
1099
949
  (11 11, 11 12, 12 12, 12 11, 11 11))
1100
- )']
1101
- tester[29, 'GEOMETRYCOLLECTION (
950
+ )')
951
+ simple_tester(:num_coordinates, 29, 'GEOMETRYCOLLECTION (
1102
952
  MULTIPOLYGON (
1103
953
  ((0 0, 1 0, 1 1, 0 1, 0 0)),
1104
954
  ((10 10, 10 14, 14 14, 14 10, 10 10),
@@ -1109,7 +959,7 @@ class GeometryTests < MiniTest::Unit::TestCase
1109
959
  LINESTRING (0 0, 2 3),
1110
960
  MULTIPOINT ((0 0), (2 3)),
1111
961
  POINT (9 0)
1112
- )']
962
+ )')
1113
963
  end
1114
964
 
1115
965
  def test_coord_seq
@@ -1128,13 +978,6 @@ class GeometryTests < MiniTest::Unit::TestCase
1128
978
  end
1129
979
 
1130
980
  def test_dimensions
1131
- tester = lambda { |expected, g|
1132
- geom = read(g)
1133
- result = geom.dimensions
1134
-
1135
- assert_equal(expected, result)
1136
- }
1137
-
1138
981
  types = {
1139
982
  :dontcare => -3,
1140
983
  :non_empty => -2,
@@ -1144,17 +987,17 @@ class GeometryTests < MiniTest::Unit::TestCase
1144
987
  :surface => 2
1145
988
  }
1146
989
 
1147
- tester[types[:point], 'POINT(0 0)']
1148
- tester[types[:point], 'MULTIPOINT (0 1, 2 3)']
1149
- tester[types[:curve], 'LINESTRING (0 0, 2 3)']
1150
- tester[types[:curve], 'MULTILINESTRING ((0 1, 2 3), (10 10, 3 4))']
1151
- tester[types[:surface], 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))']
1152
- tester[types[:surface], 'MULTIPOLYGON (
990
+ simple_tester(:dimensions, types[:point], 'POINT(0 0)')
991
+ simple_tester(:dimensions, types[:point], 'MULTIPOINT (0 1, 2 3)')
992
+ simple_tester(:dimensions, types[:curve], 'LINESTRING (0 0, 2 3)')
993
+ simple_tester(:dimensions, types[:curve], 'MULTILINESTRING ((0 1, 2 3), (10 10, 3 4))')
994
+ simple_tester(:dimensions, types[:surface], 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
995
+ simple_tester(:dimensions, types[:surface], 'MULTIPOLYGON (
1153
996
  ((0 0, 1 0, 1 1, 0 1, 0 0)),
1154
997
  ((10 10, 10 14, 14 14, 14 10, 10 10),
1155
- (11 11, 11 12, 12 12, 12 11, 11 11)))'
1156
- ]
1157
- tester[types[:surface], 'GEOMETRYCOLLECTION (
998
+ (11 11, 11 12, 12 12, 12 11, 11 11))
999
+ )')
1000
+ simple_tester(:dimensions, types[:surface], 'GEOMETRYCOLLECTION (
1158
1001
  MULTIPOLYGON (
1159
1002
  ((0 0, 1 0, 1 1, 0 1, 0 0)),
1160
1003
  ((10 10, 10 14, 14 14, 14 10, 10 10),
@@ -1165,7 +1008,7 @@ class GeometryTests < MiniTest::Unit::TestCase
1165
1008
  LINESTRING (0 0, 2 3),
1166
1009
  MULTIPOINT (0 0, 2 3),
1167
1010
  POINT (9 0)
1168
- )']
1011
+ )')
1169
1012
  end
1170
1013
 
1171
1014
  def test_project_and_project_normalized
@@ -1175,7 +1018,7 @@ class GeometryTests < MiniTest::Unit::TestCase
1175
1018
  geom_b = read('POINT(3 4)')
1176
1019
 
1177
1020
  # The method only accept lineal geometries
1178
- assert_raises(RuntimeError) do
1021
+ assert_raises(Geos::GEOSException) do
1179
1022
  geom_a.project(geom_b)
1180
1023
  end
1181
1024
 
@@ -1183,45 +1026,43 @@ class GeometryTests < MiniTest::Unit::TestCase
1183
1026
  geom_b = read('POINT(0 0)')
1184
1027
  assert_equal(0, geom_a.project(geom_b))
1185
1028
  assert_equal(0, geom_a.project(geom_b, true))
1029
+ assert_equal(0, geom_a.project_normalized(geom_b))
1186
1030
 
1187
1031
  geom_b = read('POINT(10 0)')
1188
1032
  assert_equal(10, geom_a.project(geom_b))
1189
1033
  assert_equal(1, geom_a.project(geom_b, true))
1034
+ assert_equal(1, geom_a.project_normalized(geom_b))
1190
1035
 
1191
1036
  geom_b = read('POINT(5 0)')
1192
1037
  assert_equal(5, geom_a.project(geom_b))
1193
1038
  assert_equal(0.5, geom_a.project(geom_b, true))
1039
+ assert_equal(0.5, geom_a.project_normalized(geom_b))
1194
1040
 
1195
1041
  geom_a = read('MULTILINESTRING((0 0, 10 0),(20 10, 20 20))')
1196
1042
  geom_b = read('POINT(20 0)')
1197
1043
  assert_equal(10, geom_a.project(geom_b))
1198
1044
  assert_equal(0.5, geom_a.project(geom_b, true))
1045
+ assert_equal(0.5, geom_a.project_normalized(geom_b))
1199
1046
 
1200
1047
  geom_b = read('POINT(20 5)')
1201
1048
  assert_equal(10, geom_a.project(geom_b))
1202
1049
  assert_equal(0.5, geom_a.project(geom_b, true))
1050
+ assert_equal(0.5, geom_a.project_normalized(geom_b))
1203
1051
  end
1204
1052
 
1205
1053
  def test_interpolate
1206
1054
  skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:interpolate)
1207
1055
 
1208
- tester = lambda { |expected, g, d, normalize|
1209
- geom = read(g)
1210
- assert_equal(expected, write(geom.interpolate(d, normalize)))
1211
- }
1056
+ simple_tester(:interpolate, 'POINT (0 0)', 'LINESTRING(0 0, 10 0)', 0, false)
1057
+ simple_tester(:interpolate, 'POINT (0 0)', 'LINESTRING(0 0, 10 0)', 0, true)
1212
1058
 
1213
- writer.trim = true
1059
+ simple_tester(:interpolate, 'POINT (5 0)', 'LINESTRING(0 0, 10 0)', 5, false)
1060
+ simple_tester(:interpolate, 'POINT (5 0)', 'LINESTRING(0 0, 10 0)', 0.5, true)
1214
1061
 
1215
- tester['POINT (0 0)', 'LINESTRING(0 0, 10 0)', 0, false]
1216
- tester['POINT (0 0)', 'LINESTRING(0 0, 10 0)', 0, true]
1062
+ simple_tester(:interpolate, 'POINT (10 0)', 'LINESTRING(0 0, 10 0)', 20, false)
1063
+ simple_tester(:interpolate, 'POINT (10 0)', 'LINESTRING(0 0, 10 0)', 2, true)
1217
1064
 
1218
- tester['POINT (5 0)', 'LINESTRING(0 0, 10 0)', 5, false]
1219
- tester['POINT (5 0)', 'LINESTRING(0 0, 10 0)', 0.5, true]
1220
-
1221
- tester['POINT (10 0)', 'LINESTRING(0 0, 10 0)', 20, false]
1222
- tester['POINT (10 0)', 'LINESTRING(0 0, 10 0)', 2, true]
1223
-
1224
- assert_raises(RuntimeError) do
1065
+ assert_raises(Geos::GEOSException) do
1225
1066
  read('POINT(1 2)').interpolate(0)
1226
1067
  end
1227
1068
  end
@@ -1240,7 +1081,7 @@ class GeometryTests < MiniTest::Unit::TestCase
1240
1081
  tester['POINT (5 0)', 'LINESTRING(0 0, 10 0)', 0.5]
1241
1082
  tester['POINT (10 0)', 'LINESTRING(0 0, 10 0)', 2]
1242
1083
 
1243
- assert_raises(RuntimeError) do
1084
+ assert_raises(Geos::GEOSException) do
1244
1085
  read('POINT(1 2)').interpolate_normalized(0)
1245
1086
  end
1246
1087
  end
@@ -1248,52 +1089,32 @@ class GeometryTests < MiniTest::Unit::TestCase
1248
1089
  def test_start_and_end_points
1249
1090
  skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:start_point)
1250
1091
 
1251
- writer.rounding_precision = 0
1252
-
1253
- tester = lambda { |expected, method, geom|
1254
- assert_equal(expected, write(geom.send(method)))
1255
- }
1256
-
1257
1092
  geom = read('LINESTRING (10 10, 10 14, 14 14, 14 10)')
1258
- tester['POINT (10 10)', :start_point, geom]
1259
- tester['POINT (14 10)', :end_point, geom]
1093
+ simple_tester(:start_point, 'POINT (10 10)', geom)
1094
+ simple_tester(:end_point, 'POINT (14 10)', geom)
1260
1095
 
1261
1096
  geom = read('LINEARRING (11 11, 11 12, 12 11, 11 11)')
1262
- tester['POINT (11 11)', :start_point, geom]
1263
- tester['POINT (11 11)', :end_point, geom]
1097
+ simple_tester(:start_point, 'POINT (11 11)', geom)
1098
+ simple_tester(:start_point, 'POINT (11 11)', geom)
1264
1099
  end
1265
1100
 
1266
1101
  def test_area
1267
- tester = lambda { |expected, g|
1268
- assert_in_delta(expected, read(g).area, TOLERANCE)
1269
- }
1270
-
1271
- tester[1.0, 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))']
1272
- tester[0.0, 'POINT (0 0)']
1273
- tester[0.0, 'LINESTRING (0 0 , 10 0)']
1102
+ simple_tester(:area, 1.0, 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
1103
+ simple_tester(:area, 0.0, 'POINT (0 0)')
1104
+ simple_tester(:area, 0.0, 'LINESTRING (0 0 , 10 0)')
1274
1105
  end
1275
1106
 
1276
1107
  def test_length
1277
- tester = lambda { |expected, g|
1278
- assert_in_delta(expected, read(g).length, TOLERANCE)
1279
- }
1280
-
1281
- tester[4.0, 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))']
1282
- tester[0.0, 'POINT (0 0)']
1283
- tester[10.0, 'LINESTRING (0 0 , 10 0)']
1108
+ simple_tester(:length, 4.0, 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
1109
+ simple_tester(:length, 0.0, 'POINT (0 0)')
1110
+ simple_tester(:length, 10.0, 'LINESTRING (0 0 , 10 0)')
1284
1111
  end
1285
1112
 
1286
1113
  def test_distance
1287
- tester = lambda { |expected, g1, g2|
1288
- geom_1 = read(g1)
1289
- geom_2 = read(g2)
1290
- assert_in_delta(expected, geom_1.distance(geom_2), TOLERANCE)
1291
- }
1292
-
1293
- g = 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))'
1294
- tester[0.0, g, 'POINT(0.5 0.5)']
1295
- tester[1.0, g, 'POINT (-1 0)']
1296
- tester[2.0, g, 'LINESTRING (3 0 , 10 0)']
1114
+ geom = 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))'
1115
+ simple_tester(:distance, 0.0, geom, read('POINT(0.5 0.5)'))
1116
+ simple_tester(:distance, 1.0, geom, read('POINT (-1 0)'))
1117
+ simple_tester(:distance, 2.0, geom, read('LINESTRING (3 0 , 10 0)'))
1297
1118
  end
1298
1119
 
1299
1120
  def test_hausdorff_distance
@@ -1360,24 +1181,14 @@ class GeometryTests < MiniTest::Unit::TestCase
1360
1181
  def test_snap
1361
1182
  skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:snap)
1362
1183
 
1363
- tester = lambda { |expected, g1, g2, tolerance|
1364
- geom_a = read(g1)
1365
- geom_b = read(g2)
1366
- assert_geom_eql_exact(read(expected), geom_a.snap(geom_b, tolerance))
1367
- }
1368
-
1369
- writer.trim = true
1370
-
1371
- geom = 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))'
1372
- tester['POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))', geom, 'POINT(0.1 0)', 0]
1373
- tester['POLYGON ((0.1 0, 1 0, 1 1, 0 1, 0.1 0))', geom, 'POINT(0.1 0)', 0.5]
1184
+ geom = read('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
1185
+ simple_tester(:snap, 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))', geom, read('POINT(0.1 0)'), 0)
1186
+ simple_tester(:snap, 'POLYGON ((0.1 0, 1 0, 1 1, 0 1, 0.1 0))', geom, read('POINT(0.1 0)'), 0.5)
1374
1187
  end
1375
1188
 
1376
1189
  def test_polygonize
1377
1190
  skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:polygonize)
1378
1191
 
1379
- writer.rounding_precision = 0
1380
-
1381
1192
  geom_a = read(
1382
1193
  'GEOMETRYCOLLECTION(
1383
1194
  LINESTRING(0 0, 10 10),
@@ -1404,8 +1215,6 @@ class GeometryTests < MiniTest::Unit::TestCase
1404
1215
  def test_polygonize_cut_edges
1405
1216
  skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:polygonize_cut_edges)
1406
1217
 
1407
- writer.rounding_precision = 0
1408
-
1409
1218
  geom_a = read(
1410
1219
  'GEOMETRYCOLLECTION(
1411
1220
  LINESTRING(0 0, 10 10),
@@ -1424,7 +1233,7 @@ class GeometryTests < MiniTest::Unit::TestCase
1424
1233
  def test_polygonize_full
1425
1234
  skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:polygonize_full)
1426
1235
 
1427
- writer.rounding_precision = 0
1236
+ writer.rounding_precision = 3
1428
1237
 
1429
1238
  geom_a = read(
1430
1239
  'GEOMETRYCOLLECTION(
@@ -1490,7 +1299,6 @@ class GeometryTests < MiniTest::Unit::TestCase
1490
1299
 
1491
1300
  assert_raises(ArgumentError) do
1492
1301
  geom = read('POINT(0 0)')
1493
-
1494
1302
  geom.polygonize(geom, 'gibberish')
1495
1303
  end
1496
1304
  end
@@ -1498,8 +1306,6 @@ class GeometryTests < MiniTest::Unit::TestCase
1498
1306
  def test_shared_paths
1499
1307
  skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:shared_paths)
1500
1308
 
1501
- writer.rounding_precision = 0
1502
-
1503
1309
  geom_a = read('LINESTRING(0 0, 50 0)')
1504
1310
  geom_b = read('MULTILINESTRING((5 0, 15 0),(40 0, 30 0))')
1505
1311
 
@@ -1556,8 +1362,6 @@ class GeometryTests < MiniTest::Unit::TestCase
1556
1362
  end
1557
1363
 
1558
1364
  def test_normalize
1559
- writer.trim = true
1560
-
1561
1365
  geom = read('POLYGON((0 0, 5 0, 5 5, 0 5, 0 0))')
1562
1366
  geom.normalize
1563
1367
  assert_equal('POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0))', write(geom))
@@ -1567,8 +1371,6 @@ class GeometryTests < MiniTest::Unit::TestCase
1567
1371
  end
1568
1372
 
1569
1373
  def test_normalize_bang
1570
- writer.trim = true
1571
-
1572
1374
  geom = read('POLYGON((0 0, 5 0, 5 5, 0 5, 0 0))')
1573
1375
  geom.normalize!
1574
1376
  assert_equal('POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0))', write(geom))