From 320109b524f94601cca229f58b303b67e304fa0d Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Sat, 6 Nov 2021 20:10:29 +0100 Subject: [PATCH] Remove global GeometryEngine --- CHANGELOG.md | 75 +++++ README.md | 16 +- phpunit-bootstrap.php | 3 +- src/Curve.php | 45 --- src/Engine/DatabaseEngine.php | 4 +- src/Engine/GEOSEngine.php | 4 +- src/Engine/GeometryEngine.php | 89 ++++-- src/Engine/GeometryEngineRegistry.php | 45 --- src/Geometry.php | 387 -------------------------- src/MultiCurve.php | 30 -- src/MultiSurface.php | 29 -- src/Point.php | 19 -- src/PolyhedralSurface.php | 27 -- src/Proxy/PointProxy.php | 9 - src/Surface.php | 32 +-- tests/AbstractTestCase.php | 25 +- tests/CurveTest.php | 15 +- tests/GeometryTest.php | 114 ++++---- tests/MultiCurveTest.php | 9 +- tests/MultiSurfaceTest.php | 14 +- tests/PointTest.php | 4 +- tests/SurfaceTest.php | 14 +- 22 files changed, 253 insertions(+), 756 deletions(-) delete mode 100644 src/Engine/GeometryEngineRegistry.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 3eab274..02659fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,80 @@ # Changelog +## Unreleased + +💥 **Breaking changes** + +The global `GeometryEngineRegistry`, as well as convenience methods on Geometry classes, are gone. +You should now explicitly call the `GeometryEngine`, that you can get injected with your dependency injection container. + +For example, the following call: + +```php +$lineString->length(); +``` + +Should be replaced with: + +```php +$geometryEngine->length($lineString); +``` + +**Detail of breaking changes** + +The following class has been removed: + +- `GeometryEngineRegistry` + +The following method has been added: + +- `GeometryEngine::isRing()` + +The following method signatures have been changed: + +- `GeometryEngine::boundingPolygons()` + +The following methods have been removed: + +- `Curve::isClosed()` +- `Curve::isRing()` +- `Curve::length()` +- `Geometry::boundary()` +- `Geometry::buffer()` +- `Geometry::centroid()` +- `Geometry::contains()` +- `Geometry::convexHull()` +- `Geometry::crosses()` +- `Geometry::difference()` +- `Geometry::disjoint()` +- `Geometry::distance()` +- `Geometry::equals()` +- `Geometry::envelope()` +- `Geometry::intersection()` +- `Geometry::intersects()` +- `Geometry::isSimple()` +- `Geometry::isValid()` +- `Geometry::locateAlong()` +- `Geometry::locateBetween()` +- `Geometry::maxDistance()` +- `Geometry::overlaps()` +- `Geometry::relate()` +- `Geometry::simplify()` +- `Geometry::snapToGrid()` +- `Geometry::symDifference()` +- `Geometry::touches()` +- `Geometry::transform()` +- `Geometry::union()` +- `Geometry::within()` +- `MultiCurve::isClosed()` +- `MultiCurve::length()` +- `MultiSurface::area()` +- `MultiSurface::pointOnSurface()` +- `Point::azimuth()` +- `PolyhedralSurface::boundingPolygons()` +- `PolyhedralSurface::isClosed()` +- `Surface::area()` +- `Surface::pointOnSurface()` + ## [0.7.1](https://github.com/brick/geo/releases/tag/0.7.1) - 2021-11-06 🐛 **Fixes** diff --git a/README.md b/README.md index 464e5e2..ed4fc91 100644 --- a/README.md +++ b/README.md @@ -77,11 +77,10 @@ Following is a step-by-step guide for all possible configurations: - Use this bootstrap code in your project: ```php - use Brick\Geo\Engine\GeometryEngineRegistry; use Brick\Geo\Engine\PDOEngine; $pdo = new PDO('mysql:host=localhost', 'root', ''); - GeometryEngineRegistry::set(new PDOEngine($pdo)); + $geometryEngine = new PDOEngine($pdo); ``` Update the code with your own connection parameters, or use an existing `PDO` connection if you have one (recommended). @@ -109,11 +108,10 @@ Just ensure that your MariaDB version is `5.5` or greater. - Use this bootstrap code in your project: ```php - use Brick\Geo\Engine\GeometryEngineRegistry; use Brick\Geo\Engine\PDOEngine; $pdo = new PDO('pgsql:host=localhost', 'postgres', ''); - GeometryEngineRegistry::set(new PDOEngine($pdo)); + $geometryEngine = new PDOEngine($pdo); ``` Update the code with your own connection parameters, or use an existing `PDO` connection if you have one (recommended). @@ -149,12 +147,11 @@ all you need to do is create an additional in-memory SQLite3 database just to po - Use this bootstrap code in your project: ```php - use Brick\Geo\Engine\GeometryEngineRegistry; use Brick\Geo\Engine\SQLite3Engine; $sqlite3 = new SQLite3(':memory:'); $sqlite3->loadExtension('mod_spatialite.so'); - GeometryEngineRegistry::set(new SQLite3Engine($sqlite3)); + $geometryEngine = new SQLite3Engine($sqlite3); ``` - Depending on the functions you use, you will probably need to initialize the spatial metadata by running this query: @@ -181,10 +178,9 @@ In this example we have created an in-memory database for our GIS calculations, - Use this bootstrap code in your project: ```php - use Brick\Geo\Engine\GeometryEngineRegistry; use Brick\Geo\Engine\GEOSEngine; - GeometryEngineRegistry::set(new GEOSEngine()); + $geometryEngine = new GEOSEngine(); ``` @@ -238,9 +234,9 @@ Example use Brick\Geo\Polygon; $polygon = Polygon::fromText('POLYGON ((0 0, 0 3, 3 3, 0 0))'); -echo $polygon->area(); // 4.5 +echo $geometryEngine->area($polygon); // 4.5 -$centroid = $polygon->centroid(); +$centroid = $geometryEngine->centroid($polygon); echo $centroid->asText(); // POINT (1 2) ``` diff --git a/phpunit-bootstrap.php b/phpunit-bootstrap.php index 5de80d3..55fa914 100644 --- a/phpunit-bootstrap.php +++ b/phpunit-bootstrap.php @@ -1,6 +1,5 @@ length($this); - } - /** * Returns the start Point of this Curve. * @@ -50,35 +36,4 @@ abstract public function startPoint() : Point; * @throws EmptyGeometryException If the curve is empty. */ abstract public function endPoint() : Point; - - /** - * Returns whether this Curve is closed. - * - * The curve is closed if `startPoint()` == `endPoint()`. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function isClosed() : bool - { - return GeometryEngineRegistry::get()->isClosed($this); - } - - /** - * Returns whether this Curve is a ring. - * - * The curve is a ring if it is both closed and simple. - * - * The curve is closed if its start point is equal to its end point. - * The curve is simple if it does not pass through the same point more than once. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function isRing() : bool - { - return $this->isClosed() && $this->isSimple(); - } } diff --git a/src/Engine/DatabaseEngine.php b/src/Engine/DatabaseEngine.php index d08a31b..82c818e 100644 --- a/src/Engine/DatabaseEngine.php +++ b/src/Engine/DatabaseEngine.php @@ -7,7 +7,9 @@ use Brick\Geo\Curve; use Brick\Geo\Exception\GeometryEngineException; use Brick\Geo\Geometry; +use Brick\Geo\MultiPolygon; use Brick\Geo\Point; +use Brick\Geo\Polygon; use Brick\Geo\Proxy; /** @@ -422,7 +424,7 @@ public function maxDistance(Geometry $a, Geometry $b) : float return $this->queryFloat('ST_MaxDistance', $a, $b); } - public function boundingPolygons(Geometry $g) : Geometry + public function boundingPolygons(Polygon $p) : MultiPolygon { throw GeometryEngineException::unimplementedMethod(__METHOD__); } diff --git a/src/Engine/GEOSEngine.php b/src/Engine/GEOSEngine.php index 994d37a..6eb3fb4 100644 --- a/src/Engine/GEOSEngine.php +++ b/src/Engine/GEOSEngine.php @@ -9,7 +9,9 @@ use Brick\Geo\IO\EWKBReader; use Brick\Geo\IO\EWKBWriter; use Brick\Geo\Geometry; +use Brick\Geo\MultiPolygon; use Brick\Geo\Point; +use Brick\Geo\Polygon; use GEOSWKBReader; use GEOSWKBWriter; use GEOSWKTReader; @@ -358,7 +360,7 @@ public function maxDistance(Geometry $a, Geometry $b) : float throw GeometryEngineException::unimplementedMethod(__METHOD__); } - public function boundingPolygons(Geometry $g) : Geometry + public function boundingPolygons(Polygon $p) : MultiPolygon { throw GeometryEngineException::unimplementedMethod(__METHOD__); } diff --git a/src/Engine/GeometryEngine.php b/src/Engine/GeometryEngine.php index f2c58b8..b8c4f6f 100644 --- a/src/Engine/GeometryEngine.php +++ b/src/Engine/GeometryEngine.php @@ -8,8 +8,10 @@ use Brick\Geo\Geometry; use Brick\Geo\Exception\GeometryEngineException; use Brick\Geo\MultiCurve; +use Brick\Geo\MultiPolygon; use Brick\Geo\MultiSurface; use Brick\Geo\Point; +use Brick\Geo\Polygon; use Brick\Geo\Surface; /** @@ -18,7 +20,7 @@ interface GeometryEngine { /** - * Returns a geometry that represents the point set union of the geometries. + * Returns a geometry that represents the union of the geometries. * * @param Geometry $a The first geometry. * @param Geometry $b The second geometry. @@ -44,6 +46,13 @@ public function difference(Geometry $a, Geometry $b) : Geometry; /** * Returns a geometry representing the bounding box of the supplied geometry. * + * The polygon is defined by the corner points of the bounding box + * [(MINX, MINY), (MAXX, MINY), (MAXX, MAXY), (MINX, MAXY), (MINX, MINY)]. + * Minimums for Z and M may be added. The simplest representation of an Envelope + * is as two direct positions, one containing all the minimums, and another all + * the maximums. In some cases, this coordinate will be outside the range of + * validity for the Spatial Reference System. + * * @param Geometry $g The geometry. * * @return Geometry The envelope of the geometry. @@ -55,6 +64,8 @@ public function envelope(Geometry $g) : Geometry; /** * Returns the length of a Curve or MultiCurve in its associated spatial reference. * + * The length of a MultiCurve is equal to the sum of the lengths of the element Curves. + * * @param Curve|MultiCurve $g The geometry. * * @return float The length of the geometry. @@ -90,7 +101,7 @@ public function area(Geometry $g) : float; public function azimuth(Point $observer, Point $subject) : float; /** - * Returns the geometric center of a Geometry. + * Returns the geometric center of a geometry, or equivalently, the center of mass of the geometry as a Point. * * @param Geometry $g The geometry. * @@ -114,6 +125,9 @@ public function pointOnSurface(Geometry $g) : Geometry; /** * Returns the closure of the combinatorial boundary of a Geometry. * + * Because the result of this function is a closure, and hence topologically closed, + * the resulting boundary can be represented using representational Geometry primitives. + * * @param Geometry $g The geometry. * * @return Geometry The boundary of the geometry. @@ -123,7 +137,7 @@ public function pointOnSurface(Geometry $g) : Geometry; public function boundary(Geometry $g) : Geometry; /** - * Checks whether a geometry is valid, as defined by the OGC specification. + * Returns true if the geometry is valid, as defined by the OGC specification. * * For example, a polygon with self-intersecting rings is invalid. * @@ -138,6 +152,9 @@ public function isValid(Geometry $g) : bool; /** * Returns true if the geometry is closed. * + * A Curve is closed if its start point is equal to its end point. + * A MultiCurve is considered closed if each element curve is closed. + * * @param Geometry $g The geometry. * * @return bool Whether the geometry is closed. @@ -172,7 +189,7 @@ public function isSimple(Geometry $g) : bool; public function isRing(Curve $curve) : bool; /** - * Returns true if the given geometries represent the same geometry. + * Returns true if the given geometries are spatially equal. * * @param Geometry $a The first geometry. * @param Geometry $b The second geometry. @@ -184,9 +201,10 @@ public function isRing(Curve $curve) : bool; public function equals(Geometry $a, Geometry $b) : bool; /** - * Returns true if the given geometries do not spatially intersect. + * Returns true if the given geometries are spatially disjoint. * - * Geometries spatially intersect if they share any portion of space. + * The geometries are disjoint if they do not share any space together. + * This is the opposite of `intersects()`. * * @param Geometry $a The first geometry. * @param Geometry $b The second geometry. @@ -201,6 +219,7 @@ public function disjoint(Geometry $a, Geometry $b) : bool; * Returns true if the given geometries spatially intersect. * * Geometries spatially intersect if they share any portion of space. + * This is the opposite of `disjoint()`. * * @param Geometry $a The first geometry. * @param Geometry $b The second geometry. @@ -212,7 +231,9 @@ public function disjoint(Geometry $a, Geometry $b) : bool; public function intersects(Geometry $a, Geometry $b) : bool; /** - * Returns true if the geometries have at least one point in common, but their interiors do not intersect. + * Returns true if the geometries spatially touch each other. + * + * The geometries touch if they have at least one point in common, but their interiors do not intersect. * * @param Geometry $a The first geometry. * @param Geometry $b The second geometry. @@ -224,7 +245,9 @@ public function intersects(Geometry $a, Geometry $b) : bool; public function touches(Geometry $a, Geometry $b) : bool; /** - * Returns true if the supplied geometries have some, but not all, interior points in common. + * Returns true if the supplied geometries spatially cross each other. + * + * The geometries cross if they have some, but not all, interior points in common. * * @param Geometry $a The first geometry. * @param Geometry $b The second geometry. @@ -238,6 +261,8 @@ public function crosses(Geometry $a, Geometry $b) : bool; /** * Returns true if the geometry $a is completely inside geometry $b. * + * This is the inverse of `contains()`: `within($a, $b) == contains($b, $a)`. + * * @param Geometry $a The first geometry. * @param Geometry $b The second geometry. * @@ -248,11 +273,13 @@ public function crosses(Geometry $a, Geometry $b) : bool; public function within(Geometry $a, Geometry $b) : bool; /** - * Returns true if `$a` contains `$b`. + * Returns true if `$a` spatially contains `$b`. * * `$a` contains `$b` if and only if no points of `$b` lie in the exterior of `$a`, * and at least one point of the interior of `$b` lies in the interior of `$a`. * + * This is the inverse of `within()`: `$a->contains($b) == $b->within($a)`. + * * @param Geometry $a The first geometry. * @param Geometry $b The second geometry. * @@ -263,7 +290,7 @@ public function within(Geometry $a, Geometry $b) : bool; public function contains(Geometry $a, Geometry $b) : bool; /** - * Returns true if the two geometries overlap. + * Returns true if the two geometries spatially overlap. * * The geometries overlap if they share space, are of the same dimension, * but are not completely contained by each other. @@ -280,8 +307,12 @@ public function overlaps(Geometry $a, Geometry $b) : bool; /** * Returns true if `$a` is spatially related to `$b`. * - * Tests for intersections between the Interior, Boundary and Exterior - * of the two geometries as specified by the values in the intersectionMatrixPattern. + * This method tests for intersections between the interior, boundary and exterior of the + * two geometries as specified by the values in the DE-9IM matrix pattern. + * + * This is especially useful for testing compound checks of intersection, crosses, etc. in one step. + * + * @see http://en.wikipedia.org/wiki/DE-9IM * * @param Geometry $a The first geometry. * @param Geometry $b The second geometry. @@ -319,9 +350,13 @@ public function locateAlong(Geometry $g, float $mValue) : Geometry; public function locateBetween(Geometry $g, float $mStart, float $mEnd) : Geometry; /** - * Returns the 2-dimensional cartesian minimum distance between two geometries in projected units. + * Returns the shortest distance between any two points in the two geometries. * - * The distance is based on spatial ref. + * The distance is calculated in the spatial reference system of + * this geometry. Because the geometries are closed, it is + * possible to find a point on each geometry involved, such + * that the distance between these 2 points is the returned distance + * between their geometries. * * @param Geometry $a The first geometry. * @param Geometry $b The second geometry. @@ -335,6 +370,11 @@ public function distance(Geometry $a, Geometry $b) : float; /** * Returns a geometry that represents all points whose distance from this Geometry is <= distance. * + * Calculations are in the spatial reference system of this geometry. + * Because of the limitations of linear interpolation, there will often be + * some relatively small error in this distance, but it should be near the + * resolution of the coordinates used. + * * @param Geometry $g The geometry. * @param float $distance The buffer distance. * @@ -345,7 +385,11 @@ public function distance(Geometry $a, Geometry $b) : float; public function buffer(Geometry $g, float $distance) : Geometry; /** - * Returns the minimum convex geometry that encloses all geometries within the set. + * Returns a geometry that represents the convex hull of this geometry. + * + * The convex hull of a geometry represents the minimum convex geometry that encloses all geometries within the set. + * One can think of the convex hull as the geometry you get by wrapping an elastic band around a set of geometries. + * This is different from a concave hull which is analogous to shrink-wrapping your geometries. * * @param Geometry $g The geometry. * @@ -356,7 +400,7 @@ public function buffer(Geometry $g, float $distance) : Geometry; public function convexHull(Geometry $g) : Geometry; /** - * Returns a geometry that represents the shared portion of `$a` and `$b`. + * Returns a geometry that represents the shared portion of the given geometries. * * @param Geometry $a The first geometry. * @param Geometry $b The second geometry. @@ -368,7 +412,10 @@ public function convexHull(Geometry $g) : Geometry; public function intersection(Geometry $a, Geometry $b) : Geometry; /** - * Returns a geometry that represents the portions of `$a` and `$b` that do not intersect. + * Returns a geometry that represents the symmetric difference of the given geometries. + * + * The result is a geometry that represents the portions of the two geometries that do not intersect. + * It is called a symmetric difference because `$a->symDifference($b) == $b->symDifference($a)`. * * @param Geometry $a The first geometry. * @param Geometry $b The second geometry. @@ -392,7 +439,7 @@ public function symDifference(Geometry $a, Geometry $b) : Geometry; public function snapToGrid(Geometry $g, float $size) : Geometry; /** - * Returns a "simplified" version of the given geometry using the Douglas-Peucker algorithm. + * Returns a simplified version of the given geometry using the Douglas-Peucker algorithm. * * @param Geometry $g The geometry. * @param float $tolerance The tolerance. @@ -418,13 +465,13 @@ public function maxDistance(Geometry $a, Geometry $b) : float; /** * Returns the collection of polygons that bounds the given polygon 'p' for any polygon 'p' in the surface. * - * @param Geometry $g + * @param Polygon $p * - * @return Geometry + * @return MultiPolygon * * @throws GeometryEngineException If the operation is not supported by the engine. */ - public function boundingPolygons(Geometry $g) : Geometry; + public function boundingPolygons(Polygon $p) : MultiPolygon; /** * Returns a new geometry with its coordinates transformed to a different spatial reference system. diff --git a/src/Engine/GeometryEngineRegistry.php b/src/Engine/GeometryEngineRegistry.php deleted file mode 100644 index c3b09ec..0000000 --- a/src/Engine/GeometryEngineRegistry.php +++ /dev/null @@ -1,45 +0,0 @@ -coordinateSystem->SRID(); } - /** - * Returns the minimum bounding box for this Geometry. - * - * The polygon is defined by the corner points of the bounding box - * [(MINX, MINY), (MAXX, MINY), (MAXX, MAXY), (MINX, MAXY), (MINX, MINY)]. - * Minimums for Z and M may be added. The simplest representation of an Envelope - * is as two direct positions, one containing all the minimums, and another all - * the maximums. In some cases, this coordinate will be outside the range of - * validity for the Spatial Reference System. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function envelope() : Geometry - { - return GeometryEngineRegistry::get()->envelope($this); - } - /** * Returns the WKT representation of this geometry. * @@ -243,35 +222,6 @@ public function isEmpty() : bool return $this->isEmpty; } - /** - * Returns whether this geometry is valid, as defined by the OGC specification. - * - * For example, a polygon with self-intersecting rings is invalid. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function isValid() : bool - { - return GeometryEngineRegistry::get()->isValid($this); - } - - /** - * Returns whether this Geometry is simple. - * - * A geometry is simple if it has no anomalous geometric points, - * such as self intersection or self tangency. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function isSimple() : bool - { - return GeometryEngineRegistry::get()->isSimple($this); - } - /** * Returns whether this geometry has z coordinate values. */ @@ -288,343 +238,6 @@ public function isMeasured() : bool return $this->coordinateSystem->hasM(); } - /** - * Returns the closure of the combinatorial boundary of this geometry. - * - * Because the result of this function is a closure, and hence topologically closed, - * the resulting boundary can be represented using representational Geometry primitives. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function boundary() : Geometry - { - return GeometryEngineRegistry::get()->boundary($this); - } - - /** - * Returns the geometric center of a geometry, or equivalently, the center of mass of the geometry as a Point. - * - * Some geometry engines only support this method on surfaces. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function centroid() : Point - { - return GeometryEngineRegistry::get()->centroid($this); - } - - /** - * Returns whether this geometry is spatially equal to another geometry. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function equals(Geometry $geometry) : bool - { - return GeometryEngineRegistry::get()->equals($this, $geometry); - } - - /** - * Returns whether this geometry is spatially disjoint from another geometry. - * - * The geometries are disjoint if they do not share any space together. - * This is the opposite of `intersects()`. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function disjoint(Geometry $geometry) : bool - { - return GeometryEngineRegistry::get()->disjoint($this, $geometry); - } - - /** - * Returns whether this geometry spatially intersects another geometry. - * - * The geometries intersect if they share any portion of space. - * This is the opposite of `disjoint()`. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function intersects(Geometry $geometry) : bool - { - return GeometryEngineRegistry::get()->intersects($this, $geometry); - } - - /** - * Returns whether this geometry spatially touches another geometry. - * - * The geometries touch if they have at least one point in common, but their interiors do not intersect. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function touches(Geometry $geometry) : bool - { - return GeometryEngineRegistry::get()->touches($this, $geometry); - } - - /** - * Returns whether this geometry spatially crosses another geometry. - * - * The geometries cross if they have some, but not all, interior points in common. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function crosses(Geometry $geometry) : bool - { - return GeometryEngineRegistry::get()->crosses($this, $geometry); - } - - /** - * Returns whether this geometry is spatially within another geometry. - * - * This is the inverse of `contains()`: `$a->within($b) == $b->contains($a)`. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function within(Geometry $geometry) : bool - { - return GeometryEngineRegistry::get()->within($this, $geometry); - } - - /** - * Returns whether this geometry spatially contains another geometry. - * - * This is the inverse of `within()`: `$a->contains($b) == $b->within($a)`. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function contains(Geometry $geometry) : bool - { - return GeometryEngineRegistry::get()->contains($this, $geometry); - } - - /** - * Returns whether this geometry spatially overlaps another geometry. - * - * The geometries overlap if they share space, but are not completely contained by each other. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function overlaps(Geometry $geometry) : bool - { - return GeometryEngineRegistry::get()->overlaps($this, $geometry); - } - - /** - * Returns whether this geometry is spatially related to another geometry. - * - * This method tests for intersections between the interior, boundary and exterior of the - * two geometries as specified by the values in the DE-9IM matrix pattern. - * - * This is especially useful for testing compound checks of intersection, crosses, etc. in one step. - * - * @see http://en.wikipedia.org/wiki/DE-9IM - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function relate(Geometry $geometry, string $matrix) : bool - { - return GeometryEngineRegistry::get()->relate($this, $geometry, $matrix); - } - - /** - * Returns a derived geometry collection value that matches the specified m coordinate value. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function locateAlong(float $mValue) : Geometry - { - return GeometryEngineRegistry::get()->locateAlong($this, $mValue); - } - - /** - * Returns a derived geometry collection value that matches the specified range of m coordinate values inclusively. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function locateBetween(float $mStart, float $mEnd) : Geometry - { - return GeometryEngineRegistry::get()->locateBetween($this, $mStart, $mEnd); - } - - /** - * Returns the shortest distance between any two points in the two geometries. - * - * The distance is calculated in the spatial reference system of - * this geometry. Because the geometries are closed, it is - * possible to find a point on each geometry involved, such - * that the distance between these 2 points is the returned distance - * between their geometries. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function distance(Geometry $geometry) : float - { - return GeometryEngineRegistry::get()->distance($this, $geometry); - } - - /** - * Returns a geometry that represents all points whose distance - * from this geometry is less than or equal to distance. - * - * Calculations are in the spatial reference system of this geometry. - * Because of the limitations of linear interpolation, there will often be - * some relatively small error in this distance, but it should be near the - * resolution of the coordinates used. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function buffer(float $distance) : Geometry - { - return GeometryEngineRegistry::get()->buffer($this, $distance); - } - - /** - * Returns a geometry that represents the convex hull of this geometry. - * - * The convex hull of a geometry represents the minimum convex geometry that encloses all geometries within the set. - * One can think of the convex hull as the geometry you get by wrapping an elastic band around a set of geometries. - * This is different from a concave hull which is analogous to shrink-wrapping your geometries. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function convexHull() : Geometry - { - return GeometryEngineRegistry::get()->convexHull($this); - } - - /** - * Returns a geometry that represents the intersection of this geometry and another geometry. - * - * The intersection is the shared portion of the two geometries. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function intersection(Geometry $geometry) : Geometry - { - return GeometryEngineRegistry::get()->intersection($this, $geometry); - } - - /** - * Returns a geometry that represents the union of this geometry and another geometry. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function union(Geometry $geometry) : Geometry - { - return GeometryEngineRegistry::get()->union($this, $geometry); - } - - /** - * Returns a geometry that represents the difference of this geometry and another geometry. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function difference(Geometry $geometry) : Geometry - { - return GeometryEngineRegistry::get()->difference($this, $geometry); - } - - /** - * Returns a geometry that represents the symmetric difference of this geometry and another geometry. - * - * The result is a geometry that represents the portions of the two geometries that do not intersect. - * It is called a symmetric difference because `$a->symDifference($b) == $b->symDifference($a)`. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function symDifference(Geometry $geometry) : Geometry - { - return GeometryEngineRegistry::get()->symDifference($this, $geometry); - } - - /** - * Snap all points of this geometry to a regular grid. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function snapToGrid(float $size) : Geometry - { - return GeometryEngineRegistry::get()->snapToGrid($this, $size); - } - - /** - * Returns a simplified version of this geometry using the Douglas-Peucker algorithm. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function simplify(float $tolerance) : Geometry - { - return GeometryEngineRegistry::get()->simplify($this, $tolerance); - } - - /** - * Returns the 2-dimensional largest distance between two geometries in projected units. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function maxDistance(Geometry $geometry) : float - { - return GeometryEngineRegistry::get()->maxDistance($this, $geometry); - } - - /** - * Returns a new geometry with its coordinates transformed to a different spatial reference system. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function transform(int $srid) : Geometry - { - return GeometryEngineRegistry::get()->transform($this, $srid); - } - /** * Returns the coordinate system of this geometry. */ diff --git a/src/MultiCurve.php b/src/MultiCurve.php index 4caff1f..54ea57d 100644 --- a/src/MultiCurve.php +++ b/src/MultiCurve.php @@ -4,9 +4,6 @@ namespace Brick\Geo; -use Brick\Geo\Engine\GeometryEngineRegistry; -use Brick\Geo\Exception\GeometryEngineException; - /** * A MultiCurve is a 1-dimensional GeometryCollection whose elements are Curves. * @@ -28,31 +25,4 @@ */ abstract class MultiCurve extends GeometryCollection { - /** - * Returns whether this MultiCurve is closed. - * - * The MultiCurve is considered closed if each element curve is closed. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function isClosed() : bool - { - return GeometryEngineRegistry::get()->isClosed($this); - } - - /** - * Returns the length of this MultiCurve. - * - * The length is equal to the sum of the lengths of the element Curves. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function length() : float - { - return GeometryEngineRegistry::get()->length($this); - } } diff --git a/src/MultiSurface.php b/src/MultiSurface.php index 1430395..ce00611 100644 --- a/src/MultiSurface.php +++ b/src/MultiSurface.php @@ -4,9 +4,6 @@ namespace Brick\Geo; -use Brick\Geo\Engine\GeometryEngineRegistry; -use Brick\Geo\Exception\GeometryEngineException; - /** * A MultiSurface is a 2-dimensional GeometryCollection whose elements are Surfaces. * @@ -25,30 +22,4 @@ */ abstract class MultiSurface extends GeometryCollection { - /** - * Returns the area of this MultiSurface, as measured in the spatial reference system of this MultiSurface. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function area() : float - { - return GeometryEngineRegistry::get()->area($this); - } - - /** - * Returns a Point guaranteed to be on this MultiSurface. - * - * @noproxy - * - * @psalm-suppress LessSpecificReturnStatement - * @psalm-suppress MoreSpecificReturnType - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function pointOnSurface() : Point - { - return GeometryEngineRegistry::get()->pointOnSurface($this); - } } diff --git a/src/Point.php b/src/Point.php index eedd3f3..a0f4906 100644 --- a/src/Point.php +++ b/src/Point.php @@ -5,8 +5,6 @@ namespace Brick\Geo; use ArrayIterator; -use Brick\Geo\Engine\GeometryEngineRegistry; -use Brick\Geo\Exception\GeometryEngineException; use Brick\Geo\Exception\InvalidGeometryException; /** @@ -332,21 +330,4 @@ public function getIterator() : ArrayIterator { return new ArrayIterator($this->toArray()); } - - /** - * Returns the azimuth in radians of the segment defined by the given point geometries. - * The azimuth is an angle measured from the north, and is positive clockwise: - * North = 0; East = π/2; South = π; West = 3π/2. - * - * @param Point $subject Point representing subject of observation. - * - * @return float Azimuth of the subject relative to the observer. - * - * @throws GeometryEngineException If the operation is not supported by the engine. - * @throws GeometryEngineException If observer and subject locations are coincident. - */ - public function azimuth(Point $subject) : float - { - return GeometryEngineRegistry::get()->azimuth($this, $subject); - } } diff --git a/src/PolyhedralSurface.php b/src/PolyhedralSurface.php index 69245e4..477d00c 100644 --- a/src/PolyhedralSurface.php +++ b/src/PolyhedralSurface.php @@ -5,8 +5,6 @@ namespace Brick\Geo; use ArrayIterator; -use Brick\Geo\Engine\GeometryEngineRegistry; -use Brick\Geo\Exception\GeometryEngineException; use Brick\Geo\Exception\CoordinateSystemException; use Brick\Geo\Exception\NoSuchGeometryException; @@ -110,31 +108,6 @@ public function patches() : array return $this->patches; } - /** - * Returns the collection of polygons in this surface that bounds the given polygon 'p' for any polygon 'p' in the surface. - * - * @noproxy - * - * @psalm-suppress LessSpecificReturnStatement - * @psalm-suppress MoreSpecificReturnType - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function boundingPolygons(Polygon $p) : MultiPolygon - { - return GeometryEngineRegistry::get()->boundingPolygons($p); - } - - /** - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function isClosed() : bool - { - return GeometryEngineRegistry::get()->isClosed($this); - } - /** * @noproxy */ diff --git a/src/Proxy/PointProxy.php b/src/Proxy/PointProxy.php index de20a28..31c0df8 100644 --- a/src/Proxy/PointProxy.php +++ b/src/Proxy/PointProxy.php @@ -231,15 +231,6 @@ public function getIterator() : \ArrayIterator return $this->proxyGeometry->getIterator(); } - public function azimuth(\Brick\Geo\Point $subject) : float - { - if ($this->proxyGeometry === null) { - $this->load(); - } - - return $this->proxyGeometry->azimuth($subject); - } - public function coordinateDimension() : int { if ($this->proxyGeometry === null) { diff --git a/src/Surface.php b/src/Surface.php index 0fc79f8..26b0e29 100644 --- a/src/Surface.php +++ b/src/Surface.php @@ -4,13 +4,10 @@ namespace Brick\Geo; -use Brick\Geo\Engine\GeometryEngineRegistry; -use Brick\Geo\Exception\GeometryEngineException; - /** * A Surface is a 2-dimensional geometric object. * - * A simple Surface may consists of a single "patch" that is associated with one "exterior boundary" and 0 or more + * A simple Surface may consist of a single "patch" that is associated with one "exterior boundary" and 0 or more * "interior" boundaries. A single such Surface patch in 3-dimensional space is isometric to planar Surfaces, by a * simple affine rotation matrix that rotates the patch onto the plane z = 0. If the patch is not vertical, * the projection onto the same plane is an isomorphism, and can be represented as a linear transformation, @@ -35,31 +32,4 @@ public function dimension() : int { return 2; } - - /** - * Returns the area of this Surface, as measured in the spatial reference system of this Surface. - * - * @noproxy - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function area() : float - { - return GeometryEngineRegistry::get()->area($this); - } - - /** - * Returns a Point guaranteed to be on this Surface. - * - * @noproxy - * - * @psalm-suppress LessSpecificReturnStatement - * @psalm-suppress MoreSpecificReturnType - * - * @throws GeometryEngineException If the operation is not supported by the geometry engine. - */ - public function pointOnSurface() : Point - { - return GeometryEngineRegistry::get()->pointOnSurface($this); - } } diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php index 07af9c4..cd0d945 100644 --- a/tests/AbstractTestCase.php +++ b/tests/AbstractTestCase.php @@ -4,8 +4,8 @@ namespace Brick\Geo\Tests; +use Brick\Geo\Engine\GeometryEngine; use Brick\Geo\Exception\GeometryEngineException; -use Brick\Geo\Engine\GeometryEngineRegistry; use Brick\Geo\Engine\GEOSEngine; use Brick\Geo\Engine\PDOEngine; use Brick\Geo\Engine\SQLite3Engine; @@ -33,16 +33,13 @@ */ class AbstractTestCase extends TestCase { - /** - * Marks the current test as requiring a geometry engine to be set. - * - * If no engine is set, the test will be skipped. - */ - final protected function requiresGeometryEngine() : void + final protected function getGeometryEngine(): GeometryEngine { - if (! GeometryEngineRegistry::has()) { + if (! isset($GLOBALS['GEOMETRY_ENGINE'])) { self::markTestSkipped('This test requires a geometry engine to be set.'); } + + return $GLOBALS['GEOMETRY_ENGINE']; } final protected function isMySQL(?string $operatorAndVersion = null) : bool @@ -65,7 +62,7 @@ final protected function isPostGIS() : bool */ final protected function isSpatiaLite(?string $operatorAndVersion = null) : bool { - $engine = GeometryEngineRegistry::get(); + $engine = $this->getGeometryEngine(); if ($engine instanceof SQLite3Engine) { if ($operatorAndVersion === null) { @@ -85,7 +82,7 @@ final protected function isSpatiaLite(?string $operatorAndVersion = null) : bool */ final protected function isGEOS(?string $operatorAndVersion = null) : bool { - $engine = GeometryEngineRegistry::get(); + $engine = $this->getGeometryEngine(); if ($engine instanceof GEOSEngine) { if ($operatorAndVersion === null) { @@ -221,7 +218,9 @@ final protected function assertGeometryEquals(Geometry $expected, Geometry $actu self::assertSame($expected->geometryType(), $actual->geometryType()); - self::assertTrue($actual->equals($expected), 'Failed asserting that two geometries are spatially equal.' + $geometryEngine = $this->getGeometryEngine(); + + self::assertTrue($geometryEngine->equals($actual, $expected), 'Failed asserting that two geometries are spatially equal.' . "\n---Expected" . "\n+++Actual" . "\n@@ @@" @@ -550,7 +549,7 @@ private function isVersion(string $version, string $operatorAndVersion) : bool private function isPDODriver(string $name) : bool { - $engine = GeometryEngineRegistry::get(); + $engine = $this->getGeometryEngine(); if ($engine instanceof PDOEngine) { if ($engine->getPDO()->getAttribute(\PDO::ATTR_DRIVER_NAME) === $name) { @@ -566,7 +565,7 @@ private function isPDODriver(string $name) : bool */ private function isMySQLorMariaDB(bool $testMariaDB, ?string $operatorAndVersion = null) : bool { - $engine = GeometryEngineRegistry::get(); + $engine = $this->getGeometryEngine(); if ($engine instanceof PDOEngine) { $pdo = $engine->getPDO(); diff --git a/tests/CurveTest.php b/tests/CurveTest.php index 7e346c2..7a8ba8b 100644 --- a/tests/CurveTest.php +++ b/tests/CurveTest.php @@ -20,14 +20,13 @@ class CurveTest extends AbstractTestCase */ public function testLength(string $curve, float $length) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $curve = Curve::fromText($curve); $this->skipIfUnsupportedGeometry($curve); - $actualLength = $curve->length(); + $actualLength = $geometryEngine->length($curve); - self::assertIsFloat($actualLength); self::assertEqualsWithDelta($length, $actualLength, 0.002); } @@ -132,12 +131,12 @@ public function providerEmptyCurve() : array */ public function testIsClosed(string $curve, bool $isClosed) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $curve = Curve::fromText($curve); $this->skipIfUnsupportedGeometry($curve); - self::assertSame($isClosed, $curve->isClosed()); + self::assertSame($isClosed, $geometryEngine->isClosed($curve)); } public function providerIsClosed() : array @@ -171,17 +170,17 @@ public function providerIsClosed() : array */ public function testIsRing(string $curve, bool $isRing) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $curve = Curve::fromText($curve); $this->skipIfUnsupportedGeometry($curve); - if ($curve->isClosed() && $this->isMariaDB('< 10.1.4')) { + if ($geometryEngine->isClosed($curve) && $this->isMariaDB('< 10.1.4')) { // @see https://mariadb.atlassian.net/browse/MDEV-7510 self::markTestSkipped('A bug in MariaDB returns the wrong result.'); } - self::assertSame($isRing, $curve->isRing()); + self::assertSame($isRing, $geometryEngine->isRing($curve)); } public function providerIsRing() : array diff --git a/tests/GeometryTest.php b/tests/GeometryTest.php index dd73dd0..6e8b02e 100644 --- a/tests/GeometryTest.php +++ b/tests/GeometryTest.php @@ -300,12 +300,12 @@ public function providerSRID() : array */ public function testEnvelope(string $geometry, string $envelope) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $geometry = Geometry::fromText($geometry); $envelope = Geometry::fromText($envelope); - $this->assertGeometryEquals($envelope, $geometry->envelope()); + $this->assertGeometryEquals($envelope, $geometryEngine->envelope($geometry)); } public function providerEnvelope() : array @@ -349,7 +349,7 @@ public function providerIsEmpty() : array */ public function testIsValid(string $geometry, bool $isValid) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); if ($this->isMySQL('< 5.7.6-m16') || $this->isMariaDB('>= 10.0')) { $this->expectException(GeometryEngineException::class); @@ -359,7 +359,7 @@ public function testIsValid(string $geometry, bool $isValid) : void $this->skipIfUnsupportedGeometry($geometry); - self::assertSame($isValid, $geometry->isValid()); + self::assertSame($isValid, $geometryEngine->isValid($geometry)); } public function providerIsValid() : array @@ -382,11 +382,11 @@ public function providerIsValid() : array */ public function testIsSimple(string $geometry, bool $isSimple) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $geometry = Geometry::fromText($geometry); $this->skipIfUnsupportedGeometry($geometry); - self::assertSame($isSimple, $geometry->isSimple()); + self::assertSame($isSimple, $geometryEngine->isSimple($geometry)); } public function providerIsSimple() : array @@ -446,7 +446,7 @@ public function providerDimensionality() : array */ public function testBoundary(string $geometry, string $boundary) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $geometry = Geometry::fromText($geometry); @@ -462,7 +462,7 @@ public function testBoundary(string $geometry, string $boundary) : void $this->expectException(GeometryEngineException::class); } - self::assertSame($boundary, $geometry->boundary()->asText()); + self::assertSame($boundary, $geometryEngine->boundary($geometry)->asText()); } public function providerBoundary() : array @@ -487,13 +487,13 @@ public function providerBoundary() : array */ public function testCentroid(string $geometry, float $centroidX, float $centroidY, array $supportedEngines) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $this->requireEngine($supportedEngines); $geometry = Geometry::fromText($geometry); - $centroid = $geometry->centroid(); + $centroid = $geometryEngine->centroid($geometry); $this->assertEqualsWithDelta($centroidX, $centroid->x(), 0.001); $this->assertEqualsWithDelta($centroidY, $centroid->y(), 0.001); @@ -518,7 +518,7 @@ public function providerCentroid() : array */ public function testEquals(string $geometry1, string $geometry2, bool $equals) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $geometry1 = Geometry::fromText($geometry1); $geometry2 = Geometry::fromText($geometry2); @@ -526,7 +526,7 @@ public function testEquals(string $geometry1, string $geometry2, bool $equals) : $this->skipIfUnsupportedGeometry($geometry1); $this->skipIfUnsupportedGeometry($geometry2); - self::assertSame($equals, $geometry1->equals($geometry2)); + self::assertSame($equals, $geometryEngine->equals($geometry1, $geometry2)); } public function providerEquals() : array @@ -557,14 +557,14 @@ public function providerEquals() : array */ public function testDisjoint(string $geometry1, string $geometry2, bool $disjoint) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $geometry1 = Geometry::fromText($geometry1); $geometry2 = Geometry::fromText($geometry2); $this->skipIfUnsupportedByEngine($geometry1, $geometry2, 'disjoint'); - self::assertSame($disjoint, $geometry1->disjoint($geometry2)); + self::assertSame($disjoint, $geometryEngine->disjoint($geometry1, $geometry2)); } public function providerDisjoint() : array @@ -588,14 +588,14 @@ public function providerDisjoint() : array */ public function testIntersects(string $geometry1, string $geometry2, bool $intersects) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $geometry1 = Geometry::fromText($geometry1); $geometry2 = Geometry::fromText($geometry2); $this->skipIfUnsupportedByEngine($geometry1, $geometry2, 'intersects'); - self::assertSame($intersects, $geometry1->intersects($geometry2)); + self::assertSame($intersects, $geometryEngine->intersects($geometry1, $geometry2)); } public function providerIntersects() : array @@ -619,14 +619,14 @@ public function providerIntersects() : array */ public function testTouches(string $geometry1, string $geometry2, bool $touches) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $geometry1 = Geometry::fromText($geometry1); $geometry2 = Geometry::fromText($geometry2); $this->skipIfUnsupportedByEngine($geometry1, $geometry2, 'touches'); - self::assertSame($touches, $geometry1->touches($geometry2)); + self::assertSame($touches, $geometryEngine->touches($geometry1, $geometry2)); } public function providerTouches() : array @@ -652,14 +652,14 @@ public function providerTouches() : array */ public function testCrosses(string $geometry1, string $geometry2, bool $crosses) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $geometry1 = Geometry::fromText($geometry1); $geometry2 = Geometry::fromText($geometry2); $this->skipIfUnsupportedByEngine($geometry1, $geometry2, 'crosses'); - self::assertSame($crosses, $geometry1->crosses($geometry2)); + self::assertSame($crosses, $geometryEngine->crosses($geometry1, $geometry2)); } public function providerCrosses() : array @@ -685,12 +685,12 @@ public function providerCrosses() : array */ public function testWithin(string $geometry1, string $geometry2, bool $within) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $geometry1 = Geometry::fromText($geometry1); $geometry2 = Geometry::fromText($geometry2); - self::assertSame($within, $geometry1->within($geometry2)); + self::assertSame($within, $geometryEngine->within($geometry1, $geometry2)); } public function providerWithin() : array @@ -713,12 +713,12 @@ public function providerWithin() : array */ public function testContains(string $geometry1, string $geometry2, bool $contains) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $geometry1 = Geometry::fromText($geometry1); $geometry2 = Geometry::fromText($geometry2); - self::assertSame($contains, $geometry1->contains($geometry2)); + self::assertSame($contains, $geometryEngine->contains($geometry1, $geometry2)); } public function providerContains() : array @@ -741,12 +741,12 @@ public function providerContains() : array */ public function testOverlaps(string $geometry1, string $geometry2, bool $overlaps) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $geometry1 = Geometry::fromText($geometry1); $geometry2 = Geometry::fromText($geometry2); - self::assertSame($overlaps, $geometry1->overlaps($geometry2)); + self::assertSame($overlaps, $geometryEngine->overlaps($geometry1, $geometry2)); } public function providerOverlaps() : array @@ -767,7 +767,7 @@ public function providerOverlaps() : array */ public function testRelate(string $geometry1, string $geometry2, string $matrix, bool $relate) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); if ($this->isMySQL() || $this->isMariaDB('< 10.1.2')) { $this->expectException(GeometryEngineException::class); @@ -776,7 +776,7 @@ public function testRelate(string $geometry1, string $geometry2, string $matrix, $geometry1 = Geometry::fromText($geometry1); $geometry2 = Geometry::fromText($geometry2); - self::assertSame($relate, $geometry1->relate($geometry2, $matrix)); + self::assertSame($relate, $geometryEngine->relate($geometry1, $geometry2, $matrix)); } public function providerRelate() : array @@ -798,13 +798,13 @@ public function providerRelate() : array */ public function testLocateAlong(string $geometry, float $measure, string $result) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); if ($this->isGEOS() || $this->isMySQL() || $this->isMariaDB()) { $this->expectException(GeometryEngineException::class); } - self::assertSame($result, Geometry::fromText($geometry)->locateAlong($measure)->asText()); + self::assertSame($result, $geometryEngine->locateAlong(Geometry::fromText($geometry), $measure)->asText()); } public function providerLocateAlong() : array @@ -825,13 +825,13 @@ public function providerLocateAlong() : array */ public function testLocateBetween(string $geometry, float $mStart, float $mEnd, string $result) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); if ($this->isGEOS() || $this->isMySQL() || $this->isMariaDB()) { $this->expectException(GeometryEngineException::class); } - self::assertSame($result, Geometry::fromText($geometry)->locateBetween($mStart, $mEnd)->asText()); + self::assertSame($result, $geometryEngine->locateBetween(Geometry::fromText($geometry), $mStart, $mEnd)->asText()); } public function providerLocateBetween() : array @@ -851,12 +851,12 @@ public function providerLocateBetween() : array */ public function testDistance(string $geometry1, string $geometry2, float $distance) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $geometry1 = Geometry::fromText($geometry1); $geometry2 = Geometry::fromText($geometry2); - self::assertSame($distance, $geometry1->distance($geometry2)); + self::assertSame($distance, $geometryEngine->distance($geometry1, $geometry2)); } public function providerDistance() : array @@ -875,19 +875,19 @@ public function providerDistance() : array */ public function testBuffer(string $geometry, float $distance) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $geometry = Geometry::fromText($geometry); - $buffer = $geometry->buffer($distance); + $buffer = $geometryEngine->buffer($geometry, $distance); self::assertInstanceOf(Polygon::class, $buffer); - self::assertTrue($buffer->contains($geometry)); + self::assertTrue($geometryEngine->contains($buffer, $geometry)); /** @var Polygon $buffer */ $ring = $buffer->exteriorRing(); for ($n = 1; $n <= $ring->numPoints(); $n++) { - self::assertEqualsWithDelta($distance, $ring->pointN($n)->distance($geometry), 0.001); + self::assertEqualsWithDelta($distance, $geometryEngine->distance($ring->pointN($n), $geometry), 0.001); } } @@ -908,7 +908,7 @@ public function providerBuffer() : array */ public function testConvexHull(string $geometry, string $result) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); if ($this->isMySQL('< 5.7.6-m16') || $this->isMariaDB('< 10.1.2')) { $this->expectException(GeometryEngineException::class); @@ -917,7 +917,7 @@ public function testConvexHull(string $geometry, string $result) : void $geometry = Geometry::fromText($geometry); $result = Geometry::fromText($result); - $this->assertGeometryEquals($result, $geometry->convexHull()); + $this->assertGeometryEquals($result, $geometryEngine->convexHull($geometry)); } public function providerConvexHull() : array @@ -938,7 +938,7 @@ public function providerConvexHull() : array */ public function testIntersection(string $geometry1, string $geometry2, string $result) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $geometry1 = Geometry::fromText($geometry1); $geometry2 = Geometry::fromText($geometry2); @@ -946,7 +946,7 @@ public function testIntersection(string $geometry1, string $geometry2, string $r $this->skipIfUnsupportedByEngine($geometry1, $geometry2, 'intersection'); - $this->assertGeometryEquals($result, $geometry1->intersection($geometry2)); + $this->assertGeometryEquals($result, $geometryEngine->intersection($geometry1, $geometry2)); } public function providerIntersection() : array @@ -966,7 +966,7 @@ public function providerIntersection() : array */ public function testUnion(string $geometry1, string $geometry2, string $result) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $geometry1 = Geometry::fromText($geometry1); $geometry2 = Geometry::fromText($geometry2); @@ -975,7 +975,7 @@ public function testUnion(string $geometry1, string $geometry2, string $result) $this->skipIfUnsupportedGeometry($geometry1); $this->skipIfUnsupportedGeometry($geometry2); - $union = $geometry1->union($geometry2); + $union = $geometryEngine->union($geometry1, $geometry2); if ($union->asText() === $result->asText()) { // GEOS does not consider POINT EMPTY to be equal to another POINT EMPTY; @@ -986,7 +986,7 @@ public function testUnion(string $geometry1, string $geometry2, string $result) } self::assertSame($result->geometryType(), $union->geometryType()); - self::assertTrue($union->equals($result)); + self::assertTrue($geometryEngine->equals($union, $result)); } public function providerUnion() : array @@ -1008,7 +1008,7 @@ public function providerUnion() : array */ public function testDifference(string $geometry1, string $geometry2, string $result) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); if ($this->isMySQL('< 5.7')) { self::markTestSkipped('MySQL 5.6 difference() implementation is very buggy and should not be used.'); @@ -1018,7 +1018,7 @@ public function testDifference(string $geometry1, string $geometry2, string $res $geometry2 = Geometry::fromText($geometry2); $result = Geometry::fromText($result); - $difference = $geometry1->difference($geometry2); + $difference = $geometryEngine->difference($geometry1, $geometry2); $this->assertGeometryEquals($result, $difference); } @@ -1039,13 +1039,13 @@ public function providerDifference() : array */ public function testSymDifference(string $geometry1, string $geometry2, string $result) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $geometry1 = Geometry::fromText($geometry1); $geometry2 = Geometry::fromText($geometry2); $result = Geometry::fromText($result); - $difference = $geometry1->symDifference($geometry2); + $difference = $geometryEngine->symDifference($geometry1, $geometry2); $this->assertGeometryEquals($result, $difference); } @@ -1066,7 +1066,7 @@ public function providerSymDifference() : array */ public function testSnapToGrid(string $geometry, float $size, string $result) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); if ($this->isGEOS() || $this->isMySQL() || $this->isMariaDB()) { $this->expectException(GeometryEngineException::class); @@ -1075,7 +1075,7 @@ public function testSnapToGrid(string $geometry, float $size, string $result) : $geometry = Geometry::fromText($geometry); $result = Geometry::fromText($result); - $snapToGrid = $geometry->snapToGrid($size); + $snapToGrid = $geometryEngine->snapToGrid($geometry, $size); $this->assertGeometryEquals($result, $snapToGrid); } @@ -1099,7 +1099,7 @@ public function providerSnapToGrid() : array */ public function testSimplify(string$geometry, float $tolerance, string $result) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); if ($this->isMySQL('< 5.7.6-m16') || $this->isMariaDB('>= 10.0') || $this->isSpatiaLite('< 4.1.0')) { $this->expectException(GeometryEngineException::class); @@ -1108,7 +1108,7 @@ public function testSimplify(string$geometry, float $tolerance, string $result) $geometry = Geometry::fromText($geometry); $result = Geometry::fromText($result); - $this->assertGeometryEquals($result, $geometry->simplify($tolerance)); + $this->assertGeometryEquals($result, $geometryEngine->simplify($geometry, $tolerance)); } public function providerSimplify() : array @@ -1128,7 +1128,7 @@ public function providerSimplify() : array */ public function testMaxDistance(string $geometry1, string $geometry2, float $maxDistance) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); if ($this->isGEOS() || $this->isMySQL() || $this->isMariaDB() || $this->isSpatiaLite()) { $this->expectException(GeometryEngineException::class); @@ -1137,7 +1137,7 @@ public function testMaxDistance(string $geometry1, string $geometry2, float $max $geometry1 = Geometry::fromText($geometry1); $geometry2 = Geometry::fromText($geometry2); - self::assertSame($maxDistance, $geometry1->maxDistance($geometry2)); + self::assertSame($maxDistance, $geometryEngine->maxDistance($geometry1, $geometry2)); } public function providerMaxDistance() : array @@ -1154,7 +1154,7 @@ public function providerMaxDistance() : array */ public function testTransform(string $originalWKT, int $originalSRID, int $targetSRID, string $expectedWKT) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); if ($this->isGEOS()) { $this->expectException(GeometryEngineException::class); @@ -1165,7 +1165,7 @@ public function testTransform(string $originalWKT, int $originalSRID, int $targe $originalGeometry = Geometry::fromText($originalWKT, $originalSRID); $expectedGeometry = Geometry::fromText($expectedWKT, $targetSRID); - $transformedGeometry = $originalGeometry->transform($targetSRID); + $transformedGeometry = $geometryEngine->transform($originalGeometry, $targetSRID); $this->assertGeometryEqualsWithDelta($expectedGeometry, $transformedGeometry, 0.0000001); } diff --git a/tests/MultiCurveTest.php b/tests/MultiCurveTest.php index bcbb023..c90a28b 100644 --- a/tests/MultiCurveTest.php +++ b/tests/MultiCurveTest.php @@ -64,14 +64,13 @@ public function providerInvalidFromBinary() : array */ public function testLength(string $curve, float $length) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $curve = MultiCurve::fromText($curve); $this->skipIfUnsupportedGeometry($curve); - $actualLength = $curve->length(); + $actualLength = $geometryEngine->length($curve); - self::assertIsFloat($actualLength); self::assertEqualsWithDelta($length, $actualLength, 0.001); } @@ -95,7 +94,7 @@ public function providerLength() : array */ public function testIsClosed(string $curve, bool $isClosed) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $curve = MultiCurve::fromText($curve); $this->skipIfUnsupportedGeometry($curve); @@ -105,7 +104,7 @@ public function testIsClosed(string $curve, bool $isClosed) : void $this->expectException(GeometryEngineException::class); } - self::assertSame($isClosed, $curve->isClosed()); + self::assertSame($isClosed, $geometryEngine->isClosed($curve)); } public function providerIsClosed() : array diff --git a/tests/MultiSurfaceTest.php b/tests/MultiSurfaceTest.php index df8de75..3362d9e 100644 --- a/tests/MultiSurfaceTest.php +++ b/tests/MultiSurfaceTest.php @@ -65,12 +65,12 @@ public function providerInvalidFromBinary() : array */ public function testArea(string $multiSurface, float $area) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $multiSurface = MultiSurface::fromText($multiSurface); $this->skipIfUnsupportedGeometry($multiSurface); - $actualArea = $multiSurface->area(); + $actualArea = $geometryEngine->area($multiSurface); self::assertEqualsWithDelta($area, $actualArea, 0.001); } @@ -94,11 +94,11 @@ public function providerArea() : array */ public function testCentroid(string $multiMultiSurface, string $centroid) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $multiSurface = MultiSurface::fromText($multiMultiSurface); $this->skipIfUnsupportedGeometry($multiSurface); - $this->assertWktEquals($multiSurface->centroid(), $centroid); + $this->assertWktEquals($geometryEngine->centroid($multiSurface), $centroid); } public function providerCentroid() : array @@ -117,7 +117,7 @@ public function providerCentroid() : array */ public function testPointOnSurface(string $multiMultiSurface) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); if ($this->isMySQL() || $this->isMariaDB('< 10.1.2')) { // MySQL and older MariaDB do not support ST_PointOnSurface() @@ -127,10 +127,10 @@ public function testPointOnSurface(string $multiMultiSurface) : void $multiSurface = MultiSurface::fromText($multiMultiSurface); $this->skipIfUnsupportedGeometry($multiSurface); - $pointOnSurface = $multiSurface->pointOnSurface(); + $pointOnSurface = $geometryEngine->pointOnSurface($multiSurface); self::assertInstanceOf(Point::class, $pointOnSurface); - self::assertTrue($multiSurface->contains($pointOnSurface)); + self::assertTrue($geometryEngine->contains($multiSurface, $pointOnSurface)); } public function providerPointOnSurface() : array diff --git a/tests/PointTest.php b/tests/PointTest.php index cd32fbc..7dd60c9 100644 --- a/tests/PointTest.php +++ b/tests/PointTest.php @@ -188,7 +188,7 @@ public function providerToArrayAndInterfaces() : array */ public function testAzimuth(string $observerWkt, string $subjectWkt, ?float $azimuthExpected): void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); if (! $this->isPostGIS()) { $this->expectException(GeometryEngineException::class); @@ -201,7 +201,7 @@ public function testAzimuth(string $observerWkt, string $subjectWkt, ?float $azi $this->expectException(GeometryEngineException::class); } - $azimuthActual = $observer->azimuth($subject); + $azimuthActual = $geometryEngine->azimuth($observer, $subject); self::assertEqualsWithDelta($azimuthExpected, $azimuthActual, 0.001); } diff --git a/tests/SurfaceTest.php b/tests/SurfaceTest.php index 5e4f664..2ba7d8c 100644 --- a/tests/SurfaceTest.php +++ b/tests/SurfaceTest.php @@ -21,12 +21,12 @@ class SurfaceTest extends AbstractTestCase */ public function testArea(string $surface, float $area) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $surface = Surface::fromText($surface); $this->skipIfUnsupportedGeometry($surface); - $actualArea = $surface->area(); + $actualArea = $geometryEngine->area($surface); self::assertIsFloat($actualArea); self::assertEqualsWithDelta($area, $actualArea, 0.001); @@ -53,11 +53,11 @@ public function providerArea() : array */ public function testCentroid(string $surface, string $centroid) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); $surface = Surface::fromText($surface); $this->skipIfUnsupportedGeometry($surface); - $this->assertWktEquals($surface->centroid(), $centroid); + $this->assertWktEquals($geometryEngine->centroid($surface), $centroid); } public function providerCentroid() : array @@ -77,7 +77,7 @@ public function providerCentroid() : array */ public function testPointOnSurface(string $surface) : void { - $this->requiresGeometryEngine(); + $geometryEngine = $this->getGeometryEngine(); if ($this->isMySQL() || $this->isMariaDB('< 10.1.2')) { // MySQL and older MariaDB do not support ST_PointOnSurface() @@ -87,10 +87,10 @@ public function testPointOnSurface(string $surface) : void $surface = Surface::fromText($surface); $this->skipIfUnsupportedGeometry($surface); - $pointOnSurface = $surface->pointOnSurface(); + $pointOnSurface = $geometryEngine->pointOnSurface($surface); self::assertInstanceOf(Point::class, $pointOnSurface); - self::assertTrue($surface->contains($pointOnSurface)); + self::assertTrue($geometryEngine->contains($surface, $pointOnSurface)); } public function providerPointOnSurface() : array