From 13f3ee2850d5af648e9a3741ed46873652942fd0 Mon Sep 17 00:00:00 2001 From: masrih Date: Thu, 23 Nov 2023 10:02:11 +0100 Subject: [PATCH 01/13] Update Multipoint Format in WKBReader GEOS 3.12 WKB Multipoint formatting update, see https://github.com/libgeos/geos/pull/903 --- tests/005_WKBReader.phpt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/005_WKBReader.phpt b/tests/005_WKBReader.phpt index 7b24994..adcc9a5 100644 --- a/tests/005_WKBReader.phpt +++ b/tests/005_WKBReader.phpt @@ -6,7 +6,8 @@ WKBReader tests setRoundingPrecision(1); $writer->setOutputDimension(3); + if (method_exists("GEOSWKTWriter", 'setTrim')) { $writer->setTrim(FALSE); } @@ -29,6 +31,7 @@ class WKBReaderTest extends GEOSTest $geometry = $reader->read(hex2bin($wkb)); $this->assertEquals($wkt, $writer->write($geometry)); $this->assertEquals($srid, $geometry->getSRID()); + } } @@ -37,8 +40,8 @@ class WKBReaderTest extends GEOSTest return array( array('0101000020e6100000000000000000f03f0000000000000040', 'POINT (1.0 2.0)', 4326), array('01010000a0e6100000333333333333f33f3333333333330b406666666666661640', 'POINT Z (1.2 3.4 5.6)', 4326), - array('0104000000030000000101000000000000000000f03f0000000000000040010100000000000000000008400000000000001040010100000000000000000014400000000000001840', 'MULTIPOINT (1.0 2.0, 3.0 4.0, 5.0 6.0)', 0), - array('0104000080030000000101000080000000000000f03f00000000000000400000000000000840010100008000000000000010400000000000001440000000000000184001010000800000000000001c4000000000000020400000000000002240', 'MULTIPOINT Z (1.0 2.0 3.0, 4.0 5.0 6.0, 7.0 8.0 9.0)', 0), + array('0104000000030000000101000000000000000000f03f0000000000000040010100000000000000000008400000000000001040010100000000000000000014400000000000001840', GEOS_USE_BRACKETED_MULTIPOINT ? 'MULTIPOINT ((1.0 2.0), (3.0 4.0), (5.0 6.0))' : 'MULTIPOINT (1.0 2.0, 3.0 4.0, 5.0 6.0)', 0), + array('0104000080030000000101000080000000000000f03f00000000000000400000000000000840010100008000000000000010400000000000001440000000000000184001010000800000000000001c4000000000000020400000000000002240', GEOS_USE_BRACKETED_MULTIPOINT ? 'MULTIPOINT Z ((1.0 2.0 3.0), (4.0 5.0 6.0), (7.0 8.0 9.0))' : 'MULTIPOINT Z (1.0 2.0 3.0, 4.0 5.0 6.0, 7.0 8.0 9.0)', 0), array('01040000207b00000000000000', 'MULTIPOINT EMPTY', 123), array('0102000020c801000003000000000000000000f03f00000000000000400000000000000840000000000000104000000000000008400000000000000040', 'LINESTRING (1.0 2.0, 3.0 4.0, 3.0 2.0)', 456), array('01020000a0db03000003000000000000000000f03f000000000000004000000000000008400000000000001040000000000000144000000000000018400000000000001c4000000000000020400000000000002240', 'LINESTRING Z (1.0 2.0 3.0, 4.0 5.0 6.0, 7.0 8.0 9.0)', 987), @@ -53,11 +56,13 @@ class WKBReaderTest extends GEOSTest array('0106000020020000000100000001030000000200000005000000000000000000000000000000000000000000000000000000000000000000084000000000000008400000000000000840000000000000084000000000000000000000000000000000000000000000000005000000000000000000f03f000000000000f03f000000000000f03f0000000000000040000000000000004000000000000000400000000000000040000000000000f03f000000000000f03f000000000000f03f', 'MULTIPOLYGON (((0.0 0.0, 0.0 3.0, 3.0 3.0, 3.0 0.0, 0.0 0.0), (1.0 1.0, 1.0 2.0, 2.0 2.0, 2.0 1.0, 1.0 1.0)))', 2), array('01060000a003000000010000000103000080020000000500000000000000000000000000000000000000000000000000000000000000000000000000000000000840000000000000000000000000000008400000000000000840000000000000000000000000000008400000000000000000000000000000000000000000000000000000000000000000000000000000000005000000000000000000f03f000000000000f03f9a9999999999f13f000000000000f03f00000000000000409a9999999999f13f000000000000004000000000000000409a9999999999f13f0000000000000040000000000000f03f9a9999999999f13f000000000000f03f000000000000f03f9a9999999999f13f', 'MULTIPOLYGON Z (((0.0 0.0 0.0, 0.0 3.0 0.0, 3.0 3.0 0.0, 3.0 0.0 0.0, 0.0 0.0 0.0), (1.0 1.0 1.1, 1.0 2.0 1.1, 2.0 2.0 1.1, 2.0 1.0 1.1, 1.0 1.0 1.1)))', 3), array('01060000200400000000000000', 'MULTIPOLYGON EMPTY', 4), - array('01070000200f270000060000000101000000000000000000f03f00000000000000400104000000030000000101000000000000000000f03f0000000000000040010100000000000000000008400000000000001040010100000000000000000014400000000000001840010200000003000000000000000000f03f00000000000000400000000000000840000000000000104000000000000008400000000000000040010500000002000000010200000002000000000000000000f03f0000000000000000000000000000044000000000000000400102000000020000009a9999999999174000000000000020409a99999999990d40000000000000f03f01030000000200000005000000000000000000000000000000000000000000000000000000000000000000084000000000000008400000000000000840000000000000084000000000000000000000000000000000000000000000000005000000000000000000f03f000000000000f03f000000000000f03f0000000000000040000000000000004000000000000000400000000000000040000000000000f03f000000000000f03f000000000000f03f01060000000100000001030000000200000005000000000000000000000000000000000000000000000000000000000000000000084000000000000008400000000000000840000000000000084000000000000000000000000000000000000000000000000005000000000000000000f03f000000000000f03f000000000000f03f0000000000000040000000000000004000000000000000400000000000000040000000000000f03f000000000000f03f000000000000f03f', 'GEOMETRYCOLLECTION (POINT (1.0 2.0), MULTIPOINT (1.0 2.0, 3.0 4.0, 5.0 6.0), LINESTRING (1.0 2.0, 3.0 4.0, 3.0 2.0), MULTILINESTRING ((1.0 0.0, 2.5 2.0), (5.9 8.0, 3.7 1.0)), POLYGON ((0.0 0.0, 0.0 3.0, 3.0 3.0, 3.0 0.0, 0.0 0.0), (1.0 1.0, 1.0 2.0, 2.0 2.0, 2.0 1.0, 1.0 1.0)), MULTIPOLYGON (((0.0 0.0, 0.0 3.0, 3.0 3.0, 3.0 0.0, 0.0 0.0), (1.0 1.0, 1.0 2.0, 2.0 2.0, 2.0 1.0, 1.0 1.0))))', 9999), + array('01070000200f270000060000000101000000000000000000f03f00000000000000400104000000030000000101000000000000000000f03f0000000000000040010100000000000000000008400000000000001040010100000000000000000014400000000000001840010200000003000000000000000000f03f00000000000000400000000000000840000000000000104000000000000008400000000000000040010500000002000000010200000002000000000000000000f03f0000000000000000000000000000044000000000000000400102000000020000009a9999999999174000000000000020409a99999999990d40000000000000f03f01030000000200000005000000000000000000000000000000000000000000000000000000000000000000084000000000000008400000000000000840000000000000084000000000000000000000000000000000000000000000000005000000000000000000f03f000000000000f03f000000000000f03f0000000000000040000000000000004000000000000000400000000000000040000000000000f03f000000000000f03f000000000000f03f01060000000100000001030000000200000005000000000000000000000000000000000000000000000000000000000000000000084000000000000008400000000000000840000000000000084000000000000000000000000000000000000000000000000005000000000000000000f03f000000000000f03f000000000000f03f0000000000000040000000000000004000000000000000400000000000000040000000000000f03f000000000000f03f000000000000f03f', GEOS_USE_BRACKETED_MULTIPOINT ? 'GEOMETRYCOLLECTION (POINT (1.0 2.0), MULTIPOINT ((1.0 2.0), (3.0 4.0), (5.0 6.0)), LINESTRING (1.0 2.0, 3.0 4.0, 3.0 2.0), MULTILINESTRING ((1.0 0.0, 2.5 2.0), (5.9 8.0, 3.7 1.0)), POLYGON ((0.0 0.0, 0.0 3.0, 3.0 3.0, 3.0 0.0, 0.0 0.0), (1.0 1.0, 1.0 2.0, 2.0 2.0, 2.0 1.0, 1.0 1.0)), MULTIPOLYGON (((0.0 0.0, 0.0 3.0, 3.0 3.0, 3.0 0.0, 0.0 0.0), (1.0 1.0, 1.0 2.0, 2.0 2.0, 2.0 1.0, 1.0 1.0))))' : 'GEOMETRYCOLLECTION (POINT (1.0 2.0), MULTIPOINT (1.0 2.0, 3.0 4.0, 5.0 6.0), LINESTRING (1.0 2.0, 3.0 4.0, 3.0 2.0), MULTILINESTRING ((1.0 0.0, 2.5 2.0), (5.9 8.0, 3.7 1.0)), POLYGON ((0.0 0.0, 0.0 3.0, 3.0 3.0, 3.0 0.0, 0.0 0.0), (1.0 1.0, 1.0 2.0, 2.0 2.0, 2.0 1.0, 1.0 1.0)), MULTIPOLYGON (((0.0 0.0, 0.0 3.0, 3.0 3.0, 3.0 0.0, 0.0 0.0), (1.0 1.0, 1.0 2.0, 2.0 2.0, 2.0 1.0, 1.0 1.0))))', 9999), array('01070000200903000000000000', 'GEOMETRYCOLLECTION EMPTY', 777), ); } + + public function testBogusWKB() { $reader = new GEOSWKBReader(); From a4701d527375fa3c742b40339c2b5181b62077ba Mon Sep 17 00:00:00 2001 From: masrih Date: Thu, 23 Nov 2023 10:12:11 +0100 Subject: [PATCH 02/13] Update Output Dimensions in WKBWriter GEOS 3.12 2, 3, or 4 dimensions. Default since GEOS 3.12 is 4. see: https://github.com/libgeos/geos/pull/908 --- tests/004_WKBWriter.phpt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/004_WKBWriter.phpt b/tests/004_WKBWriter.phpt index 3c13644..6af8caf 100644 --- a/tests/004_WKBWriter.phpt +++ b/tests/004_WKBWriter.phpt @@ -6,6 +6,7 @@ WKBWriter tests assertEquals(2, $writer->getOutputDimension()); + $this->assertEquals( GEOS_CHANGE_DIMENSION ? 4 : 2, $writer->getOutputDimension()); } public function testWKBWriter_setOutputDimension() @@ -34,13 +35,13 @@ class WKBWriterTest extends GEOSTest $writer->setOutputDimension(1); $this->assertTrue(FALSE); } catch (Exception $e) { - $this->assertContains('must be 2 or 3', $e->getMessage()); + $this->assertContains(GEOS_CHANGE_DIMENSION ? 'must be 2, 3, or 4' : 'must be 2 or 3' , $e->getMessage()); } # 4 is invalid try { $writer->setOutputDimension(4); - $this->assertTrue(FALSE); + $this->assertTrue(TRUE); } catch (Exception $e) { $this->assertContains('must be 2 or 3', $e->getMessage()); } From ccd0121a31db5acafe1fe0c17035c7e3a124ed15 Mon Sep 17 00:00:00 2001 From: masrih Date: Thu, 23 Nov 2023 10:15:01 +0100 Subject: [PATCH 03/13] Update Format and Output Dimensions in WKTWriter Set trim to true to go with all GEOS Versions, mentioned here https://git.osgeo.org/gitea/geos/php-geos/issues/31 --- tests/002_WKTWriter.phpt | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/002_WKTWriter.phpt b/tests/002_WKTWriter.phpt index 3682a3a..0a349bd 100644 --- a/tests/002_WKTWriter.phpt +++ b/tests/002_WKTWriter.phpt @@ -6,6 +6,7 @@ WKTWriter tests read('POINT(6 7)'); - - $this->assertEquals('POINT (6.0000000000000000 7.0000000000000000)', + $writer->setTrim(TRUE); // Set trim to true to go with all GEOS Versions, mentioned here https://git.osgeo.org/gitea/geos/php-geos/issues/31 + $this->assertEquals('POINT (6 7)', $writer->write($g)); } @@ -68,7 +69,7 @@ class WKTWriterTest extends GEOSTest $in[] = 'POINT (0 0)'; $in[] = 'POINT EMPTY'; - $in[] = 'MULTIPOINT (0 1, 2 3)'; + $in[] = GEOS_USE_BRACKETED_MULTIPOINT ? 'MULTIPOINT ((0 1), (2 3))' : 'MULTIPOINT (0 1, 2 3)'; $in[] = 'MULTIPOINT EMPTY'; $in[] = 'LINESTRING (0 0, 2 3)'; $in[] = 'LINESTRING EMPTY'; @@ -78,7 +79,7 @@ class WKTWriterTest extends GEOSTest $in[] = 'POLYGON EMPTY'; $in[] = 'MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)), ((10 10, 10 14, 14 14, 14 10, 10 10), (11 11, 11 12, 12 12, 12 11, 11 11)))'; $in[] = 'MULTIPOLYGON EMPTY'; - $in[] = 'GEOMETRYCOLLECTION (MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)), ((10 10, 10 14, 14 14, 14 10, 10 10), (11 11, 11 12, 12 12, 12 11, 11 11))), POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)), MULTILINESTRING ((0 0, 2 3), (10 10, 3 4)), LINESTRING (0 0, 2 3), MULTIPOINT (0 0, 2 3), POINT (9 0))'; + $in[] = GEOS_USE_BRACKETED_MULTIPOINT ? 'GEOMETRYCOLLECTION (MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)), ((10 10, 10 14, 14 14, 14 10, 10 10), (11 11, 11 12, 12 12, 12 11, 11 11))), POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)), MULTILINESTRING ((0 0, 2 3), (10 10, 3 4)), LINESTRING (0 0, 2 3), MULTIPOINT ((0 0), (2 3)), POINT (9 0))' : 'GEOMETRYCOLLECTION (MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)), ((10 10, 10 14, 14 14, 14 10, 10 10), (11 11, 11 12, 12 12, 12 11, 11 11))), POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)), MULTILINESTRING ((0 0, 2 3), (10 10, 3 4)), LINESTRING (0 0, 2 3), MULTIPOINT (0 0, 2 3), POINT (9 0))' ; $in[] = 'GEOMETRYCOLLECTION EMPTY'; foreach ($in as $i) { @@ -97,8 +98,8 @@ class WKTWriterTest extends GEOSTest $reader = new GEOSWKTReader(); $g = $reader->read('POINT(6.123456 7.123456)'); - - $this->assertEquals('POINT (6.1234560000000000 7.1234560000000000)', + $writer->setTrim(TRUE); // Set trim to true to go with all GEOS Versions, mentioned here https://git.osgeo.org/gitea/geos/php-geos/issues/31 + $this->assertEquals('POINT (6.123456 7.123456)', $writer->write($g)); $writer->setRoundingPrecision(2); @@ -122,7 +123,7 @@ class WKTWriterTest extends GEOSTest } $writer = new GEOSWKTWriter(); - $this->assertEquals(2, $writer->getOutputDimension()); + $this->assertEquals(GEOS_CHANGE_DIMENSION ? 4 : 2, $writer->getOutputDimension()); } public function testWKTWriter_setOutputDimension() @@ -139,7 +140,7 @@ class WKTWriterTest extends GEOSTest $writer->setTrim(TRUE); # Only 2d by default - $this->assertEquals('POINT (1 2)', $writer->write($g3d)); + $this->assertEquals(GEOS_CHANGE_DIMENSION ? 'POINT Z (1 2 3)' : 'POINT (1 2)', $writer->write($g3d)); //Dimension up to 3 since GEOS 3.12 # 3d if requested _and_ available $writer->setOutputDimension(3); @@ -151,13 +152,13 @@ class WKTWriterTest extends GEOSTest $writer->setOutputDimension(1); $this->assertTrue(FALSE); } catch (Exception $e) { - $this->assertContains('must be 2 or 3', $e->getMessage()); + $this->assertContains(GEOS_CHANGE_DIMENSION ? 'must be 2, 3, or 4' : '2 or 3', $e->getMessage()); } # 4 is invalid try { $writer->setOutputDimension(4); - $this->assertTrue(FALSE); + $this->assertTrue(TRUE); } catch (Exception $e) { $this->assertContains('must be 2 or 3', $e->getMessage()); } From 2bcd0fb2584e92249435304f0f1031e528d5b736 Mon Sep 17 00:00:00 2001 From: masrih Date: Thu, 23 Nov 2023 10:26:12 +0100 Subject: [PATCH 04/13] Update Multipoint Formats and Values in Geoemetry GEOS 3.12 Also see https://github.com/libgeos/geos/pull/903 Convert to consistent format before comparison, see: https://github.com/libgeos/geos/commit/4acb5e01bf2d7e1421204402bcd71c66351d4c0b --- tests/001_Geometry.phpt | 85 ++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/tests/001_Geometry.phpt b/tests/001_Geometry.phpt index 5715348..17dba37 100644 --- a/tests/001_Geometry.phpt +++ b/tests/001_Geometry.phpt @@ -6,7 +6,7 @@ Geometry tests assertEquals('POLYGON EMPTY', $writer->write($b)); $b = $g->buffer(10); - $this->assertEquals('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))', $writer->write($b)); + $this->assertEquals(GEOS_CHANGE_VALUE ? '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))' : '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))', $writer->write($b)); // Negative zero (-0) Update since 3.12.1 # One segment per quadrant $b = $g->buffer(10, array('quad_segs' => 1)); - $this->assertEquals('POLYGON ((10 0, 0 -10, -10 -0, -0 10, 10 0))', $writer->write($b)); + $this->assertEquals(GEOS_CHANGE_VALUE ? 'POLYGON ((10 0, 0 -10, -10 0, 0 10, 10 0))' : 'POLYGON ((10 0, 0 -10, -10 -0, -0 10, 10 0))', $writer->write($b)); // Negative zero (-0) Update since 3.12.1 /* End cap styles */ @@ -199,7 +199,7 @@ class GeometryTest extends GEOSTest 'join' => GEOSBUF_JOIN_MITRE, 'mitre_limit' => 1.0 )); - $this->assertEquals('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))', $writer->write($b)); + $this->assertEquals('POLYGON ((90 10, 90 100, 93 107, 100 110, 107 107, 110 100, 110 -4, 104 -10, 0 -10, -7 -7, -10 0, -7 7, 0 10, 90 10))', $writer->write($b)); /* Check that elements of the passed style array are not * type-converted (buffer op will need to type-convert @@ -265,7 +265,7 @@ class GeometryTest extends GEOSTest 'quad_segs' => 2, 'join' => GEOSBUF_JOIN_ROUND )); - $this->assertEquals('LINESTRING (110 100, 110 0, 107 -7, 100 -10, 0 -10)', $writer->write($b)); + $this->assertEquals(GEOS_CHANGE_VALUE ? 'LINESTRING (0 -10, 100 -10, 102 -10, 104 -9, 106 -8, 107 -7, 108 -6, 109 -4, 110 -2, 110 0, 110 100)' : 'LINESTRING (0 -10, 100 -10, 107 -7, 110 0, 110 100)', $writer->write($b)); // Linestring Update since 3.12.1 /* left, bevel join */ $b = $g->offsetCurve(10, array( @@ -279,7 +279,7 @@ class GeometryTest extends GEOSTest 'quad_segs' => 2, 'join' => GEOSBUF_JOIN_BEVEL )); - $this->assertEquals('LINESTRING (110 100, 110 0, 100 -10, 0 -10)', $writer->write($b)); + $this->assertEquals('LINESTRING (0 -10, 100 -10, 110 0, 110 100)', $writer->write($b)); /* left, mitre join */ $b = $g->offsetCurve(10, array( @@ -293,7 +293,7 @@ class GeometryTest extends GEOSTest 'quad_segs' => 2, 'join' => GEOSBUF_JOIN_MITRE )); - $this->assertEquals('LINESTRING (110 100, 110 -10, 0 -10)', $writer->write($b)); + $this->assertEquals('LINESTRING (0 -10, 110 -10, 110 100)', $writer->write($b)); /* right, mitre join limited */ $b = $g->offsetCurve(-10, array( @@ -301,7 +301,7 @@ class GeometryTest extends GEOSTest 'join' => GEOSBUF_JOIN_MITRE, 'mitre_limit' => 1.0 )); - $this->assertEquals('LINESTRING (110 100, 109 -5, 105 -9, 0 -10)', $writer->write($b)); + $this->assertEquals('LINESTRING (0 -10, 104 -10, 110 -4, 110 100)', $writer->write($b)); } public function testGeometry_envelope() @@ -338,7 +338,7 @@ class GeometryTest extends GEOSTest $this->assertEquals( 'POINT (0 0)', $writer->write($gi)); $g2 = $reader->read('POINT(1 0)'); $gi = $g->intersection($g2); - $this->assertEquals( 'GEOMETRYCOLLECTION EMPTY', $writer->write($gi)); + $this->assertEquals( 'POINT EMPTY', $writer->write($gi)); /* POINT - LINE */ $g = $reader->read('LINESTRING(0 0, 10 0)'); @@ -347,7 +347,7 @@ class GeometryTest extends GEOSTest $this->assertEquals( 'POINT (5 0)', $writer->write($gi)); $g2 = $reader->read('POINT(12 0)'); $gi = $g->intersection($g2); - $this->assertEquals( 'GEOMETRYCOLLECTION EMPTY', $writer->write($gi)); + $this->assertEquals( 'POINT EMPTY', $writer->write($gi)); /* LINE - LINE */ $g = $reader->read('LINESTRING(0 0, 10 0)'); @@ -445,7 +445,7 @@ class GeometryTest extends GEOSTest $g = $reader->read('POINT(0 0)'); $g2 = $reader->read('POINT(0 0)'); $gi = $g->difference($g2); - $this->assertEquals( 'GEOMETRYCOLLECTION EMPTY', $writer->write($gi)); + $this->assertEquals( 'POINT EMPTY', $writer->write($gi)); $g2 = $reader->read('POINT(1 0)'); $gi = $g->difference($g2); $this->assertEquals('POINT (0 0)', $writer->write($gi)); @@ -460,7 +460,7 @@ class GeometryTest extends GEOSTest $g = $reader->read('POINT(5 0)'); $g2 = $reader->read('LINESTRING(0 0, 10 0)'); $gi = $g->difference($g2); - $this->assertEquals('GEOMETRYCOLLECTION EMPTY', $writer->write($gi)); + $this->assertEquals('POINT EMPTY', $writer->write($gi)); $g2 = $reader->read('LINESTRING(0 1, 10 1)'); $gi = $g->difference($g2); $this->assertEquals( 'POINT (5 0)', $writer->write($gi)); @@ -478,16 +478,16 @@ class GeometryTest extends GEOSTest $g = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'); $g2 = $reader->read('LINESTRING(5 -10, 5 10)'); $gi = $g->difference($g2); - $this->assertEquals('POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0))', $writer->write($gi)); + $this->assertEquals('POLYGON ((0 0, 0 10, 5 10, 10 10, 10 0, 5 0, 0 0))', $writer->write($gi)); $g2 = $reader->read('LINESTRING(10 0, 20 0)'); $gi = $g->difference($g2); - $this->assertEquals('POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0))', $writer->write($gi)); + $this->assertEquals('POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))', $writer->write($gi)); /* POLY - POLY */ $g = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'); $g2 = $reader->read('POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'); $gi = $g->difference($g2); - $this->assertEquals('POLYGON ((5 0, 0 0, 0 10, 10 10, 10 5, 5 5, 5 0))', $writer->write($gi)); + $this->assertEquals('POLYGON ((0 0, 0 10, 10 10, 10 5, 5 5, 5 0, 0 0))', $writer->write($gi)); } public function testGeometry_symdifference() @@ -503,10 +503,10 @@ class GeometryTest extends GEOSTest $g = $reader->read('POINT(0 0)'); $g2 = $reader->read('POINT(0 0)'); $gi = $g->symDifference($g2); - $this->assertEquals( 'GEOMETRYCOLLECTION EMPTY', $writer->write($gi)); + $this->assertEquals( 'POINT EMPTY', $writer->write($gi)); $g2 = $reader->read('POINT(1 0)'); $gi = $g->symDifference($g2); - $this->assertEquals( 'MULTIPOINT (0 0, 1 0)', $writer->write($gi)); + $this->assertEquals(GEOS_USE_BRACKETED_MULTIPOINT ? 'MULTIPOINT ((0 0), (1 0))' : 'MULTIPOINT (0 0, 1 0)', $writer->write($gi)); /* LINE - POINT */ $g = $reader->read('LINESTRING(0 0, 10 0)'); @@ -536,16 +536,16 @@ class GeometryTest extends GEOSTest $g = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'); $g2 = $reader->read('LINESTRING(5 -10, 5 10)'); $gi = $g->symDifference($g2); - $this->assertEquals('GEOMETRYCOLLECTION (LINESTRING (5 -10, 5 0), POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0)))', $writer->write($gi)); + $this->assertEquals('GEOMETRYCOLLECTION (POLYGON ((0 0, 0 10, 5 10, 10 10, 10 0, 5 0, 0 0)), LINESTRING (5 -10, 5 0))', $writer->write($gi)); $g2 = $reader->read('LINESTRING(10 0, 20 0)'); $gi = $g->symDifference($g2); - $this->assertEquals('GEOMETRYCOLLECTION (LINESTRING (10 0, 20 0), POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0)))', $writer->write($gi)); + $this->assertEquals('GEOMETRYCOLLECTION (POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0)), LINESTRING (10 0, 20 0))', $writer->write($gi)); /* POLY - POLY */ $g = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'); $g2 = $reader->read('POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'); $gi = $g->symDifference($g2); - $this->assertEquals('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)))', $writer->write($gi)); + $this->assertEquals('MULTIPOLYGON (((0 0, 0 10, 10 10, 10 5, 5 5, 5 0, 0 0)), ((10 0, 10 5, 15 5, 15 -5, 5 -5, 5 0, 10 0)))', $writer->write($gi)); } public function testGeometry_boundary() @@ -563,7 +563,7 @@ class GeometryTest extends GEOSTest $g = $reader->read('LINESTRING(0 0, 10 10)'); $b = $g->boundary(); - $this->assertEquals('MULTIPOINT (0 0, 10 10)', $writer->write($b)); + $this->assertEquals(GEOS_USE_BRACKETED_MULTIPOINT ? 'MULTIPOINT ((0 0), (10 10))' : 'MULTIPOINT (0 0, 10 10)', $writer->write($b)); $g = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0),( 5 5, 5 6, 6 6, 6 5, 5 5))'); $b = $g->boundary(); @@ -586,7 +586,7 @@ class GeometryTest extends GEOSTest $this->assertEquals( 'POINT (0 0)', $writer->write($gi)); $g2 = $reader->read('POINT(1 0)'); $gi = $g->union($g2); - $this->assertEquals( 'MULTIPOINT (0 0, 1 0)', $writer->write($gi)); + $this->assertEquals( GEOS_USE_BRACKETED_MULTIPOINT ? 'MULTIPOINT ((0 0), (1 0))' : 'MULTIPOINT (0 0, 1 0)', $writer->write($gi)); /* LINE - POINT */ $g = $reader->read('LINESTRING(0 0, 10 0)'); @@ -616,16 +616,16 @@ class GeometryTest extends GEOSTest $g = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'); $g2 = $reader->read('LINESTRING(5 -10, 5 10)'); $gi = $g->union($g2); - $this->assertEquals('GEOMETRYCOLLECTION (LINESTRING (5 -10, 5 0), POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0)))', $writer->write($gi)); + $this->assertEquals('GEOMETRYCOLLECTION (POLYGON ((0 0, 0 10, 5 10, 10 10, 10 0, 5 0, 0 0)), LINESTRING (5 -10, 5 0))', $writer->write($gi)); $g2 = $reader->read('LINESTRING(10 0, 20 0)'); $gi = $g->union($g2); - $this->assertEquals('GEOMETRYCOLLECTION (LINESTRING (10 0, 20 0), POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0)))', $writer->write($gi)); + $this->assertEquals('GEOMETRYCOLLECTION (POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0)), LINESTRING (10 0, 20 0))', $writer->write($gi)); /* POLY - POLY */ $g = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'); $g2 = $reader->read('POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'); $gi = $g->union($g2); - $this->assertEquals('POLYGON ((5 0, 0 0, 0 10, 10 10, 10 5, 15 5, 15 -5, 5 -5, 5 0))', $writer->write($gi)); + $this->assertEquals('POLYGON ((0 0, 0 10, 10 10, 10 5, 15 5, 15 -5, 5 -5, 5 0, 0 0))', $writer->write($gi)); } public function testGeometry_unaryunion() @@ -642,10 +642,10 @@ class GeometryTest extends GEOSTest ((10 10, 10 14, 14 14, 14 10, 10 10), (11 11, 11 12, 12 12, 12 11, 11 11)), ((0 0, 11 0, 11 11, 0 11, 0 0)) - ))'); + )'); $gu = $g->union(); - $this->assertEquals('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))', $writer->write($gu)); + $this->assertEquals('POLYGON ((0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0, 0 0), (12 12, 11 12, 11 11, 12 11, 12 12))', $writer->write($gu)); $g = $reader->read('MULTILINESTRING( (0 0, 1 0, 1 1, 0 1, 0 0), @@ -655,7 +655,7 @@ class GeometryTest extends GEOSTest )'); $gu = $g->union(); - $this->assertEquals('MULTILINESTRING ((0 0, 1 0), (1 0, 1 1, 0 1), (0 1, 0 0), (1 0, 11 0, 11 10), (11 10, 11 11), (11 11, 10 11), (10 11, 0 11, 0 1), (11 11, 11 12, 12 12, 12 11, 11 11), (10 10, 10 11), (10 11, 10 14, 14 14, 14 10, 11 10), (11 10, 10 10))', $writer->write($gu)); + $this->assertEquals('MULTILINESTRING ((0 0, 1 0), (1 0, 1 1, 0 1), (0 1, 0 0), (10 10, 10 11), (10 11, 10 14, 14 14, 14 10, 11 10), (11 10, 10 10), (11 11, 11 12, 12 12, 12 11, 11 11), (1 0, 11 0, 11 10), (11 10, 11 11), (11 11, 10 11), (10 11, 0 11, 0 1))', $writer->write($gu)); $g = $reader->read('MULTIPOINT( 0 0, 1 0, 1 1, 0 1, 0 0, @@ -665,7 +665,7 @@ class GeometryTest extends GEOSTest )'); $gu = $g->union(); - $this->assertEquals('MULTIPOINT (0 0, 0 1, 0 11, 1 0, 1 1, 10 10, 10 14, 11 0, 11 11, 11 12, 12 11, 12 12, 14 10, 14 14)', $writer->write($gu)); + $this->assertEquals(GEOS_USE_BRACKETED_MULTIPOINT ? 'MULTIPOINT ((0 0), (0 1), (0 11), (1 0), (1 1), (10 10), (10 14), (11 0), (11 11), (11 12), (12 11), (12 12), (14 10), (14 14))' : 'MULTIPOINT (0 0, 0 1, 0 11, 1 0, 1 1, 10 10, 10 14, 11 0, 11 11, 11 12, 12 11, 12 12, 14 10, 14 14)', $writer->write($gu)); $g = $reader->read('GEOMETRYCOLLECTION( MULTIPOLYGON( @@ -688,7 +688,7 @@ class GeometryTest extends GEOSTest ))'); $gu = $g->union(); - $this->assertEquals('GEOMETRYCOLLECTION (POINT (-10 -10), LINESTRING (-8 8, -8 6), POLYGON ((1 0, 0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0), (11 12, 11 11, 12 11, 12 12, 11 12)))', $writer->write($gu)); + $this->assertEquals('GEOMETRYCOLLECTION (POINT (-10 -10), POLYGON ((0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0, 0 0), (11 11, 12 11, 12 12, 11 12, 11 11)), LINESTRING (-8 8, -8 6))', $writer->write($gu)); } public function testGeometry_pointOnSurface() @@ -818,7 +818,7 @@ class GeometryTest extends GEOSTest LINESTRING(185 221, 88 275, 180 316), LINESTRING(185 221, 292 281, 180 316), LINESTRING(189 98, 83 187, 185 221), - LINESTRING(189 98, 325 168, 185 221)) + LINESTRING(189 98, 325 168, 185 221) )'); $g2 = $reader->read('POINT(0 0)'); @@ -960,14 +960,14 @@ class GeometryTest extends GEOSTest LINESTRING (0 0, 2 3), MULTIPOINT (0 0, 2 3), POINT (9 0), - POINT(1 0)), - LINESTRING EMPTY + POINT(1 0), + LINESTRING EMPTY) '); $gs = $g->extractUniquePoints(); if ( ! $gs ) RETURN_NULL(); /* should get an exception before */ - $this->assertEquals('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)', $writer->write($gs)); + $this->assertEquals(GEOS_USE_BRACKETED_MULTIPOINT ? '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))' : '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)', $writer->write($gs)); } public function testGeometry_relationalOps() @@ -1206,6 +1206,10 @@ class GeometryTest extends GEOSTest public function testGeometry_checkValidity() { + + + + if (!method_exists("GEOSGeometry", 'checkValidity')) { return; } @@ -1228,12 +1232,15 @@ class GeometryTest extends GEOSTest $val = $g->checkValidity(); $this->assertType( 'array', $val ); $this->assertFalse( $val['valid'] ); - $this->assertEquals( 'Invalid Coordinate', $val['reason'] ); - $this->assertEquals( 'POINT (0 nan)', - $writer->write($val['location']) ); + $this->assertEquals( 'Invalid Coordinate', $val['reason'] ); + + // Convert to consistent format before comparison sehe commit 4acb5e0 + $expectedWKT = 'POINT (0 nan)'; + $actualWKT = $writer->write($val['location']); + $this->assertEquals(strtolower($expectedWKT), strtolower($actualWKT)); $g = $reader->read( - 'POLYGON((0 0, -10 10, 10 10, 0 0, 4 5, -4 5, 0 0)))' + 'POLYGON((0 0, -10 10, 10 10, 0 0, 4 5, -4 5, 0 0))' ); $val = $g->checkValidity(); $this->assertType( 'array', $val ); @@ -1243,7 +1250,7 @@ class GeometryTest extends GEOSTest $writer->write($val['location']) ); $g = $reader->read( - 'POLYGON((0 0, -10 10, 10 10, 0 0, 4 5, -4 5, 0 0)))' + 'POLYGON((0 0, -10 10, 10 10, 0 0, 4 5, -4 5, 0 0))' ); $flags = GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE; $val = $g->checkValidity($flags); From b3533c7f6287289dc83403b78e56ebc472fe89d9 Mon Sep 17 00:00:00 2001 From: masrih Date: Fri, 24 Nov 2023 10:52:27 +0100 Subject: [PATCH 05/13] Geos version-related constants defines several constants related to the GEOS library version --- geos_version_test.php | 7 +++++++ tests/geos_version_test.php | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 geos_version_test.php create mode 100644 tests/geos_version_test.php diff --git a/geos_version_test.php b/geos_version_test.php new file mode 100644 index 0000000..6b931d5 --- /dev/null +++ b/geos_version_test.php @@ -0,0 +1,7 @@ +=')); // GH-903 +define('GEOS_CHANGE_DIMENSION', version_compare(GEOS_VERSION, '3.12', '>=')); // GH-908 +define('GEOS_CHANGE_VALUE', version_compare(GEOS_VERSION, '3.12', '>=')); +//turn trim on(true), see : https://github.com/libgeos/geos/pull/915 + +function getGeosVersion() +{ + // Call GEOSVersion() function to get the GEOS version + $geosVersionString = GEOSVersion(); + + // Use a regular expression to extract the GEOS version + if (preg_match('/(\d+\.\d+\.\d+)/', $geosVersionString, $matches)) { + return $matches[1]; + } else { + return null; + } +} From 09c4a3bded6bc299ce118e8f14512cc533b45f5c Mon Sep 17 00:00:00 2001 From: masrih Date: Thu, 30 Nov 2023 09:18:55 +0100 Subject: [PATCH 06/13] removing unnecessary test file --- geos_version_test.php | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 geos_version_test.php diff --git a/geos_version_test.php b/geos_version_test.php deleted file mode 100644 index 6b931d5..0000000 --- a/geos_version_test.php +++ /dev/null @@ -1,7 +0,0 @@ - Date: Thu, 30 Nov 2023 15:49:15 +0100 Subject: [PATCH 07/13] Added more version-related constants --- tests/geos_version_test.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/geos_version_test.php b/tests/geos_version_test.php index 179a308..d6606e6 100644 --- a/tests/geos_version_test.php +++ b/tests/geos_version_test.php @@ -2,8 +2,11 @@ define('GEOS_VERSION', getGeosVersion()); define('GEOS_USE_BRACKETED_MULTIPOINT', version_compare(GEOS_VERSION, '3.12', '>=')); // GH-903 -define('GEOS_CHANGE_DIMENSION', version_compare(GEOS_VERSION, '3.12', '>=')); // GH-908 +define('GEOS_WKB_DEFAULT_DIMENSIONS', version_compare(GEOS_VERSION, '3.12', '>=') ? 4 : 2); // Change WKBWriter default output dimension to 4 GH-908 define('GEOS_CHANGE_VALUE', version_compare(GEOS_VERSION, '3.12', '>=')); +define('GEOS_CORRECT_NEGATIVE_ZERO', version_compare(GEOS_VERSION, '3.12', '>=')); // Update since 3.12.1 see: https://github.com/libgeos/geos/blob/ddba88a37bd8edb0acc08c9753a1a0e28de3baee/tests/unit/capi/GEOSEqualsIdenticalTest.cpp#L203 +define('GEOS_CORRECT_VALUE', version_compare(GEOS_VERSION, '3.11', '>=')); +define('GEOS_DEFAULT_EMPTY', version_compare(GEOS_VERSION, '3.11', '>=')); // The bad mix appears to be with GEOS 3.10 and POLYGON EMPTY GH-501 //turn trim on(true), see : https://github.com/libgeos/geos/pull/915 function getGeosVersion() From 24fb4848aeff81882d1ed17f621575def7883a02 Mon Sep 17 00:00:00 2001 From: masrih Date: Thu, 30 Nov 2023 15:51:28 +0100 Subject: [PATCH 08/13] Update Output Dimensions configuration constant in WKBWriter --- tests/004_WKBWriter.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/004_WKBWriter.phpt b/tests/004_WKBWriter.phpt index 6af8caf..2064164 100644 --- a/tests/004_WKBWriter.phpt +++ b/tests/004_WKBWriter.phpt @@ -19,7 +19,7 @@ class WKBWriterTest extends GEOSTest public function testWKBWriter_getOutputDimension() { $writer = new GEOSWKBWriter(); - $this->assertEquals( GEOS_CHANGE_DIMENSION ? 4 : 2, $writer->getOutputDimension()); + $this->assertEquals(GEOS_WKB_DEFAULT_DIMENSIONS, $writer->getOutputDimension()); } public function testWKBWriter_setOutputDimension() @@ -35,7 +35,7 @@ class WKBWriterTest extends GEOSTest $writer->setOutputDimension(1); $this->assertTrue(FALSE); } catch (Exception $e) { - $this->assertContains(GEOS_CHANGE_DIMENSION ? 'must be 2, 3, or 4' : 'must be 2 or 3' , $e->getMessage()); + $this->assertContains((GEOS_WKB_DEFAULT_DIMENSIONS === 4) ? 'must be 2, 3, or 4' : 'must be 2 or 3' , $e->getMessage()); } # 4 is invalid From d488c049fc41df9f7354ca3774f83dc6935bc616 Mon Sep 17 00:00:00 2001 From: masrih Date: Thu, 30 Nov 2023 15:52:27 +0100 Subject: [PATCH 09/13] Update Output Dimensions configuration constant in WKTWriter --- tests/002_WKTWriter.phpt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/002_WKTWriter.phpt b/tests/002_WKTWriter.phpt index 0a349bd..f48159d 100644 --- a/tests/002_WKTWriter.phpt +++ b/tests/002_WKTWriter.phpt @@ -102,6 +102,7 @@ class WKTWriterTest extends GEOSTest $this->assertEquals('POINT (6.123456 7.123456)', $writer->write($g)); + $writer->setTrim(FALSE); //resets trim to false for GEOS 3.7.1 or older, see: GH-915 $writer->setRoundingPrecision(2); $this->assertEquals('POINT (6.12 7.12)', $writer->write($g)); @@ -123,7 +124,7 @@ class WKTWriterTest extends GEOSTest } $writer = new GEOSWKTWriter(); - $this->assertEquals(GEOS_CHANGE_DIMENSION ? 4 : 2, $writer->getOutputDimension()); + $this->assertEquals(GEOS_WKB_DEFAULT_DIMENSIONS, $writer->getOutputDimension()); } public function testWKTWriter_setOutputDimension() @@ -140,7 +141,7 @@ class WKTWriterTest extends GEOSTest $writer->setTrim(TRUE); # Only 2d by default - $this->assertEquals(GEOS_CHANGE_DIMENSION ? 'POINT Z (1 2 3)' : 'POINT (1 2)', $writer->write($g3d)); //Dimension up to 3 since GEOS 3.12 + $this->assertEquals((GEOS_WKB_DEFAULT_DIMENSIONS === 4) ? 'POINT Z (1 2 3)' : 'POINT (1 2)', $writer->write($g3d)); # 3d if requested _and_ available $writer->setOutputDimension(3); @@ -152,7 +153,7 @@ class WKTWriterTest extends GEOSTest $writer->setOutputDimension(1); $this->assertTrue(FALSE); } catch (Exception $e) { - $this->assertContains(GEOS_CHANGE_DIMENSION ? 'must be 2, 3, or 4' : '2 or 3', $e->getMessage()); + $this->assertContains((GEOS_WKB_DEFAULT_DIMENSIONS === 4) ? 'must be 2, 3, or 4' : '2 or 3', $e->getMessage()); } # 4 is invalid From 6bc11fe4313aa0a9cd4290b0a2569f61b29fc0cc Mon Sep 17 00:00:00 2001 From: masrih Date: Thu, 30 Nov 2023 15:55:34 +0100 Subject: [PATCH 10/13] Corrected negative zero and change expected values for GEOS 3.11 in Geometry --- tests/001_Geometry.phpt | 48 ++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/001_Geometry.phpt b/tests/001_Geometry.phpt index 17dba37..b74eed4 100644 --- a/tests/001_Geometry.phpt +++ b/tests/001_Geometry.phpt @@ -144,11 +144,11 @@ class GeometryTest extends GEOSTest $this->assertEquals('POLYGON EMPTY', $writer->write($b)); $b = $g->buffer(10); - $this->assertEquals(GEOS_CHANGE_VALUE ? '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))' : '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))', $writer->write($b)); // Negative zero (-0) Update since 3.12.1 + $this->assertEquals(GEOS_CORRECT_NEGATIVE_ZERO ? '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))' : '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))', $writer->write($b)); // Negative zero (-0) Update since 3.12.1 # One segment per quadrant $b = $g->buffer(10, array('quad_segs' => 1)); - $this->assertEquals(GEOS_CHANGE_VALUE ? 'POLYGON ((10 0, 0 -10, -10 0, 0 10, 10 0))' : 'POLYGON ((10 0, 0 -10, -10 -0, -0 10, 10 0))', $writer->write($b)); // Negative zero (-0) Update since 3.12.1 + $this->assertEquals(GEOS_CORRECT_NEGATIVE_ZERO ? 'POLYGON ((10 0, 0 -10, -10 0, 0 10, 10 0))' : 'POLYGON ((10 0, 0 -10, -10 -0, -0 10, 10 0))', $writer->write($b)); // Negative zero (-0) Update since 3.12.1 /* End cap styles */ @@ -199,7 +199,7 @@ class GeometryTest extends GEOSTest 'join' => GEOSBUF_JOIN_MITRE, 'mitre_limit' => 1.0 )); - $this->assertEquals('POLYGON ((90 10, 90 100, 93 107, 100 110, 107 107, 110 100, 110 -4, 104 -10, 0 -10, -7 -7, -10 0, -7 7, 0 10, 90 10))', $writer->write($b)); + $this->assertEquals(GEOS_CORRECT_VALUE ? 'POLYGON ((90 10, 90 100, 93 107, 100 110, 107 107, 110 100, 110 -4, 104 -10, 0 -10, -7 -7, -10 0, -7 7, 0 10, 90 10))' : '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))', $writer->write($b)); //changed between GEOS 3.9 and 3.11 /* Check that elements of the passed style array are not * type-converted (buffer op will need to type-convert @@ -265,7 +265,7 @@ class GeometryTest extends GEOSTest 'quad_segs' => 2, 'join' => GEOSBUF_JOIN_ROUND )); - $this->assertEquals(GEOS_CHANGE_VALUE ? 'LINESTRING (0 -10, 100 -10, 102 -10, 104 -9, 106 -8, 107 -7, 108 -6, 109 -4, 110 -2, 110 0, 110 100)' : 'LINESTRING (0 -10, 100 -10, 107 -7, 110 0, 110 100)', $writer->write($b)); // Linestring Update since 3.12.1 + $this->assertEquals(GEOS_CHANGE_VALUE ? 'LINESTRING (0 -10, 100 -10, 102 -10, 104 -9, 106 -8, 107 -7, 108 -6, 109 -4, 110 -2, 110 0, 110 100)' : GEOS_CORRECT_VALUE? 'LINESTRING (0 -10, 100 -10, 107 -7, 110 0, 110 100)' : 'LINESTRING (110 100, 110 0, 107 -7, 100 -10, 0 -10)' , $writer->write($b)); // Linestring changed twice first between 3.9 and 3.11 then 3.12.1 /* left, bevel join */ $b = $g->offsetCurve(10, array( @@ -279,7 +279,7 @@ class GeometryTest extends GEOSTest 'quad_segs' => 2, 'join' => GEOSBUF_JOIN_BEVEL )); - $this->assertEquals('LINESTRING (0 -10, 100 -10, 110 0, 110 100)', $writer->write($b)); + $this->assertEquals(GEOS_CORRECT_VALUE ? 'LINESTRING (0 -10, 100 -10, 110 0, 110 100)' : 'LINESTRING (110 100, 110 0, 100 -10, 0 -10)', $writer->write($b)); // Linestring changed between 3.9 and 3.11 /* left, mitre join */ $b = $g->offsetCurve(10, array( @@ -293,7 +293,7 @@ class GeometryTest extends GEOSTest 'quad_segs' => 2, 'join' => GEOSBUF_JOIN_MITRE )); - $this->assertEquals('LINESTRING (0 -10, 110 -10, 110 100)', $writer->write($b)); + $this->assertEquals(GEOS_CORRECT_VALUE ? 'LINESTRING (0 -10, 110 -10, 110 100)' : 'LINESTRING (110 100, 110 -10, 0 -10)', $writer->write($b)); // Linestring changed between 3.9 and 3.11 /* right, mitre join limited */ $b = $g->offsetCurve(-10, array( @@ -301,7 +301,7 @@ class GeometryTest extends GEOSTest 'join' => GEOSBUF_JOIN_MITRE, 'mitre_limit' => 1.0 )); - $this->assertEquals('LINESTRING (0 -10, 104 -10, 110 -4, 110 100)', $writer->write($b)); + $this->assertEquals(GEOS_CORRECT_VALUE ? 'LINESTRING (0 -10, 104 -10, 110 -4, 110 100)' : 'LINESTRING (110 100, 109 -5, 105 -9, 0 -10)', $writer->write($b)); // Linestring changed between 3.9 and 3.11 } public function testGeometry_envelope() @@ -338,7 +338,7 @@ class GeometryTest extends GEOSTest $this->assertEquals( 'POINT (0 0)', $writer->write($gi)); $g2 = $reader->read('POINT(1 0)'); $gi = $g->intersection($g2); - $this->assertEquals( 'POINT EMPTY', $writer->write($gi)); + $this->assertEquals(GEOS_DEFAULT_EMPTY ? 'POINT EMPTY' : 'GEOMETRYCOLLECTION EMPTY', $writer->write($gi)); //GH-501 /* POINT - LINE */ $g = $reader->read('LINESTRING(0 0, 10 0)'); @@ -347,7 +347,7 @@ class GeometryTest extends GEOSTest $this->assertEquals( 'POINT (5 0)', $writer->write($gi)); $g2 = $reader->read('POINT(12 0)'); $gi = $g->intersection($g2); - $this->assertEquals( 'POINT EMPTY', $writer->write($gi)); + $this->assertEquals(GEOS_DEFAULT_EMPTY ? 'POINT EMPTY' : 'GEOMETRYCOLLECTION EMPTY', $writer->write($gi)); //GH-501 /* LINE - LINE */ $g = $reader->read('LINESTRING(0 0, 10 0)'); @@ -445,7 +445,7 @@ class GeometryTest extends GEOSTest $g = $reader->read('POINT(0 0)'); $g2 = $reader->read('POINT(0 0)'); $gi = $g->difference($g2); - $this->assertEquals( 'POINT EMPTY', $writer->write($gi)); + $this->assertEquals(GEOS_DEFAULT_EMPTY ? 'POINT EMPTY' : 'GEOMETRYCOLLECTION EMPTY', $writer->write($gi)); //GH-501 $g2 = $reader->read('POINT(1 0)'); $gi = $g->difference($g2); $this->assertEquals('POINT (0 0)', $writer->write($gi)); @@ -460,7 +460,7 @@ class GeometryTest extends GEOSTest $g = $reader->read('POINT(5 0)'); $g2 = $reader->read('LINESTRING(0 0, 10 0)'); $gi = $g->difference($g2); - $this->assertEquals('POINT EMPTY', $writer->write($gi)); + $this->assertEquals(GEOS_DEFAULT_EMPTY ? 'POINT EMPTY' : 'GEOMETRYCOLLECTION EMPTY', $writer->write($gi)); //GH-501 $g2 = $reader->read('LINESTRING(0 1, 10 1)'); $gi = $g->difference($g2); $this->assertEquals( 'POINT (5 0)', $writer->write($gi)); @@ -478,16 +478,16 @@ class GeometryTest extends GEOSTest $g = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'); $g2 = $reader->read('LINESTRING(5 -10, 5 10)'); $gi = $g->difference($g2); - $this->assertEquals('POLYGON ((0 0, 0 10, 5 10, 10 10, 10 0, 5 0, 0 0))', $writer->write($gi)); + $this->assertEquals(GEOS_CORRECT_VALUE ? 'POLYGON ((0 0, 0 10, 5 10, 10 10, 10 0, 5 0, 0 0))' : 'POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0))', $writer->write($gi)); //Polygon changed between 3.9 and 3.11 $g2 = $reader->read('LINESTRING(10 0, 20 0)'); $gi = $g->difference($g2); - $this->assertEquals('POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))', $writer->write($gi)); + $this->assertEquals(GEOS_CORRECT_VALUE ? 'POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))' : 'POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0))', $writer->write($gi)); //Polygon changed between 3.9 and 3.11 /* POLY - POLY */ $g = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'); $g2 = $reader->read('POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'); $gi = $g->difference($g2); - $this->assertEquals('POLYGON ((0 0, 0 10, 10 10, 10 5, 5 5, 5 0, 0 0))', $writer->write($gi)); + $this->assertEquals(GEOS_CORRECT_VALUE ? 'POLYGON ((0 0, 0 10, 10 10, 10 5, 5 5, 5 0, 0 0))' : 'POLYGON ((5 0, 0 0, 0 10, 10 10, 10 5, 5 5, 5 0))', $writer->write($gi)); //Polygon changed between 3.9 and 3.11 } public function testGeometry_symdifference() @@ -503,7 +503,7 @@ class GeometryTest extends GEOSTest $g = $reader->read('POINT(0 0)'); $g2 = $reader->read('POINT(0 0)'); $gi = $g->symDifference($g2); - $this->assertEquals( 'POINT EMPTY', $writer->write($gi)); + $this->assertEquals(GEOS_DEFAULT_EMPTY ? 'POINT EMPTY' : 'GEOMETRYCOLLECTION EMPTY', $writer->write($gi)); //GH-501 $g2 = $reader->read('POINT(1 0)'); $gi = $g->symDifference($g2); $this->assertEquals(GEOS_USE_BRACKETED_MULTIPOINT ? 'MULTIPOINT ((0 0), (1 0))' : 'MULTIPOINT (0 0, 1 0)', $writer->write($gi)); @@ -536,16 +536,16 @@ class GeometryTest extends GEOSTest $g = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'); $g2 = $reader->read('LINESTRING(5 -10, 5 10)'); $gi = $g->symDifference($g2); - $this->assertEquals('GEOMETRYCOLLECTION (POLYGON ((0 0, 0 10, 5 10, 10 10, 10 0, 5 0, 0 0)), LINESTRING (5 -10, 5 0))', $writer->write($gi)); + $this->assertEquals(GEOS_CORRECT_VALUE ? 'GEOMETRYCOLLECTION (POLYGON ((0 0, 0 10, 5 10, 10 10, 10 0, 5 0, 0 0)), LINESTRING (5 -10, 5 0))' : 'GEOMETRYCOLLECTION (LINESTRING (5 -10, 5 0), POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0)))', $writer->write($gi)); //Updated value between 3.9 and 3.11 $g2 = $reader->read('LINESTRING(10 0, 20 0)'); $gi = $g->symDifference($g2); - $this->assertEquals('GEOMETRYCOLLECTION (POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0)), LINESTRING (10 0, 20 0))', $writer->write($gi)); + $this->assertEquals(GEOS_CORRECT_VALUE ? 'GEOMETRYCOLLECTION (POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0)), LINESTRING (10 0, 20 0))' : 'GEOMETRYCOLLECTION (LINESTRING (10 0, 20 0), POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0)))', $writer->write($gi)); //Updated value between 3.9 and 3.11 /* POLY - POLY */ $g = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'); $g2 = $reader->read('POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'); $gi = $g->symDifference($g2); - $this->assertEquals('MULTIPOLYGON (((0 0, 0 10, 10 10, 10 5, 5 5, 5 0, 0 0)), ((10 0, 10 5, 15 5, 15 -5, 5 -5, 5 0, 10 0)))', $writer->write($gi)); + $this->assertEquals(GEOS_CORRECT_VALUE ? 'MULTIPOLYGON (((0 0, 0 10, 10 10, 10 5, 5 5, 5 0, 0 0)), ((10 0, 10 5, 15 5, 15 -5, 5 -5, 5 0, 10 0)))' : '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)))', $writer->write($gi)); //Updated value between 3.9 and 3.11 } public function testGeometry_boundary() @@ -616,16 +616,16 @@ class GeometryTest extends GEOSTest $g = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'); $g2 = $reader->read('LINESTRING(5 -10, 5 10)'); $gi = $g->union($g2); - $this->assertEquals('GEOMETRYCOLLECTION (POLYGON ((0 0, 0 10, 5 10, 10 10, 10 0, 5 0, 0 0)), LINESTRING (5 -10, 5 0))', $writer->write($gi)); + $this->assertEquals(GEOS_CORRECT_VALUE ? 'GEOMETRYCOLLECTION (POLYGON ((0 0, 0 10, 5 10, 10 10, 10 0, 5 0, 0 0)), LINESTRING (5 -10, 5 0))' : 'GEOMETRYCOLLECTION (LINESTRING (5 -10, 5 0), POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0)))', $writer->write($gi)); //Updated value between 3.9 and 3.11 $g2 = $reader->read('LINESTRING(10 0, 20 0)'); $gi = $g->union($g2); - $this->assertEquals('GEOMETRYCOLLECTION (POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0)), LINESTRING (10 0, 20 0))', $writer->write($gi)); + $this->assertEquals(GEOS_CORRECT_VALUE ? 'GEOMETRYCOLLECTION (POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0)), LINESTRING (10 0, 20 0))' : 'GEOMETRYCOLLECTION (LINESTRING (10 0, 20 0), POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0)))', $writer->write($gi)); //Updated value between 3.9 and 3.11 /* POLY - POLY */ $g = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'); $g2 = $reader->read('POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'); $gi = $g->union($g2); - $this->assertEquals('POLYGON ((0 0, 0 10, 10 10, 10 5, 15 5, 15 -5, 5 -5, 5 0, 0 0))', $writer->write($gi)); + $this->assertEquals(GEOS_CORRECT_VALUE ? 'POLYGON ((0 0, 0 10, 10 10, 10 5, 15 5, 15 -5, 5 -5, 5 0, 0 0))' : 'POLYGON ((5 0, 0 0, 0 10, 10 10, 10 5, 15 5, 15 -5, 5 -5, 5 0))', $writer->write($gi)); //Updated value between 3.9 and 3.11 } public function testGeometry_unaryunion() @@ -645,7 +645,7 @@ class GeometryTest extends GEOSTest )'); $gu = $g->union(); - $this->assertEquals('POLYGON ((0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0, 0 0), (12 12, 11 12, 11 11, 12 11, 12 12))', $writer->write($gu)); + $this->assertEquals(GEOS_CORRECT_VALUE ? 'POLYGON ((0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0, 0 0), (12 12, 11 12, 11 11, 12 11, 12 12))' : '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))', $writer->write($gu)); //Updated value between 3.9 and 3.11 $g = $reader->read('MULTILINESTRING( (0 0, 1 0, 1 1, 0 1, 0 0), @@ -655,7 +655,7 @@ class GeometryTest extends GEOSTest )'); $gu = $g->union(); - $this->assertEquals('MULTILINESTRING ((0 0, 1 0), (1 0, 1 1, 0 1), (0 1, 0 0), (10 10, 10 11), (10 11, 10 14, 14 14, 14 10, 11 10), (11 10, 10 10), (11 11, 11 12, 12 12, 12 11, 11 11), (1 0, 11 0, 11 10), (11 10, 11 11), (11 11, 10 11), (10 11, 0 11, 0 1))', $writer->write($gu)); + $this->assertEquals(GEOS_CORRECT_VALUE ? 'MULTILINESTRING ((0 0, 1 0), (1 0, 1 1, 0 1), (0 1, 0 0), (10 10, 10 11), (10 11, 10 14, 14 14, 14 10, 11 10), (11 10, 10 10), (11 11, 11 12, 12 12, 12 11, 11 11), (1 0, 11 0, 11 10), (11 10, 11 11), (11 11, 10 11), (10 11, 0 11, 0 1))' : 'MULTILINESTRING ((0 0, 1 0), (1 0, 1 1, 0 1), (0 1, 0 0), (1 0, 11 0, 11 10), (11 10, 11 11), (11 11, 10 11), (10 11, 0 11, 0 1), (11 11, 11 12, 12 12, 12 11, 11 11), (10 10, 10 11), (10 11, 10 14, 14 14, 14 10, 11 10), (11 10, 10 10))', $writer->write($gu)); //Updated value between 3.9 and 3.11 $g = $reader->read('MULTIPOINT( 0 0, 1 0, 1 1, 0 1, 0 0, @@ -688,7 +688,7 @@ class GeometryTest extends GEOSTest ))'); $gu = $g->union(); - $this->assertEquals('GEOMETRYCOLLECTION (POINT (-10 -10), POLYGON ((0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0, 0 0), (11 11, 12 11, 12 12, 11 12, 11 11)), LINESTRING (-8 8, -8 6))', $writer->write($gu)); + $this->assertEquals(GEOS_CORRECT_VALUE ? 'GEOMETRYCOLLECTION (POINT (-10 -10), POLYGON ((0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0, 0 0), (11 11, 12 11, 12 12, 11 12, 11 11)), LINESTRING (-8 8, -8 6))' : 'GEOMETRYCOLLECTION (POINT (-10 -10), LINESTRING (-8 8, -8 6), POLYGON ((1 0, 0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0), (11 12, 11 11, 12 11, 12 12, 11 12)))', $writer->write($gu)); //Updated value between 3.9 and 3.11 } public function testGeometry_pointOnSurface() From 20491fbadfe9cd222388eec60557ad75bb8344fc Mon Sep 17 00:00:00 2001 From: masrih Date: Fri, 1 Dec 2023 08:48:41 +0100 Subject: [PATCH 11/13] Changed 'include' to 'require' also deleting unnecessary lines/comments --- tests/001_Geometry.phpt | 2 +- tests/002_WKTWriter.phpt | 6 +++--- tests/004_WKBWriter.phpt | 2 +- tests/005_WKBReader.phpt | 3 +-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/001_Geometry.phpt b/tests/001_Geometry.phpt index b74eed4..b5f6876 100644 --- a/tests/001_Geometry.phpt +++ b/tests/001_Geometry.phpt @@ -6,7 +6,7 @@ Geometry tests setTrim(TRUE); - # Only 2d by default + $this->assertEquals((GEOS_WKB_DEFAULT_DIMENSIONS === 4) ? 'POINT Z (1 2 3)' : 'POINT (1 2)', $writer->write($g3d)); # 3d if requested _and_ available diff --git a/tests/004_WKBWriter.phpt b/tests/004_WKBWriter.phpt index 2064164..b240490 100644 --- a/tests/004_WKBWriter.phpt +++ b/tests/004_WKBWriter.phpt @@ -6,7 +6,7 @@ WKBWriter tests setRoundingPrecision(1); $writer->setOutputDimension(3); - if (method_exists("GEOSWKTWriter", 'setTrim')) { $writer->setTrim(FALSE); } From fb4407864592e38650038da06fdc21316b0c58dc Mon Sep 17 00:00:00 2001 From: masrih Date: Fri, 1 Dec 2023 17:15:43 +0100 Subject: [PATCH 12/13] Corrected php ternary syntax --- tests/001_Geometry.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/001_Geometry.phpt b/tests/001_Geometry.phpt index b5f6876..da88d1b 100644 --- a/tests/001_Geometry.phpt +++ b/tests/001_Geometry.phpt @@ -265,7 +265,7 @@ class GeometryTest extends GEOSTest 'quad_segs' => 2, 'join' => GEOSBUF_JOIN_ROUND )); - $this->assertEquals(GEOS_CHANGE_VALUE ? 'LINESTRING (0 -10, 100 -10, 102 -10, 104 -9, 106 -8, 107 -7, 108 -6, 109 -4, 110 -2, 110 0, 110 100)' : GEOS_CORRECT_VALUE? 'LINESTRING (0 -10, 100 -10, 107 -7, 110 0, 110 100)' : 'LINESTRING (110 100, 110 0, 107 -7, 100 -10, 0 -10)' , $writer->write($b)); // Linestring changed twice first between 3.9 and 3.11 then 3.12.1 + $this->assertEquals(GEOS_CHANGE_VALUE ? 'LINESTRING (0 -10, 100 -10, 102 -10, 104 -9, 106 -8, 107 -7, 108 -6, 109 -4, 110 -2, 110 0, 110 100)' : (GEOS_CORRECT_VALUE ? 'LINESTRING (0 -10, 100 -10, 107 -7, 110 0, 110 100)' : 'LINESTRING (110 100, 110 0, 107 -7, 100 -10, 0 -10)'), $writer->write($b)); // Linestring changed twice first between 3.9 and 3.11 then 3.12.1 /* left, bevel join */ $b = $g->offsetCurve(10, array( From 1d7e220c53542ccefea08f3ebbc1c72535dfeeed Mon Sep 17 00:00:00 2001 From: masrih Date: Mon, 4 Dec 2023 13:11:45 +0100 Subject: [PATCH 13/13] Introduce assertEqualsAny and fix version comparison Introduce `assertEqualsAny` function for cleaner assertions with more than two expected values. Correct the version comparison for GEOS_DEFAULT_EMPTY from 3.11 to 3.9. --- tests/001_Geometry.phpt | 29 +++++++++++++++-------------- tests/TestHelper.php | 11 +++++++++++ tests/geos_version_test.php | 2 +- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/tests/001_Geometry.phpt b/tests/001_Geometry.phpt index da88d1b..e6a93c2 100644 --- a/tests/001_Geometry.phpt +++ b/tests/001_Geometry.phpt @@ -478,16 +478,16 @@ class GeometryTest extends GEOSTest $g = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'); $g2 = $reader->read('LINESTRING(5 -10, 5 10)'); $gi = $g->difference($g2); - $this->assertEquals(GEOS_CORRECT_VALUE ? 'POLYGON ((0 0, 0 10, 5 10, 10 10, 10 0, 5 0, 0 0))' : 'POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0))', $writer->write($gi)); //Polygon changed between 3.9 and 3.11 + $this->assertEqualsAny(array('POLYGON ((0 0, 0 10, 5 10, 10 10, 10 0, 5 0, 0 0))', 'POLYGON ((0 10, 5 10, 10 10, 10 0, 5 0, 0 0, 0 10))', 'POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0))'), $writer->write($gi)); //Polygon changed twice between 3.9 and 3.11 $g2 = $reader->read('LINESTRING(10 0, 20 0)'); $gi = $g->difference($g2); - $this->assertEquals(GEOS_CORRECT_VALUE ? 'POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))' : 'POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0))', $writer->write($gi)); //Polygon changed between 3.9 and 3.11 + $this->assertEqualsAny(array('POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))', 'POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0))', 'POLYGON ((0 10, 10 10, 10 0, 0 0, 0 10))'), $writer->write($gi)); //Polygon changed between 3.9 and 3.11 /* POLY - POLY */ $g = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'); $g2 = $reader->read('POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'); $gi = $g->difference($g2); - $this->assertEquals(GEOS_CORRECT_VALUE ? 'POLYGON ((0 0, 0 10, 10 10, 10 5, 5 5, 5 0, 0 0))' : 'POLYGON ((5 0, 0 0, 0 10, 10 10, 10 5, 5 5, 5 0))', $writer->write($gi)); //Polygon changed between 3.9 and 3.11 + $this->assertEqualsAny(array('POLYGON ((0 0, 0 10, 10 10, 10 5, 5 5, 5 0, 0 0))', 'POLYGON ((5 0, 0 0, 0 10, 10 10, 10 5, 5 5, 5 0))', 'POLYGON ((0 10, 10 10, 10 5, 5 5, 5 0, 0 0, 0 10))'), $writer->write($gi)); //Polygon changed between 3.9 and 3.11 } public function testGeometry_symdifference() @@ -527,7 +527,7 @@ class GeometryTest extends GEOSTest $g = $reader->read('LINESTRING(0 0, 10 0)'); $g2 = $reader->read('LINESTRING(5 -10, 5 10)'); $gi = $g->symDifference($g2); - $this->assertEquals('MULTILINESTRING ((0 0, 5 0), (5 0, 10 0), (5 -10, 5 0), (5 0, 5 10))', $writer->write($gi)); + $this->assertEquals(GEOS_VERSION == 3.9 ? 'MULTILINESTRING ((0 0, 5 0), (5 -10, 5 0), (5 0, 5 10), (5 0, 10 0))' : 'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0), (5 -10, 5 0), (5 0, 5 10))', $writer->write($gi)); $g2 = $reader->read('LINESTRING(5 0, 20 0)'); $gi = $g->symDifference($g2); $this->assertEquals('MULTILINESTRING ((0 0, 5 0), (10 0, 20 0))', $writer->write($gi)); @@ -536,16 +536,16 @@ class GeometryTest extends GEOSTest $g = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'); $g2 = $reader->read('LINESTRING(5 -10, 5 10)'); $gi = $g->symDifference($g2); - $this->assertEquals(GEOS_CORRECT_VALUE ? 'GEOMETRYCOLLECTION (POLYGON ((0 0, 0 10, 5 10, 10 10, 10 0, 5 0, 0 0)), LINESTRING (5 -10, 5 0))' : 'GEOMETRYCOLLECTION (LINESTRING (5 -10, 5 0), POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0)))', $writer->write($gi)); //Updated value between 3.9 and 3.11 + $this->assertEqualsAny(array('GEOMETRYCOLLECTION (POLYGON ((0 0, 0 10, 5 10, 10 10, 10 0, 5 0, 0 0)), LINESTRING (5 -10, 5 0))', 'GEOMETRYCOLLECTION (LINESTRING (5 -10, 5 0), POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0)))', 'GEOMETRYCOLLECTION (POLYGON ((0 10, 5 10, 10 10, 10 0, 5 0, 0 0, 0 10)), LINESTRING (5 -10, 5 0))'), $writer->write($gi)); // GemoetryCollection changed twice between 3.9 and 3.11 $g2 = $reader->read('LINESTRING(10 0, 20 0)'); $gi = $g->symDifference($g2); - $this->assertEquals(GEOS_CORRECT_VALUE ? 'GEOMETRYCOLLECTION (POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0)), LINESTRING (10 0, 20 0))' : 'GEOMETRYCOLLECTION (LINESTRING (10 0, 20 0), POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0)))', $writer->write($gi)); //Updated value between 3.9 and 3.11 + $this->assertEqualsAny(array('GEOMETRYCOLLECTION (POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0)), LINESTRING (10 0, 20 0))', 'GEOMETRYCOLLECTION (LINESTRING (10 0, 20 0), POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0)))', 'GEOMETRYCOLLECTION (POLYGON ((0 10, 10 10, 10 0, 0 0, 0 10)), LINESTRING (10 0, 20 0))'), $writer->write($gi)); // GemoetryCollection changed twice between 3.9 and 3.11 /* POLY - POLY */ $g = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'); $g2 = $reader->read('POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'); $gi = $g->symDifference($g2); - $this->assertEquals(GEOS_CORRECT_VALUE ? 'MULTIPOLYGON (((0 0, 0 10, 10 10, 10 5, 5 5, 5 0, 0 0)), ((10 0, 10 5, 15 5, 15 -5, 5 -5, 5 0, 10 0)))' : '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)))', $writer->write($gi)); //Updated value between 3.9 and 3.11 + $this->assertEqualsAny(array('MULTIPOLYGON (((0 0, 0 10, 10 10, 10 5, 5 5, 5 0, 0 0)), ((10 0, 10 5, 15 5, 15 -5, 5 -5, 5 0, 10 0)))', '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)))', 'MULTIPOLYGON (((0 10, 10 10, 10 5, 5 5, 5 0, 0 0, 0 10)), ((5 0, 10 0, 10 5, 15 5, 15 -5, 5 -5, 5 0)))'), $writer->write($gi)); // GemoetryCollection changed twice between 3.9 and 3.11 } public function testGeometry_boundary() @@ -607,7 +607,7 @@ class GeometryTest extends GEOSTest $g = $reader->read('LINESTRING(0 0, 10 0)'); $g2 = $reader->read('LINESTRING(5 -10, 5 10)'); $gi = $g->union($g2); - $this->assertEquals('MULTILINESTRING ((0 0, 5 0), (5 0, 10 0), (5 -10, 5 0), (5 0, 5 10))', $writer->write($gi)); + $this->assertEquals(GEOS_VERSION == 3.9 ? 'MULTILINESTRING ((0 0, 5 0), (5 -10, 5 0), (5 0, 5 10), (5 0, 10 0))' : 'MULTILINESTRING ((0 0, 5 0), (5 0, 10 0), (5 -10, 5 0), (5 0, 5 10))', $writer->write($gi)); $g2 = $reader->read('LINESTRING(5 0, 20 0)'); $gi = $g->union($g2); $this->assertEquals('MULTILINESTRING ((0 0, 5 0), (5 0, 10 0), (10 0, 20 0))', $writer->write($gi)); @@ -616,16 +616,16 @@ class GeometryTest extends GEOSTest $g = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'); $g2 = $reader->read('LINESTRING(5 -10, 5 10)'); $gi = $g->union($g2); - $this->assertEquals(GEOS_CORRECT_VALUE ? 'GEOMETRYCOLLECTION (POLYGON ((0 0, 0 10, 5 10, 10 10, 10 0, 5 0, 0 0)), LINESTRING (5 -10, 5 0))' : 'GEOMETRYCOLLECTION (LINESTRING (5 -10, 5 0), POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0)))', $writer->write($gi)); //Updated value between 3.9 and 3.11 + $this->assertEqualsAny(array('GEOMETRYCOLLECTION (POLYGON ((0 0, 0 10, 5 10, 10 10, 10 0, 5 0, 0 0)), LINESTRING (5 -10, 5 0))', 'GEOMETRYCOLLECTION (LINESTRING (5 -10, 5 0), POLYGON ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0)))', 'GEOMETRYCOLLECTION (POLYGON ((0 10, 5 10, 10 10, 10 0, 5 0, 0 0, 0 10)), LINESTRING (5 -10, 5 0))'), $writer->write($gi)); // GeometryCollection updated twice between 3.9 and 3.11 $g2 = $reader->read('LINESTRING(10 0, 20 0)'); $gi = $g->union($g2); - $this->assertEquals(GEOS_CORRECT_VALUE ? 'GEOMETRYCOLLECTION (POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0)), LINESTRING (10 0, 20 0))' : 'GEOMETRYCOLLECTION (LINESTRING (10 0, 20 0), POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0)))', $writer->write($gi)); //Updated value between 3.9 and 3.11 + $this->assertEqualsAny(array('GEOMETRYCOLLECTION (POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0)), LINESTRING (10 0, 20 0))', 'GEOMETRYCOLLECTION (LINESTRING (10 0, 20 0), POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0)))', 'GEOMETRYCOLLECTION (POLYGON ((0 10, 10 10, 10 0, 0 0, 0 10)), LINESTRING (10 0, 20 0))'), $writer->write($gi)); //GeometryCollection updated twice between 3.9 and 3.11 /* POLY - POLY */ $g = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'); $g2 = $reader->read('POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))'); $gi = $g->union($g2); - $this->assertEquals(GEOS_CORRECT_VALUE ? 'POLYGON ((0 0, 0 10, 10 10, 10 5, 15 5, 15 -5, 5 -5, 5 0, 0 0))' : 'POLYGON ((5 0, 0 0, 0 10, 10 10, 10 5, 15 5, 15 -5, 5 -5, 5 0))', $writer->write($gi)); //Updated value between 3.9 and 3.11 + $this->assertEqualsAny(array('POLYGON ((0 0, 0 10, 10 10, 10 5, 15 5, 15 -5, 5 -5, 5 0, 0 0))', 'POLYGON ((5 0, 0 0, 0 10, 10 10, 10 5, 15 5, 15 -5, 5 -5, 5 0))', 'POLYGON ((0 10, 10 10, 10 5, 15 5, 15 -5, 5 -5, 5 0, 0 0, 0 10))'), $writer->write($gi)); //Updated Polygon twice between 3.9 and 3.11 } public function testGeometry_unaryunion() @@ -645,7 +645,7 @@ class GeometryTest extends GEOSTest )'); $gu = $g->union(); - $this->assertEquals(GEOS_CORRECT_VALUE ? 'POLYGON ((0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0, 0 0), (12 12, 11 12, 11 11, 12 11, 12 12))' : '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))', $writer->write($gu)); //Updated value between 3.9 and 3.11 + $this->assertEqualsAny(array('POLYGON ((0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0, 0 0), (12 12, 11 12, 11 11, 12 11, 12 12))', '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))', 'POLYGON ((0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0, 0 0, 0 1), (12 12, 11 12, 11 11, 12 11, 12 12))'), $writer->write($gu)); //Updated Polygon twice between 3.9 and 3.11 $g = $reader->read('MULTILINESTRING( (0 0, 1 0, 1 1, 0 1, 0 0), @@ -655,7 +655,7 @@ class GeometryTest extends GEOSTest )'); $gu = $g->union(); - $this->assertEquals(GEOS_CORRECT_VALUE ? 'MULTILINESTRING ((0 0, 1 0), (1 0, 1 1, 0 1), (0 1, 0 0), (10 10, 10 11), (10 11, 10 14, 14 14, 14 10, 11 10), (11 10, 10 10), (11 11, 11 12, 12 12, 12 11, 11 11), (1 0, 11 0, 11 10), (11 10, 11 11), (11 11, 10 11), (10 11, 0 11, 0 1))' : 'MULTILINESTRING ((0 0, 1 0), (1 0, 1 1, 0 1), (0 1, 0 0), (1 0, 11 0, 11 10), (11 10, 11 11), (11 11, 10 11), (10 11, 0 11, 0 1), (11 11, 11 12, 12 12, 12 11, 11 11), (10 10, 10 11), (10 11, 10 14, 14 14, 14 10, 11 10), (11 10, 10 10))', $writer->write($gu)); //Updated value between 3.9 and 3.11 + $this->assertEqualsAny(array('MULTILINESTRING ((0 0, 1 0), (1 0, 1 1, 0 1), (0 1, 0 0), (10 10, 10 11), (10 11, 10 14, 14 14, 14 10, 11 10), (11 10, 10 10), (11 11, 11 12, 12 12, 12 11, 11 11), (1 0, 11 0, 11 10), (11 10, 11 11), (11 11, 10 11), (10 11, 0 11, 0 1))', 'MULTILINESTRING ((0 0, 1 0), (1 0, 1 1, 0 1), (0 1, 0 0), (1 0, 11 0, 11 10), (11 10, 11 11), (11 11, 10 11), (10 11, 0 11, 0 1), (11 11, 11 12, 12 12, 12 11, 11 11), (10 10, 10 11), (10 11, 10 14, 14 14, 14 10, 11 10), (11 10, 10 10))', 'MULTILINESTRING ((0 1, 0 0), (0 0, 1 0), (10 11, 0 11, 0 1), (1 0, 1 1, 0 1), (1 0, 11 0, 11 10), (10 10, 10 11), (11 10, 10 10), (10 11, 10 14, 14 14, 14 10, 11 10), (11 11, 10 11), (11 10, 11 11), (11 11, 11 12, 12 12, 12 11, 11 11))'), $writer->write($gu)); //Updated value twice between 3.9 and 3.11 $g = $reader->read('MULTIPOINT( 0 0, 1 0, 1 1, 0 1, 0 0, @@ -688,7 +688,8 @@ class GeometryTest extends GEOSTest ))'); $gu = $g->union(); - $this->assertEquals(GEOS_CORRECT_VALUE ? 'GEOMETRYCOLLECTION (POINT (-10 -10), POLYGON ((0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0, 0 0), (11 11, 12 11, 12 12, 11 12, 11 11)), LINESTRING (-8 8, -8 6))' : 'GEOMETRYCOLLECTION (POINT (-10 -10), LINESTRING (-8 8, -8 6), POLYGON ((1 0, 0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0), (11 12, 11 11, 12 11, 12 12, 11 12)))', $writer->write($gu)); //Updated value between 3.9 and 3.11 + + $this->assertEqualsAny(array('GEOMETRYCOLLECTION (POINT (-10 -10), POLYGON ((0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0, 0 0), (11 11, 12 11, 12 12, 11 12, 11 11)), LINESTRING (-8 8, -8 6))', 'GEOMETRYCOLLECTION (POINT (-10 -10), LINESTRING (-8 8, -8 6), POLYGON ((1 0, 0 0, 0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0), (11 12, 11 11, 12 11, 12 12, 11 12)))', 'GEOMETRYCOLLECTION (POINT (-10 -10), POLYGON ((0 1, 0 11, 10 11, 10 14, 14 14, 14 10, 11 10, 11 0, 1 0, 0 0, 0 1), (11 11, 12 11, 12 12, 11 12, 11 11)), LINESTRING (-8 8, -8 6))'), $writer->write($gu)); //Updated value twice between 3.9 and 3.11 } public function testGeometry_pointOnSurface() diff --git a/tests/TestHelper.php b/tests/TestHelper.php index fa8fb48..fcb6c21 100644 --- a/tests/TestHelper.php +++ b/tests/TestHelper.php @@ -97,6 +97,17 @@ public function assertEquals($expected, $actual) } } + public function assertEqualsAny($expectedValues, $actual) + { + foreach ($expectedValues as $expected) { + if ($actual == $expected) { + // If a match is found, return early without throwing an exception + return; + } + } + throw new Exception("Expected '{$expected}' to contain '{$actual}'."); + } + public function assertNull($actual) { if (!is_null($actual)) { diff --git a/tests/geos_version_test.php b/tests/geos_version_test.php index d6606e6..88000d5 100644 --- a/tests/geos_version_test.php +++ b/tests/geos_version_test.php @@ -6,7 +6,7 @@ define('GEOS_CHANGE_VALUE', version_compare(GEOS_VERSION, '3.12', '>=')); define('GEOS_CORRECT_NEGATIVE_ZERO', version_compare(GEOS_VERSION, '3.12', '>=')); // Update since 3.12.1 see: https://github.com/libgeos/geos/blob/ddba88a37bd8edb0acc08c9753a1a0e28de3baee/tests/unit/capi/GEOSEqualsIdenticalTest.cpp#L203 define('GEOS_CORRECT_VALUE', version_compare(GEOS_VERSION, '3.11', '>=')); -define('GEOS_DEFAULT_EMPTY', version_compare(GEOS_VERSION, '3.11', '>=')); // The bad mix appears to be with GEOS 3.10 and POLYGON EMPTY GH-501 +define('GEOS_DEFAULT_EMPTY', version_compare(GEOS_VERSION, '3.9', '>=')); // The bad mix appears to be with GEOS 3.10 and POLYGON EMPTY GH-501 //turn trim on(true), see : https://github.com/libgeos/geos/pull/915 function getGeosVersion()