diff --git a/tests/001_Geometry.phpt b/tests/001_Geometry.phpt index 5715348..e6a93c2 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_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('POLYGON ((10 0, 0 -10, -10 -0, -0 10, 10 0))', $writer->write($b)); + $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, 109 -5, 105 -9, 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('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)' : (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 (110 100, 110 0, 100 -10, 0 -10)', $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 (110 100, 110 -10, 0 -10)', $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 (110 100, 109 -5, 105 -9, 0 -10)', $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( 'GEOMETRYCOLLECTION 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( 'GEOMETRYCOLLECTION 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( 'GEOMETRYCOLLECTION 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('GEOMETRYCOLLECTION 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 ((5 0, 0 0, 0 10, 5 10, 10 10, 10 0, 5 0))', $writer->write($gi)); + $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('POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0))', $writer->write($gi)); + $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('POLYGON ((5 0, 0 0, 0 10, 10 10, 10 5, 5 5, 5 0))', $writer->write($gi)); + $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() @@ -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(GEOS_DEFAULT_EMPTY ? 'POINT EMPTY' : 'GEOMETRYCOLLECTION EMPTY', $writer->write($gi)); //GH-501 $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)'); @@ -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('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->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('GEOMETRYCOLLECTION (LINESTRING (10 0, 20 0), POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0)))', $writer->write($gi)); + $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('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->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() @@ -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)'); @@ -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('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->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('GEOMETRYCOLLECTION (LINESTRING (10 0, 20 0), POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0)))', $writer->write($gi)); + $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('POLYGON ((5 0, 0 0, 0 10, 10 10, 10 5, 15 5, 15 -5, 5 -5, 5 0))', $writer->write($gi)); + $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() @@ -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->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('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->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, @@ -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,8 @@ 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->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() @@ -818,7 +819,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 +961,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 +1207,10 @@ class GeometryTest extends GEOSTest public function testGeometry_checkValidity() { + + + + if (!method_exists("GEOSGeometry", 'checkValidity')) { return; } @@ -1228,12 +1233,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 +1251,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); diff --git a/tests/002_WKTWriter.phpt b/tests/002_WKTWriter.phpt index 3682a3a..fea4170 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,10 +98,11 @@ 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->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)); @@ -122,7 +124,7 @@ class WKTWriterTest extends GEOSTest } $writer = new GEOSWKTWriter(); - $this->assertEquals(2, $writer->getOutputDimension()); + $this->assertEquals(GEOS_WKB_DEFAULT_DIMENSIONS, $writer->getOutputDimension()); } public function testWKTWriter_setOutputDimension() @@ -138,8 +140,8 @@ class WKTWriterTest extends GEOSTest $writer = new GEOSWKTWriter(); $writer->setTrim(TRUE); - # Only 2d by default - $this->assertEquals('POINT (1 2)', $writer->write($g3d)); + + $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); @@ -151,13 +153,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_WKB_DEFAULT_DIMENSIONS === 4) ? '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()); } diff --git a/tests/004_WKBWriter.phpt b/tests/004_WKBWriter.phpt index 3c13644..b240490 100644 --- a/tests/004_WKBWriter.phpt +++ b/tests/004_WKBWriter.phpt @@ -6,6 +6,7 @@ WKBWriter tests assertEquals(2, $writer->getOutputDimension()); + $this->assertEquals(GEOS_WKB_DEFAULT_DIMENSIONS, $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_WKB_DEFAULT_DIMENSIONS === 4) ? '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()); } diff --git a/tests/005_WKBReader.phpt b/tests/005_WKBReader.phpt index 7b24994..177444d 100644 --- a/tests/005_WKBReader.phpt +++ b/tests/005_WKBReader.phpt @@ -6,7 +6,8 @@ WKBReader tests read(hex2bin($wkb)); $this->assertEquals($wkt, $writer->write($geometry)); $this->assertEquals($srid, $geometry->getSRID()); + } } @@ -37,8 +39,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 +55,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(); 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 new file mode 100644 index 0000000..88000d5 --- /dev/null +++ b/tests/geos_version_test.php @@ -0,0 +1,23 @@ +=')); // GH-903 +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.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() +{ + // 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; + } +}