ffi-geos 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTIxMDI2MjAzYTBlNmI2MTJlNDU2NzVkN2I2ZGJhY2U5MmVmMWNmYQ==
5
+ data.tar.gz: !binary |-
6
+ MjY3YWI1MzAzMTNkZDhlNDEyMzRkNTlmOGE1NzA5MWQ3NzliNWU1Yw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZjRhYjc0ZDdjMWE3YzllYmRlYmQ4MmZjMDM1MWFhNTZjNTFjOTUzNWY0YmFm
10
+ ODcxNzY0MTBkOWVhNmUxNzdjZjE2ZTZiOTA4YTM2OGI5YTRiNDgzMWM4Mzdk
11
+ YWQ3NWNjOThmM2VlOThmMTI4YmQwNDQyMjcxOTMzOWZkMjcwNGE=
12
+ data.tar.gz: !binary |-
13
+ YjU2NTI1NjZjM2VhNDE0ZmI4Y2NlMzhmYmEwNzY3OWQzNjk3NWY4ZmE1MDhl
14
+ NzAxOGJlYmJmZWIxMTcyZTlmZGI1YzBmODMwNmFmM2Y2MDBhZTZjZGFiMzUz
15
+ MTljMGQ3NThjYTYxMTdlODYyMWQzMjhjMjIwMGRmNWFmMzNlOTM=
data/lib/ffi-geos.rb CHANGED
@@ -55,6 +55,7 @@ module Geos
55
55
  ENV['PATH'].split(File::PATH_SEPARATOR)
56
56
  else
57
57
  [ '/usr/local/{lib64,lib}', '/opt/local/{lib64,lib}', '/usr/{lib64,lib}' ]
58
+ [ '/usr/local/{lib64,lib}', '/opt/local/{lib64,lib}', '/usr/{lib64,lib}', '/usr/lib/{x86_64,i386}-linux-gnu' ]
58
59
  end
59
60
  end
60
61
  end
@@ -186,38 +186,38 @@ module Geos
186
186
  # Gets the x value of a coordinate. Can also be retrieved via #x[].
187
187
  def get_x(idx)
188
188
  self.check_bounds(idx)
189
- FFI::MemoryPointer.new(:double).tap { |ret|
190
- FFIGeos.GEOSCoordSeq_getX_r(Geos.current_handle, self.ptr, idx, ret)
191
- }.read_double
189
+ double_ptr = FFI::MemoryPointer.new(:double)
190
+ FFIGeos.GEOSCoordSeq_getX_r(Geos.current_handle, self.ptr, idx, double_ptr)
191
+ double_ptr.read_double
192
192
  end
193
193
 
194
194
  # Gets the y value of a coordinate. Can also be retrieved via #y[].
195
195
  def get_y(idx)
196
196
  self.check_bounds(idx)
197
- FFI::MemoryPointer.new(:double).tap { |ret|
198
- FFIGeos.GEOSCoordSeq_getY_r(Geos.current_handle, self.ptr, idx, ret)
199
- }.read_double
197
+ double_ptr = FFI::MemoryPointer.new(:double)
198
+ FFIGeos.GEOSCoordSeq_getY_r(Geos.current_handle, self.ptr, idx, double_ptr)
199
+ double_ptr.read_double
200
200
  end
201
201
 
202
202
  # Gets the z value of a coordinate. Can also be retrieved via #z[].
203
203
  def get_z(idx)
204
204
  self.check_bounds(idx)
205
- FFI::MemoryPointer.new(:double).tap { |ret|
206
- FFIGeos.GEOSCoordSeq_getZ_r(Geos.current_handle, self.ptr, idx, ret)
207
- }.read_double
205
+ double_ptr = FFI::MemoryPointer.new(:double)
206
+ FFIGeos.GEOSCoordSeq_getZ_r(Geos.current_handle, self.ptr, idx, double_ptr)
207
+ double_ptr.read_double
208
208
  end
209
209
 
210
210
  def get_ordinate(idx, dim)
211
211
  self.check_bounds(idx)
212
- FFI::MemoryPointer.new(:double).tap { |ret|
213
- FFIGeos.GEOSCoordSeq_getOrdinate_r(Geos.current_handle, self.ptr, idx, dim, ret)
214
- }.read_double
212
+ double_ptr = FFI::MemoryPointer.new(:double)
213
+ FFIGeos.GEOSCoordSeq_getOrdinate_r(Geos.current_handle, self.ptr, idx, dim, double_ptr)
214
+ double_ptr.read_double
215
215
  end
216
216
 
217
217
  def length
218
- FFI::MemoryPointer.new(:int).tap { |ret|
219
- FFIGeos.GEOSCoordSeq_getSize_r(Geos.current_handle, self.ptr, ret)
220
- }.read_int
218
+ int_ptr = FFI::MemoryPointer.new(:int)
219
+ FFIGeos.GEOSCoordSeq_getSize_r(Geos.current_handle, self.ptr, int_ptr)
220
+ int_ptr.read_int
221
221
  end
222
222
  alias :size :length
223
223
 
@@ -226,9 +226,13 @@ module Geos
226
226
  end
227
227
 
228
228
  def dimensions
229
- @dimensions ||= FFI::MemoryPointer.new(:int).tap { |ret|
230
- FFIGeos.GEOSCoordSeq_getDimensions_r(Geos.current_handle, self.ptr, ret)
231
- }.read_int
229
+ if defined?(@dimensions)
230
+ @dimensions
231
+ else
232
+ int_ptr = FFI::MemoryPointer.new(:int)
233
+ FFIGeos.GEOSCoordSeq_getDimensions_r(Geos.current_handle, self.ptr, int_ptr)
234
+ @dimensions = int_ptr.read_int
235
+ end
232
236
  end
233
237
 
234
238
  def to_point(options = {})
@@ -431,9 +431,9 @@ module Geos
431
431
  if self.empty?
432
432
  0
433
433
  else
434
- FFI::MemoryPointer.new(:double).tap { |ret|
435
- FFIGeos.GEOSArea_r(Geos.current_handle, self.ptr, ret)
436
- }.read_double
434
+ double_ptr = FFI::MemoryPointer.new(:double)
435
+ FFIGeos.GEOSArea_r(Geos.current_handle, self.ptr, double_ptr)
436
+ double_ptr.read_double
437
437
  end
438
438
  end
439
439
 
@@ -441,28 +441,31 @@ module Geos
441
441
  if self.empty?
442
442
  0
443
443
  else
444
- FFI::MemoryPointer.new(:double).tap { |ret|
445
- FFIGeos.GEOSLength_r(Geos.current_handle, self.ptr, ret)
446
- }.read_double
444
+ double_ptr = FFI::MemoryPointer.new(:double)
445
+ FFIGeos.GEOSLength_r(Geos.current_handle, self.ptr, double_ptr)
446
+ double_ptr.read_double
447
447
  end
448
448
  end
449
449
 
450
450
  def distance(geom)
451
451
  check_geometry(geom)
452
- FFI::MemoryPointer.new(:double).tap { |ret|
453
- FFIGeos.GEOSDistance_r(Geos.current_handle, self.ptr, geom.ptr, ret)
454
- }.read_double
452
+ double_ptr = FFI::MemoryPointer.new(:double)
453
+ FFIGeos.GEOSDistance_r(Geos.current_handle, self.ptr, geom.ptr, double_ptr)
454
+ double_ptr.read_double
455
455
  end
456
456
 
457
457
  def hausdorff_distance(geom, densify_frac = nil)
458
458
  check_geometry(geom)
459
- FFI::MemoryPointer.new(:double).tap { |ret|
460
- if densify_frac
461
- FFIGeos.GEOSHausdorffDistanceDensify_r(Geos.current_handle, self.ptr, geom.ptr, densify_frac, ret)
462
- else
463
- FFIGeos.GEOSHausdorffDistance_r(Geos.current_handle, self.ptr, geom.ptr, ret)
464
- end
465
- }.read_double
459
+
460
+ double_ptr = FFI::MemoryPointer.new(:double)
461
+
462
+ if densify_frac
463
+ FFIGeos.GEOSHausdorffDistanceDensify_r(Geos.current_handle, self.ptr, geom.ptr, densify_frac, double_ptr)
464
+ else
465
+ FFIGeos.GEOSHausdorffDistance_r(Geos.current_handle, self.ptr, geom.ptr, double_ptr)
466
+ end
467
+
468
+ double_ptr.read_double
466
469
  end
467
470
 
468
471
  def snap(geom, tolerance)
@@ -4,9 +4,9 @@ module Geos
4
4
  class Point < Geometry
5
5
  if FFIGeos.respond_to?(:GEOSGeomGetX_r)
6
6
  def get_x
7
- FFI::MemoryPointer.new(:double).tap { |ret|
8
- FFIGeos.GEOSGeomGetX_r(Geos.current_handle, self.ptr, ret)
9
- }.read_double
7
+ double_ptr = FFI::MemoryPointer.new(:double)
8
+ FFIGeos.GEOSGeomGetX_r(Geos.current_handle, self.ptr, double_ptr)
9
+ double_ptr.read_double
10
10
  end
11
11
  else
12
12
  def get_x
@@ -17,9 +17,9 @@ module Geos
17
17
 
18
18
  if FFIGeos.respond_to?(:GEOSGeomGetY_r)
19
19
  def get_y
20
- FFI::MemoryPointer.new(:double).tap { |ret|
21
- FFIGeos.GEOSGeomGetY_r(Geos.current_handle, self.ptr, ret)
22
- }.read_double
20
+ double_ptr = FFI::MemoryPointer.new(:double)
21
+ FFIGeos.GEOSGeomGetY_r(Geos.current_handle, self.ptr, double_ptr)
22
+ double_ptr.read_double
23
23
  end
24
24
  else
25
25
  def get_y
@@ -30,9 +30,9 @@ module Geos
30
30
 
31
31
  if FFIGeos.respond_to?(:GEOSGeomGetZ_r)
32
32
  def get_z
33
- FFI::MemoryPointer.new(:double).tap { |ret|
34
- FFIGeos.GEOSGeomGetZ_r(Geos.current_handle, self.ptr, ret)
35
- }.read_double
33
+ double_ptr = FFI::MemoryPointer.new(:double)
34
+ FFIGeos.GEOSGeomGetZ_r(Geos.current_handle, self.ptr, double_ptr)
35
+ double_ptr.read_double
36
36
  end
37
37
  else
38
38
  def get_z
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Geos
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
6
6
 
@@ -6,52 +6,54 @@ require 'test_helper'
6
6
  class GeometryCollectionTests < MiniTest::Unit::TestCase
7
7
  include TestHelper
8
8
 
9
- if ENV['FORCE_TESTS'] || Geos::GeometryCollection.method_defined?(:[])
10
- def test_geometry_collection_enumerator
11
- geom = read('GEOMETRYCOLLECTION(POINT(0 0))')
12
- assert_kind_of(Enumerable, geom.each)
13
- assert_kind_of(Enumerable, geom.to_enum)
14
- assert_equal(geom, geom.each {})
15
- end
16
-
17
- def test_geometry_collection_array
18
- writer.trim = true
19
- geom = read('GEOMETRYCOLLECTION(
20
- LINESTRING(0 0, 1 1, 2 2, 3 3),
21
- POINT(10 20),
22
- POLYGON((0 0, 0 5, 5 5, 5 0, 0 0)),
23
- POINT(10 20)
24
- )')
25
-
26
- assert_equal('LINESTRING (0 0, 1 1, 2 2, 3 3)', write(geom[0]))
27
- assert_equal('POINT (10 20)', write(geom[-1]))
28
-
29
- assert_equal([
30
- 'LINESTRING (0 0, 1 1, 2 2, 3 3)',
31
- 'POINT (10 20)'
32
- ], geom[0, 2].collect { |g| write(g) })
33
-
34
- assert_equal(nil, geom[0, -1])
35
- assert_equal([], geom[-1, 0])
36
- assert_equal([
37
- 'POINT (10 20)',
38
- 'POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0))'
39
- ], geom[1..2].collect { |g| write(g) })
40
- end
9
+ def test_geometry_collection_enumerator
10
+ skip unless ENV['FORCE_TESTS'] || Geos::GeometryCollection.method_defined?(:[])
11
+
12
+ geom = read('GEOMETRYCOLLECTION(POINT(0 0))')
13
+ assert_kind_of(Enumerable, geom.each)
14
+ assert_kind_of(Enumerable, geom.to_enum)
15
+ assert_equal(geom, geom.each {})
41
16
  end
42
17
 
43
- if ENV['FORCE_TESTS'] || Geos::GeometryCollection.method_defined?(:detect)
44
- def test_geometry_collection_enumerable
45
- writer.trim = true
46
- geom = read('GEOMETRYCOLLECTION(
47
- LINESTRING(0 0, 1 1, 2 2, 3 3, 10 0, 2 2),
48
- POINT(10 20),
49
- POLYGON((0 0, 0 5, 5 5, 5 0, 0 0)),
50
- POINT(10 20)
51
- )')
52
-
53
- assert_equal(2, geom.select { |point| point == read('POINT(10 20)') }.length)
54
- end
18
+ def test_geometry_collection_array
19
+ skip unless ENV['FORCE_TESTS'] || Geos::GeometryCollection.method_defined?(:[])
20
+
21
+ writer.trim = true
22
+ geom = read('GEOMETRYCOLLECTION(
23
+ LINESTRING(0 0, 1 1, 2 2, 3 3),
24
+ POINT(10 20),
25
+ POLYGON((0 0, 0 5, 5 5, 5 0, 0 0)),
26
+ POINT(10 20)
27
+ )')
28
+
29
+ assert_equal('LINESTRING (0 0, 1 1, 2 2, 3 3)', write(geom[0]))
30
+ assert_equal('POINT (10 20)', write(geom[-1]))
31
+
32
+ assert_equal([
33
+ 'LINESTRING (0 0, 1 1, 2 2, 3 3)',
34
+ 'POINT (10 20)'
35
+ ], geom[0, 2].collect { |g| write(g) })
36
+
37
+ assert_equal(nil, geom[0, -1])
38
+ assert_equal([], geom[-1, 0])
39
+ assert_equal([
40
+ 'POINT (10 20)',
41
+ 'POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0))'
42
+ ], geom[1..2].collect { |g| write(g) })
43
+ end
44
+
45
+ def test_geometry_collection_enumerable
46
+ skip unless ENV['FORCE_TESTS'] || Geos::GeometryCollection.method_defined?(:detect)
47
+
48
+ writer.trim = true
49
+ geom = read('GEOMETRYCOLLECTION(
50
+ LINESTRING(0 0, 1 1, 2 2, 3 3, 10 0, 2 2),
51
+ POINT(10 20),
52
+ POLYGON((0 0, 0 5, 5 5, 5 0, 0 0)),
53
+ POINT(10 20)
54
+ )')
55
+
56
+ assert_equal(2, geom.select { |point| point == read('POINT(10 20)') }.length)
55
57
  end
56
58
 
57
59
  def test_default_srid
@@ -443,42 +443,42 @@ class GeometryTests < MiniTest::Unit::TestCase
443
443
  )
444
444
  end
445
445
 
446
- if ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:union_cascaded)
447
- def test_union_cascaded
448
- self_tester(
449
- :union_cascaded,
450
- 'MULTIPOLYGON(
451
- ((0 0, 1 0, 1 1, 0 1, 0 0)),
452
- ((10 10, 10 14, 14 14, 14 10, 10 10),
453
- (11 11, 11 12, 12 12, 12 11, 11 11)),
454
- ((0 0, 11 0, 11 11, 0 11, 0 0))
455
- ))',
456
- 'POLYGON ((
457
- 1 0, 0 0, 0 1, 0 11, 10 11,
458
- 10 14, 14 14, 14 10, 11 10,
459
- 11 0, 1 0
460
- ), (11 11, 12 11, 12 12, 11 12, 11 11))'
461
- )
462
- end
446
+ def test_union_cascaded
447
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:union_cascaded)
448
+
449
+ self_tester(
450
+ :union_cascaded,
451
+ 'MULTIPOLYGON(
452
+ ((0 0, 1 0, 1 1, 0 1, 0 0)),
453
+ ((10 10, 10 14, 14 14, 14 10, 10 10),
454
+ (11 11, 11 12, 12 12, 12 11, 11 11)),
455
+ ((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))'
462
+ )
463
463
  end
464
464
 
465
- if ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:unary_union)
466
- def test_unary_union
467
- self_tester(
468
- :unary_union,
469
- 'MULTIPOLYGON(
470
- ((0 0, 1 0, 1 1, 0 1, 0 0)),
471
- ((10 10, 10 14, 14 14, 14 10, 10 10),
472
- (11 11, 11 12, 12 12, 12 11, 11 11)),
473
- ((0 0, 11 0, 11 11, 0 11, 0 0))
474
- ))',
475
- 'POLYGON ((
476
- 1 0, 0 0, 0 1, 0 11, 10 11,
477
- 10 14, 14 14, 14 10, 11 10,
478
- 11 0, 1 0
479
- ), (11 11, 12 11, 12 12, 11 12, 11 11))'
480
- )
481
- end
465
+ def test_unary_union
466
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:unary_union)
467
+
468
+ self_tester(
469
+ :unary_union,
470
+ 'MULTIPOLYGON(
471
+ ((0 0, 1 0, 1 1, 0 1, 0 0)),
472
+ ((10 10, 10 14, 14 14, 14 10, 10 10),
473
+ (11 11, 11 12, 12 12, 12 11, 11 11)),
474
+ ((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))'
481
+ )
482
482
  end
483
483
 
484
484
  def test_union_without_arguments
@@ -513,8 +513,8 @@ class GeometryTests < MiniTest::Unit::TestCase
513
513
 
514
514
  self_tester(
515
515
  :point_on_surface,
516
- 'POLYGON((0 0, 0 10, 5 5, 10 10, 10 0, 0 0))',
517
- 'POINT (2.5 5)'
516
+ 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
517
+ 'POINT (5 5)'
518
518
  )
519
519
  end
520
520
 
@@ -527,14 +527,14 @@ class GeometryTests < MiniTest::Unit::TestCase
527
527
 
528
528
  self_tester(
529
529
  :representative_point,
530
- 'LINESTRING(0 0, 5 5, 10 10)',
531
- 'POINT (5 5)'
530
+ 'LINESTRING(0 0, 5 0, 10 0)',
531
+ 'POINT (5 0)'
532
532
  )
533
533
 
534
534
  self_tester(
535
535
  :representative_point,
536
- 'POLYGON((0 0, 0 10, 5 5, 10 10, 10 0, 0 0))',
537
- 'POINT (2.5 5)'
536
+ 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))',
537
+ 'POINT (5 5)'
538
538
  )
539
539
  end
540
540
 
@@ -614,20 +614,20 @@ class GeometryTests < MiniTest::Unit::TestCase
614
614
  tester['T*******2', geom_a, geom_b, false]
615
615
  end
616
616
 
617
- if ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:relate_boundary_node_rule)
618
- def test_relate_boundary_node_rule
619
- geom_a = read('LINESTRING(0 0, 2 4, 5 5, 0 0)')
620
- geom_b = read('POINT(0 0)')
617
+ def test_relate_boundary_node_rule
618
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:relate_boundary_node_rule)
621
619
 
622
- ret = geom_a.relate_boundary_node_rule(geom_b, :ogc)
623
- assert_equal('0F1FFFFF2', ret)
620
+ geom_a = read('LINESTRING(0 0, 2 4, 5 5, 0 0)')
621
+ geom_b = read('POINT(0 0)')
624
622
 
625
- ret = geom_a.relate_boundary_node_rule(geom_b, :endpoint)
626
- assert_equal('FF10FFFF2', ret)
623
+ ret = geom_a.relate_boundary_node_rule(geom_b, :ogc)
624
+ assert_equal('0F1FFFFF2', ret)
627
625
 
628
- assert_raises(TypeError) do
629
- geom_a.relate_boundary_node_rule(geom_b, :gibberish)
630
- end
626
+ ret = geom_a.relate_boundary_node_rule(geom_b, :endpoint)
627
+ assert_equal('FF10FFFF2', ret)
628
+
629
+ assert_raises(TypeError) do
630
+ geom_a.relate_boundary_node_rule(geom_b, :gibberish)
631
631
  end
632
632
  end
633
633
 
@@ -660,30 +660,30 @@ class GeometryTests < MiniTest::Unit::TestCase
660
660
  )
661
661
  end
662
662
 
663
- if ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:extract_unique_points)
664
- def test_extract_unique_points
665
- writer.rounding_precision = 0
666
-
667
- geom = read('GEOMETRYCOLLECTION (
668
- MULTIPOLYGON (
669
- ((0 0, 1 0, 1 1, 0 1, 0 0)),
670
- ((10 10, 10 14, 14 14, 14 10, 10 10),
671
- (11 11, 11 12, 12 12, 12 11, 11 11))
672
- ),
673
- POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)),
674
- MULTILINESTRING ((0 0, 2 3), (10 10, 3 4)),
675
- LINESTRING (0 0, 2 3),
676
- MULTIPOINT (0 0, 2 3),
677
- POINT (9 0),
678
- POINT(1 0)),
679
- LINESTRING EMPTY
680
- ')
681
-
682
- assert_equal(
683
- '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)',
684
- write(geom.extract_unique_points)
685
- )
686
- end
663
+ def test_extract_unique_points
664
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:extract_unique_points)
665
+
666
+ writer.rounding_precision = 0
667
+
668
+ geom = read('GEOMETRYCOLLECTION (
669
+ MULTIPOLYGON (
670
+ ((0 0, 1 0, 1 1, 0 1, 0 0)),
671
+ ((10 10, 10 14, 14 14, 14 10, 10 10),
672
+ (11 11, 11 12, 12 12, 12 11, 11 11))
673
+ ),
674
+ POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)),
675
+ MULTILINESTRING ((0 0, 2 3), (10 10, 3 4)),
676
+ LINESTRING (0 0, 2 3),
677
+ MULTIPOINT (0 0, 2 3),
678
+ POINT (9 0),
679
+ POINT(1 0)),
680
+ LINESTRING EMPTY
681
+ ')
682
+
683
+ assert_equal(
684
+ '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)',
685
+ write(geom.extract_unique_points)
686
+ )
687
687
  end
688
688
 
689
689
  def test_relationships
@@ -827,35 +827,35 @@ class GeometryTests < MiniTest::Unit::TestCase
827
827
  refute_geom_valid(read('POINT(0 nan)'))
828
828
  end
829
829
 
830
- if ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:valid_reason)
831
- def test_valid_reason
832
- assert_equal("Valid Geometry", read('POINT(0 0)').valid_reason)
833
- assert_equal("Invalid Coordinate[0 nan]", read('POINT(0 NaN)').valid_reason)
834
- assert_equal("Invalid Coordinate[0 nan]", read('POINT(0 nan)').valid_reason)
835
- assert_equal("Self-intersection[2.5 5]", read('POLYGON((0 0, 0 5, 5 5, 5 10, 0 0))').valid_reason)
836
- end
830
+ def test_valid_reason
831
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:valid_reason)
832
+
833
+ assert_equal("Valid Geometry", read('POINT(0 0)').valid_reason)
834
+ assert_equal("Invalid Coordinate[0 nan]", read('POINT(0 NaN)').valid_reason)
835
+ assert_equal("Invalid Coordinate[0 nan]", read('POINT(0 nan)').valid_reason)
836
+ assert_equal("Self-intersection[2.5 5]", read('POLYGON((0 0, 0 5, 5 5, 5 10, 0 0))').valid_reason)
837
837
  end
838
838
 
839
- if ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:valid_detail)
840
- def test_valid_detail
841
- tester = lambda { |detail, location, geom, flags|
842
- ret = read(geom).valid_detail(flags)
843
- assert_equal(detail, ret[:detail])
844
- assert_equal(location, write(ret[:location]))
845
- }
839
+ def test_valid_detail
840
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:valid_detail)
846
841
 
847
- writer.rounding_precision = 0
842
+ tester = lambda { |detail, location, geom, flags|
843
+ ret = read(geom).valid_detail(flags)
844
+ assert_equal(detail, ret[:detail])
845
+ assert_equal(location, write(ret[:location]))
846
+ }
848
847
 
849
- assert_nil(read('POINT(0 0)').valid_detail)
850
- tester["Invalid Coordinate", 'POINT (0 nan)', 'POINT(0 NaN)', 0]
851
- tester["Self-intersection", 'POINT (2 5)', 'POLYGON((0 0, 0 5, 5 5, 5 10, 0 0))', 0]
848
+ writer.rounding_precision = 0
852
849
 
853
- tester["Ring Self-intersection", 'POINT (0 0)', 'POLYGON((0 0, -10 10, 10 10, 0 0, 4 5, -4 5, 0 0)))', 0]
850
+ assert_nil(read('POINT(0 0)').valid_detail)
851
+ tester["Invalid Coordinate", 'POINT (0 nan)', 'POINT(0 NaN)', 0]
852
+ tester["Self-intersection", 'POINT (2 5)', 'POLYGON((0 0, 0 5, 5 5, 5 10, 0 0))', 0]
854
853
 
855
- assert_nil(read('POLYGON((0 0, -10 10, 10 10, 0 0, 4 5, -4 5, 0 0)))').valid_detail(
856
- :allow_selftouching_ring_forming_hole
857
- ))
858
- end
854
+ tester["Ring Self-intersection", 'POINT (0 0)', 'POLYGON((0 0, -10 10, 10 10, 0 0, 4 5, -4 5, 0 0)))', 0]
855
+
856
+ assert_nil(read('POLYGON((0 0, -10 10, 10 10, 0 0, 4 5, -4 5, 0 0)))').valid_detail(
857
+ :allow_selftouching_ring_forming_hole
858
+ ))
859
859
  end
860
860
 
861
861
  def test_simple
@@ -906,23 +906,23 @@ class GeometryTests < MiniTest::Unit::TestCase
906
906
  end
907
907
 
908
908
  # get_geometry_n is segfaulting in the binary GEOS build
909
- if defined?(Geos::FFIGeos)
910
- def test_get_geometry_n
911
- tester = lambda { |expected, g, n|
912
- geom = read(g)
913
- result = geom.get_geometry_n(n)
914
-
915
- if expected.nil?
916
- assert_nil(result)
917
- else
918
- assert_geom_eql_exact(result, read(expected))
919
- end
920
- }
909
+ def test_get_geometry_n
910
+ skip unless defined?(Geos::FFIGeos)
921
911
 
922
- tester['POINT(0 1)', 'MULTIPOINT (0 1, 2 3)', 0]
923
- tester['POINT(2 3)', 'MULTIPOINT (0 1, 2 3)', 1]
924
- tester[nil, 'MULTIPOINT (0 1, 2 3)', 2]
925
- end
912
+ tester = lambda { |expected, g, n|
913
+ geom = read(g)
914
+ result = geom.get_geometry_n(n)
915
+
916
+ if expected.nil?
917
+ assert_nil(result)
918
+ else
919
+ assert_geom_eql_exact(result, read(expected))
920
+ end
921
+ }
922
+
923
+ tester['POINT(0 1)', 'MULTIPOINT (0 1, 2 3)', 0]
924
+ tester['POINT(2 3)', 'MULTIPOINT (0 1, 2 3)', 1]
925
+ tester[nil, 'MULTIPOINT (0 1, 2 3)', 2]
926
926
  end
927
927
 
928
928
  def test_num_interior_rings
@@ -1068,38 +1068,38 @@ class GeometryTests < MiniTest::Unit::TestCase
1068
1068
  ]
1069
1069
  end
1070
1070
 
1071
- if ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:num_coordinates)
1072
- def test_num_coordinates
1073
- tester = lambda { |expected, g|
1074
- geom = read(g)
1075
- result = geom.num_coordinates
1071
+ def test_num_coordinates
1072
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:num_coordinates)
1076
1073
 
1077
- assert_equal(expected, result)
1078
- }
1074
+ tester = lambda { |expected, g|
1075
+ geom = read(g)
1076
+ result = geom.num_coordinates
1077
+
1078
+ assert_equal(expected, result)
1079
+ }
1079
1080
 
1080
- tester[1, 'POINT(0 0)']
1081
- tester[2, 'MULTIPOINT (0 1, 2 3)']
1082
- tester[2, 'LINESTRING (0 0, 2 3)']
1083
- tester[4, 'MULTILINESTRING ((0 1, 2 3), (10 10, 3 4))']
1084
- tester[5, 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))']
1085
- tester[15, 'MULTIPOLYGON (
1081
+ tester[1, 'POINT(0 0)']
1082
+ tester[2, 'MULTIPOINT (0 1, 2 3)']
1083
+ tester[2, 'LINESTRING (0 0, 2 3)']
1084
+ tester[4, 'MULTILINESTRING ((0 1, 2 3), (10 10, 3 4))']
1085
+ tester[5, 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))']
1086
+ tester[15, 'MULTIPOLYGON (
1087
+ ((0 0, 1 0, 1 1, 0 1, 0 0)),
1088
+ ((10 10, 10 14, 14 14, 14 10, 10 10),
1089
+ (11 11, 11 12, 12 12, 12 11, 11 11))
1090
+ )']
1091
+ tester[29, 'GEOMETRYCOLLECTION (
1092
+ MULTIPOLYGON (
1086
1093
  ((0 0, 1 0, 1 1, 0 1, 0 0)),
1087
1094
  ((10 10, 10 14, 14 14, 14 10, 10 10),
1088
1095
  (11 11, 11 12, 12 12, 12 11, 11 11))
1089
- )']
1090
- tester[29, 'GEOMETRYCOLLECTION (
1091
- MULTIPOLYGON (
1092
- ((0 0, 1 0, 1 1, 0 1, 0 0)),
1093
- ((10 10, 10 14, 14 14, 14 10, 10 10),
1094
- (11 11, 11 12, 12 12, 12 11, 11 11))
1095
- ),
1096
- POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)),
1097
- MULTILINESTRING ((0 0, 2 3), (10 10, 3 4)),
1098
- LINESTRING (0 0, 2 3),
1099
- MULTIPOINT ((0 0), (2 3)),
1100
- POINT (9 0)
1101
- )']
1102
- end
1096
+ ),
1097
+ POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)),
1098
+ MULTILINESTRING ((0 0, 2 3), (10 10, 3 4)),
1099
+ LINESTRING (0 0, 2 3),
1100
+ MULTIPOINT ((0 0), (2 3)),
1101
+ POINT (9 0)
1102
+ )']
1103
1103
  end
1104
1104
 
1105
1105
  def test_coord_seq
@@ -1158,80 +1158,80 @@ class GeometryTests < MiniTest::Unit::TestCase
1158
1158
  )']
1159
1159
  end
1160
1160
 
1161
- if ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:project)
1162
- def test_project_and_project_normalized
1163
- geom_a = read('POINT(1 2)')
1164
- geom_b = read('POINT(3 4)')
1161
+ def test_project_and_project_normalized
1162
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:project)
1165
1163
 
1166
- # The method only accept lineal geometries
1167
- assert_raises(RuntimeError) do
1168
- geom_a.project(geom_b)
1169
- end
1164
+ geom_a = read('POINT(1 2)')
1165
+ geom_b = read('POINT(3 4)')
1170
1166
 
1171
- geom_a = read('LINESTRING(0 0, 10 0)')
1172
- geom_b = read('POINT(0 0)')
1173
- assert_equal(0, geom_a.project(geom_b))
1174
- assert_equal(0, geom_a.project(geom_b, true))
1167
+ # The method only accept lineal geometries
1168
+ assert_raises(RuntimeError) do
1169
+ geom_a.project(geom_b)
1170
+ end
1175
1171
 
1176
- geom_b = read('POINT(10 0)')
1177
- assert_equal(10, geom_a.project(geom_b))
1178
- assert_equal(1, geom_a.project(geom_b, true))
1172
+ geom_a = read('LINESTRING(0 0, 10 0)')
1173
+ geom_b = read('POINT(0 0)')
1174
+ assert_equal(0, geom_a.project(geom_b))
1175
+ assert_equal(0, geom_a.project(geom_b, true))
1179
1176
 
1180
- geom_b = read('POINT(5 0)')
1181
- assert_equal(5, geom_a.project(geom_b))
1182
- assert_equal(0.5, geom_a.project(geom_b, true))
1177
+ geom_b = read('POINT(10 0)')
1178
+ assert_equal(10, geom_a.project(geom_b))
1179
+ assert_equal(1, geom_a.project(geom_b, true))
1183
1180
 
1184
- geom_a = read('MULTILINESTRING((0 0, 10 0),(20 10, 20 20))')
1185
- geom_b = read('POINT(20 0)')
1186
- assert_equal(10, geom_a.project(geom_b))
1187
- assert_equal(0.5, geom_a.project(geom_b, true))
1181
+ geom_b = read('POINT(5 0)')
1182
+ assert_equal(5, geom_a.project(geom_b))
1183
+ assert_equal(0.5, geom_a.project(geom_b, true))
1188
1184
 
1189
- geom_b = read('POINT(20 5)')
1190
- assert_equal(10, geom_a.project(geom_b))
1191
- assert_equal(0.5, geom_a.project(geom_b, true))
1192
- end
1185
+ geom_a = read('MULTILINESTRING((0 0, 10 0),(20 10, 20 20))')
1186
+ geom_b = read('POINT(20 0)')
1187
+ assert_equal(10, geom_a.project(geom_b))
1188
+ assert_equal(0.5, geom_a.project(geom_b, true))
1189
+
1190
+ geom_b = read('POINT(20 5)')
1191
+ assert_equal(10, geom_a.project(geom_b))
1192
+ assert_equal(0.5, geom_a.project(geom_b, true))
1193
1193
  end
1194
1194
 
1195
- if ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:interpolate)
1196
- def test_interpolate
1197
- tester = lambda { |expected, g, d, normalize|
1198
- geom = read(g)
1199
- assert_equal(expected, write(geom.interpolate(d, normalize)))
1200
- }
1195
+ def test_interpolate
1196
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:interpolate)
1197
+
1198
+ tester = lambda { |expected, g, d, normalize|
1199
+ geom = read(g)
1200
+ assert_equal(expected, write(geom.interpolate(d, normalize)))
1201
+ }
1201
1202
 
1202
- writer.trim = true
1203
+ writer.trim = true
1203
1204
 
1204
- tester['POINT (0 0)', 'LINESTRING(0 0, 10 0)', 0, false]
1205
- tester['POINT (0 0)', 'LINESTRING(0 0, 10 0)', 0, true]
1205
+ tester['POINT (0 0)', 'LINESTRING(0 0, 10 0)', 0, false]
1206
+ tester['POINT (0 0)', 'LINESTRING(0 0, 10 0)', 0, true]
1206
1207
 
1207
- tester['POINT (5 0)', 'LINESTRING(0 0, 10 0)', 5, false]
1208
- tester['POINT (5 0)', 'LINESTRING(0 0, 10 0)', 0.5, true]
1208
+ tester['POINT (5 0)', 'LINESTRING(0 0, 10 0)', 5, false]
1209
+ tester['POINT (5 0)', 'LINESTRING(0 0, 10 0)', 0.5, true]
1209
1210
 
1210
- tester['POINT (10 0)', 'LINESTRING(0 0, 10 0)', 20, false]
1211
- tester['POINT (10 0)', 'LINESTRING(0 0, 10 0)', 2, true]
1211
+ tester['POINT (10 0)', 'LINESTRING(0 0, 10 0)', 20, false]
1212
+ tester['POINT (10 0)', 'LINESTRING(0 0, 10 0)', 2, true]
1212
1213
 
1213
- assert_raises(RuntimeError) do
1214
- read('POINT(1 2)').interpolate(0)
1215
- end
1214
+ assert_raises(RuntimeError) do
1215
+ read('POINT(1 2)').interpolate(0)
1216
1216
  end
1217
1217
  end
1218
1218
 
1219
- if ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:start_point)
1220
- def test_start_and_end_points
1221
- writer.rounding_precision = 0
1219
+ def test_start_and_end_points
1220
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:start_point)
1222
1221
 
1223
- tester = lambda { |expected, method, geom|
1224
- assert_equal(expected, write(geom.send(method)))
1225
- }
1222
+ writer.rounding_precision = 0
1226
1223
 
1227
- geom = read('LINESTRING (10 10, 10 14, 14 14, 14 10)')
1228
- tester['POINT (10 10)', :start_point, geom]
1229
- tester['POINT (14 10)', :end_point, geom]
1224
+ tester = lambda { |expected, method, geom|
1225
+ assert_equal(expected, write(geom.send(method)))
1226
+ }
1230
1227
 
1231
- geom = read('LINEARRING (11 11, 11 12, 12 11, 11 11)')
1232
- tester['POINT (11 11)', :start_point, geom]
1233
- tester['POINT (11 11)', :end_point, geom]
1234
- end
1228
+ geom = read('LINESTRING (10 10, 10 14, 14 14, 14 10)')
1229
+ tester['POINT (10 10)', :start_point, geom]
1230
+ tester['POINT (14 10)', :end_point, geom]
1231
+
1232
+ geom = read('LINEARRING (11 11, 11 12, 12 11, 11 11)')
1233
+ tester['POINT (11 11)', :start_point, geom]
1234
+ tester['POINT (11 11)', :end_point, geom]
1235
1235
  end
1236
1236
 
1237
1237
  def test_area
@@ -1267,192 +1267,196 @@ class GeometryTests < MiniTest::Unit::TestCase
1267
1267
  tester[2.0, g, 'LINESTRING (3 0 , 10 0)']
1268
1268
  end
1269
1269
 
1270
- if ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:hausdorff_distance)
1271
- def test_hausdorff_distance
1272
- tester = lambda { |expected, g1, g2|
1273
- geom_1 = read(g1)
1274
- geom_2 = read(g2)
1275
- assert_in_delta(expected, geom_1.hausdorff_distance(geom_2), TOLERANCE)
1276
- }
1270
+ def test_hausdorff_distance
1271
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:hausdorff_distance)
1272
+
1273
+ tester = lambda { |expected, g1, g2|
1274
+ geom_1 = read(g1)
1275
+ geom_2 = read(g2)
1276
+ assert_in_delta(expected, geom_1.hausdorff_distance(geom_2), TOLERANCE)
1277
+ }
1277
1278
 
1278
- geom_a = 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))'
1279
+ geom_a = 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))'
1279
1280
 
1280
- tester[10.0498756211209, geom_a, 'POINT(0 10)']
1281
- tester[2.23606797749979, geom_a, 'POINT(-1 0)']
1282
- tester[9.0, geom_a, 'LINESTRING (3 0 , 10 0)']
1283
- end
1281
+ tester[10.0498756211209, geom_a, 'POINT(0 10)']
1282
+ tester[2.23606797749979, geom_a, 'POINT(-1 0)']
1283
+ tester[9.0, geom_a, 'LINESTRING (3 0 , 10 0)']
1284
+ end
1285
+
1286
+ def test_hausdorff_distance_with_densify_fract
1287
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:hausdorff_distance)
1284
1288
 
1285
- def test_hausdorff_distance_with_densify_fract
1286
- tester = lambda { |expected, g1, g2|
1287
- geom_1 = read(g1)
1288
- geom_2 = read(g2)
1289
- assert_in_delta(expected, geom_1.hausdorff_distance(geom_2, 0.001), TOLERANCE)
1290
- }
1289
+ tester = lambda { |expected, g1, g2|
1290
+ geom_1 = read(g1)
1291
+ geom_2 = read(g2)
1292
+ assert_in_delta(expected, geom_1.hausdorff_distance(geom_2, 0.001), TOLERANCE)
1293
+ }
1291
1294
 
1292
- geom_a = 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))'
1295
+ geom_a = 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))'
1293
1296
 
1294
- tester[10.0498756211209, geom_a, 'POINT(0 10)']
1295
- tester[2.23606797749979, geom_a, 'POINT(-1 0)']
1296
- tester[9.0, geom_a, 'LINESTRING (3 0 , 10 0)']
1297
- end
1297
+ tester[10.0498756211209, geom_a, 'POINT(0 10)']
1298
+ tester[2.23606797749979, geom_a, 'POINT(-1 0)']
1299
+ tester[9.0, geom_a, 'LINESTRING (3 0 , 10 0)']
1298
1300
  end
1299
1301
 
1300
- if ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:snap)
1301
- def test_snap
1302
- tester = lambda { |expected, g1, g2, tolerance|
1303
- geom_a = read(g1)
1304
- geom_b = read(g2)
1305
- assert_geom_eql_exact(read(expected), geom_a.snap(geom_b, tolerance))
1306
- }
1302
+ def test_snap
1303
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:snap)
1307
1304
 
1308
- writer.trim = true
1305
+ tester = lambda { |expected, g1, g2, tolerance|
1306
+ geom_a = read(g1)
1307
+ geom_b = read(g2)
1308
+ assert_geom_eql_exact(read(expected), geom_a.snap(geom_b, tolerance))
1309
+ }
1309
1310
 
1310
- geom = 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))'
1311
- tester['POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))', geom, 'POINT(0.1 0)', 0]
1312
- tester['POLYGON ((0.1 0, 1 0, 1 1, 0 1, 0.1 0))', geom, 'POINT(0.1 0)', 0.5]
1313
- end
1311
+ writer.trim = true
1312
+
1313
+ geom = 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))'
1314
+ tester['POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))', geom, 'POINT(0.1 0)', 0]
1315
+ tester['POLYGON ((0.1 0, 1 0, 1 1, 0 1, 0.1 0))', geom, 'POINT(0.1 0)', 0.5]
1314
1316
  end
1315
1317
 
1316
- if ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:polygonize)
1317
- def test_polygonize
1318
- writer.rounding_precision = 0
1319
-
1320
- geom_a = read(
1321
- 'GEOMETRYCOLLECTION(
1322
- LINESTRING(0 0, 10 10),
1323
- LINESTRING(185 221, 100 100),
1324
- LINESTRING(185 221, 88 275, 180 316),
1325
- LINESTRING(185 221, 292 281, 180 316),
1326
- LINESTRING(189 98, 83 187, 185 221),
1327
- LINESTRING(189 98, 325 168, 185 221)
1328
- )'
1329
- )
1330
-
1331
- polygonized = geom_a.polygonize
1332
- assert_equal(2, polygonized.length)
1333
- assert_equal(
1334
- 'POLYGON ((185 221, 88 275, 180 316, 292 281, 185 221))',
1335
- write(polygonized[0])
1336
- )
1337
- assert_equal(
1338
- 'POLYGON ((189 98, 83 187, 185 221, 325 168, 189 98))',
1339
- write(polygonized[1])
1340
- )
1341
- end
1318
+ def test_polygonize
1319
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:polygonize)
1320
+
1321
+ writer.rounding_precision = 0
1322
+
1323
+ geom_a = read(
1324
+ 'GEOMETRYCOLLECTION(
1325
+ LINESTRING(0 0, 10 10),
1326
+ LINESTRING(185 221, 100 100),
1327
+ LINESTRING(185 221, 88 275, 180 316),
1328
+ LINESTRING(185 221, 292 281, 180 316),
1329
+ LINESTRING(189 98, 83 187, 185 221),
1330
+ LINESTRING(189 98, 325 168, 185 221)
1331
+ )'
1332
+ )
1333
+
1334
+ polygonized = geom_a.polygonize
1335
+ assert_equal(2, polygonized.length)
1336
+ assert_equal(
1337
+ 'POLYGON ((185 221, 88 275, 180 316, 292 281, 185 221))',
1338
+ write(polygonized[0])
1339
+ )
1340
+ assert_equal(
1341
+ 'POLYGON ((189 98, 83 187, 185 221, 325 168, 189 98))',
1342
+ write(polygonized[1])
1343
+ )
1342
1344
  end
1343
1345
 
1344
- if ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:polygonize_cut_edges)
1345
- def test_polygonize_cut_edges
1346
- writer.rounding_precision = 0
1346
+ def test_polygonize_cut_edges
1347
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:polygonize_cut_edges)
1347
1348
 
1348
- geom_a = read(
1349
- 'GEOMETRYCOLLECTION(
1350
- LINESTRING(0 0, 10 10),
1351
- LINESTRING(185 221, 100 100),
1352
- LINESTRING(185 221, 88 275, 180 316),
1353
- LINESTRING(185 221, 292 281, 180 316),
1354
- LINESTRING(189 98, 83 187, 185 221),
1355
- LINESTRING(189 98, 325 168, 185 221)
1356
- )'
1357
- )
1349
+ writer.rounding_precision = 0
1358
1350
 
1359
- cut_edges = geom_a.polygonize_cut_edges
1360
- assert_equal(0, cut_edges.length)
1361
- end
1351
+ geom_a = read(
1352
+ 'GEOMETRYCOLLECTION(
1353
+ LINESTRING(0 0, 10 10),
1354
+ LINESTRING(185 221, 100 100),
1355
+ LINESTRING(185 221, 88 275, 180 316),
1356
+ LINESTRING(185 221, 292 281, 180 316),
1357
+ LINESTRING(189 98, 83 187, 185 221),
1358
+ LINESTRING(189 98, 325 168, 185 221)
1359
+ )'
1360
+ )
1361
+
1362
+ cut_edges = geom_a.polygonize_cut_edges
1363
+ assert_equal(0, cut_edges.length)
1362
1364
  end
1363
1365
 
1364
- if ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:polygonize_full)
1365
- def test_polygonize_full
1366
- writer.rounding_precision = 0
1367
-
1368
- geom_a = read(
1369
- 'GEOMETRYCOLLECTION(
1370
- LINESTRING(0 0, 10 10),
1371
- LINESTRING(185 221, 100 100),
1372
- LINESTRING(185 221, 88 275, 180 316),
1373
- LINESTRING(185 221, 292 281, 180 316),
1374
- LINESTRING(189 98, 83 187, 185 221),
1375
- LINESTRING(189 98, 325 168, 185 221)
1376
- )')
1377
-
1378
- polygonized = geom_a.polygonize_full
1379
-
1380
- assert_kind_of(Array, polygonized[:rings])
1381
- assert_kind_of(Array, polygonized[:cuts])
1382
- assert_kind_of(Array, polygonized[:dangles])
1383
- assert_kind_of(Array, polygonized[:invalid_rings])
1384
-
1385
- assert_equal(2, polygonized[:rings].length)
1386
- assert_equal(0, polygonized[:cuts].length)
1387
- assert_equal(2, polygonized[:dangles].length)
1388
- assert_equal(0, polygonized[:invalid_rings].length)
1389
-
1390
- assert_equal(
1391
- 'POLYGON ((185 221, 88 275, 180 316, 292 281, 185 221))',
1392
- write(polygonized[:rings][0])
1393
- )
1394
-
1395
- assert_equal(
1396
- 'POLYGON ((189 98, 83 187, 185 221, 325 168, 189 98))',
1397
- write(polygonized[:rings][1])
1398
- )
1399
-
1400
- assert_equal(
1401
- 'LINESTRING (185 221, 100 100)',
1402
- write(polygonized[:dangles][0])
1403
- )
1404
-
1405
- assert_equal(
1406
- 'LINESTRING (0 0, 10 10)',
1407
- write(polygonized[:dangles][1])
1408
- )
1409
-
1410
- geom_b = geom_a.union(read('POINT(0 0)'))
1411
- polygonized = geom_b.polygonize_full
1412
-
1413
- assert_equal(2, polygonized[:dangles].length)
1414
- assert_equal(0, polygonized[:invalid_rings].length)
1415
-
1416
- assert_equal(
1417
- 'LINESTRING (132 146, 100 100)',
1418
- write(polygonized[:dangles][0])
1419
- )
1420
-
1421
- assert_equal(
1422
- 'LINESTRING (0 0, 10 10)',
1423
- write(polygonized[:dangles][1])
1424
- )
1425
- end
1366
+ def test_polygonize_full
1367
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:polygonize_full)
1426
1368
 
1427
- def test_polygonize_with_bad_arguments
1428
- assert_raises(ArgumentError) do
1429
- geom = read('POINT(0 0)')
1369
+ writer.rounding_precision = 0
1430
1370
 
1431
- geom.polygonize(geom, 'gibberish')
1432
- end
1433
- end
1371
+ geom_a = read(
1372
+ 'GEOMETRYCOLLECTION(
1373
+ LINESTRING(0 0, 10 10),
1374
+ LINESTRING(185 221, 100 100),
1375
+ LINESTRING(185 221, 88 275, 180 316),
1376
+ LINESTRING(185 221, 292 281, 180 316),
1377
+ LINESTRING(189 98, 83 187, 185 221),
1378
+ LINESTRING(189 98, 325 168, 185 221)
1379
+ )')
1380
+
1381
+ polygonized = geom_a.polygonize_full
1382
+
1383
+ assert_kind_of(Array, polygonized[:rings])
1384
+ assert_kind_of(Array, polygonized[:cuts])
1385
+ assert_kind_of(Array, polygonized[:dangles])
1386
+ assert_kind_of(Array, polygonized[:invalid_rings])
1387
+
1388
+ assert_equal(2, polygonized[:rings].length)
1389
+ assert_equal(0, polygonized[:cuts].length)
1390
+ assert_equal(2, polygonized[:dangles].length)
1391
+ assert_equal(0, polygonized[:invalid_rings].length)
1392
+
1393
+ assert_equal(
1394
+ 'POLYGON ((185 221, 88 275, 180 316, 292 281, 185 221))',
1395
+ write(polygonized[:rings][0])
1396
+ )
1397
+
1398
+ assert_equal(
1399
+ 'POLYGON ((189 98, 83 187, 185 221, 325 168, 189 98))',
1400
+ write(polygonized[:rings][1])
1401
+ )
1402
+
1403
+ assert_equal(
1404
+ 'LINESTRING (185 221, 100 100)',
1405
+ write(polygonized[:dangles][0])
1406
+ )
1407
+
1408
+ assert_equal(
1409
+ 'LINESTRING (0 0, 10 10)',
1410
+ write(polygonized[:dangles][1])
1411
+ )
1412
+
1413
+ geom_b = geom_a.union(read('POINT(0 0)'))
1414
+ polygonized = geom_b.polygonize_full
1415
+
1416
+ assert_equal(2, polygonized[:dangles].length)
1417
+ assert_equal(0, polygonized[:invalid_rings].length)
1418
+
1419
+ assert_equal(
1420
+ 'LINESTRING (132 146, 100 100)',
1421
+ write(polygonized[:dangles][0])
1422
+ )
1423
+
1424
+ assert_equal(
1425
+ 'LINESTRING (0 0, 10 10)',
1426
+ write(polygonized[:dangles][1])
1427
+ )
1434
1428
  end
1435
1429
 
1436
- if ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:shared_paths)
1437
- def test_shared_paths
1438
- writer.rounding_precision = 0
1430
+ def test_polygonize_with_bad_arguments
1431
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:polygonize_full)
1439
1432
 
1440
- geom_a = read('LINESTRING(0 0, 50 0)')
1441
- geom_b = read('MULTILINESTRING((5 0, 15 0),(40 0, 30 0))')
1433
+ assert_raises(ArgumentError) do
1434
+ geom = read('POINT(0 0)')
1442
1435
 
1443
- paths = geom_a.shared_paths(geom_b)
1444
- assert_equal(2, paths.length)
1445
- assert_equal(
1446
- 'MULTILINESTRING ((5 0, 15 0))',
1447
- write(paths[0])
1448
- )
1449
- assert_equal(
1450
- 'MULTILINESTRING ((30 0, 40 0))',
1451
- write(paths[1])
1452
- )
1436
+ geom.polygonize(geom, 'gibberish')
1453
1437
  end
1454
1438
  end
1455
1439
 
1440
+ def test_shared_paths
1441
+ skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:shared_paths)
1442
+
1443
+ writer.rounding_precision = 0
1444
+
1445
+ geom_a = read('LINESTRING(0 0, 50 0)')
1446
+ geom_b = read('MULTILINESTRING((5 0, 15 0),(40 0, 30 0))')
1447
+
1448
+ paths = geom_a.shared_paths(geom_b)
1449
+ assert_equal(2, paths.length)
1450
+ assert_equal(
1451
+ 'MULTILINESTRING ((5 0, 15 0))',
1452
+ write(paths[0])
1453
+ )
1454
+ assert_equal(
1455
+ 'MULTILINESTRING ((30 0, 40 0))',
1456
+ write(paths[1])
1457
+ )
1458
+ end
1459
+
1456
1460
  def test_clone
1457
1461
  geom_a = read('POINT(0 0)')
1458
1462
  geom_b = geom_a.clone