-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
Geometry#orient_polygons
and #orient_polygons!
.
- Loading branch information
1 parent
e56bf7d
commit a33a1b3
Showing
3 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
describe '#orient_polygons' do | ||
include TestHelper | ||
|
||
def setup | ||
super | ||
writer.trim = true | ||
end | ||
|
||
it 'does not overwrite the original geometry' do | ||
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:orient_polygons) | ||
|
||
geom = read('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1))') | ||
|
||
result = geom.orient_polygons(true) | ||
|
||
assert_equal('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1))', write(geom)) | ||
assert_equal('POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1))', write(result)) | ||
refute_same(geom, result) | ||
end | ||
|
||
it 'does overwrite the original geometry with bang method' do | ||
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:orient_polygons!) | ||
|
||
geom = read('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1))') | ||
|
||
result = geom.orient_polygons!(true) | ||
|
||
assert_equal('POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1))', write(geom)) | ||
assert_equal('POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1))', write(result)) | ||
assert_same(geom, result) | ||
end | ||
|
||
it 'handles empty polygons' do | ||
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:orient_polygons) | ||
|
||
simple_tester( | ||
:orient_polygons, | ||
'POLYGON EMPTY', | ||
'POLYGON EMPTY' | ||
) | ||
end | ||
|
||
it 'hole orientation is opposite to shell' do | ||
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:orient_polygons) | ||
|
||
simple_tester( | ||
:orient_polygons, | ||
'POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1))', | ||
'POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1))' | ||
) | ||
|
||
simple_tester( | ||
:orient_polygons, | ||
'POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1))', | ||
'POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1))', | ||
true | ||
) | ||
end | ||
|
||
it 'ensures all polygons in collection are processed' do | ||
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:orient_polygons) | ||
|
||
simple_tester( | ||
:orient_polygons, | ||
'MULTIPOLYGON (((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1)), ((100 100, 200 100, 200 200, 100 100)))', | ||
'MULTIPOLYGON (((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1)), ((100 100, 200 100, 200 200, 100 100)))' | ||
) | ||
|
||
simple_tester( | ||
:orient_polygons, | ||
'MULTIPOLYGON (((0 0, 0 10, 10 10, 10 0, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1)), ((100 100, 200 200, 200 100, 100 100)))', | ||
'MULTIPOLYGON (((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1)), ((100 100, 200 100, 200 200, 100 100)))', | ||
true | ||
) | ||
end | ||
|
||
it 'polygons in collection are oriented, closed linestring unchanged' do | ||
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:orient_polygons) | ||
|
||
simple_tester( | ||
:orient_polygons, | ||
'GEOMETRYCOLLECTION (POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1)), LINESTRING (100 100, 200 100, 200 200, 100 100))', | ||
'GEOMETRYCOLLECTION (POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1)), LINESTRING (100 100, 200 100, 200 200, 100 100))', | ||
true | ||
) | ||
end | ||
|
||
it 'nested collection handled correctly' do | ||
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:orient_polygons) | ||
|
||
simple_tester( | ||
:orient_polygons, | ||
'GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (MULTIPOLYGON (((0 0, 10 0, 10 10, 0 10, 0 0)))))', | ||
'GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (MULTIPOLYGON (((0 0, 10 0, 10 10, 0 10, 0 0)))))' | ||
) | ||
end | ||
end |