diff --git a/README.md b/README.md index 0024266..cfeed26 100644 --- a/README.md +++ b/README.md @@ -25,18 +25,23 @@ composer require longitude-one/spatial-types ## Usage +Concrete spatial classes now have an `Immutable` suffix and are final. Update +imports and constructor calls to the new names; former names have no aliases. +Read-only interfaces remain shared. See [Immutability](docs/immutability.md#read-copy-and-mutation-contracts) +for the separate immutable and mutable contracts and the staged mutable rollout. + ```php -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; -$point = new Point(1, 2); +$point = new PointImmutable(1, 2); echo $point->getX(); // 1 echo $point->getY(); // 2 -$lineString = new LineString([ - new Point(1, 2, 4326), - new Point(3, 4, 4326), - new Point(5, 6, 4326), +$lineString = new LineStringImmutable([ + new PointImmutable(1, 2, 4326), + new PointImmutable(3, 4, 4326), + new PointImmutable(5, 6, 4326), ], 4326); $lineString->getSrid(); // 4326 ``` @@ -56,18 +61,18 @@ classes, see [Type class hierarchy](docs/type-class-hierarchy.md). ```text AbstractSpatialType -├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\Point -├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\LineString -├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\Polygon -├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\CircularString -├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\CompoundCurve -├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\Triangle -├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\MultiPoint -├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\MultiLineString -├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\MultiPolygon -├── Dimension{3z,4zm}\{Geometry,Geography}\PolyhedralSurface -├── Dimension{2,3m,3z,4zm}\Geometry\GeometryCollection -└── Dimension{2,3m,3z,4zm}\Geography\GeographyCollection +├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\PointImmutable +├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\LineStringImmutable +├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\PolygonImmutable +├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\CircularStringImmutable +├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\CompoundCurveImmutable +├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\TriangleImmutable +├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\MultiPointImmutable +├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\MultiLineStringImmutable +├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\MultiPolygonImmutable +├── Dimension{3z,4zm}\{Geometry,Geography}\PolyhedralSurfaceImmutable +├── Dimension{2,3m,3z,4zm}\Geometry\GeometryCollectionImmutable +└── Dimension{2,3m,3z,4zm}\Geography\GeographyCollectionImmutable ``` ### Types not yet available @@ -85,7 +90,7 @@ the public API. Use `withCoordinates()` with an immutable `Value\Coordinates` value to represent another location, or `withSpatialReference()` to associate the same coordinates with another declared reference. Both return new objects. -`LineString`, `Polygon`, `Triangle`, and `PolyhedralSurface` also provide +`LineStringImmutable`, `PolygonImmutable`, `TriangleImmutable`, and `PolyhedralSurfaceImmutable` also provide `withArrayOfCoordinates()` to create a new instance with replacement coordinates. This preserves their family, dimension, and SRID without changing the source object. diff --git a/docs/immutability.md b/docs/immutability.md index 736c641..017b675 100644 --- a/docs/immutability.md +++ b/docs/immutability.md @@ -5,7 +5,10 @@ as immutable makes that reuse safe and makes a value's location explicit. ## Current contract -Every spatial type is immutable through the public API. Its coordinates, spatial reference, +Every currently available concrete spatial class has an `Immutable` suffix and +is final and immutable through the public API. Former concrete names are removed, +without deprecated aliases. `Value\Coordinates` and `Reference\SpatialReference` +remain immutable auxiliary values with their existing names. Its coordinates, spatial reference, and aggregate membership are set by its constructor, and it has no public setter or membership mutator. `getCoordinates()` returns an immutable `Value\Coordinates` value. `withCoordinates()` creates a distinct point with @@ -13,11 +16,11 @@ replacement coordinates, while `withSpatialReference()` creates a distinct point same coordinates and a different declared spatial reference. ```php -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -$paris = new Point(2.3522, 48.8566, 4326); +$paris = new PointImmutable(2.3522, 48.8566, 4326); $movedParis = $paris->withCoordinates(Coordinates::xy(2.3600, 48.8566)); $parisInLambert93 = $paris->withSpatialReference(SpatialReference::epsg(2154)); $parisInLambert93 = $parisInLambert93->withCoordinates( @@ -30,16 +33,16 @@ point is part of an aggregate. `withSpatialReference()` only changes the declared reference; it never converts ordinates. The Lambert 93 values in the example must be calculated by an external coordinate transformer. -`LineString`, `CircularString`, `MultiPoint`, and `Polygon` provide an equally immutable +`LineStringImmutable`, `CircularStringImmutable`, `MultiPointImmutable`, and `PolygonImmutable` provide an equally immutable point-replacement operation. `withPoint()` returns a deep copy: the source aggregate, its rings, and its points remain unchanged. ```php -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\LineString; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPoint; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\LineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPointImmutable; -$line = new LineString([[1, 2, 10], [3, 4, 20]], 2154); -$multiPoint = new MultiPoint([[1, 2, 10], [3, 4, 20]], 2154); +$line = new LineStringImmutable([[1, 2, 10], [3, 4, 20]], 2154); +$multiPoint = new MultiPointImmutable([[1, 2, 10], [3, 4, 20]], 2154); $movedLine = $line->withPoint(1, Coordinates::xym(5, 6, 30)); $movedMultiPoint = $multiPoint->withPoint(0, Coordinates::xym(5, 6, 30)); ``` @@ -53,7 +56,7 @@ $movedExterior = $polygon->withPoint(0, 0, Coordinates::xym(5, 6, 30)); $movedHole = $polygon->withPoint(1, -1, Coordinates::xym(7, 8, 40)); ``` -`Polygon::withRing()` and `MultiLineString::withLineString()` replace a +`PolygonImmutable::withRing()` and `MultiLineStringImmutable::withLineString()` replace a complete ring or line string from coordinate tuples. They also return deep copies and preserve the source aggregate's family, dimension, and SRID. @@ -65,7 +68,7 @@ $updatedMultiLine = $multiLine->withLineString(1, [[5, 6], [7, 8]]); $movedMultiLinePoint = $multiLine->withPoint(1, 0, Coordinates::xy(5, 6)); ``` -`MultiPolygon` follows the same rule at every nesting level: +`MultiPolygonImmutable` follows the same rule at every nesting level: `withPoint()` selects a polygon, ring, and point; `withRing()` selects a polygon and ring; and `withPolygon()` selects a polygon. Every method returns a deep copy and preserves the family, dimension, and SRID. @@ -78,8 +81,39 @@ $replacedMultiPolygon = $multiPolygon->withPolygon(0, [ ]); ``` -`GeometryCollection` and `GeographyCollection` use `withElement()` to replace -one indexed element. The replacement must implement `SpatialInterface`; unchanged elements are deeply copied. +`GeometryCollectionImmutable` and `GeographyCollectionImmutable` use `withElement()` to replace +one indexed element. The replacement must implement `ImmutableSpatialInterface`; unchanged elements are deeply copied. + +## Read, copy and mutation contracts + +| Contract | Operations | +| --- | --- | +| `SpatialInterface` and type interfaces such as `PointInterface` | Read coordinates, metadata and members | +| `ImmutableSpatialInterface` and `ImmutableInterface` | Read operations and the applicable `with…` operations | +| `MutableSpatialInterface` and `MutableInterface` | Read operations and mutation contracts; no `with…` operations | + +`MutableSpatialInterface` declares `setFamily(SpatialModelEnum $family)`, +`setSpatialReference(SpatialReference $reference)` and `setSrid(int $srid)`, all +returning `static`. These metadata operations must preserve ordinates. Neither +variant has a dimension setter. Immutable concrete namespaces fix the family +and dimension; `withSpatialReference()` and `withSrid()` preserve them. + +Concrete mutable classes and detailed type-specific editing methods arrive in +the following Stories of Epic #38. They are not available in this change. Existing +factories currently create the explicitly named immutable classes and expose +immutable return contracts. + +Immutable aggregate constructors and replacement paths accept only immutable +spatial components. Immutable component getters retain that contract: for example, +`ImmutablePolygonInterface::getRing()` returns `ImmutableLineStringInterface`, +and a ring's `getPoint()` returns `ImmutablePointInterface`. + +Coordinate arrays remain supported and create immutable descendants. Mutable +objects, including mutable descendants inside a supplied custom aggregate, are +rejected without conversion or modification of the source or supplied objects. +Invalid array members raise `InvalidValueException`; incompatible typed +arguments can raise PHP `TypeError`. This ownership check does not validate +geometry, family, coordinate-dimension or reference compatibility. ## Why coordinates are immutable @@ -87,16 +121,16 @@ Consider a point used by a line string, where that line string is then used by a multi-line string: ```php -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiLineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiLineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; -$point = new Point(2.3522, 48.8566, 4326); -$line = new LineString([ +$point = new PointImmutable(2.3522, 48.8566, 4326); +$line = new LineStringImmutable([ $point, - new Point(2.3600, 48.8600, 4326), + new PointImmutable(2.3600, 48.8600, 4326), ], 4326); -$multiLine = new MultiLineString([$line], 4326); +$multiLine = new MultiLineStringImmutable([$line], 4326); ``` `$point` is referenced by `$line`, and `$line` is referenced by `$multiLine`. @@ -122,10 +156,10 @@ and factory concern because it depends on the point family. The value carries its dimension, so it cannot represent an `XY` point with a Z or M ordinate. ```php -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\PointImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; -$paris = new Point(2.3522, 48.8566, 28, 12, 4326); +$paris = new PointImmutable(2.3522, 48.8566, 28, 12, 4326); $higherParis = $paris->withCoordinates( Coordinates::xyzm(2.3522, 48.8566, 42, 12) ); @@ -137,26 +171,26 @@ ranges are not checked. ## Aggregate types -The coordinate-replacement API applies to `Point`, `LineString`, `MultiPoint`, -and `Polygon` (including `Triangle`). `LineString::withPoint()` and -`MultiPoint::withPoint()` select a point; `Polygon::withPoint()` selects a ring then a point. All use the +The coordinate-replacement API applies to `PointImmutable`, `LineStringImmutable`, `MultiPointImmutable`, +and `PolygonImmutable` (including `TriangleImmutable`). `LineStringImmutable::withPoint()` and +`MultiPointImmutable::withPoint()` select a point; `PolygonImmutable::withPoint()` selects a ring then a point. All use the immutable `Value\Coordinates` value, so a replacement must match the receiver's coordinate dimension. -`Polygon::withRing()` selects a ring from coordinate tuples. `MultiLineString::withPoint()` selects a line string then a point, -while `MultiLineString::withLineString()` selects one of its line strings. +`PolygonImmutable::withRing()` selects a ring from coordinate tuples. `MultiLineStringImmutable::withPoint()` selects a line string then a point, +while `MultiLineStringImmutable::withLineString()` selects one of its line strings. Both derive the expected coordinate layout from the receiver. -`MultiPolygon::withPoint()` selects a polygon, ring, then point. -`MultiPolygon::withRing()` selects a polygon then ring, while -`MultiPolygon::withPolygon()` replaces an entire polygon. Each operation -creates a deep copy of every polygon in the collection. `PolyhedralSurface` +`MultiPolygonImmutable::withPoint()` selects a polygon, ring, then point. +`MultiPolygonImmutable::withRing()` selects a polygon then ring, while +`MultiPolygonImmutable::withPolygon()` replaces an entire polygon. Each operation +creates a deep copy of every polygon in the collection. `PolyhedralSurfaceImmutable` uses patch indexes with `withPoint()`, `withRing()` and `withPatch()`. Its `withArrayOfCoordinates()` replaces all patches atomically, or returns an empty surface for `[]`. Indexed replacements on an empty surface are invalid. Neighbouring faces are never changed implicitly when editing a shared vertex. -`GeometryCollection::withElement()` and `GeographyCollection::withElement()` +`GeometryCollectionImmutable::withElement()` and `GeographyCollectionImmutable::withElement()` replace one element and deeply copy every unchanged element. Aggregate membership is fixed at construction. Their plural getters return PHP @@ -173,7 +207,7 @@ validity checks. Reference replacements preserve defining coordinates and copy the contained points. Editing an endpoint does not automatically edit the other end of a closed circular string. -Compound curves retain immutable ordered `CurveInterface` components with +Compound curves retain immutable ordered `ImmutableCurveInterface` components with numeric or null coordinate tuples. Their `withSpatialReference()` and legacy `withSrid()` operations deeply copy components without checking continuity. Construct a new compound from replacement curves to change its path; modifying diff --git a/docs/instantiable-spatial-types.md b/docs/instantiable-spatial-types.md index 8ec3887..93471a6 100644 --- a/docs/instantiable-spatial-types.md +++ b/docs/instantiable-spatial-types.md @@ -122,11 +122,11 @@ handling and [Spatial validation](validators.md) for explicit functional checks. ## Class catalogue -All classes in the following matrix are concrete and instantiable. The class +All classes in the following matrix are final, concrete and immutable. The class name is composed from the dimension, family, and type: ```php -LongitudeOne\SpatialTypes\Types\\\ +LongitudeOne\SpatialTypes\Types\\\Immutable ``` | Dimension | Namespace segment | Coordinates | @@ -140,21 +140,23 @@ For each dimension, both `Geometry` and `Geography` provide: | Type | Geometry class | Geography class | | ------------------------ | ------------------------------- | --------------------------------- | -| Point | `…\Geometry\Point` | `…\Geography\Point` | -| Line string | `…\Geometry\LineString` | `…\Geography\LineString` | -| Polygon | `…\Geometry\Polygon` | `…\Geography\Polygon` | -| Triangle | `…\Geometry\Triangle` | `…\Geography\Triangle` | -| Multi-point | `…\Geometry\MultiPoint` | `…\Geography\MultiPoint` | -| Multi-line string | `…\Geometry\MultiLineString` | `…\Geography\MultiLineString` | -| Multi-polygon | `…\Geometry\MultiPolygon` | `…\Geography\MultiPolygon` | -| Heterogeneous collection | `…\Geometry\GeometryCollection` | `…\Geography\GeographyCollection` | - -`PolyhedralSurface` is additionally available in `Dimension3z` and +| Point | `…\Geometry\PointImmutable` | `…\Geography\PointImmutable` | +| Line string | `…\Geometry\LineStringImmutable` | `…\Geography\LineStringImmutable` | +| Circular string | `…\Geometry\CircularStringImmutable` | `…\Geography\CircularStringImmutable` | +| Compound curve | `…\Geometry\CompoundCurveImmutable` | `…\Geography\CompoundCurveImmutable` | +| Polygon | `…\Geometry\PolygonImmutable` | `…\Geography\PolygonImmutable` | +| Triangle | `…\Geometry\TriangleImmutable` | `…\Geography\TriangleImmutable` | +| Multi-point | `…\Geometry\MultiPointImmutable` | `…\Geography\MultiPointImmutable` | +| Multi-line string | `…\Geometry\MultiLineStringImmutable` | `…\Geography\MultiLineStringImmutable` | +| Multi-polygon | `…\Geometry\MultiPolygonImmutable` | `…\Geography\MultiPolygonImmutable` | +| Heterogeneous collection | `…\Geometry\GeometryCollectionImmutable` | `…\Geography\GeographyCollectionImmutable` | + +`PolyhedralSurfaceImmutable` is additionally available in `Dimension3z` and `Dimension4zm`, in both families. Its faces require Z; XY and XYM variants are not provided. It is a surface, not a heterogeneous collection or a solid. For example, a four-dimensional geographic polygon is -`LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Polygon`. +`LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PolygonImmutable`. `AbstractSpatialType` and the other `Abstract*` classes are internal base classes, not part of the instantiable API. @@ -168,10 +170,10 @@ the unnamed reference identified by `0` in every constructor. ### Point ```php -new Point($x, $y, int|SpatialReference $srid = 0); // Dimension2 -new Point($x, $y, $z, int|SpatialReference $srid = 0); // Dimension3z -new Point($x, $y, $m, int|SpatialReference $srid = 0); // Dimension3m -new Point($x, $y, $z, $m, int|SpatialReference $srid = 0); // Dimension4zm +new PointImmutable($x, $y, int|SpatialReference $srid = 0); // Dimension2 +new PointImmutable($x, $y, $z, int|SpatialReference $srid = 0); // Dimension3z +new PointImmutable($x, $y, $m, int|SpatialReference $srid = 0); // Dimension3m +new PointImmutable($x, $y, $z, $m, int|SpatialReference $srid = 0); // Dimension4zm ``` `$x` and `$y` accept `int`, `float`, or a coordinate string accepted by the @@ -185,7 +187,7 @@ zero is a supplied value. Null ordinates do not change the declared dimension. This preserves the selected coordinate layout and optional SRID: ```php -$emptyPoint = new Point(srid: 4326); +$emptyPoint = new PointImmutable(srid: 4326); assert($emptyPoint->isEmpty()); assert([] === $emptyPoint->toArray()); ``` @@ -197,13 +199,13 @@ contain every index declared by the requested dimension; an explicit null is different from an absent index. ```php -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PointImmutable; -$point = new Point(2.3522, 48.8566, 35, 4326); // longitude, latitude, elevation +$point = new PointImmutable(2.3522, 48.8566, 35, 4326); // longitude, latitude, elevation ``` ```php -$partialPoint = new Point(0, null, null, 4326); // XYZ Geography +$partialPoint = new PointImmutable(0, null, null, 4326); // XYZ Geography assert(!$partialPoint->isEmpty()); assert([0, null, null] === $partialPoint->toArray()); assert($partialPoint->hasZ()); // The Z axis exists even when its value is null. @@ -222,7 +224,7 @@ the coordinate dimension: `Coordinates::xy()`, `Coordinates::xym()`, `Coordinates::xyz()`, and `Coordinates::xyzm()`. `PointInterface::getCoordinates()` returns this value object. -`PointInterface::withCoordinates(Coordinates $coordinates)` returns a new point +`ImmutablePointInterface::withCoordinates(Coordinates $coordinates)` returns a new point of the same concrete class and SRID. The supplied coordinates must have the same dimension as the point. Its accessors and `toArray()` retain null values for axes in that dimension; reading or replacing an axis outside the dimension @@ -238,38 +240,38 @@ $higherPoint = $point->withCoordinates(Coordinates::xyz(2.3522, 48.8566, 42)); ### Point-based types ```php -new LineString(array $points, int|SpatialReference $srid = 0); -new MultiPoint(array $points, int|SpatialReference $srid = 0); +new LineStringImmutable(array $points, int|SpatialReference $srid = 0); +new MultiPointImmutable(array $points, int|SpatialReference $srid = 0); ``` -`$points` may contain instances of `PointInterface` or coordinate tuples for +`$points` may contain instances of `ImmutablePointInterface` or coordinate tuples for the selected dimension, for example `[[0, 0], [1, 1]]` for `XY` or `[[0, 0, 12, 3], [1, 1, 15, 4]]` for `XYZM`. ```php -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable; -$lineString = new LineString([[0, 0], [2, 1], [5, 1]], 3857); +$lineString = new LineStringImmutable([[0, 0], [2, 1], [5, 1]], 3857); ``` ### Ring-, line-, and polygon-based types ```php -new Polygon(array $rings, int|SpatialReference $srid = 0); -new Triangle(array $rings, int|SpatialReference $srid = 0); -new MultiLineString(array $lineStrings, int|SpatialReference $srid = 0); -new MultiPolygon(array $polygons, int|SpatialReference $srid = 0); -new PolyhedralSurface(array $patches = [], int|SpatialReference $srid = 0); +new PolygonImmutable(array $rings, int|SpatialReference $srid = 0); +new TriangleImmutable(array $rings, int|SpatialReference $srid = 0); +new MultiLineStringImmutable(array $lineStrings, int|SpatialReference $srid = 0); +new MultiPolygonImmutable(array $polygons, int|SpatialReference $srid = 0); +new PolyhedralSurfaceImmutable(array $patches = [], int|SpatialReference $srid = 0); ``` -- A polygon ring is a `LineStringInterface` or an array of point tuples. +- A polygon ring is an `ImmutableLineStringInterface` or an array of point tuples. - A triangle uses the same ring representation as a polygon. Cardinality, closure and absence of holes are not enforced; `[]` is an empty triangle. -- A multi-line-string element is a `LineStringInterface` or point-tuple array. +- A multi-line-string element is an `ImmutableLineStringInterface` or point-tuple array. `[]` as an element creates an empty line string in the aggregate's context. -- A multi-polygon element is a `PolygonInterface` or an array of rings. +- A multi-polygon element is an `ImmutablePolygonInterface` or an array of rings. Empty member polygons retain their positions. -- A polyhedral-surface patch is a `PolygonInterface` (including a triangle) +- A polyhedral-surface patch is an `ImmutablePolygonInterface` (including a triangle) or an array of rings. Empty patches, disconnected faces and non-planar faces can be represented. `[]` creates a surface with zero patches. @@ -278,21 +280,21 @@ and geometric validity are explicit consumer concerns. Coordinate tuples are hydrated in the receiving aggregate's family, dimension and reference. ```php -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Polygon; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PolygonImmutable; -$polygon = new Polygon([ +$polygon = new PolygonImmutable([ [[0, 0], [4, 0], [4, 3], [0, 0]], ], 3857); ``` -`new MultiLineString([])` has zero members, whereas -`new MultiLineString([[]])` has one empty member. `getElements()`, +`new MultiLineStringImmutable([])` has zero members, whereas +`new MultiLineStringImmutable([[]])` has one empty member. `getElements()`, `getLineStrings()`, `getLineString()` and `toArray()` preserve this distinction. -The current `MultiLineString::isEmpty()` checks whether it has zero members; +The current `MultiLineStringImmutable::isEmpty()` checks whether it has zero members; inspect the member arrays when the distinction matters. -`new MultiPolygon([])` has zero members and `isEmpty()` returns `true`. -`new MultiPolygon([[]])` and `new MultiPolygon([new Polygon([])])` each +`new MultiPolygonImmutable([])` has zero members and `isEmpty()` returns `true`. +`new MultiPolygonImmutable([[]])` and `new MultiPolygonImmutable([new PolygonImmutable([])])` each contain one empty polygon and `isEmpty()` returns `false`. `getElements()`, `getPolygons()` and `getPolygon()` expose that member, whose own `isEmpty()` returns `true`. `toArray()` preserves the distinction as `[]` versus `[[]]`; @@ -309,13 +311,13 @@ See [empty MultiLineString interoperability](empty-multilinestring-interoperabil for the WKT/WKB verification and the current WKT parser limitation. `TriangleInterface` extends `PolygonInterface`. All eight dimension/family -combinations provide a concrete `Triangle`: +combinations provide a concrete `TriangleImmutable`: ```php -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Triangle; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\TriangleImmutable; -$triangle = new Triangle([[[0, 0], [4, 0], [0, 4], [0, 0]]], 3857); -$empty = new Triangle([]); +$triangle = new TriangleImmutable([[[0, 0], [4, 0], [0, 4], [0, 0]]], 3857); +$empty = new TriangleImmutable([]); ``` Triangle cardinality and closure are functional validity rules and are no @@ -330,18 +332,20 @@ conversion routines are not currently exposed. ### Heterogeneous collections ```php -new GeometryCollection(int|SpatialReference $srid = 0, array $elements = []); -new GeographyCollection(int|SpatialReference $srid = 0, array $elements = []); +new GeometryCollectionImmutable(int|SpatialReference $srid = 0, array $elements = []); +new GeographyCollectionImmutable(int|SpatialReference $srid = 0, array $elements = []); ``` Collections accept their initial elements in their constructor. They accept any -spatial type implementing `SpatialInterface`, including nested collections. +immutable spatial type implementing `ImmutableSpatialInterface`, including nested +immutable collections. Mutable components and mutable descendants are rejected +without conversion. ```php -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollection; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollectionImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; -$collection = new GeometryCollection(3857, [new Point(0, 0, 3857)]); +$collection = new GeometryCollectionImmutable(3857, [new PointImmutable(0, 0, 3857)]); ``` ## Observing spatial values @@ -380,13 +384,13 @@ returns one tuple in the layout's order. | Type | Element access | Predicates | | -------------------------------------------- | ------------------------------------------------------------ | ------------------------------------- | -| `LineString` | `getPoints()`, `getPoint($index)`, `getElements()` | `isEmpty()`, `isLine()`, `isClosed()` | -| `MultiPoint` | `getPoints()`, `getPoint($index)`, `getElements()` | `isEmpty()`, `isSimple()` | -| `Polygon` / `Triangle` | `getRings()`, `getRing($index)`, `getElements()` | `isEmpty()` | -| `MultiLineString` | `getLineStrings()`, `getLineString($index)`, `getElements()` | `isEmpty()` | -| `MultiPolygon` | `getPolygons()`, `getPolygon($index)`, `getElements()` | `isEmpty()` | -| `PolyhedralSurface` | `getPatches()`, `getPatch($index)`, `getElements()` | `isEmpty()` | -| `GeometryCollection` / `GeographyCollection` | `getElements()` | `isEmpty()`, `hasElement($spatial)` | +| `LineStringImmutable` | `getPoints()`, `getPoint($index)`, `getElements()` | `isEmpty()`, `isLine()`, `isClosed()` | +| `MultiPointImmutable` | `getPoints()`, `getPoint($index)`, `getElements()` | `isEmpty()`, `isSimple()` | +| `PolygonImmutable` / `TriangleImmutable` | `getRings()`, `getRing($index)`, `getElements()` | `isEmpty()` | +| `MultiLineStringImmutable` | `getLineStrings()`, `getLineString($index)`, `getElements()` | `isEmpty()` | +| `MultiPolygonImmutable` | `getPolygons()`, `getPolygon($index)`, `getElements()` | `isEmpty()` | +| `PolyhedralSurfaceImmutable` | `getPatches()`, `getPatch($index)`, `getElements()` | `isEmpty()` | +| `GeometryCollectionImmutable` / `GeographyCollectionImmutable` | `getElements()` | `isEmpty()`, `hasElement($spatial)` | For point, ring, line-string, polygon, and patch single-element accessors, negative indexes count from the end (`-1` is the last element). An index is wrapped by @@ -405,52 +409,52 @@ ordinates, SRID, and aggregate membership, and no public mutator exists. replacement coordinates of the same dimension; `withSpatialReference(SpatialReference $reference): static` returns one with the same coordinates and a new declared reference. -`LineString`, `Polygon`, `Triangle`, and `PolyhedralSurface` provide +`LineStringImmutable`, `PolygonImmutable`, `TriangleImmutable`, and `PolyhedralSurfaceImmutable` provide `withArrayOfCoordinates(array $coordinates): static`. These methods return a new aggregate with replacement coordinates while preserving family, dimension, and SRID. The line-string method accepts coordinate tuples; the polygon method accepts arrays of rings. The receiving aggregate determines whether tuples are -XY, XYM, XYZ, or XYZM. For `PolyhedralSurface`, replacement coordinates are +XY, XYM, XYZ, or XYZM. For `PolyhedralSurfaceImmutable`, replacement coordinates are arrays of patches and use XYZ or XYZM; `[]` returns an empty surface. -`LineString::withPoint(int $pointIndex, Coordinates $coordinates): static` +`LineStringImmutable::withPoint(int $pointIndex, Coordinates $coordinates): static` returns a deep copy with one replacement point. For polygons, -`Polygon::withPoint(int $ringIndex, int $pointIndex, Coordinates $coordinates): static` +`PolygonImmutable::withPoint(int $ringIndex, int $pointIndex, Coordinates $coordinates): static` uses a ring index followed by a point index. Replacing either endpoint of a ring updates both endpoints to preserve its closure. Both methods retain the family, dimension, and SRID of the receiving aggregate. -`MultiPoint::withPoint(int $pointIndex, Coordinates $coordinates): static` +`MultiPointImmutable::withPoint(int $pointIndex, Coordinates $coordinates): static` returns a deep copy with one replacement point and preserves the receiving multi-point's family, dimension, and SRID. -`Polygon::withRing(int $ringIndex, array $coordinates): static` replaces -one ring. `MultiLineString::withLineString(int $lineStringIndex, array +`PolygonImmutable::withRing(int $ringIndex, array $coordinates): static` replaces +one ring. `MultiLineStringImmutable::withLineString(int $lineStringIndex, array $coordinates): static` replaces one line string. Both return deep copies and derive the expected XY, XYM, XYZ, or XYZM layout from the receiving aggregate. -`MultiLineString::withPoint(int $lineStringIndex, int $pointIndex, Coordinates +`MultiLineStringImmutable::withPoint(int $lineStringIndex, int $pointIndex, Coordinates $coordinates): static` replaces one point in one line string and returns a deep copy. -`MultiPolygon::withPoint(int $polygonIndex, int $ringIndex, int $pointIndex, +`MultiPolygonImmutable::withPoint(int $polygonIndex, int $ringIndex, int $pointIndex, Coordinates $coordinates): static` replaces one point. -`MultiPolygon::withRing(int $polygonIndex, int $ringIndex, array -$coordinates): static` replaces one ring, and `MultiPolygon::withPolygon(int +`MultiPolygonImmutable::withRing(int $polygonIndex, int $ringIndex, array +$coordinates): static` replaces one ring, and `MultiPolygonImmutable::withPolygon(int $polygonIndex, array $coordinates): static` replaces one polygon. All three methods return deep copies and preserve family, dimension, and SRID. -`PolyhedralSurface` provides `withPoint($patchIndex, $ringIndex, $pointIndex, +`PolyhedralSurfaceImmutable` provides `withPoint($patchIndex, $ringIndex, $pointIndex, $coordinates)`, `withRing($patchIndex, $ringIndex, $coordinates)` and `withPatch($patchIndex, $coordinates)` with the same deep-copy semantics. Surface topology is not checked. Editing a shared vertex does not silently move neighbouring faces. Empty surfaces reject indexed access and indexed replacements. -`GeometryCollection::withElement(int $elementIndex, SpatialInterface -$element): static` and `GeographyCollection::withElement(...)` replace one -element implementing `SpatialInterface` and deeply copy the unchanged elements. +`GeometryCollectionImmutable::withElement(int $elementIndex, ImmutableSpatialInterface +$element): static` and `GeographyCollectionImmutable::withElement(...)` replace one +element implementing `ImmutableSpatialInterface` and deeply copy the unchanged elements. -All spatial types implement `withSpatialReference(SpatialReference $reference): static`. +All concrete immutable types implement `withSpatialReference(SpatialReference $reference): static`. For aggregates, it returns a deep copy whose contained values receive the requested reference, so the result remains internally reference-consistent. `withSrid(int $srid)` remains as a legacy integer adapter. @@ -489,25 +493,25 @@ This is an approved breaking change before 1.0.0: third-party implementations of these curve interfaces must implement the three common methods. Existing concrete line-string closure behavior is preserved. -`Types\Dimension{2,3z,3m,4zm}\{Geometry,Geography}\CircularString` supports +`Types\Dimension{2,3z,3m,4zm}\{Geometry,Geography}\CircularStringImmutable` supports XY, XYZ, XYM and XYZM in both families. Its constructor is: ```php public function __construct(array $points, int|SpatialReference $srid = 0); ``` -Pass defining `PointInterface` values or coordinate tuples. `[]` creates an +Pass defining `ImmutablePointInterface` values or coordinate tuples. `[]` creates an empty circular string. Odd cardinality, non-empty members and distinct arc points are geometric validity rules and are not automatically checked. Stored points are never replaced by a linear approximation. ```php -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularString; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularStringImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; -$arc = new CircularString([[0, 0], [1, 1], [2, 0]], 4326); -$circle = new CircularString([[1, 0], [-1, 0], [1, 0]], 4326); -$empty = new CircularString([], 4326); +$arc = new CircularStringImmutable([[0, 0], [1, 1], [2, 0]], 4326); +$circle = new CircularStringImmutable([[1, 0], [-1, 0], [1, 0]], 4326); +$empty = new CircularStringImmutable([], 4326); $replacement = $arc->withPoint(1, Coordinates::xy(1, 2)); ``` @@ -524,24 +528,24 @@ every point without transforming coordinates. ## Compound curves -`Types\Dimension{2,3z,3m,4zm}\{Geometry,Geography}\CompoundCurve` implements -`CompoundCurveInterface` in XY, XYZ, XYM and XYZM. Construct it with ordered -`CurveInterface` components and an optional integer or `SpatialReference`: +`Types\Dimension{2,3z,3m,4zm}\{Geometry,Geography}\CompoundCurveImmutable` implements +`ImmutableCompoundCurveInterface` in XY, XYZ, XYM and XYZM. Construct it with ordered +`ImmutableCurveInterface` components and an optional integer or `SpatialReference`: ```php -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CompoundCurve; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CompoundCurveImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable; -$curve = new CompoundCurve([ - new LineString([[0, 0], [1, 1]], 4326), - new CircularString([[1, 1], [2, 2], [3, 1]], 4326), +$curve = new CompoundCurveImmutable([ + new LineStringImmutable([[0, 0], [1, 1]], 4326), + new CircularStringImmutable([[1, 1], [2, 2], [3, 1]], 4326), ], 4326); -$empty = new CompoundCurve([], 4326); +$empty = new CompoundCurveImmutable([], 4326); ``` -`new CompoundCurve()` creates an empty XY Geometry value with SRID 0 when -using the class imported above. Components must implement `CurveInterface` +`new CompoundCurveImmutable()` creates an empty XY Geometry value with SRID 0 when +using the class imported above. Components must implement `ImmutableCurveInterface` and expose point tuples with numeric or null ordinates. Null entries retain their positions through array access and immutable reference copies. Family, dimension, reference, component kind, non-empty endpoints and continuity are @@ -549,7 +553,7 @@ not validated automatically. Components are preserved as objects without flattening, reversal or linear approximation. `getCurves()` and `getElements()` expose the ordered components as -`CurveInterface[]`. `getCurve($index)` uses wrapping indexes and negative +`ImmutableCurveInterface[]`. `getCurve($index)` uses wrapping indexes and negative indexes from the end; EMPTY indexed access raises `OutOfBoundsException`. `getStartPoint()` and `getEndPoint()` expose the outer endpoints. `isClosed()` compares those endpoints without checking intermediate continuity. Closure does not claim simplicity; no compound ring or simplicity diff --git a/docs/spatial-reference-systems.md b/docs/spatial-reference-systems.md index 1aa188b..2ec37b7 100644 --- a/docs/spatial-reference-systems.md +++ b/docs/spatial-reference-systems.md @@ -33,10 +33,10 @@ the target `SpatialReference`. ```php use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; -$paris = new Point(2.3522, 48.8566, SpatialReference::epsg(4326)); +$paris = new PointImmutable(2.3522, 48.8566, SpatialReference::epsg(4326)); $lambert93 = $paris->withSpatialReference(SpatialReference::epsg(2154)); $lambert93 = $lambert93->withCoordinates(Coordinates::xy(652469.0227, 6862035.2594)); ``` diff --git a/docs/type-class-hierarchy.md b/docs/type-class-hierarchy.md index b2f09f7..705e1e9 100644 --- a/docs/type-class-hierarchy.md +++ b/docs/type-class-hierarchy.md @@ -5,44 +5,48 @@ file layout. `{Dimension2, Dimension3m, Dimension3z, Dimension4zm}` represents one branch for each listed coordinate dimension and `{Geometry, Geography}` one concrete class for each spatial model. +`AbstractSpatialTypeImmutable` extends the read-only `AbstractSpatialType` base. +The following hierarchy contains only immutable implementation bases; future mutable +classes do not inherit their copy operations. + ```text -AbstractSpatialType -├── AbstractCompoundCurve -│ └── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\CompoundCurve -├── AbstractCircularString -│ └── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\CircularString -├── AbstractPoint -│ └── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\Point -├── AbstractPolygon -│ ├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\Polygon -│ └── AbstractTriangle -│ └── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\Triangle -├── AbstractPolyhedralSurface -│ └── Dimension{3z,4zm}\{Geometry,Geography}\PolyhedralSurface -├── AbstractMultiPolygon -│ └── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\MultiPolygon -├── AbstractCollection -│ ├── Dimension2\AbstractCollection -│ │ ├── Dimension2\Geometry\GeometryCollection -│ │ └── Dimension2\Geography\GeographyCollection -│ └── Dimension{3m,3z,4zm}\{Geometry\GeometryCollection,Geography\GeographyCollection} -├── Collection\AbstractPointCollection -│ ├── AbstractLineString -│ │ └── Dimension{2,3m,3z,4zm}\AbstractLineString -│ │ └── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\LineString -│ └── AbstractMultiPoint -│ └── Dimension{2,3m,3z,4zm}\AbstractMultiPoint -│ └── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\MultiPoint -└── Collection\AbstractLineStringCollection - └── AbstractMultiLineString - └── Dimension{2,3m,3z,4zm}\AbstractMultiLineString - └── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\MultiLineString +AbstractSpatialTypeImmutable +├── AbstractCompoundCurveImmutable +│ └── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\CompoundCurveImmutable +├── AbstractCircularStringImmutable +│ └── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\CircularStringImmutable +├── AbstractPointImmutable +│ └── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\PointImmutable +├── AbstractPolygonImmutable +│ ├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\PolygonImmutable +│ └── AbstractTriangleImmutable +│ └── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\TriangleImmutable +├── AbstractPolyhedralSurfaceImmutable +│ └── Dimension{3z,4zm}\{Geometry,Geography}\PolyhedralSurfaceImmutable +├── AbstractMultiPolygonImmutable +│ └── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\MultiPolygonImmutable +├── AbstractCollectionImmutable +│ ├── Dimension2\AbstractCollectionImmutable +│ │ ├── Dimension2\Geometry\GeometryCollectionImmutable +│ │ └── Dimension2\Geography\GeographyCollectionImmutable +│ └── Dimension{3m,3z,4zm}\{Geometry\GeometryCollectionImmutable,Geography\GeographyCollectionImmutable} +├── Collection\AbstractPointCollectionImmutable +│ ├── AbstractLineStringImmutable +│ │ └── Dimension{2,3m,3z,4zm}\AbstractLineStringImmutable +│ │ └── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\LineStringImmutable +│ └── AbstractMultiPointImmutable +│ └── Dimension{2,3m,3z,4zm}\AbstractMultiPointImmutable +│ └── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\MultiPointImmutable +└── Collection\AbstractLineStringCollectionImmutable + └── AbstractMultiLineStringImmutable + └── Dimension{2,3m,3z,4zm}\AbstractMultiLineStringImmutable + └── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\MultiLineStringImmutable ``` `LineStringInterface`, `CircularStringInterface` and `CompoundCurveInterface` extend `CurveInterface`, which exposes nullable start/end points and closure in addition to `SpatialInterface`. Circular strings have their own point storage; they are not line strings and do not inherit point-set -simplicity checks. Compound curves retain ordered `CurveInterface` components +simplicity checks. Compound curves retain ordered `ImmutableCurveInterface` components and require curve interfaces and point tuples with numeric or null ordinates; functional compatibility and endpoint continuity are not checked. diff --git a/lib/Boundary/PolygonBoundary.php b/lib/Boundary/PolygonBoundary.php index 7fc622b..7af8ffe 100644 --- a/lib/Boundary/PolygonBoundary.php +++ b/lib/Boundary/PolygonBoundary.php @@ -17,7 +17,7 @@ namespace LongitudeOne\SpatialTypes\Boundary; use LongitudeOne\SpatialTypes\Collection\LineStringCollection; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; /** * Polygon boundary: one exterior ring followed by zero or more interior rings. @@ -29,7 +29,7 @@ final class PolygonBoundary private LineStringCollection $rings; /** - * @param LineStringInterface[] $rings Boundary rings, exterior first + * @param ImmutableLineStringInterface[] $rings Boundary rings, exterior first */ public function __construct(array $rings = []) { @@ -39,9 +39,9 @@ public function __construct(array $rings = []) /** * Add a boundary ring. * - * @param LineStringInterface $ring Ring to add + * @param ImmutableLineStringInterface $ring Ring to add */ - public function addRing(LineStringInterface $ring): void + public function addRing(ImmutableLineStringInterface $ring): void { $this->rings->add($ring); } @@ -63,12 +63,12 @@ public function isEmpty(): bool * * @param int $index Requested index */ - public function ringAt(int $index): LineStringInterface + public function ringAt(int $index): ImmutableLineStringInterface { return $this->rings->at($index); } - /** @return LineStringInterface[] */ + /** @return ImmutableLineStringInterface[] */ public function rings(): array { return $this->rings->all(); diff --git a/lib/Collection/LineStringCollection.php b/lib/Collection/LineStringCollection.php index 3c7c55d..635024c 100644 --- a/lib/Collection/LineStringCollection.php +++ b/lib/Collection/LineStringCollection.php @@ -17,7 +17,7 @@ namespace LongitudeOne\SpatialTypes\Collection; use LongitudeOne\SpatialTypes\Exception\OutOfBoundsException; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; /** * Collection of line strings used by multi-line strings. @@ -26,11 +26,11 @@ */ final class LineStringCollection { - /** @var LineStringInterface[] */ + /** @var ImmutableLineStringInterface[] */ private array $lineStrings = []; /** - * @param LineStringInterface[] $lineStrings Line strings in this collection + * @param ImmutableLineStringInterface[] $lineStrings Line strings in this collection */ public function __construct(array $lineStrings = []) { @@ -42,14 +42,14 @@ public function __construct(array $lineStrings = []) /** * Add a line string. * - * @param LineStringInterface $lineString Line string to add + * @param ImmutableLineStringInterface $lineString Line string to add */ - public function add(LineStringInterface $lineString): void + public function add(ImmutableLineStringInterface $lineString): void { $this->lineStrings[] = $lineString; } - /** @return LineStringInterface[] */ + /** @return ImmutableLineStringInterface[] */ public function all(): array { return $this->lineStrings; @@ -60,7 +60,7 @@ public function all(): array * * @param int $index Requested index */ - public function at(int $index): LineStringInterface + public function at(int $index): ImmutableLineStringInterface { if ([] === $this->lineStrings) { throw new OutOfBoundsException('The current collection of line strings is empty.'); @@ -84,7 +84,7 @@ public function isEmpty(): bool } /** - * @param LineStringInterface[] $lineStrings Replacement line strings + * @param ImmutableLineStringInterface[] $lineStrings Replacement line strings */ public function replace(array $lineStrings): void { diff --git a/lib/Factory/FromIndexedArrayFactory.php b/lib/Factory/FromIndexedArrayFactory.php index f973151..f4a4f13 100644 --- a/lib/Factory/FromIndexedArrayFactory.php +++ b/lib/Factory/FromIndexedArrayFactory.php @@ -19,9 +19,9 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Exception\SpatialTypeExceptionInterface; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; -use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolygonInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; /** @@ -34,14 +34,14 @@ class FromIndexedArrayFactory /** * Create a line string from an indexed array. * - * @param (array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}|PointInterface)[] $indexedArray indexed array - * @param int|SpatialReference $srid SRID - * @param SpatialModelEnum $family family - * @param CoordinateDimensionEnum $dimension dimension + * @param (array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}|ImmutablePointInterface)[] $indexedArray indexed array + * @param int|SpatialReference $srid SRID + * @param SpatialModelEnum $family family + * @param CoordinateDimensionEnum $dimension dimension * * @throws SpatialTypeExceptionInterface when the point or line string cannot be created */ - public static function createLineString(array $indexedArray, int|SpatialReference $srid = 0, SpatialModelEnum $family = SpatialModelEnum::GEOMETRY, CoordinateDimensionEnum $dimension = CoordinateDimensionEnum::XY): LineStringInterface + public static function createLineString(array $indexedArray, int|SpatialReference $srid = 0, SpatialModelEnum $family = SpatialModelEnum::GEOMETRY, CoordinateDimensionEnum $dimension = CoordinateDimensionEnum::XY): ImmutableLineStringInterface { return DefaultSpatialFactoryFactory::create()->createLineStringFromIndexedArray($indexedArray, new SpatialContext($srid, $family, $dimension)); } @@ -56,7 +56,7 @@ public static function createLineString(array $indexedArray, int|SpatialReferenc * * @throws SpatialTypeExceptionInterface when something goes wrong during the creation of the point */ - public static function createPoint(array $coordinates, int|SpatialReference $srid = 0, SpatialModelEnum $family = SpatialModelEnum::GEOMETRY, CoordinateDimensionEnum $dimensionEnum = CoordinateDimensionEnum::XY): PointInterface + public static function createPoint(array $coordinates, int|SpatialReference $srid = 0, SpatialModelEnum $family = SpatialModelEnum::GEOMETRY, CoordinateDimensionEnum $dimensionEnum = CoordinateDimensionEnum::XY): ImmutablePointInterface { return DefaultSpatialFactoryFactory::create()->createPointFromIndexedArray($coordinates, new SpatialContext($srid, $family, $dimensionEnum)); } @@ -64,14 +64,14 @@ public static function createPoint(array $coordinates, int|SpatialReference $sri /** * Create a polygon from an indexed array of closed line strings. * - * @param (array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}[]|LineStringInterface)[] $indexedArray indexed array of rings - * @param int|SpatialReference $srid SRID - * @param SpatialModelEnum $family family - * @param CoordinateDimensionEnum $dimension dimension + * @param (array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}[]|ImmutableLineStringInterface)[] $indexedArray indexed array of rings + * @param int|SpatialReference $srid SRID + * @param SpatialModelEnum $family family + * @param CoordinateDimensionEnum $dimension dimension * * @throws SpatialTypeExceptionInterface when something goes wrong during the creation of a line string or the polygon */ - public static function createPolygon(array $indexedArray, int|SpatialReference $srid = 0, SpatialModelEnum $family = SpatialModelEnum::GEOMETRY, CoordinateDimensionEnum $dimension = CoordinateDimensionEnum::XY): PolygonInterface + public static function createPolygon(array $indexedArray, int|SpatialReference $srid = 0, SpatialModelEnum $family = SpatialModelEnum::GEOMETRY, CoordinateDimensionEnum $dimension = CoordinateDimensionEnum::XY): ImmutablePolygonInterface { return DefaultSpatialFactoryFactory::create()->createPolygonFromIndexedArray($indexedArray, new SpatialContext($srid, $family, $dimension)); } diff --git a/lib/Factory/Hydrator/SpatialArrayHydrator.php b/lib/Factory/Hydrator/SpatialArrayHydrator.php index 72ed4f1..abe4fda 100644 --- a/lib/Factory/Hydrator/SpatialArrayHydrator.php +++ b/lib/Factory/Hydrator/SpatialArrayHydrator.php @@ -19,8 +19,8 @@ use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Factory\SpatialContext; use LongitudeOne\SpatialTypes\Factory\SpatialFactoryRegistry; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; /** * Hydrates spatial components from nested indexed arrays. @@ -42,10 +42,10 @@ public function __construct( /** * Hydrate the points of a line string. * - * @param array $points points - * @param SpatialContext $context family, dimension, and SRID expected for every point + * @param array $points points + * @param SpatialContext $context family, dimension, and SRID expected for every point * - * @return PointInterface[] + * @return ImmutablePointInterface[] * * @throws InvalidValueException when a point has an unsupported representation */ @@ -53,11 +53,11 @@ public function hydrateLineString(array $points, SpatialContext $context): array { $hydratedPoints = []; foreach ($points as $point) { - if (!is_array($point) && !$point instanceof PointInterface) { - throw new InvalidValueException('The array must contain only objects implementing PointInterface or array of coordinates.'); + if (!is_array($point) && !$point instanceof ImmutablePointInterface) { + throw new InvalidValueException('The array must contain only objects implementing ImmutablePointInterface or array of coordinates.'); } - if ($point instanceof PointInterface) { + if ($point instanceof ImmutablePointInterface) { $hydratedPoints[] = $point; continue; @@ -81,10 +81,10 @@ public function hydrateLineString(array $points, SpatialContext $context): array /** * Hydrate the rings of a polygon. * - * @param array|LineStringInterface> $rings rings - * @param SpatialContext $context family, dimension, and SRID expected for every ring + * @param array|ImmutableLineStringInterface> $rings rings + * @param SpatialContext $context family, dimension, and SRID expected for every ring * - * @return LineStringInterface[] + * @return ImmutableLineStringInterface[] * * @throws InvalidValueException when a ring has an unsupported representation */ @@ -92,11 +92,11 @@ public function hydratePolygon(array $rings, SpatialContext $context): array { $lineStrings = []; foreach ($rings as $ring) { - if (!is_array($ring) && !$ring instanceof LineStringInterface) { - throw new InvalidValueException('The array must contain only objects implementing LineStringInterface or array of PointInterface or "array of array of coordinates".'); + if (!is_array($ring) && !$ring instanceof ImmutableLineStringInterface) { + throw new InvalidValueException('The array must contain only objects implementing ImmutableLineStringInterface or array of ImmutablePointInterface or "array of array of coordinates".'); } - if ($ring instanceof LineStringInterface) { + if ($ring instanceof ImmutableLineStringInterface) { $lineStrings[] = $ring; continue; diff --git a/lib/Factory/Internal/GeographicLineStringFactory.php b/lib/Factory/Internal/GeographicLineStringFactory.php index 33944df..42ed462 100644 --- a/lib/Factory/Internal/GeographicLineStringFactory.php +++ b/lib/Factory/Internal/GeographicLineStringFactory.php @@ -18,12 +18,12 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\SpatialTypes\Factory\SpatialContext; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\LineString as LineString2D; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\LineString as LineString3Dm; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\LineString as LineString3Dz; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\LineString as LineString4Dzm; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\LineStringImmutable as LineString2D; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\LineStringImmutable as LineString3Dm; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\LineStringImmutable as LineString3Dz; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\LineStringImmutable as LineString4Dzm; /** * Creates geographic line strings. @@ -35,10 +35,10 @@ final class GeographicLineStringFactory implements LineStringFactoryInterface /** * Create a geographic line string. * - * @param PointInterface[] $points points composing the line string - * @param SpatialContext $context family, dimension, and SRID to apply + * @param ImmutablePointInterface[] $points points composing the line string + * @param SpatialContext $context family, dimension, and SRID to apply */ - public function create(array $points, SpatialContext $context): LineStringInterface + public function create(array $points, SpatialContext $context): ImmutableLineStringInterface { return match ($context->dimension) { CoordinateDimensionEnum::XY => new LineString2D($points, $context->reference), diff --git a/lib/Factory/Internal/GeographicPointFactory.php b/lib/Factory/Internal/GeographicPointFactory.php index ad4055e..906ba2d 100644 --- a/lib/Factory/Internal/GeographicPointFactory.php +++ b/lib/Factory/Internal/GeographicPointFactory.php @@ -19,11 +19,11 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\SpatialTypes\Factory\Coordinates; use LongitudeOne\SpatialTypes\Factory\SpatialContext; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Point as Point2D; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Point as Point3Dm; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point as Point3Dz; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Point as Point4Dzm; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PointImmutable as Point2D; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\PointImmutable as Point3Dm; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PointImmutable as Point3Dz; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PointImmutable as Point4Dzm; /** * Creates geographic points. @@ -38,7 +38,7 @@ final class GeographicPointFactory implements PointFactoryInterface * @param Coordinates $coordinates normalized longitude, latitude, Z, and M values * @param SpatialContext $context family, dimension, and SRID to apply */ - public function create(Coordinates $coordinates, SpatialContext $context): PointInterface + public function create(Coordinates $coordinates, SpatialContext $context): ImmutablePointInterface { return match ($context->dimension) { CoordinateDimensionEnum::XY => new Point2D($coordinates->x, $coordinates->y, $context->reference), @@ -53,7 +53,7 @@ public function create(Coordinates $coordinates, SpatialContext $context): Point * * @param SpatialContext $context family, dimension, and SRID to apply */ - public function createEmpty(SpatialContext $context): PointInterface + public function createEmpty(SpatialContext $context): ImmutablePointInterface { return match ($context->dimension) { CoordinateDimensionEnum::XY => new Point2D(srid: $context->reference), diff --git a/lib/Factory/Internal/GeographicPolygonFactory.php b/lib/Factory/Internal/GeographicPolygonFactory.php index 910740c..45e5aae 100644 --- a/lib/Factory/Internal/GeographicPolygonFactory.php +++ b/lib/Factory/Internal/GeographicPolygonFactory.php @@ -18,12 +18,12 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\SpatialTypes\Factory\SpatialContext; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Polygon as Polygon2D; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Polygon as Polygon3Dm; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Polygon as Polygon3Dz; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Polygon as Polygon4Dzm; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolygonInterface; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PolygonImmutable as Polygon2D; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\PolygonImmutable as Polygon3Dm; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PolygonImmutable as Polygon3Dz; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PolygonImmutable as Polygon4Dzm; /** * Creates geographic polygons. @@ -35,10 +35,10 @@ final class GeographicPolygonFactory implements PolygonFactoryInterface /** * Create a geographic polygon. * - * @param LineStringInterface[] $rings exterior ring followed by optional interior rings - * @param SpatialContext $context family, dimension, and SRID to apply + * @param ImmutableLineStringInterface[] $rings exterior ring followed by optional interior rings + * @param SpatialContext $context family, dimension, and SRID to apply */ - public function create(array $rings, SpatialContext $context): PolygonInterface + public function create(array $rings, SpatialContext $context): ImmutablePolygonInterface { return match ($context->dimension) { CoordinateDimensionEnum::XY => new Polygon2D($rings, $context->reference), diff --git a/lib/Factory/Internal/GeometricLineStringFactory.php b/lib/Factory/Internal/GeometricLineStringFactory.php index d5b173d..874f339 100644 --- a/lib/Factory/Internal/GeometricLineStringFactory.php +++ b/lib/Factory/Internal/GeometricLineStringFactory.php @@ -18,12 +18,12 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\SpatialTypes\Factory\SpatialContext; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString as LineString2D; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\LineString as LineString3Dm; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\LineString as LineString3Dz; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\LineString as LineString4Dzm; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable as LineString2D; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\LineStringImmutable as LineString3Dm; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\LineStringImmutable as LineString3Dz; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\LineStringImmutable as LineString4Dzm; /** * Creates geometric line strings. @@ -35,10 +35,10 @@ final class GeometricLineStringFactory implements LineStringFactoryInterface /** * Create a geometric line string. * - * @param PointInterface[] $points points composing the line string - * @param SpatialContext $context family, dimension, and SRID to apply + * @param ImmutablePointInterface[] $points points composing the line string + * @param SpatialContext $context family, dimension, and SRID to apply */ - public function create(array $points, SpatialContext $context): LineStringInterface + public function create(array $points, SpatialContext $context): ImmutableLineStringInterface { return match ($context->dimension) { CoordinateDimensionEnum::XY => new LineString2D($points, $context->reference), diff --git a/lib/Factory/Internal/GeometricPointFactory.php b/lib/Factory/Internal/GeometricPointFactory.php index 7565983..087bedf 100644 --- a/lib/Factory/Internal/GeometricPointFactory.php +++ b/lib/Factory/Internal/GeometricPointFactory.php @@ -19,11 +19,11 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\SpatialTypes\Factory\Coordinates; use LongitudeOne\SpatialTypes\Factory\SpatialContext; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point as Point2D; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Point as Point3Dm; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point as Point3Dz; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Point as Point4Dzm; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable as Point2D; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\PointImmutable as Point3Dm; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PointImmutable as Point3Dz; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\PointImmutable as Point4Dzm; /** * Creates geometric points. @@ -38,7 +38,7 @@ final class GeometricPointFactory implements PointFactoryInterface * @param Coordinates $coordinates normalized X, Y, Z, and M values * @param SpatialContext $context family, dimension, and SRID to apply */ - public function create(Coordinates $coordinates, SpatialContext $context): PointInterface + public function create(Coordinates $coordinates, SpatialContext $context): ImmutablePointInterface { return match ($context->dimension) { CoordinateDimensionEnum::XY => new Point2D($coordinates->x, $coordinates->y, $context->reference), @@ -53,7 +53,7 @@ public function create(Coordinates $coordinates, SpatialContext $context): Point * * @param SpatialContext $context family, dimension, and SRID to apply */ - public function createEmpty(SpatialContext $context): PointInterface + public function createEmpty(SpatialContext $context): ImmutablePointInterface { return match ($context->dimension) { CoordinateDimensionEnum::XY => new Point2D(srid: $context->reference), diff --git a/lib/Factory/Internal/GeometricPolygonFactory.php b/lib/Factory/Internal/GeometricPolygonFactory.php index d10cca1..6449eca 100644 --- a/lib/Factory/Internal/GeometricPolygonFactory.php +++ b/lib/Factory/Internal/GeometricPolygonFactory.php @@ -18,12 +18,12 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\SpatialTypes\Factory\SpatialContext; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Polygon as Polygon2D; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Polygon as Polygon3Dm; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Polygon as Polygon3Dz; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Polygon as Polygon4Dzm; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolygonInterface; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PolygonImmutable as Polygon2D; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\PolygonImmutable as Polygon3Dm; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PolygonImmutable as Polygon3Dz; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\PolygonImmutable as Polygon4Dzm; /** * Creates geometric polygons. @@ -35,10 +35,10 @@ final class GeometricPolygonFactory implements PolygonFactoryInterface /** * Create a geometric polygon. * - * @param LineStringInterface[] $rings exterior ring followed by optional interior rings - * @param SpatialContext $context family, dimension, and SRID to apply + * @param ImmutableLineStringInterface[] $rings exterior ring followed by optional interior rings + * @param SpatialContext $context family, dimension, and SRID to apply */ - public function create(array $rings, SpatialContext $context): PolygonInterface + public function create(array $rings, SpatialContext $context): ImmutablePolygonInterface { return match ($context->dimension) { CoordinateDimensionEnum::XY => new Polygon2D($rings, $context->reference), diff --git a/lib/Factory/Internal/LineStringFactoryInterface.php b/lib/Factory/Internal/LineStringFactoryInterface.php index 851f74a..4633a8e 100644 --- a/lib/Factory/Internal/LineStringFactoryInterface.php +++ b/lib/Factory/Internal/LineStringFactoryInterface.php @@ -17,8 +17,8 @@ namespace LongitudeOne\SpatialTypes\Factory\Internal; use LongitudeOne\SpatialTypes\Factory\SpatialContext; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; /** * Creates line strings for a spatial family. @@ -30,8 +30,8 @@ interface LineStringFactoryInterface /** * Create a line string. * - * @param PointInterface[] $points points composing the line string - * @param SpatialContext $context family, dimension, and SRID to apply + * @param ImmutablePointInterface[] $points points composing the line string + * @param SpatialContext $context family, dimension, and SRID to apply */ - public function create(array $points, SpatialContext $context): LineStringInterface; + public function create(array $points, SpatialContext $context): ImmutableLineStringInterface; } diff --git a/lib/Factory/Internal/PointFactoryInterface.php b/lib/Factory/Internal/PointFactoryInterface.php index 6f7de8c..be3fe8a 100644 --- a/lib/Factory/Internal/PointFactoryInterface.php +++ b/lib/Factory/Internal/PointFactoryInterface.php @@ -18,7 +18,7 @@ use LongitudeOne\SpatialTypes\Factory\Coordinates; use LongitudeOne\SpatialTypes\Factory\SpatialContext; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; /** * Creates points for a spatial family. @@ -33,12 +33,12 @@ interface PointFactoryInterface * @param Coordinates $coordinates normalized X, Y, Z, and M values * @param SpatialContext $context family, dimension, and SRID to apply */ - public function create(Coordinates $coordinates, SpatialContext $context): PointInterface; + public function create(Coordinates $coordinates, SpatialContext $context): ImmutablePointInterface; /** * Create an empty point in the supplied context. * * @param SpatialContext $context family, dimension, and SRID to apply */ - public function createEmpty(SpatialContext $context): PointInterface; + public function createEmpty(SpatialContext $context): ImmutablePointInterface; } diff --git a/lib/Factory/Internal/PolygonFactoryInterface.php b/lib/Factory/Internal/PolygonFactoryInterface.php index f39b53d..708c3c7 100644 --- a/lib/Factory/Internal/PolygonFactoryInterface.php +++ b/lib/Factory/Internal/PolygonFactoryInterface.php @@ -17,8 +17,8 @@ namespace LongitudeOne\SpatialTypes\Factory\Internal; use LongitudeOne\SpatialTypes\Factory\SpatialContext; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolygonInterface; /** * Creates polygons for a spatial family. @@ -30,8 +30,8 @@ interface PolygonFactoryInterface /** * Create a polygon. * - * @param LineStringInterface[] $rings exterior ring followed by optional interior rings - * @param SpatialContext $context family, dimension, and SRID to apply + * @param ImmutableLineStringInterface[] $rings exterior ring followed by optional interior rings + * @param SpatialContext $context family, dimension, and SRID to apply */ - public function create(array $rings, SpatialContext $context): PolygonInterface; + public function create(array $rings, SpatialContext $context): ImmutablePolygonInterface; } diff --git a/lib/Factory/SpatialFactory.php b/lib/Factory/SpatialFactory.php index 93df932..75d20b6 100644 --- a/lib/Factory/SpatialFactory.php +++ b/lib/Factory/SpatialFactory.php @@ -20,9 +20,9 @@ use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Factory\Hydrator\CoordinatesHydrator; use LongitudeOne\SpatialTypes\Factory\Hydrator\SpatialArrayHydrator; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; -use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolygonInterface; /** * Creates spatial types using injected constructors and hydrators. @@ -46,16 +46,16 @@ public function __construct( /** * Create a line string from typed points. * - * @param PointInterface[] $points points composing the line string - * @param SpatialContext $context family, dimension, and SRID to apply + * @param ImmutablePointInterface[] $points points composing the line string + * @param SpatialContext $context family, dimension, and SRID to apply * * @throws InvalidValueException when an element is not a point */ - public function createLineString(array $points, SpatialContext $context): LineStringInterface + public function createLineString(array $points, SpatialContext $context): ImmutableLineStringInterface { foreach ($points as $point) { - if (!$point instanceof PointInterface) { - throw new InvalidValueException('The array must contain only objects implementing PointInterface.'); + if (!$point instanceof ImmutablePointInterface) { + throw new InvalidValueException('The array must contain only objects implementing ImmutablePointInterface.'); } } @@ -65,10 +65,10 @@ public function createLineString(array $points, SpatialContext $context): LineSt /** * Create a line string from an indexed array. * - * @param array $points points - * @param SpatialContext $context family, dimension, and SRID to apply + * @param array $points points + * @param SpatialContext $context family, dimension, and SRID to apply */ - public function createLineStringFromIndexedArray(array $points, SpatialContext $context): LineStringInterface + public function createLineStringFromIndexedArray(array $points, SpatialContext $context): ImmutableLineStringInterface { return $this->createLineString($this->spatialArrayHydrator->hydrateLineString($points, $context), $context); } @@ -81,7 +81,7 @@ public function createLineStringFromIndexedArray(array $points, SpatialContext $ * * @throws InvalidDimensionException when a coordinate is not supported by the requested dimension */ - public function createPoint(Coordinates $coordinates, SpatialContext $context): PointInterface + public function createPoint(Coordinates $coordinates, SpatialContext $context): ImmutablePointInterface { if ((!$context->dimension->hasZ() && null !== $coordinates->z) || (!$context->dimension->hasM() && null !== $coordinates->m)) { throw new InvalidDimensionException('The third and fourth dimensions are not supported for two-dimensions points. Did you miss the 7th parameter CoordinateDimensionEnum?'); @@ -96,7 +96,7 @@ public function createPoint(Coordinates $coordinates, SpatialContext $context): * @param array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}|array{} $coordinates coordinates * @param SpatialContext $context family, dimension, and SRID to apply */ - public function createPointFromIndexedArray(array $coordinates, SpatialContext $context): PointInterface + public function createPointFromIndexedArray(array $coordinates, SpatialContext $context): ImmutablePointInterface { if ([] === $coordinates) { return $this->factoryRegistry->pointFactory($context->family)->createEmpty($context); @@ -108,16 +108,16 @@ public function createPointFromIndexedArray(array $coordinates, SpatialContext $ /** * Create a polygon from typed line strings. * - * @param LineStringInterface[] $lineStrings line strings that form polygon rings - * @param SpatialContext $context family, dimension, and SRID to apply + * @param ImmutableLineStringInterface[] $lineStrings line strings that form polygon rings + * @param SpatialContext $context family, dimension, and SRID to apply * * @throws InvalidValueException when an element is not a line string */ - public function createPolygon(array $lineStrings, SpatialContext $context): PolygonInterface + public function createPolygon(array $lineStrings, SpatialContext $context): ImmutablePolygonInterface { foreach ($lineStrings as $lineString) { - if (!$lineString instanceof LineStringInterface) { - throw new InvalidValueException('The array must contain only objects implementing LineStringInterface.'); + if (!$lineString instanceof ImmutableLineStringInterface) { + throw new InvalidValueException('The array must contain only objects implementing ImmutableLineStringInterface.'); } } @@ -127,10 +127,10 @@ public function createPolygon(array $lineStrings, SpatialContext $context): Poly /** * Create a polygon from an indexed array. * - * @param array|LineStringInterface> $rings rings - * @param SpatialContext $context family, dimension, and SRID to apply + * @param array|ImmutableLineStringInterface> $rings rings + * @param SpatialContext $context family, dimension, and SRID to apply */ - public function createPolygonFromIndexedArray(array $rings, SpatialContext $context): PolygonInterface + public function createPolygonFromIndexedArray(array $rings, SpatialContext $context): ImmutablePolygonInterface { return $this->createPolygon($this->spatialArrayHydrator->hydratePolygon($rings, $context), $context); } diff --git a/lib/Interfaces/CircularStringInterface.php b/lib/Interfaces/CircularStringInterface.php index 5d4cfbd..36256d3 100644 --- a/lib/Interfaces/CircularStringInterface.php +++ b/lib/Interfaces/CircularStringInterface.php @@ -16,8 +16,6 @@ namespace LongitudeOne\SpatialTypes\Interfaces; -use LongitudeOne\SpatialTypes\Value\Coordinates; - /** * Defining points of a circularly interpolated curve. * @@ -61,27 +59,4 @@ public function isEmpty(): bool; * @return (null|float|int)[][] */ public function toArray(): array; - - /** - * Return a new circular string with replacement coordinates. - * - * The returned circular string preserves this instance's family, dimension, - * and Spatial Reference Identifier (SRID). Each tuple must therefore match - * this instance's coordinate layout: XY, XYM, XYZ, or XYZM. - * - * @param array $coordinates replacement coordinates - */ - public function withArrayOfCoordinates(array $coordinates): static; - - /** - * Return a new circular string with one replacement point. - * - * The returned circular string preserves this instance's family, dimension, - * and Spatial Reference Identifier (SRID). The coordinate dimension must - * match the point selected by the index. - * - * @param int $pointIndex index of the point to replace; negative indexes count from the end - * @param Coordinates $coordinates replacement point coordinates - */ - public function withPoint(int $pointIndex, Coordinates $coordinates): static; } diff --git a/lib/Interfaces/ImmutableCircularStringInterface.php b/lib/Interfaces/ImmutableCircularStringInterface.php new file mode 100644 index 0000000..32f5332 --- /dev/null +++ b/lib/Interfaces/ImmutableCircularStringInterface.php @@ -0,0 +1,80 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +use LongitudeOne\SpatialTypes\Value\Coordinates; + +/** Immutable circularstring read and copy contract. */ +interface ImmutableCircularStringInterface extends CircularStringInterface, ImmutableCurveInterface +{ + /** + * Return the points that compose the circular string. + * + * @return ImmutablePointInterface[] + */ + public function getElements(): array; + + /** Return the immutable end point, or null for EMPTY. */ + public function getEndPoint(): ?ImmutablePointInterface; + + /** + * Return a point from the circular string. + * + * @param int $index index of the point. -1 is the last point. -2 is the penultimate point, etc. + */ + public function getPoint(int $index): ImmutablePointInterface; + + /** + * Return the points that compose the circular string. + * + * @return ImmutablePointInterface[] + */ + public function getPoints(): array; + + /** Return the immutable start point, or null for EMPTY. */ + public function getStartPoint(): ?ImmutablePointInterface; + + /** + * Return an array of coordinates. + * + * @return (null|float|int)[][] + */ + public function toArray(): array; + + /** + * Return a new circular string with replacement coordinates. + * + * The returned circular string preserves this instance's family, dimension, + * and Spatial Reference Identifier (SRID). Each tuple must therefore match + * this instance's coordinate layout: XY, XYM, XYZ, or XYZM. + * + * @param array $coordinates replacement coordinates + */ + public function withArrayOfCoordinates(array $coordinates): static; + + /** + * Return a new circular string with one replacement point. + * + * The returned circular string preserves this instance's family, dimension, + * and Spatial Reference Identifier (SRID). The coordinate dimension must + * match the point selected by the index. + * + * @param int $pointIndex index of the point to replace; negative indexes count from the end + * @param Coordinates $coordinates replacement point coordinates + */ + public function withPoint(int $pointIndex, Coordinates $coordinates): static; +} diff --git a/lib/Interfaces/ImmutableCollectionInterface.php b/lib/Interfaces/ImmutableCollectionInterface.php new file mode 100644 index 0000000..a4f9da0 --- /dev/null +++ b/lib/Interfaces/ImmutableCollectionInterface.php @@ -0,0 +1,28 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +/** Immutable collection read and copy contract. */ +interface ImmutableCollectionInterface extends CollectionInterface, ImmutableSpatialInterface +{ + /** + * Return an ordered array of spatial interfaces in the collection. + * + * @return ImmutableSpatialInterface[] + */ + public function getElements(): array; +} diff --git a/lib/Interfaces/ImmutableCompoundCurveInterface.php b/lib/Interfaces/ImmutableCompoundCurveInterface.php new file mode 100644 index 0000000..aaf89ca --- /dev/null +++ b/lib/Interfaces/ImmutableCompoundCurveInterface.php @@ -0,0 +1,43 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +/** Immutable compoundcurve read and copy contract. */ +interface ImmutableCompoundCurveInterface extends CompoundCurveInterface, ImmutableCurveInterface +{ + /** + * Return a component using the collection index convention. + * + * @param int $index Requested index; negative indexes count from the end + */ + public function getCurve(int $index): ImmutableCurveInterface; + + /** @return ImmutableCurveInterface[] */ + public function getCurves(): array; + + /** @return ImmutableCurveInterface[] */ + public function getElements(): array; + + /** Return the immutable end point, or null for EMPTY. */ + public function getEndPoint(): ?ImmutablePointInterface; + + /** Return the immutable start point, or null for EMPTY. */ + public function getStartPoint(): ?ImmutablePointInterface; + + /** @return (null|float|int)[][][] */ + public function toArray(): array; +} diff --git a/lib/Interfaces/ImmutableCurveInterface.php b/lib/Interfaces/ImmutableCurveInterface.php new file mode 100644 index 0000000..47aa0d1 --- /dev/null +++ b/lib/Interfaces/ImmutableCurveInterface.php @@ -0,0 +1,27 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +/** Immutable curve read and copy contract. */ +interface ImmutableCurveInterface extends CurveInterface, ImmutableSpatialInterface +{ + /** Return the end point, or null for an empty curve. */ + public function getEndPoint(): ?ImmutablePointInterface; + + /** Return the start point, or null for an empty curve. */ + public function getStartPoint(): ?ImmutablePointInterface; +} diff --git a/lib/Interfaces/ImmutableLineStringInterface.php b/lib/Interfaces/ImmutableLineStringInterface.php new file mode 100644 index 0000000..d837c9f --- /dev/null +++ b/lib/Interfaces/ImmutableLineStringInterface.php @@ -0,0 +1,80 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +use LongitudeOne\SpatialTypes\Value\Coordinates; + +/** Immutable linestring read and copy contract. */ +interface ImmutableLineStringInterface extends ImmutableCurveInterface, LineStringInterface +{ + /** + * Return the points that compose the line string. + * + * @return ImmutablePointInterface[] + */ + public function getElements(): array; + + /** Return the immutable end point, or null for EMPTY. */ + public function getEndPoint(): ?ImmutablePointInterface; + + /** + * Return a point from the line string. + * + * @param int $index index of the point. -1 is the last point. -2 is the penultimate point, etc. + */ + public function getPoint(int $index): ImmutablePointInterface; + + /** + * Return the points that compose the line string. + * + * @return ImmutablePointInterface[] + */ + public function getPoints(): array; + + /** Return the immutable start point, or null for EMPTY. */ + public function getStartPoint(): ?ImmutablePointInterface; + + /** + * Return an array of coordinates. + * + * @return (null|float|int)[][] + */ + public function toArray(): array; + + /** + * Return a new line string with replacement coordinates. + * + * The returned line string preserves this instance's family, dimension, + * and Spatial Reference Identifier (SRID). Each tuple must therefore match + * this instance's coordinate layout: XY, XYM, XYZ, or XYZM. + * + * @param array $coordinates replacement coordinates + */ + public function withArrayOfCoordinates(array $coordinates): static; + + /** + * Return a new line string with one replacement point. + * + * The returned line string preserves this instance's family, dimension, + * and Spatial Reference Identifier (SRID). The coordinate dimension must + * match the point selected by the index. + * + * @param int $pointIndex index of the point to replace; negative indexes count from the end + * @param Coordinates $coordinates replacement point coordinates + */ + public function withPoint(int $pointIndex, Coordinates $coordinates): static; +} diff --git a/lib/Interfaces/ImmutableMultiLineStringInterface.php b/lib/Interfaces/ImmutableMultiLineStringInterface.php new file mode 100644 index 0000000..69d877f --- /dev/null +++ b/lib/Interfaces/ImmutableMultiLineStringInterface.php @@ -0,0 +1,65 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +use LongitudeOne\SpatialTypes\Value\Coordinates; + +/** Immutable multilinestring read and copy contract. */ +interface ImmutableMultiLineStringInterface extends ImmutableCollectionInterface, MultiLineStringInterface +{ + /** + * Return an ordered array of spatial interfaces in the collection. + * + * @return ImmutableLineStringInterface[] + */ + public function getElements(): array; + + /** + * Return the line strings that compose the multi-line string. + * + * @return ImmutableLineStringInterface[] + */ + public function getLineStrings(): array; + + /** + * Return an array of coordinates. + * + * @return (null|float|int)[][][] + */ + public function toArray(): array; + + /** + * Return a new multi-line string with one replacement line string. + * + * The returned multi-line string preserves this instance's family, + * dimension, and Spatial Reference Identifier (SRID). Every replacement + * coordinate tuple must match this instance's coordinate layout. + * + * @param int $lineStringIndex index of the line string to replace; negative indexes count from the end + * @param array $coordinates replacement line-string coordinates + */ + public function withLineString(int $lineStringIndex, array $coordinates): static; + + /** + * Return a new multi-line string with one replacement point. + * + * @param int $lineStringIndex index of the line string to replace; negative indexes count from the end + * @param int $pointIndex index of the point to replace; negative indexes count from the end + * @param Coordinates $coordinates replacement point coordinates + */ + public function withPoint(int $lineStringIndex, int $pointIndex, Coordinates $coordinates): static; +} diff --git a/lib/Interfaces/ImmutableMultiPointInterface.php b/lib/Interfaces/ImmutableMultiPointInterface.php new file mode 100644 index 0000000..8b318c0 --- /dev/null +++ b/lib/Interfaces/ImmutableMultiPointInterface.php @@ -0,0 +1,56 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +use LongitudeOne\SpatialTypes\Value\Coordinates; + +/** Immutable multipoint read and copy contract. */ +interface ImmutableMultiPointInterface extends ImmutableCollectionInterface, MultiPointInterface +{ + /** + * Return an ordered array of spatial interfaces in the collection. + * + * @return ImmutablePointInterface[] + */ + public function getElements(): array; + + /** + * Return the points that compose the multi-point. + * + * @return ImmutablePointInterface[] + */ + public function getPoints(): array; + + /** + * Return an array of coordinates. + * + * @return (null|float|int)[][] + */ + public function toArray(): array; + + /** + * Return a new multi-point with one replacement point. + * + * The returned multi-point preserves this instance's family, dimension, + * and Spatial Reference Identifier (SRID). The coordinate dimension must + * match the point selected by the index. + * + * @param int $pointIndex index of the point to replace; negative indexes count from the end + * @param Coordinates $coordinates replacement point coordinates + */ + public function withPoint(int $pointIndex, Coordinates $coordinates): static; +} diff --git a/lib/Interfaces/ImmutableMultiPolygonInterface.php b/lib/Interfaces/ImmutableMultiPolygonInterface.php new file mode 100644 index 0000000..6e1df94 --- /dev/null +++ b/lib/Interfaces/ImmutableMultiPolygonInterface.php @@ -0,0 +1,71 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +use LongitudeOne\SpatialTypes\Value\Coordinates; + +/** Immutable multipolygon read and copy contract. */ +interface ImmutableMultiPolygonInterface extends ImmutableCollectionInterface, MultiPolygonInterface +{ + /** + * Return an ordered array of spatial interfaces in the collection. + * + * @return ImmutablePolygonInterface[] + */ + public function getElements(): array; + + /** + * Return the polygons that compose the multi-polygon. + * + * @return ImmutablePolygonInterface[] + */ + public function getPolygons(): array; + + /** + * Return an array of coordinates. + * + * @return (null|float|int)[][][][] + */ + public function toArray(): array; + + /** + * Return a new multi-polygon with one replacement point. + * + * @param int $polygonIndex index of the polygon to replace; negative indexes count from the end + * @param int $ringIndex index of the ring to replace; negative indexes count from the end + * @param int $pointIndex index of the point to replace; negative indexes count from the end + * @param Coordinates $coordinates replacement point coordinates + */ + public function withPoint(int $polygonIndex, int $ringIndex, int $pointIndex, Coordinates $coordinates): static; + + /** + * Return a new multi-polygon with one replacement polygon. + * + * @param int $polygonIndex index of the polygon to replace; negative indexes count from the end + * @param array> $coordinates replacement polygon coordinates + */ + public function withPolygon(int $polygonIndex, array $coordinates): static; + + /** + * Return a new multi-polygon with one replacement ring. + * + * @param int $polygonIndex index of the polygon to replace; negative indexes count from the end + * @param int $ringIndex index of the ring to replace; negative indexes count from the end + * @param array $coordinates replacement ring coordinates + */ + public function withRing(int $polygonIndex, int $ringIndex, array $coordinates): static; +} diff --git a/lib/Interfaces/ImmutablePointInterface.php b/lib/Interfaces/ImmutablePointInterface.php new file mode 100644 index 0000000..4d644f8 --- /dev/null +++ b/lib/Interfaces/ImmutablePointInterface.php @@ -0,0 +1,40 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +use LongitudeOne\SpatialTypes\Value\Coordinates; + +/** Immutable point read and copy contract. */ +interface ImmutablePointInterface extends ImmutableSpatialInterface, PointInterface +{ + /** + * Return an array of all coordinates. + * + * @return (null|float|int)[] + */ + public function toArray(): array; + + /** + * Return a new point with the supplied normalized coordinates. + * + * The coordinates must use the same dimension as this point. The point's + * family and Spatial Reference Identifier (SRID) are preserved. + * + * @param Coordinates $coordinates replacement coordinates + */ + public function withCoordinates(Coordinates $coordinates): static; +} diff --git a/lib/Interfaces/ImmutablePolygonInterface.php b/lib/Interfaces/ImmutablePolygonInterface.php new file mode 100644 index 0000000..f88b1ad --- /dev/null +++ b/lib/Interfaces/ImmutablePolygonInterface.php @@ -0,0 +1,83 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +use LongitudeOne\SpatialTypes\Value\Coordinates; + +/** Immutable polygon read and copy contract. */ +interface ImmutablePolygonInterface extends ImmutableSpatialInterface, PolygonInterface +{ + /** @return ImmutableLineStringInterface[] */ + public function getElements(): array; + + /** + * Return a ring from the polygon. + * + * @param int $index Index of the ring + */ + public function getRing(int $index): ImmutableLineStringInterface; + + /** + * Return the rings that compose the polygon. + * + * @return ImmutableLineStringInterface[] + */ + public function getRings(): array; + + /** + * Return an array of coordinates. + * + * @return (null|float|int)[][][] + */ + public function toArray(): array; + + /** + * Return a new polygon with replacement ring coordinates. + * + * The returned polygon preserves this instance's family, dimension, and + * Spatial Reference Identifier (SRID). Every coordinate tuple must match + * this instance's coordinate layout; ring closure is not checked. + * + * @param array> $coordinates replacement ring coordinates + */ + public function withArrayOfCoordinates(array $coordinates): static; + + /** + * Return a new polygon with one replacement point in a ring. + * + * The returned polygon preserves this instance's family, dimension, and + * Spatial Reference Identifier (SRID). A replacement of the first or last + * point of a ring is applied to both endpoints to preserve ring closure. + * + * @param int $ringIndex index of the ring to replace; negative indexes count from the end + * @param int $pointIndex index of the point to replace; negative indexes count from the end + * @param Coordinates $coordinates replacement point coordinates + */ + public function withPoint(int $ringIndex, int $pointIndex, Coordinates $coordinates): static; + + /** + * Return a new polygon with one replacement ring. + * + * The returned polygon preserves this instance's family, dimension, and + * Spatial Reference Identifier (SRID). The replacement coordinates must + * use this polygon's coordinate layout; ring closure is not checked. + * + * @param int $ringIndex index of the ring to replace; negative indexes count from the end + * @param array $coordinates replacement ring coordinates + */ + public function withRing(int $ringIndex, array $coordinates): static; +} diff --git a/lib/Interfaces/ImmutablePolyhedralSurfaceInterface.php b/lib/Interfaces/ImmutablePolyhedralSurfaceInterface.php new file mode 100644 index 0000000..ac6336c --- /dev/null +++ b/lib/Interfaces/ImmutablePolyhedralSurfaceInterface.php @@ -0,0 +1,85 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +use LongitudeOne\SpatialTypes\Value\Coordinates; + +/** Immutable polyhedralsurface read and copy contract. */ +interface ImmutablePolyhedralSurfaceInterface extends ImmutableSpatialInterface, PolyhedralSurfaceInterface +{ + /** + * Return an ordered array of spatial interfaces in the collection. + * + * @return ImmutablePolygonInterface[] + */ + public function getElements(): array; + + /** + * Return a patch using wrapped indexes, with negative indexes from the end. + * + * @param int $index Patch index + */ + public function getPatch(int $index): ImmutablePolygonInterface; + + /** + * Return the polygons that compose the polyhedral surface. + * + * @return ImmutablePolygonInterface[] + */ + public function getPatches(): array; + + /** + * Return an array of coordinates. + * + * @return (null|float|int)[][][][] + */ + public function toArray(): array; + + /** + * Return an independent surface with replacement patch coordinates. + * + * @param array>> $coordinates Patch coordinates + */ + public function withArrayOfCoordinates(array $coordinates): static; + + /** + * Return a new polyhedral surface with one replacement polygon. + * + * @param int $patchIndex index of the polygon to replace; negative indexes count from the end + * @param array> $coordinates replacement polygon coordinates + */ + public function withPatch(int $patchIndex, array $coordinates): static; + + /** + * Return a new polyhedral surface with one replacement point. + * + * @param int $patchIndex index of the polygon to replace; negative indexes count from the end + * @param int $ringIndex index of the ring to replace; negative indexes count from the end + * @param int $pointIndex index of the point to replace; negative indexes count from the end + * @param Coordinates $coordinates replacement point coordinates + */ + public function withPoint(int $patchIndex, int $ringIndex, int $pointIndex, Coordinates $coordinates): static; + + /** + * Return a new polyhedral surface with one replacement ring. + * + * @param int $patchIndex index of the polygon to replace; negative indexes count from the end + * @param int $ringIndex index of the ring to replace; negative indexes count from the end + * @param array $coordinates replacement ring coordinates + */ + public function withRing(int $patchIndex, int $ringIndex, array $coordinates): static; +} diff --git a/lib/Interfaces/ImmutableSpatialInterface.php b/lib/Interfaces/ImmutableSpatialInterface.php new file mode 100644 index 0000000..182ed9a --- /dev/null +++ b/lib/Interfaces/ImmutableSpatialInterface.php @@ -0,0 +1,57 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +use LongitudeOne\SpatialTypes\Reference\SpatialReference; + +/** Immutable spatial read and copy contract. */ +interface ImmutableSpatialInterface extends SpatialInterface +{ + /** + * Convert this spatial object to its array representation. + * + * The array contains only nested arrays of floats and integers, or is empty + * when the spatial object corresponds to the empty set. + * + * Some information is lost in this representation. For example, a line string + * containing two points has the same representation as a multi-point containing + * those points, and the SRID is not exported. + * + * Use the longitude-one/spatial-writer library to export all data. + * + * @return (null|float|int)[]|(null|float|int)[][]|(null|float|int)[][][]|(null|float|int)[][][][] + */ + public function toArray(): array; + + /** + * Return a copy declared in another spatial reference without transforming + * its coordinates. Use a coordinate transformation service for reprojection. + * + * @param SpatialReference $reference Target spatial reference + */ + public function withSpatialReference(SpatialReference $reference): static; + + /** + * Return a new spatial object with the given Spatial Reference Identifier (SRID). + * + * Coordinates, family, and dimension are preserved. For aggregate spatial + * objects, every contained spatial object receives the requested SRID. + * + * @param int $srid Spatial Reference Identifier + */ + public function withSrid(int $srid): static; +} diff --git a/lib/Interfaces/ImmutableTriangleInterface.php b/lib/Interfaces/ImmutableTriangleInterface.php new file mode 100644 index 0000000..7b059df --- /dev/null +++ b/lib/Interfaces/ImmutableTriangleInterface.php @@ -0,0 +1,26 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +/** Immutable triangle read and copy contract. */ +interface ImmutableTriangleInterface extends ImmutablePolygonInterface, TriangleInterface +{ + /** Return an immutable boundary ring. + * @param int $index Ring index + */ + public function getRing(int $index): ImmutableLineStringInterface; +} diff --git a/lib/Interfaces/LineStringInterface.php b/lib/Interfaces/LineStringInterface.php index ddb9360..104a3a4 100644 --- a/lib/Interfaces/LineStringInterface.php +++ b/lib/Interfaces/LineStringInterface.php @@ -16,8 +16,6 @@ namespace LongitudeOne\SpatialTypes\Interfaces; -use LongitudeOne\SpatialTypes\Value\Coordinates; - /** * LineString interface. * @@ -72,27 +70,4 @@ public function isLine(): bool; * @return (null|float|int)[][] */ public function toArray(): array; - - /** - * Return a new line string with replacement coordinates. - * - * The returned line string preserves this instance's family, dimension, - * and Spatial Reference Identifier (SRID). Each tuple must therefore match - * this instance's coordinate layout: XY, XYM, XYZ, or XYZM. - * - * @param array $coordinates replacement coordinates - */ - public function withArrayOfCoordinates(array $coordinates): static; - - /** - * Return a new line string with one replacement point. - * - * The returned line string preserves this instance's family, dimension, - * and Spatial Reference Identifier (SRID). The coordinate dimension must - * match the point selected by the index. - * - * @param int $pointIndex index of the point to replace; negative indexes count from the end - * @param Coordinates $coordinates replacement point coordinates - */ - public function withPoint(int $pointIndex, Coordinates $coordinates): static; } diff --git a/lib/Interfaces/MultiLineStringInterface.php b/lib/Interfaces/MultiLineStringInterface.php index b83c98e..7b627f6 100644 --- a/lib/Interfaces/MultiLineStringInterface.php +++ b/lib/Interfaces/MultiLineStringInterface.php @@ -16,8 +16,6 @@ namespace LongitudeOne\SpatialTypes\Interfaces; -use LongitudeOne\SpatialTypes\Value\Coordinates; - /** * Multi-line string interface. * @@ -47,25 +45,4 @@ public function getLineStrings(): array; * @return (null|float|int)[][][] */ public function toArray(): array; - - /** - * Return a new multi-line string with one replacement line string. - * - * The returned multi-line string preserves this instance's family, - * dimension, and Spatial Reference Identifier (SRID). Every replacement - * coordinate tuple must match this instance's coordinate layout. - * - * @param int $lineStringIndex index of the line string to replace; negative indexes count from the end - * @param array $coordinates replacement line-string coordinates - */ - public function withLineString(int $lineStringIndex, array $coordinates): static; - - /** - * Return a new multi-line string with one replacement point. - * - * @param int $lineStringIndex index of the line string to replace; negative indexes count from the end - * @param int $pointIndex index of the point to replace; negative indexes count from the end - * @param Coordinates $coordinates replacement point coordinates - */ - public function withPoint(int $lineStringIndex, int $pointIndex, Coordinates $coordinates): static; } diff --git a/lib/Interfaces/MultiPointInterface.php b/lib/Interfaces/MultiPointInterface.php index e98403d..d8784a2 100644 --- a/lib/Interfaces/MultiPointInterface.php +++ b/lib/Interfaces/MultiPointInterface.php @@ -16,8 +16,6 @@ namespace LongitudeOne\SpatialTypes\Interfaces; -use LongitudeOne\SpatialTypes\Value\Coordinates; - /** * Multi-point interface. * @@ -55,16 +53,4 @@ public function isSimple(): bool; * @return (null|float|int)[][] */ public function toArray(): array; - - /** - * Return a new multi-point with one replacement point. - * - * The returned multi-point preserves this instance's family, dimension, - * and Spatial Reference Identifier (SRID). The coordinate dimension must - * match the point selected by the index. - * - * @param int $pointIndex index of the point to replace; negative indexes count from the end - * @param Coordinates $coordinates replacement point coordinates - */ - public function withPoint(int $pointIndex, Coordinates $coordinates): static; } diff --git a/lib/Interfaces/MultiPolygonInterface.php b/lib/Interfaces/MultiPolygonInterface.php index 03baf89..3c8e676 100644 --- a/lib/Interfaces/MultiPolygonInterface.php +++ b/lib/Interfaces/MultiPolygonInterface.php @@ -16,8 +16,6 @@ namespace LongitudeOne\SpatialTypes\Interfaces; -use LongitudeOne\SpatialTypes\Value\Coordinates; - /** * Multi-polygon interface. * @@ -47,31 +45,4 @@ public function getPolygons(): array; * @return (null|float|int)[][][][] */ public function toArray(): array; - - /** - * Return a new multi-polygon with one replacement point. - * - * @param int $polygonIndex index of the polygon to replace; negative indexes count from the end - * @param int $ringIndex index of the ring to replace; negative indexes count from the end - * @param int $pointIndex index of the point to replace; negative indexes count from the end - * @param Coordinates $coordinates replacement point coordinates - */ - public function withPoint(int $polygonIndex, int $ringIndex, int $pointIndex, Coordinates $coordinates): static; - - /** - * Return a new multi-polygon with one replacement polygon. - * - * @param int $polygonIndex index of the polygon to replace; negative indexes count from the end - * @param array> $coordinates replacement polygon coordinates - */ - public function withPolygon(int $polygonIndex, array $coordinates): static; - - /** - * Return a new multi-polygon with one replacement ring. - * - * @param int $polygonIndex index of the polygon to replace; negative indexes count from the end - * @param int $ringIndex index of the ring to replace; negative indexes count from the end - * @param array $coordinates replacement ring coordinates - */ - public function withRing(int $polygonIndex, int $ringIndex, array $coordinates): static; } diff --git a/lib/Interfaces/MutableCircularStringInterface.php b/lib/Interfaces/MutableCircularStringInterface.php new file mode 100644 index 0000000..e80f673 --- /dev/null +++ b/lib/Interfaces/MutableCircularStringInterface.php @@ -0,0 +1,22 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +/** Mutable circularstring contract; type-specific editing is introduced separately. */ +interface MutableCircularStringInterface extends CircularStringInterface, MutableCurveInterface +{ +} diff --git a/lib/Interfaces/MutableCollectionInterface.php b/lib/Interfaces/MutableCollectionInterface.php new file mode 100644 index 0000000..30f421b --- /dev/null +++ b/lib/Interfaces/MutableCollectionInterface.php @@ -0,0 +1,22 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +/** Mutable collection contract; type-specific editing is introduced separately. */ +interface MutableCollectionInterface extends CollectionInterface, MutableSpatialInterface +{ +} diff --git a/lib/Interfaces/MutableCompoundCurveInterface.php b/lib/Interfaces/MutableCompoundCurveInterface.php new file mode 100644 index 0000000..29317c4 --- /dev/null +++ b/lib/Interfaces/MutableCompoundCurveInterface.php @@ -0,0 +1,22 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +/** Mutable compoundcurve contract; type-specific editing is introduced separately. */ +interface MutableCompoundCurveInterface extends CompoundCurveInterface, MutableCurveInterface +{ +} diff --git a/lib/Interfaces/MutableCurveInterface.php b/lib/Interfaces/MutableCurveInterface.php new file mode 100644 index 0000000..0aa73e4 --- /dev/null +++ b/lib/Interfaces/MutableCurveInterface.php @@ -0,0 +1,22 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +/** Mutable curve contract; type-specific editing is introduced separately. */ +interface MutableCurveInterface extends CurveInterface, MutableSpatialInterface +{ +} diff --git a/lib/Interfaces/MutableLineStringInterface.php b/lib/Interfaces/MutableLineStringInterface.php new file mode 100644 index 0000000..8a2a7f9 --- /dev/null +++ b/lib/Interfaces/MutableLineStringInterface.php @@ -0,0 +1,22 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +/** Mutable linestring contract; type-specific editing is introduced separately. */ +interface MutableLineStringInterface extends LineStringInterface, MutableCurveInterface +{ +} diff --git a/lib/Interfaces/MutableMultiLineStringInterface.php b/lib/Interfaces/MutableMultiLineStringInterface.php new file mode 100644 index 0000000..bddc63e --- /dev/null +++ b/lib/Interfaces/MutableMultiLineStringInterface.php @@ -0,0 +1,22 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +/** Mutable multilinestring contract; type-specific editing is introduced separately. */ +interface MutableMultiLineStringInterface extends MultiLineStringInterface, MutableCollectionInterface +{ +} diff --git a/lib/Interfaces/MutableMultiPointInterface.php b/lib/Interfaces/MutableMultiPointInterface.php new file mode 100644 index 0000000..b7334c2 --- /dev/null +++ b/lib/Interfaces/MutableMultiPointInterface.php @@ -0,0 +1,22 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +/** Mutable multipoint contract; type-specific editing is introduced separately. */ +interface MutableMultiPointInterface extends MultiPointInterface, MutableCollectionInterface +{ +} diff --git a/lib/Interfaces/MutableMultiPolygonInterface.php b/lib/Interfaces/MutableMultiPolygonInterface.php new file mode 100644 index 0000000..07d9171 --- /dev/null +++ b/lib/Interfaces/MutableMultiPolygonInterface.php @@ -0,0 +1,22 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +/** Mutable multipolygon contract; type-specific editing is introduced separately. */ +interface MutableMultiPolygonInterface extends MultiPolygonInterface, MutableCollectionInterface +{ +} diff --git a/lib/Interfaces/MutablePointInterface.php b/lib/Interfaces/MutablePointInterface.php new file mode 100644 index 0000000..c03e3b1 --- /dev/null +++ b/lib/Interfaces/MutablePointInterface.php @@ -0,0 +1,22 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +/** Mutable point contract; type-specific editing is introduced separately. */ +interface MutablePointInterface extends MutableSpatialInterface, PointInterface +{ +} diff --git a/lib/Interfaces/MutablePolygonInterface.php b/lib/Interfaces/MutablePolygonInterface.php new file mode 100644 index 0000000..f278f63 --- /dev/null +++ b/lib/Interfaces/MutablePolygonInterface.php @@ -0,0 +1,22 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +/** Mutable polygon contract; type-specific editing is introduced separately. */ +interface MutablePolygonInterface extends MutableSpatialInterface, PolygonInterface +{ +} diff --git a/lib/Interfaces/MutablePolyhedralSurfaceInterface.php b/lib/Interfaces/MutablePolyhedralSurfaceInterface.php new file mode 100644 index 0000000..a1a203f --- /dev/null +++ b/lib/Interfaces/MutablePolyhedralSurfaceInterface.php @@ -0,0 +1,22 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +/** Mutable polyhedralsurface contract; type-specific editing is introduced separately. */ +interface MutablePolyhedralSurfaceInterface extends MutableSpatialInterface, PolyhedralSurfaceInterface +{ +} diff --git a/lib/Interfaces/MutableSpatialInterface.php b/lib/Interfaces/MutableSpatialInterface.php new file mode 100644 index 0000000..79747b9 --- /dev/null +++ b/lib/Interfaces/MutableSpatialInterface.php @@ -0,0 +1,39 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +use LongitudeOne\Core\Enum\SpatialModelEnum; +use LongitudeOne\SpatialTypes\Reference\SpatialReference; + +/** Mutable spatial contract; type-specific editing is introduced separately. */ +interface MutableSpatialInterface extends SpatialInterface +{ + /** Change the declared family without transforming coordinates. + * @param SpatialModelEnum $family Declared spatial family + */ + public function setFamily(SpatialModelEnum $family): static; + + /** Change the declared reference without transforming coordinates. + * @param SpatialReference $reference Declared reference + */ + public function setSpatialReference(SpatialReference $reference): static; + + /** Change the declared SRID without transforming coordinates. + * @param int $srid Declared reference identifier + */ + public function setSrid(int $srid): static; +} diff --git a/lib/Interfaces/MutableTriangleInterface.php b/lib/Interfaces/MutableTriangleInterface.php new file mode 100644 index 0000000..2e5b5a8 --- /dev/null +++ b/lib/Interfaces/MutableTriangleInterface.php @@ -0,0 +1,22 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Interfaces; + +/** Mutable triangle contract; type-specific editing is introduced separately. */ +interface MutableTriangleInterface extends MutablePolygonInterface, TriangleInterface +{ +} diff --git a/lib/Interfaces/PointInterface.php b/lib/Interfaces/PointInterface.php index a22839b..707fc1f 100644 --- a/lib/Interfaces/PointInterface.php +++ b/lib/Interfaces/PointInterface.php @@ -76,14 +76,4 @@ public function getZ(): float|int|null; * @return (null|float|int)[] */ public function toArray(): array; - - /** - * Return a new point with the supplied normalized coordinates. - * - * The coordinates must use the same dimension as this point. The point's - * family and Spatial Reference Identifier (SRID) are preserved. - * - * @param Coordinates $coordinates replacement coordinates - */ - public function withCoordinates(Coordinates $coordinates): static; } diff --git a/lib/Interfaces/PolygonInterface.php b/lib/Interfaces/PolygonInterface.php index fb00fbd..b55e6b2 100644 --- a/lib/Interfaces/PolygonInterface.php +++ b/lib/Interfaces/PolygonInterface.php @@ -16,8 +16,6 @@ namespace LongitudeOne\SpatialTypes\Interfaces; -use LongitudeOne\SpatialTypes\Value\Coordinates; - /** * Polygon interface. * @@ -47,40 +45,4 @@ public function getRings(): array; * @return (null|float|int)[][][] */ public function toArray(): array; - - /** - * Return a new polygon with replacement ring coordinates. - * - * The returned polygon preserves this instance's family, dimension, and - * Spatial Reference Identifier (SRID). Every coordinate tuple must match - * this instance's coordinate layout; ring closure is not checked. - * - * @param array> $coordinates replacement ring coordinates - */ - public function withArrayOfCoordinates(array $coordinates): static; - - /** - * Return a new polygon with one replacement point in a ring. - * - * The returned polygon preserves this instance's family, dimension, and - * Spatial Reference Identifier (SRID). A replacement of the first or last - * point of a ring is applied to both endpoints to preserve ring closure. - * - * @param int $ringIndex index of the ring to replace; negative indexes count from the end - * @param int $pointIndex index of the point to replace; negative indexes count from the end - * @param Coordinates $coordinates replacement point coordinates - */ - public function withPoint(int $ringIndex, int $pointIndex, Coordinates $coordinates): static; - - /** - * Return a new polygon with one replacement ring. - * - * The returned polygon preserves this instance's family, dimension, and - * Spatial Reference Identifier (SRID). The replacement coordinates must - * use this polygon's coordinate layout; ring closure is not checked. - * - * @param int $ringIndex index of the ring to replace; negative indexes count from the end - * @param array $coordinates replacement ring coordinates - */ - public function withRing(int $ringIndex, array $coordinates): static; } diff --git a/lib/Interfaces/PolyhedralSurfaceInterface.php b/lib/Interfaces/PolyhedralSurfaceInterface.php index bba1cba..1726ca8 100644 --- a/lib/Interfaces/PolyhedralSurfaceInterface.php +++ b/lib/Interfaces/PolyhedralSurfaceInterface.php @@ -16,8 +16,6 @@ namespace LongitudeOne\SpatialTypes\Interfaces; -use LongitudeOne\SpatialTypes\Value\Coordinates; - /** A connected surface of polygon patches, with an optional open boundary. */ interface PolyhedralSurfaceInterface extends SpatialInterface { @@ -48,38 +46,4 @@ public function getPatches(): array; * @return (null|float|int)[][][][] */ public function toArray(): array; - - /** - * Return an independent surface with replacement patch coordinates. - * - * @param array>> $coordinates Patch coordinates - */ - public function withArrayOfCoordinates(array $coordinates): static; - - /** - * Return a new polyhedral surface with one replacement polygon. - * - * @param int $patchIndex index of the polygon to replace; negative indexes count from the end - * @param array> $coordinates replacement polygon coordinates - */ - public function withPatch(int $patchIndex, array $coordinates): static; - - /** - * Return a new polyhedral surface with one replacement point. - * - * @param int $patchIndex index of the polygon to replace; negative indexes count from the end - * @param int $ringIndex index of the ring to replace; negative indexes count from the end - * @param int $pointIndex index of the point to replace; negative indexes count from the end - * @param Coordinates $coordinates replacement point coordinates - */ - public function withPoint(int $patchIndex, int $ringIndex, int $pointIndex, Coordinates $coordinates): static; - - /** - * Return a new polyhedral surface with one replacement ring. - * - * @param int $patchIndex index of the polygon to replace; negative indexes count from the end - * @param int $ringIndex index of the ring to replace; negative indexes count from the end - * @param array $coordinates replacement ring coordinates - */ - public function withRing(int $patchIndex, int $ringIndex, array $coordinates): static; } diff --git a/lib/Interfaces/SpatialInterface.php b/lib/Interfaces/SpatialInterface.php index 00fce8f..c62d213 100644 --- a/lib/Interfaces/SpatialInterface.php +++ b/lib/Interfaces/SpatialInterface.php @@ -29,8 +29,8 @@ * the type, spatial reference identifier (SRID), and coordinate-dimension * information required by the concrete spatial types. * - * Operations prefixed with {@see with} return a new instance and never alter - * the instance on which they are called. + * This common contract exposes read operations only. Copy operations belong + * to ImmutableSpatialInterface; mutation belongs to MutableSpatialInterface. */ interface SpatialInterface extends \JsonSerializable { @@ -98,22 +98,4 @@ public function isEmpty(): bool; * @return (null|float|int)[]|(null|float|int)[][]|(null|float|int)[][][]|(null|float|int)[][][][] */ public function toArray(): array; - - /** - * Return a copy declared in another spatial reference without transforming - * its coordinates. Use a coordinate transformation service for reprojection. - * - * @param SpatialReference $reference Target spatial reference - */ - public function withSpatialReference(SpatialReference $reference): static; - - /** - * Return a new spatial object with the given Spatial Reference Identifier (SRID). - * - * Coordinates, family, and dimension are preserved. For aggregate spatial - * objects, every contained spatial object receives the requested SRID. - * - * @param int $srid Spatial Reference Identifier - */ - public function withSrid(int $srid): static; } diff --git a/lib/Types/AbstractCircularString.php b/lib/Types/AbstractCircularStringImmutable.php similarity index 75% rename from lib/Types/AbstractCircularString.php rename to lib/Types/AbstractCircularStringImmutable.php index 3b1667b..d186f0e 100644 --- a/lib/Types/AbstractCircularString.php +++ b/lib/Types/AbstractCircularStringImmutable.php @@ -21,8 +21,8 @@ use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\MissingValueException; use LongitudeOne\SpatialTypes\Exception\OutOfBoundsException; -use LongitudeOne\SpatialTypes\Interfaces\CircularStringInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableCircularStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; use LongitudeOne\SpatialTypes\Value\Coordinates; @@ -31,14 +31,14 @@ * * @internal */ -abstract class AbstractCircularString extends AbstractSpatialType implements CircularStringInterface +abstract class AbstractCircularStringImmutable extends AbstractSpatialTypeImmutable implements ImmutableCircularStringInterface { - /** @var PointInterface[] */ + /** @var ImmutablePointInterface[] */ protected array $points = []; /** - * @param array $points Defining points or tuples - * @param int|SpatialReference $srid Spatial reference + * @param array $points Defining points or tuples + * @param int|SpatialReference $srid Spatial reference */ final public function __construct(array $points, int|SpatialReference $srid = 0) { @@ -46,14 +46,14 @@ final public function __construct(array $points, int|SpatialReference $srid = 0) $this->addPoints($points); } - /** @return PointInterface[] */ + /** @return ImmutablePointInterface[] */ public function getElements(): array { return $this->getPoints(); } /** Return the last defining point, or null for an empty curve. */ - public function getEndPoint(): ?PointInterface + public function getEndPoint(): ?ImmutablePointInterface { return $this->isEmpty() ? null : $this->getPoint(-1); } @@ -63,7 +63,7 @@ public function getEndPoint(): ?PointInterface * * @param int $index Requested index */ - public function getPoint(int $index): PointInterface + public function getPoint(int $index): ImmutablePointInterface { if ([] === $this->points) { throw new OutOfBoundsException('The current collection of points is empty.'); @@ -74,14 +74,14 @@ public function getPoint(int $index): PointInterface return $this->points[$index < 0 ? count($this->points) + $index : $index]; } - /** @return PointInterface[] */ + /** @return ImmutablePointInterface[] */ public function getPoints(): array { return $this->points; } /** Return the first defining point, or null for an empty curve. */ - public function getStartPoint(): ?PointInterface + public function getStartPoint(): ?ImmutablePointInterface { return $this->isEmpty() ? null : $this->getPoint(0); } @@ -110,7 +110,7 @@ public function isEmpty(): bool public function toArray(): array { return array_map( - static fn (PointInterface $point): array => $point->toArray(), + static fn (ImmutablePointInterface $point): array => $point->toArray(), $this->points ); } @@ -135,7 +135,7 @@ public function withPoint(int $pointIndex, Coordinates $coordinates): static $pointIndex += count($this->points); } $points = array_map( - static fn (PointInterface $item): PointInterface => $item->withSpatialReference($item->getSpatialReference()), + static fn (ImmutablePointInterface $item): ImmutablePointInterface => $item->withSpatialReference($item->getSpatialReference()), $this->points ); $points[$pointIndex] = $point->withCoordinates($coordinates); @@ -149,37 +149,38 @@ public function withPoint(int $pointIndex, Coordinates $coordinates): static public function withSpatialReference(SpatialReference $reference): static { return new static(array_map( - static fn (PointInterface $point): PointInterface => $point->withSpatialReference($reference), + static fn (ImmutablePointInterface $point): ImmutablePointInterface => $point->withSpatialReference($reference), $this->points ), $reference); } /** - * @param array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}|PointInterface $point Point or coordinate tuple to add + * @param array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}|ImmutablePointInterface $point Point or coordinate tuple to add * * @throws InvalidDimensionException When a coordinate tuple has an incompatible layout * @throws InvalidValueException When coordinates are invalid * @throws MissingValueException When a coordinate is missing */ - protected function addPoint(array|PointInterface $point): static + protected function addPoint(array|ImmutablePointInterface $point): static { if (is_array($point)) { $point = $this->createPointFromCoordinates($point); } + ImmutableComponentGuard::check($point); $this->points[] = $point; return $this; } /** - * @param array $points Points or tuples to add + * @param array $points Points or tuples to add */ protected function addPoints(array $points): static { foreach ($points as $point) { - if (!is_array($point) && !$point instanceof PointInterface) { - throw new InvalidValueException('Argument shall contain an array of PointInterface or an array of coordinates.'); + if (!is_array($point) && !$point instanceof ImmutablePointInterface) { + throw new InvalidValueException('Argument shall contain an array of ImmutablePointInterface or an array of coordinates.'); } $this->addPoint($point); diff --git a/lib/Types/AbstractCollection.php b/lib/Types/AbstractCollectionImmutable.php similarity index 74% rename from lib/Types/AbstractCollection.php rename to lib/Types/AbstractCollectionImmutable.php index 733bcd3..b57398a 100644 --- a/lib/Types/AbstractCollection.php +++ b/lib/Types/AbstractCollectionImmutable.php @@ -18,28 +18,28 @@ use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\OutOfBoundsException; -use LongitudeOne\SpatialTypes\Interfaces\CollectionInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableCollectionInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableSpatialInterface; use LongitudeOne\SpatialTypes\Interfaces\SpatialInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollection; /** * Abstract collection class. * * @internal this class provides common behaviour for geometry and geography collections */ -abstract class AbstractCollection extends AbstractSpatialType implements CollectionInterface +abstract class AbstractCollectionImmutable extends AbstractSpatialTypeImmutable implements ImmutableCollectionInterface { /** - * @var SpatialInterface[] Elements of the collection + * @var ImmutableSpatialInterface[] Elements of the collection */ private array $elements = []; /** * GeometryCollection constructor. * - * @param int|SpatialReference $srid Spatial Reference Identifier - * @param SpatialInterface[] $elements initial elements of the collection + * @param int|SpatialReference $srid Spatial Reference Identifier + * @param ImmutableSpatialInterface[] $elements initial elements of the collection */ public function __construct(int|SpatialReference $srid = 0, array $elements = []) { @@ -50,7 +50,7 @@ public function __construct(int|SpatialReference $srid = 0, array $elements = [] /** * Get an array of spatial objects in the collection. * - * @return SpatialInterface[] Elements of the collection + * @return ImmutableSpatialInterface[] Elements of the collection */ public function getElements(): array { @@ -93,15 +93,15 @@ public function toArray(): array /** * Return a deep copy of this collection with one replacement element. * - * The replacement must implement SpatialInterface. Every unchanged element is copied to keep the returned collection + * The replacement must implement ImmutableSpatialInterface. Every unchanged element is copied to keep the returned collection * independent from its source. * - * @param int $elementIndex index of the element to replace; negative indexes count from the end - * @param SpatialInterface $element replacement spatial element + * @param int $elementIndex index of the element to replace; negative indexes count from the end + * @param ImmutableSpatialInterface $element replacement spatial element * * @throws OutOfBoundsException when the collection has no elements */ - public function withElement(int $elementIndex, SpatialInterface $element): static + public function withElement(int $elementIndex, ImmutableSpatialInterface $element): static { $elementIndex = $this->normalizeElementIndex($elementIndex); $collection = clone $this; @@ -123,7 +123,7 @@ public function withSpatialReference(SpatialReference $reference): static { $collection = parent::withSpatialReference($reference); $collection->elements = array_map( - static fn (SpatialInterface $element): SpatialInterface => $element->withSpatialReference($reference), + static fn (ImmutableSpatialInterface $element): ImmutableSpatialInterface => $element->withSpatialReference($reference), $this->elements ); @@ -146,10 +146,11 @@ public function withSrid(int $srid): static /** * Add a spatial object to the collection. * - * @param SpatialInterface $spatial Spatial object to add to the collection + * @param ImmutableSpatialInterface $spatial Spatial object to add to the collection */ - protected function addElement(SpatialInterface $spatial): static + protected function addElement(ImmutableSpatialInterface $spatial): static { + ImmutableComponentGuard::check($spatial); $this->elements[] = $spatial; return $this; @@ -158,13 +159,13 @@ protected function addElement(SpatialInterface $spatial): static /** * Add spatial objects to the collection. * - * @param SpatialInterface[] $elements spatial objects to add to the collection + * @param ImmutableSpatialInterface[] $elements spatial objects to add to the collection */ protected function addElements(array $elements): static { foreach ($elements as $element) { - if (!$element instanceof SpatialInterface) { - throw new InvalidValueException('The array must contain only objects implementing SpatialInterface.'); + if (!$element instanceof ImmutableSpatialInterface) { + throw new InvalidValueException('The array must contain only objects implementing ImmutableSpatialInterface.'); } $this->addElement($element); diff --git a/lib/Types/AbstractCompoundCurve.php b/lib/Types/AbstractCompoundCurveImmutable.php similarity index 73% rename from lib/Types/AbstractCompoundCurve.php rename to lib/Types/AbstractCompoundCurveImmutable.php index 25a4ed6..5e4222d 100644 --- a/lib/Types/AbstractCompoundCurve.php +++ b/lib/Types/AbstractCompoundCurveImmutable.php @@ -19,9 +19,9 @@ use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\OutOfBoundsException; -use LongitudeOne\SpatialTypes\Interfaces\CompoundCurveInterface; -use LongitudeOne\SpatialTypes\Interfaces\CurveInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableCompoundCurveInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableCurveInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; /** @@ -31,21 +31,21 @@ * * @internal */ -abstract class AbstractCompoundCurve extends AbstractSpatialType implements CompoundCurveInterface +abstract class AbstractCompoundCurveImmutable extends AbstractSpatialTypeImmutable implements ImmutableCompoundCurveInterface { - /** @var CurveInterface[] */ + /** @var ImmutableCurveInterface[] */ protected array $curves = []; /** - * @param CurveInterface[] $curves Ordered line-string or circular-string components - * @param int|SpatialReference $srid Spatial reference + * @param ImmutableCurveInterface[] $curves Ordered line-string or circular-string components + * @param int|SpatialReference $srid Spatial reference */ final public function __construct(array $curves = [], int|SpatialReference $srid = 0) { $this->initializeSpatialReference($srid); foreach ($curves as $curve) { - if (!$curve instanceof CurveInterface) { - throw new InvalidValueException('A compound curve requires CurveInterface components.'); + if (!$curve instanceof ImmutableCurveInterface) { + throw new InvalidValueException('A compound curve requires ImmutableCurveInterface components.'); } $this->addCurve($curve); } @@ -56,7 +56,7 @@ final public function __construct(array $curves = [], int|SpatialReference $srid * * @param int $index Requested index */ - public function getCurve(int $index): CurveInterface + public function getCurve(int $index): ImmutableCurveInterface { if ([] === $this->curves) { throw new OutOfBoundsException('The current collection of curves is empty.'); @@ -66,26 +66,26 @@ public function getCurve(int $index): CurveInterface return $this->curves[$index < 0 ? count($this->curves) + $index : $index]; } - /** @return CurveInterface[] */ + /** @return ImmutableCurveInterface[] */ public function getCurves(): array { return $this->curves; } - /** @return CurveInterface[] */ + /** @return ImmutableCurveInterface[] */ public function getElements(): array { return $this->getCurves(); } /** Return the final component's endpoint, or null for EMPTY. */ - public function getEndPoint(): ?PointInterface + public function getEndPoint(): ?ImmutablePointInterface { return $this->isEmpty() ? null : $this->getCurve(-1)->getEndPoint(); } /** Return the first component's start point, or null for EMPTY. */ - public function getStartPoint(): ?PointInterface + public function getStartPoint(): ?ImmutablePointInterface { return $this->isEmpty() ? null : $this->getCurve(0)->getStartPoint(); } @@ -115,7 +115,7 @@ public function isEmpty(): bool public function toArray(): array { return array_map( - fn (CurveInterface $curve): array => $this->componentCoordinates($curve), + fn (ImmutableCurveInterface $curve): array => $this->componentCoordinates($curve), $this->curves ); } @@ -128,7 +128,7 @@ public function toArray(): array public function withSpatialReference(SpatialReference $reference): static { return new static(array_map( - static fn (CurveInterface $curve): CurveInterface => $curve->withSpatialReference($reference), + static fn (ImmutableCurveInterface $curve): ImmutableCurveInterface => $curve->withSpatialReference($reference), $this->curves ), $reference); } @@ -136,22 +136,23 @@ public function withSpatialReference(SpatialReference $reference): static /** * Append a typed component without altering its interpolation. * - * @param CurveInterface $curve Component to append + * @param ImmutableCurveInterface $curve Component to append */ - private function addCurve(CurveInterface $curve): void + private function addCurve(ImmutableCurveInterface $curve): void { $this->componentCoordinates($curve); + ImmutableComponentGuard::check($curve); $this->curves[] = $curve; } /** * Read the point tuples of a supported component without losing ordinates. * - * @param CurveInterface $curve Component whose coordinates are requested + * @param ImmutableCurveInterface $curve Component whose coordinates are requested * * @return (null|float|int)[][] */ - private function componentCoordinates(CurveInterface $curve): array + private function componentCoordinates(ImmutableCurveInterface $curve): array { $coordinates = []; foreach ($curve->toArray() as $point) { diff --git a/lib/Types/AbstractLineString.php b/lib/Types/AbstractLineStringImmutable.php similarity index 87% rename from lib/Types/AbstractLineString.php rename to lib/Types/AbstractLineStringImmutable.php index e73892e..06a6fad 100644 --- a/lib/Types/AbstractLineString.php +++ b/lib/Types/AbstractLineStringImmutable.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Types; use LongitudeOne\SpatialTypes\Exception\OutOfBoundsException; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Collection\AbstractPointCollection; +use LongitudeOne\SpatialTypes\Types\Collection\AbstractPointCollectionImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; /** @@ -28,12 +28,12 @@ * * @internal this class provides common behaviour for geometry and geography line strings */ -abstract class AbstractLineString extends AbstractPointCollection implements LineStringInterface +abstract class AbstractLineStringImmutable extends AbstractPointCollectionImmutable implements ImmutableLineStringInterface { /** * Get the elements of this line string. * - * @return PointInterface[] + * @return ImmutablePointInterface[] */ public function getElements(): array { @@ -41,13 +41,13 @@ public function getElements(): array } /** Return the last defining point, or null for an empty curve. */ - public function getEndPoint(): ?PointInterface + public function getEndPoint(): ?ImmutablePointInterface { return $this->isEmpty() ? null : $this->getPoint(-1); } /** Return the first defining point, or null for an empty curve. */ - public function getStartPoint(): ?PointInterface + public function getStartPoint(): ?ImmutablePointInterface { return $this->isEmpty() ? null : $this->getPoint(0); } @@ -80,7 +80,7 @@ public function toArray(): array $points = $this->getPoints(); return array_map( - static fn (PointInterface $point) => $point->toArray(), + static fn (ImmutablePointInterface $point) => $point->toArray(), $points ); } @@ -122,7 +122,7 @@ public function withPoint(int $pointIndex, Coordinates $coordinates): static $pointIndex = $this->normalizePointIndex($pointIndex); $lineString = clone $this; $lineString->points = array_map( - static fn (PointInterface $point): PointInterface => $point->withSrid($point->getSrid()), + static fn (ImmutablePointInterface $point): ImmutablePointInterface => $point->withSrid($point->getSrid()), $this->points ); $lineString->points[$pointIndex] = $lineString->points[$pointIndex]->withCoordinates($coordinates); @@ -139,7 +139,7 @@ public function withSpatialReference(SpatialReference $reference): static { $lineString = parent::withSpatialReference($reference); $lineString->points = array_map( - static fn (PointInterface $point): PointInterface => $point->withSpatialReference($reference), + static fn (ImmutablePointInterface $point): ImmutablePointInterface => $point->withSpatialReference($reference), $this->points ); diff --git a/lib/Types/AbstractMultiLineString.php b/lib/Types/AbstractMultiLineStringImmutable.php similarity index 82% rename from lib/Types/AbstractMultiLineString.php rename to lib/Types/AbstractMultiLineStringImmutable.php index 2ac1911..6a65073 100644 --- a/lib/Types/AbstractMultiLineString.php +++ b/lib/Types/AbstractMultiLineStringImmutable.php @@ -21,11 +21,11 @@ use LongitudeOne\SpatialTypes\Exception\MissingValueException; use LongitudeOne\SpatialTypes\Exception\OutOfBoundsException; use LongitudeOne\SpatialTypes\Exception\SpatialTypeExceptionInterface; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Interfaces\MultiLineStringInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Collection\AbstractLineStringCollection; +use LongitudeOne\SpatialTypes\Types\Collection\AbstractLineStringCollectionImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; /** @@ -33,13 +33,13 @@ * * @internal this class provides common behaviour for geometry and geography multi-line strings */ -abstract class AbstractMultiLineString extends AbstractLineStringCollection implements MultiLineStringInterface +abstract class AbstractMultiLineStringImmutable extends AbstractLineStringCollectionImmutable implements ImmutableMultiLineStringInterface { /** - * AbstractMultiLineString constructor. + * AbstractMultiLineStringImmutable constructor. * - * @param (array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}[]|LineStringInterface|PointInterface[])[] $lineStrings lineStrings of the multiLineString - * @param int|SpatialReference $srid Spatial Reference Identifier + * @param (array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}[]|ImmutableLineStringInterface|ImmutablePointInterface[])[] $lineStrings lineStrings of the multiLineString + * @param int|SpatialReference $srid Spatial Reference Identifier * * @throws InvalidDimensionException when the point dimension is not compatible with the multiLineStlineString dimension * @throws InvalidValueException when coordinates of the point are invalid @@ -54,7 +54,7 @@ public function __construct(array $lineStrings, int|SpatialReference $srid = 0) /** * Get the elements of this multiLineString. * - * @return LineStringInterface[] + * @return ImmutableLineStringInterface[] */ public function getElements(): array { @@ -66,7 +66,7 @@ public function getElements(): array * * @param int $index Index of the lineString */ - public function getLineString(int $index): LineStringInterface + public function getLineString(int $index): ImmutableLineStringInterface { if (empty($this->getLineStrings())) { throw new OutOfBoundsException('The current collection of lineStrings is empty.'); @@ -84,7 +84,7 @@ public function getLineString(int $index): LineStringInterface /** * Get the line strings of the spatial collection. * - * @return LineStringInterface[] + * @return ImmutableLineStringInterface[] */ public function getLineStrings(): array { @@ -109,7 +109,7 @@ public function toArray(): array $lineStrings = $this->getLineStrings(); return array_map( - static fn (LineStringInterface $lineString) => $lineString->toArray(), + static fn (ImmutableLineStringInterface $lineString) => $lineString->toArray(), $lineStrings ); } @@ -153,7 +153,7 @@ public function withPoint(int $lineStringIndex, int $pointIndex, Coordinates $co $lineStringIndex = $this->normalizeLineStringIndex($lineStringIndex); $multiLineString = clone $this; $multiLineString->lineStrings = array_map( - static fn (LineStringInterface $lineString): LineStringInterface => $lineString->withSrid($lineString->getSrid()), + static fn (ImmutableLineStringInterface $lineString): ImmutableLineStringInterface => $lineString->withSrid($lineString->getSrid()), $this->lineStrings ); $multiLineString->lineStrings[$lineStringIndex] = $multiLineString->lineStrings[$lineStringIndex]->withPoint($pointIndex, $coordinates); @@ -170,7 +170,7 @@ public function withSpatialReference(SpatialReference $reference): static { $multiLineString = parent::withSpatialReference($reference); $multiLineString->lineStrings = array_map( - static fn (LineStringInterface $lineString): LineStringInterface => $lineString->withSpatialReference($reference), + static fn (ImmutableLineStringInterface $lineString): ImmutableLineStringInterface => $lineString->withSpatialReference($reference), $this->lineStrings ); @@ -193,11 +193,11 @@ public function withSrid(int $srid): static /** * Add a line string to the spatial collection. * - * @param array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}[]|LineStringInterface|PointInterface[] $lineString line string to add + * @param array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}[]|ImmutableLineStringInterface|ImmutablePointInterface[] $lineString line string to add * * @throws InvalidValueException when the line string dimension is not compatible with the current dimension */ - protected function addLineString(array|LineStringInterface $lineString): static + protected function addLineString(array|ImmutableLineStringInterface $lineString): static { return $this->addLineStringMember($lineString); } @@ -205,7 +205,7 @@ protected function addLineString(array|LineStringInterface $lineString): static /** * Add line strings to the spatial collection. * - * @param array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}[][]|LineStringInterface[]|PointInterface[][] $lineStrings the ring to add + * @param array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}[][]|ImmutableLineStringInterface[]|ImmutablePointInterface[][] $lineStrings the ring to add * * @throws SpatialTypeExceptionInterface when something is wrong during the addition */ diff --git a/lib/Types/AbstractMultiPoint.php b/lib/Types/AbstractMultiPointImmutable.php similarity index 84% rename from lib/Types/AbstractMultiPoint.php rename to lib/Types/AbstractMultiPointImmutable.php index 5e45afb..61373e7 100644 --- a/lib/Types/AbstractMultiPoint.php +++ b/lib/Types/AbstractMultiPointImmutable.php @@ -20,10 +20,10 @@ use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\MissingValueException; use LongitudeOne\SpatialTypes\Exception\OutOfBoundsException; -use LongitudeOne\SpatialTypes\Interfaces\MultiPointInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Collection\AbstractPointCollection; +use LongitudeOne\SpatialTypes\Types\Collection\AbstractPointCollectionImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; /** @@ -31,13 +31,13 @@ * * @internal this class provides common behaviour for geometry and geography multi-points */ -abstract class AbstractMultiPoint extends AbstractPointCollection implements MultiPointInterface +abstract class AbstractMultiPointImmutable extends AbstractPointCollectionImmutable implements ImmutableMultiPointInterface { /** - * AbstractMultiPoint constructor. + * AbstractMultiPointImmutable constructor. * - * @param (array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}|PointInterface)[] $points points of the multipoint - * @param int|SpatialReference $srid Spatial Reference Identifier + * @param (array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}|ImmutablePointInterface)[] $points points of the multipoint + * @param int|SpatialReference $srid Spatial Reference Identifier * * @throws InvalidDimensionException when the point dimension is not compatible with the multipoint dimension * @throws InvalidValueException when coordinates of the point are invalid @@ -48,7 +48,7 @@ abstract public function __construct(array $points, int|SpatialReference $srid = /** * Get the elements (the points) of this multipoint. * - * @return PointInterface[] + * @return ImmutablePointInterface[] */ public function getElements(): array { @@ -73,7 +73,7 @@ public function withPoint(int $pointIndex, Coordinates $coordinates): static $pointIndex = $this->normalizePointIndex($pointIndex); $multiPoint = clone $this; $multiPoint->points = array_map( - static fn (PointInterface $point): PointInterface => $point->withSrid($point->getSrid()), + static fn (ImmutablePointInterface $point): ImmutablePointInterface => $point->withSrid($point->getSrid()), $this->points ); $multiPoint->points[$pointIndex] = $multiPoint->points[$pointIndex]->withCoordinates($coordinates); @@ -90,7 +90,7 @@ public function withSpatialReference(SpatialReference $reference): static { $multiPoint = parent::withSpatialReference($reference); $multiPoint->points = array_map( - static fn (PointInterface $point): PointInterface => $point->withSpatialReference($reference), + static fn (ImmutablePointInterface $point): ImmutablePointInterface => $point->withSpatialReference($reference), $this->points ); diff --git a/lib/Types/AbstractMultiPolygon.php b/lib/Types/AbstractMultiPolygonImmutable.php similarity index 85% rename from lib/Types/AbstractMultiPolygon.php rename to lib/Types/AbstractMultiPolygonImmutable.php index b95d675..a68f3ed 100644 --- a/lib/Types/AbstractMultiPolygon.php +++ b/lib/Types/AbstractMultiPolygonImmutable.php @@ -21,8 +21,8 @@ use LongitudeOne\SpatialTypes\Exception\MissingValueException; use LongitudeOne\SpatialTypes\Exception\OutOfBoundsException; use LongitudeOne\SpatialTypes\Exception\SpatialTypeExceptionInterface; -use LongitudeOne\SpatialTypes\Interfaces\MultiPolygonInterface; -use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPolygonInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolygonInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; use LongitudeOne\SpatialTypes\Value\Coordinates; @@ -34,18 +34,18 @@ * * @internal this class provides common behaviour for geometry and geography multi-polygons */ -abstract class AbstractMultiPolygon extends AbstractSpatialType implements MultiPolygonInterface +abstract class AbstractMultiPolygonImmutable extends AbstractSpatialTypeImmutable implements ImmutableMultiPolygonInterface { /** - * @var PolygonInterface[] Polygons + * @var ImmutablePolygonInterface[] Polygons */ private array $polygons = []; /** - * AbstractMultiPolygon constructor. + * AbstractMultiPolygonImmutable constructor. * - * @param (IndexedPolygon|PolygonInterface)[] $polygons polygons - * @param int|SpatialReference $srid Spatial Reference Identifier + * @param (ImmutablePolygonInterface|IndexedPolygon)[] $polygons polygons + * @param int|SpatialReference $srid Spatial Reference Identifier * * @throws InvalidDimensionException when a coordinate tuple does not match the polygon dimension * @throws InvalidValueException when coordinates of the point are invalid @@ -60,7 +60,7 @@ public function __construct(array $polygons, int|SpatialReference $srid = 0) /** * Return the polygons in this multi-polygon. * - * @return PolygonInterface[] + * @return ImmutablePolygonInterface[] */ public function getElements(): array { @@ -74,7 +74,7 @@ public function getElements(): array * * @throws OutOfBoundsException when the multipolygon is empty */ - public function getPolygon(int $index): PolygonInterface + public function getPolygon(int $index): ImmutablePolygonInterface { if (empty($this->getPolygons())) { throw new OutOfBoundsException('The current collection of polygons is empty.'); @@ -92,7 +92,7 @@ public function getPolygon(int $index): PolygonInterface /** * Get the rings of the spatial collection. * - * @return PolygonInterface[] + * @return ImmutablePolygonInterface[] * * @throws InvalidValueException when at least one of the line strings is not a ring */ @@ -119,7 +119,7 @@ public function toArray(): array $polygons = $this->getPolygons(); return array_map( - static fn (PolygonInterface $polygon) => $polygon->toArray(), + static fn (ImmutablePolygonInterface $polygon) => $polygon->toArray(), $polygons ); } @@ -140,7 +140,7 @@ public function withPoint(int $polygonIndex, int $ringIndex, int $pointIndex, Co return $this->withReplacedPolygon( $polygonIndex, - fn (PolygonInterface $polygon): PolygonInterface => $polygon->withPoint($ringIndex, $pointIndex, $coordinates) + fn (ImmutablePolygonInterface $polygon): ImmutablePolygonInterface => $polygon->withPoint($ringIndex, $pointIndex, $coordinates) ); } @@ -180,7 +180,7 @@ public function withRing(int $polygonIndex, int $ringIndex, array $coordinates): return $this->withReplacedPolygon( $polygonIndex, - fn (PolygonInterface $polygon): PolygonInterface => $polygon->withRing($ringIndex, $coordinates) + fn (ImmutablePolygonInterface $polygon): ImmutablePolygonInterface => $polygon->withRing($ringIndex, $coordinates) ); } @@ -193,7 +193,7 @@ public function withSpatialReference(SpatialReference $reference): static { $multiPolygon = parent::withSpatialReference($reference); $multiPolygon->polygons = array_map( - static fn (PolygonInterface $polygon): PolygonInterface => $polygon->withSpatialReference($reference), + static fn (ImmutablePolygonInterface $polygon): ImmutablePolygonInterface => $polygon->withSpatialReference($reference), $this->polygons ); @@ -216,16 +216,17 @@ public function withSrid(int $srid): static /** * Add a polygon to this multi-polygon. * - * @param IndexedPolygon|PolygonInterface $polygon polygon + * @param ImmutablePolygonInterface|IndexedPolygon $polygon polygon * * @throws SpatialTypeExceptionInterface when something is wrong during the addition of the polygon */ - protected function addPolygon(array|PolygonInterface $polygon): static + protected function addPolygon(array|ImmutablePolygonInterface $polygon): static { if (is_array($polygon)) { $polygon = $this->createPolygonFromCoordinates($polygon); } + ImmutableComponentGuard::check($polygon); $this->polygons[] = $polygon; return $this; @@ -234,7 +235,7 @@ protected function addPolygon(array|PolygonInterface $polygon): static /** * Add polygons to the multipolygon instance. * - * @param (IndexedPolygon|PolygonInterface)[] $polygons polygons + * @param (ImmutablePolygonInterface|IndexedPolygon)[] $polygons polygons * * @throws SpatialTypeExceptionInterface when something is wrong during the addition of the polygons */ diff --git a/lib/Types/AbstractPoint.php b/lib/Types/AbstractPointImmutable.php similarity index 97% rename from lib/Types/AbstractPoint.php rename to lib/Types/AbstractPointImmutable.php index 6f7126a..2a35c9b 100644 --- a/lib/Types/AbstractPoint.php +++ b/lib/Types/AbstractPointImmutable.php @@ -24,6 +24,7 @@ use LongitudeOne\SpatialTypes\Exception\InvalidDimensionException; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\RangeException; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Interfaces\PointInterface; use LongitudeOne\SpatialTypes\Value\Coordinates; @@ -35,7 +36,7 @@ * * @internal this class provides common behaviour for geometry and geography points */ -abstract class AbstractPoint extends AbstractSpatialType implements PointInterface +abstract class AbstractPointImmutable extends AbstractSpatialTypeImmutable implements ImmutablePointInterface { /** * The X coordinate or the longitude. @@ -299,7 +300,7 @@ protected function setCartesianCoordinate(float|int|string|null $coordinate): fl * Convert point into an array of coordinates. * SRID is NOT exported. * - * The array contains coordinate values only; it does not contain SpatialInterface instances. + * The array contains coordinate values only; it does not contain spatial object instances. */ abstract public function toArray(): array; } diff --git a/lib/Types/AbstractPolygon.php b/lib/Types/AbstractPolygonImmutable.php similarity index 82% rename from lib/Types/AbstractPolygon.php rename to lib/Types/AbstractPolygonImmutable.php index 44f2fd2..a62a04a 100644 --- a/lib/Types/AbstractPolygon.php +++ b/lib/Types/AbstractPolygonImmutable.php @@ -22,9 +22,9 @@ use LongitudeOne\SpatialTypes\Exception\MissingValueException; use LongitudeOne\SpatialTypes\Exception\OutOfBoundsException; use LongitudeOne\SpatialTypes\Exception\SpatialTypeExceptionInterface; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; -use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolygonInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; use LongitudeOne\SpatialTypes\Value\Coordinates; @@ -33,16 +33,16 @@ * * @internal this class provides common behaviour for geometry and geography polygons */ -abstract class AbstractPolygon extends AbstractSpatialType implements PolygonInterface +abstract class AbstractPolygonImmutable extends AbstractSpatialTypeImmutable implements ImmutablePolygonInterface { /** ISO polygon boundary: an exterior ring followed by interior rings. */ protected PolygonBoundary $boundary; /** - * AbstractPolygon constructor. + * AbstractPolygonImmutable constructor. * - * @param (array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}[]|LineStringInterface|PointInterface[])[] $rings rings of the polygon - * @param int|SpatialReference $srid Spatial Reference Identifier + * @param (array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}[]|ImmutableLineStringInterface|ImmutablePointInterface[])[] $rings rings of the polygon + * @param int|SpatialReference $srid Spatial Reference Identifier * * @throws InvalidDimensionException when a coordinate tuple does not match the polygon dimension * @throws InvalidValueException when coordinates of the point are invalid @@ -58,7 +58,7 @@ public function __construct(array $rings, int|SpatialReference $srid = 0) /** * Return the rings in this polygon. * - * @return LineStringInterface[] + * @return ImmutableLineStringInterface[] */ public function getElements(): array { @@ -70,7 +70,7 @@ public function getElements(): array * * @param int $index Index of the ring */ - public function getRing(int $index): LineStringInterface + public function getRing(int $index): ImmutableLineStringInterface { return $this->boundary->ringAt($index); } @@ -78,7 +78,7 @@ public function getRing(int $index): LineStringInterface /** * Get the rings of the spatial collection. * - * @return LineStringInterface[] + * @return ImmutableLineStringInterface[] */ public function getRings(): array { @@ -103,7 +103,7 @@ public function toArray(): array $rings = $this->getRings(); return array_map( - static fn (LineStringInterface $ring) => $ring->toArray(), + static fn (ImmutableLineStringInterface $ring) => $ring->toArray(), $rings ); } @@ -193,7 +193,7 @@ public function withSpatialReference(SpatialReference $reference): static { $polygon = parent::withSpatialReference($reference); $polygon->boundary = new PolygonBoundary(array_map( - static fn (LineStringInterface $ring): LineStringInterface => $ring->withSpatialReference($reference), + static fn (ImmutableLineStringInterface $ring): ImmutableLineStringInterface => $ring->withSpatialReference($reference), $this->getRings() )); @@ -216,16 +216,17 @@ public function withSrid(int $srid): static /** * Get the line strings of the spatial collection. * - * @param array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}[]|LineStringInterface|PointInterface[] $ring the ring to add + * @param array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}[]|ImmutableLineStringInterface|ImmutablePointInterface[] $ring the ring to add * * @throws SpatialTypeExceptionInterface when something is wrong during the addition of the ring */ - protected function addRing(array|LineStringInterface $ring): static + protected function addRing(array|ImmutableLineStringInterface $ring): static { if (is_array($ring)) { $ring = $this->createLineStringFromCoordinates($ring); } + ImmutableComponentGuard::check($ring); $this->boundary->addRing($ring); return $this; @@ -234,15 +235,15 @@ protected function addRing(array|LineStringInterface $ring): static /** * Add a ring to the spatial collection. * - * @param array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}[][]|LineStringInterface[]|PointInterface[][] $rings the ring to add + * @param array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}[][]|ImmutableLineStringInterface[]|ImmutablePointInterface[][] $rings the ring to add * * @throws SpatialTypeExceptionInterface when an input does not provide a line-string interface or coordinate tuples */ protected function addRings(array $rings): static { foreach ($rings as $ring) { - if (!is_array($ring) && !$ring instanceof LineStringInterface) { - throw new InvalidValueException('The array must contain only objects implementing LineStringInterface or array of coordinates.'); + if (!is_array($ring) && !$ring instanceof ImmutableLineStringInterface) { + throw new InvalidValueException('The array must contain only objects implementing ImmutableLineStringInterface or array of coordinates.'); } $this->addRing($ring); @@ -273,11 +274,11 @@ private function normalizeRingIndex(int $ringIndex): int /** * Replace a point in a copied ring while preserving its closure. * - * @param LineStringInterface $ring ring to copy and update - * @param int $pointIndex index of the point to replace - * @param Coordinates $coordinates replacement point coordinates + * @param ImmutableLineStringInterface $ring ring to copy and update + * @param int $pointIndex index of the point to replace + * @param Coordinates $coordinates replacement point coordinates */ - private function replaceRingPoint(LineStringInterface $ring, int $pointIndex, Coordinates $coordinates): LineStringInterface + private function replaceRingPoint(ImmutableLineStringInterface $ring, int $pointIndex, Coordinates $coordinates): ImmutableLineStringInterface { $pointCount = count($ring->getPoints()); if (0 === $pointCount) { diff --git a/lib/Types/AbstractPolyhedralSurface.php b/lib/Types/AbstractPolyhedralSurfaceImmutable.php similarity index 86% rename from lib/Types/AbstractPolyhedralSurface.php rename to lib/Types/AbstractPolyhedralSurfaceImmutable.php index b85ebb7..d6a10d4 100644 --- a/lib/Types/AbstractPolyhedralSurface.php +++ b/lib/Types/AbstractPolyhedralSurfaceImmutable.php @@ -21,8 +21,8 @@ use LongitudeOne\SpatialTypes\Exception\MissingValueException; use LongitudeOne\SpatialTypes\Exception\OutOfBoundsException; use LongitudeOne\SpatialTypes\Exception\SpatialTypeExceptionInterface; -use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface; -use LongitudeOne\SpatialTypes\Interfaces\PolyhedralSurfaceInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolygonInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolyhedralSurfaceInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; use LongitudeOne\SpatialTypes\Value\Coordinates; @@ -34,18 +34,18 @@ * * @internal this class provides common behaviour for geometry and geography polyhedral surfaces */ -abstract class AbstractPolyhedralSurface extends AbstractSpatialType implements PolyhedralSurfaceInterface +abstract class AbstractPolyhedralSurfaceImmutable extends AbstractSpatialTypeImmutable implements ImmutablePolyhedralSurfaceInterface { /** - * @var PolygonInterface[] Surface patches + * @var ImmutablePolygonInterface[] Surface patches */ private array $patches = []; /** - * AbstractPolyhedralSurface constructor. + * AbstractPolyhedralSurfaceImmutable constructor. * - * @param (IndexedPolygon|PolygonInterface)[] $patches Surface patches - * @param int|SpatialReference $srid Spatial Reference Identifier + * @param (ImmutablePolygonInterface|IndexedPolygon)[] $patches Surface patches + * @param int|SpatialReference $srid Spatial Reference Identifier * * @throws InvalidDimensionException when a coordinate tuple does not match the polygon dimension * @throws InvalidValueException when coordinates or surface topology are invalid @@ -60,7 +60,7 @@ public function __construct(array $patches = [], int|SpatialReference $srid = 0) /** * Return the polygons in this polyhedral surface. * - * @return PolygonInterface[] + * @return ImmutablePolygonInterface[] */ public function getElements(): array { @@ -74,7 +74,7 @@ public function getElements(): array * * @throws OutOfBoundsException when the polyhedral surface is empty */ - public function getPatch(int $index): PolygonInterface + public function getPatch(int $index): ImmutablePolygonInterface { if (empty($this->getPatches())) { throw new OutOfBoundsException('The current surface has no patches.'); @@ -92,7 +92,7 @@ public function getPatch(int $index): PolygonInterface /** * Return the polygon patches of this surface. * - * @return PolygonInterface[] + * @return ImmutablePolygonInterface[] */ public function getPatches(): array { @@ -117,7 +117,7 @@ public function toArray(): array $patches = $this->getPatches(); return array_map( - static fn (PolygonInterface $patch) => $patch->toArray(), + static fn (ImmutablePolygonInterface $patch) => $patch->toArray(), $patches ); } @@ -177,7 +177,7 @@ public function withPoint(int $patchIndex, int $ringIndex, int $pointIndex, Coor return $this->withReplacedPatch( $patchIndex, - fn (PolygonInterface $patch): PolygonInterface => $patch->withPoint($ringIndex, $pointIndex, $coordinates) + fn (ImmutablePolygonInterface $patch): ImmutablePolygonInterface => $patch->withPoint($ringIndex, $pointIndex, $coordinates) ); } @@ -197,7 +197,7 @@ public function withRing(int $patchIndex, int $ringIndex, array $coordinates): s return $this->withReplacedPatch( $patchIndex, - fn (PolygonInterface $patch): PolygonInterface => $patch->withRing($ringIndex, $coordinates) + fn (ImmutablePolygonInterface $patch): ImmutablePolygonInterface => $patch->withRing($ringIndex, $coordinates) ); } @@ -210,7 +210,7 @@ public function withSpatialReference(SpatialReference $reference): static { $surface = parent::withSpatialReference($reference); $surface->patches = array_map( - static fn (PolygonInterface $patch): PolygonInterface => $patch->withSpatialReference($reference), + static fn (ImmutablePolygonInterface $patch): ImmutablePolygonInterface => $patch->withSpatialReference($reference), $this->patches ); @@ -233,16 +233,17 @@ public function withSrid(int $srid): static /** * Add a polygon to this polyhedral surface. * - * @param IndexedPolygon|PolygonInterface $patch polygon + * @param ImmutablePolygonInterface|IndexedPolygon $patch polygon * * @throws SpatialTypeExceptionInterface when something is wrong during the addition of the polygon */ - protected function addPatch(array|PolygonInterface $patch): static + protected function addPatch(array|ImmutablePolygonInterface $patch): static { if (is_array($patch)) { $patch = $this->createPolygonFromCoordinates($patch); } + ImmutableComponentGuard::check($patch); $this->patches[] = $patch; return $this; @@ -251,7 +252,7 @@ protected function addPatch(array|PolygonInterface $patch): static /** * Add polygons to the polyhedral surface instance. * - * @param (IndexedPolygon|PolygonInterface)[] $patches Surface patches + * @param (ImmutablePolygonInterface|IndexedPolygon)[] $patches Surface patches * * @throws SpatialTypeExceptionInterface when something is wrong during the addition of the polygons */ diff --git a/lib/Types/AbstractSpatialType.php b/lib/Types/AbstractSpatialType.php index b36f122..b69a7c6 100644 --- a/lib/Types/AbstractSpatialType.php +++ b/lib/Types/AbstractSpatialType.php @@ -19,11 +19,6 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Factory\DefaultSpatialFactoryFactory; -use LongitudeOne\SpatialTypes\Factory\SpatialContext; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; -use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface; use LongitudeOne\SpatialTypes\Interfaces\SpatialInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; @@ -93,71 +88,6 @@ public function jsonSerialize(): array ]; } - /** - * Return a copy declared with the supplied spatial reference. - * - * @param SpatialReference $reference Target spatial reference - */ - public function withSpatialReference(SpatialReference $reference): static - { - $spatial = clone $this; - $spatial->spatialReference = $reference; - - return $spatial; - } - - /** - * Return a copy of this spatial object with the given Spatial Reference Identifier (SRID). - * - * Aggregate spatial types override this method to copy their contained - * elements with the same SRID. - * - * @param int $srid Spatial Reference Identifier - */ - public function withSrid(int $srid): static - { - return $this->withSpatialReference(SpatialReference::fromSrid($srid)); - } - - /** - * Hydrate a line-string tuple collection in this spatial value's context. - * - * @param array $coordinates Point tuples - */ - final protected function createLineStringFromCoordinates(array $coordinates): LineStringInterface - { - return DefaultSpatialFactoryFactory::create()->createLineStringFromIndexedArray( - $coordinates, - new SpatialContext($this->getSpatialReference(), $this->getFamily(), $this->getDimension()) - ); - } - - /** - * Hydrate a point tuple in this spatial value's complete context. - * - * @param array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int} $coordinates Point tuple - */ - final protected function createPointFromCoordinates(array $coordinates): PointInterface - { - return DefaultSpatialFactoryFactory::create()->createPointFromIndexedArray( - $coordinates, - new SpatialContext($this->getSpatialReference(), $this->getFamily(), $this->getDimension()) - ); - } - - /** - * Hydrate polygon rings in this spatial value's context. - * - * @param array|LineStringInterface> $rings Polygon rings - */ - final protected function createPolygonFromCoordinates(array $rings): PolygonInterface - { - return DefaultSpatialFactoryFactory::create()->createPolygonFromIndexedArray( - $rings, - new SpatialContext($this->getSpatialReference(), $this->getFamily(), $this->getDimension()) - ); - } - /** * Initialize the reference system from the typed API or its legacy SRID adapter. * diff --git a/lib/Types/AbstractSpatialTypeImmutable.php b/lib/Types/AbstractSpatialTypeImmutable.php new file mode 100644 index 0000000..0e08a7b --- /dev/null +++ b/lib/Types/AbstractSpatialTypeImmutable.php @@ -0,0 +1,96 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Types; + +use LongitudeOne\SpatialTypes\Factory\DefaultSpatialFactoryFactory; +use LongitudeOne\SpatialTypes\Factory\SpatialContext; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolygonInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableSpatialInterface; +use LongitudeOne\SpatialTypes\Reference\SpatialReference; + +/** Common immutable reference replacement. + * @internal + */ +abstract class AbstractSpatialTypeImmutable extends AbstractSpatialType implements ImmutableSpatialInterface +{ + /** + * Return a copy declared with the supplied spatial reference. + * + * @param SpatialReference $reference Target spatial reference + */ + public function withSpatialReference(SpatialReference $reference): static + { + $spatial = clone $this; + $spatial->spatialReference = $reference; + + return $spatial; + } + + /** + * Return a copy of this spatial object with the given Spatial Reference Identifier (SRID). + * + * Aggregate spatial types override this method to copy their contained + * elements with the same SRID. + * + * @param int $srid Spatial Reference Identifier + */ + public function withSrid(int $srid): static + { + return $this->withSpatialReference(SpatialReference::fromSrid($srid)); + } + + /** + * Hydrate a line-string tuple collection in this spatial value's context. + * + * @param array $coordinates Point tuples + */ + final protected function createLineStringFromCoordinates(array $coordinates): ImmutableLineStringInterface + { + return DefaultSpatialFactoryFactory::create()->createLineStringFromIndexedArray( + $coordinates, + new SpatialContext($this->getSpatialReference(), $this->getFamily(), $this->getDimension()) + ); + } + + /** + * Hydrate a point tuple in this spatial value's complete context. + * + * @param array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int} $coordinates Point tuple + */ + final protected function createPointFromCoordinates(array $coordinates): ImmutablePointInterface + { + return DefaultSpatialFactoryFactory::create()->createPointFromIndexedArray( + $coordinates, + new SpatialContext($this->getSpatialReference(), $this->getFamily(), $this->getDimension()) + ); + } + + /** + * Hydrate polygon rings in this spatial value's context. + * + * @param array|ImmutableLineStringInterface> $rings Polygon rings + */ + final protected function createPolygonFromCoordinates(array $rings): ImmutablePolygonInterface + { + return DefaultSpatialFactoryFactory::create()->createPolygonFromIndexedArray( + $rings, + new SpatialContext($this->getSpatialReference(), $this->getFamily(), $this->getDimension()) + ); + } +} diff --git a/lib/Types/AbstractTriangle.php b/lib/Types/AbstractTriangleImmutable.php similarity index 72% rename from lib/Types/AbstractTriangle.php rename to lib/Types/AbstractTriangleImmutable.php index 90d9125..a3c2d60 100644 --- a/lib/Types/AbstractTriangle.php +++ b/lib/Types/AbstractTriangleImmutable.php @@ -16,13 +16,13 @@ namespace LongitudeOne\SpatialTypes\Types; -use LongitudeOne\SpatialTypes\Interfaces\TriangleInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableTriangleInterface; /** * Shared polygon representation for SQL/MM triangles. * * @internal */ -abstract class AbstractTriangle extends AbstractPolygon implements TriangleInterface +abstract class AbstractTriangleImmutable extends AbstractPolygonImmutable implements ImmutableTriangleInterface { } diff --git a/lib/Types/Collection/AbstractLineStringCollection.php b/lib/Types/Collection/AbstractLineStringCollectionImmutable.php similarity index 59% rename from lib/Types/Collection/AbstractLineStringCollection.php rename to lib/Types/Collection/AbstractLineStringCollectionImmutable.php index c6cf80e..9cc0338 100644 --- a/lib/Types/Collection/AbstractLineStringCollection.php +++ b/lib/Types/Collection/AbstractLineStringCollectionImmutable.php @@ -17,38 +17,40 @@ namespace LongitudeOne\SpatialTypes\Types\Collection; use LongitudeOne\SpatialTypes\Exception\SpatialTypeExceptionInterface; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; -use LongitudeOne\SpatialTypes\Types\AbstractSpatialType; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; +use LongitudeOne\SpatialTypes\Types\AbstractSpatialTypeImmutable; +use LongitudeOne\SpatialTypes\Types\ImmutableComponentGuard; /** * Common line-string collection for multi-line strings. * * @internal */ -abstract class AbstractLineStringCollection extends AbstractSpatialType +abstract class AbstractLineStringCollectionImmutable extends AbstractSpatialTypeImmutable { - /** @var LineStringInterface[] */ + /** @var ImmutableLineStringInterface[] */ protected array $lineStrings = []; /** - * @param array|LineStringInterface $lineString Line string or its point tuples + * @param array|ImmutableLineStringInterface $lineString Line string or its point tuples * * @throws SpatialTypeExceptionInterface When the member is incompatible */ - protected function addLineStringMember(array|LineStringInterface $lineString): static + protected function addLineStringMember(array|ImmutableLineStringInterface $lineString): static { if (is_array($lineString)) { $lineString = $this->createLineStringFromCoordinates($lineString); } + ImmutableComponentGuard::check($lineString); $this->lineStrings[] = $lineString; return $this; } /** - * @param array>|LineStringInterface[] $lineStrings Line strings or their point tuples + * @param array>|ImmutableLineStringInterface[] $lineStrings Line strings or their point tuples */ protected function addLineStringMembers(array $lineStrings): static { @@ -59,7 +61,7 @@ protected function addLineStringMembers(array $lineStrings): static return $this; } - /** @return LineStringInterface[] */ + /** @return ImmutableLineStringInterface[] */ protected function lineStringMembers(): array { return $this->lineStrings; diff --git a/lib/Types/Collection/AbstractPointCollection.php b/lib/Types/Collection/AbstractPointCollectionImmutable.php similarity index 74% rename from lib/Types/Collection/AbstractPointCollection.php rename to lib/Types/Collection/AbstractPointCollectionImmutable.php index 442ba26..1e15709 100644 --- a/lib/Types/Collection/AbstractPointCollection.php +++ b/lib/Types/Collection/AbstractPointCollectionImmutable.php @@ -20,8 +20,9 @@ use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\MissingValueException; use LongitudeOne\SpatialTypes\Exception\OutOfBoundsException; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; -use LongitudeOne\SpatialTypes\Types\AbstractSpatialType; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; +use LongitudeOne\SpatialTypes\Types\AbstractSpatialTypeImmutable; +use LongitudeOne\SpatialTypes\Types\ImmutableComponentGuard; /** * Common point collection for point-defined spatial values. @@ -32,9 +33,9 @@ * * @internal */ -abstract class AbstractPointCollection extends AbstractSpatialType +abstract class AbstractPointCollectionImmutable extends AbstractSpatialTypeImmutable { - /** @var PointInterface[] */ + /** @var ImmutablePointInterface[] */ protected array $points = []; /** @@ -42,7 +43,7 @@ abstract class AbstractPointCollection extends AbstractSpatialType * * @param int $index Requested index */ - public function getPoint(int $index): PointInterface + public function getPoint(int $index): ImmutablePointInterface { if ([] === $this->points) { throw new OutOfBoundsException('The current collection of points is empty.'); @@ -53,7 +54,7 @@ public function getPoint(int $index): PointInterface return $this->points[$index < 0 ? count($this->points) + $index : $index]; } - /** @return PointInterface[] */ + /** @return ImmutablePointInterface[] */ public function getPoints(): array { return $this->points; @@ -85,37 +86,38 @@ public function isSimple(): bool public function toArray(): array { return array_map( - static fn (PointInterface $point): array => $point->toArray(), + static fn (ImmutablePointInterface $point): array => $point->toArray(), $this->points ); } /** - * @param array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}|PointInterface $point Point or coordinate tuple to add + * @param array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}|ImmutablePointInterface $point Point or coordinate tuple to add * * @throws InvalidDimensionException When a coordinate tuple has an incompatible layout * @throws InvalidValueException When coordinates are invalid * @throws MissingValueException When a coordinate is missing */ - protected function addPoint(array|PointInterface $point): static + protected function addPoint(array|ImmutablePointInterface $point): static { if (is_array($point)) { $point = $this->createPointFromCoordinates($point); } + ImmutableComponentGuard::check($point); $this->points[] = $point; return $this; } /** - * @param array $points Points or tuples to add + * @param array $points Points or tuples to add */ protected function addPoints(array $points): static { foreach ($points as $point) { - if (!is_array($point) && !$point instanceof PointInterface) { - throw new InvalidValueException('Argument shall contain an array of PointInterface or an array of coordinates.'); + if (!is_array($point) && !$point instanceof ImmutablePointInterface) { + throw new InvalidValueException('Argument shall contain an array of ImmutablePointInterface or an array of coordinates.'); } $this->addPoint($point); diff --git a/lib/Types/Dimension2/AbstractCollection.php b/lib/Types/Dimension2/AbstractCollectionImmutable.php similarity index 76% rename from lib/Types/Dimension2/AbstractCollection.php rename to lib/Types/Dimension2/AbstractCollectionImmutable.php index 2bb2f50..dcfe911 100644 --- a/lib/Types/Dimension2/AbstractCollection.php +++ b/lib/Types/Dimension2/AbstractCollectionImmutable.php @@ -18,10 +18,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; -use LongitudeOne\SpatialTypes\Interfaces\CollectionInterface; -use LongitudeOne\SpatialTypes\Types\AbstractCollection as ParentCollection; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableCollectionInterface; +use LongitudeOne\SpatialTypes\Types\AbstractCollectionImmutable as ParentCollection; -abstract class AbstractCollection extends ParentCollection implements CollectionInterface +abstract class AbstractCollectionImmutable extends ParentCollection implements ImmutableCollectionInterface { /** * Return the two-dimensional coordinate layout. diff --git a/lib/Types/Dimension2/AbstractLineString.php b/lib/Types/Dimension2/AbstractLineStringImmutable.php similarity index 76% rename from lib/Types/Dimension2/AbstractLineString.php rename to lib/Types/Dimension2/AbstractLineStringImmutable.php index c1b1d42..570acb6 100644 --- a/lib/Types/Dimension2/AbstractLineString.php +++ b/lib/Types/Dimension2/AbstractLineStringImmutable.php @@ -21,18 +21,18 @@ use LongitudeOne\SpatialTypes\Exception\InvalidDimensionException; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\MissingValueException; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\AbstractLineString as ParentLineString; +use LongitudeOne\SpatialTypes\Types\AbstractLineStringImmutable as ParentLineString; -abstract class AbstractLineString extends ParentLineString implements LineStringInterface +abstract class AbstractLineStringImmutable extends ParentLineString implements ImmutableLineStringInterface { /** - * AbstractLineString constructor. + * AbstractLineStringImmutable constructor. * - * @param (array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}|PointInterface)[] $points points of the line string - * @param int|SpatialReference $srid Spatial Reference Identifier + * @param (array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}|ImmutablePointInterface)[] $points points of the line string + * @param int|SpatialReference $srid Spatial Reference Identifier * * @throws InvalidDimensionException when a coordinate tuple does not match the line string dimension * @throws InvalidValueException when coordinates of the point are invalid diff --git a/lib/Types/Dimension2/AbstractMultiLineString.php b/lib/Types/Dimension2/AbstractMultiLineStringImmutable.php similarity index 74% rename from lib/Types/Dimension2/AbstractMultiLineString.php rename to lib/Types/Dimension2/AbstractMultiLineStringImmutable.php index 3df1074..a89c066 100644 --- a/lib/Types/Dimension2/AbstractMultiLineString.php +++ b/lib/Types/Dimension2/AbstractMultiLineStringImmutable.php @@ -18,10 +18,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiLineStringInterface; -use LongitudeOne\SpatialTypes\Types\AbstractMultiLineString as ParentMultiLineString; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiLineStringInterface; +use LongitudeOne\SpatialTypes\Types\AbstractMultiLineStringImmutable as ParentMultiLineString; -abstract class AbstractMultiLineString extends ParentMultiLineString implements MultiLineStringInterface +abstract class AbstractMultiLineStringImmutable extends ParentMultiLineString implements ImmutableMultiLineStringInterface { /** * Initialize the dimension of the object. diff --git a/lib/Types/Dimension2/AbstractMultiPoint.php b/lib/Types/Dimension2/AbstractMultiPointImmutable.php similarity index 76% rename from lib/Types/Dimension2/AbstractMultiPoint.php rename to lib/Types/Dimension2/AbstractMultiPointImmutable.php index 7671051..c56191c 100644 --- a/lib/Types/Dimension2/AbstractMultiPoint.php +++ b/lib/Types/Dimension2/AbstractMultiPointImmutable.php @@ -21,18 +21,18 @@ use LongitudeOne\SpatialTypes\Exception\InvalidDimensionException; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\MissingValueException; -use LongitudeOne\SpatialTypes\Interfaces\MultiPointInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\AbstractMultiPoint as ParentMultiPoint; +use LongitudeOne\SpatialTypes\Types\AbstractMultiPointImmutable as ParentMultiPoint; -abstract class AbstractMultiPoint extends ParentMultiPoint implements MultiPointInterface +abstract class AbstractMultiPointImmutable extends ParentMultiPoint implements ImmutableMultiPointInterface { /** - * AbstractMultiPoint constructor. + * AbstractMultiPointImmutable constructor. * - * @param (array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}|PointInterface)[] $points points of the multipoint - * @param int|SpatialReference $srid Spatial Reference Identifier + * @param (array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}|ImmutablePointInterface)[] $points points of the multipoint + * @param int|SpatialReference $srid Spatial Reference Identifier * * @throws InvalidDimensionException when the point dimension is not compatible with the multipoint dimension * @throws InvalidValueException when coordinates of the point are invalid diff --git a/lib/Types/Dimension2/Geography/CircularString.php b/lib/Types/Dimension2/Geography/CircularStringImmutable.php similarity index 86% rename from lib/Types/Dimension2/Geography/CircularString.php rename to lib/Types/Dimension2/Geography/CircularStringImmutable.php index 394950a..26aa20e 100644 --- a/lib/Types/Dimension2/Geography/CircularString.php +++ b/lib/Types/Dimension2/Geography/CircularStringImmutable.php @@ -18,10 +18,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Types\AbstractCircularString; +use LongitudeOne\SpatialTypes\Types\AbstractCircularStringImmutable; /** Circular string with XY coordinates in the Geography family. */ -class CircularString extends AbstractCircularString +final class CircularStringImmutable extends AbstractCircularStringImmutable { /** Return the coordinate layout. */ public function getDimension(): CoordinateDimensionEnum diff --git a/lib/Types/Dimension2/Geography/CompoundCurve.php b/lib/Types/Dimension2/Geography/CompoundCurveImmutable.php similarity index 86% rename from lib/Types/Dimension2/Geography/CompoundCurve.php rename to lib/Types/Dimension2/Geography/CompoundCurveImmutable.php index cd085c3..05c54c0 100644 --- a/lib/Types/Dimension2/Geography/CompoundCurve.php +++ b/lib/Types/Dimension2/Geography/CompoundCurveImmutable.php @@ -18,10 +18,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Types\AbstractCompoundCurve; +use LongitudeOne\SpatialTypes\Types\AbstractCompoundCurveImmutable; /** Compound curve with XY coordinates in the Geography family. */ -class CompoundCurve extends AbstractCompoundCurve +final class CompoundCurveImmutable extends AbstractCompoundCurveImmutable { /** Return the coordinate layout. */ public function getDimension(): CoordinateDimensionEnum diff --git a/lib/Types/Dimension2/Geography/GeographyCollection.php b/lib/Types/Dimension2/Geography/GeographyCollectionImmutable.php similarity index 77% rename from lib/Types/Dimension2/Geography/GeographyCollection.php rename to lib/Types/Dimension2/Geography/GeographyCollectionImmutable.php index 03772bc..81b4c0e 100644 --- a/lib/Types/Dimension2/Geography/GeographyCollection.php +++ b/lib/Types/Dimension2/Geography/GeographyCollectionImmutable.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension2\Geography; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\CollectionInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\AbstractCollection; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableCollectionInterface; +use LongitudeOne\SpatialTypes\Types\Dimension2\AbstractCollectionImmutable; -class GeographyCollection extends AbstractCollection implements CollectionInterface +final class GeographyCollectionImmutable extends AbstractCollectionImmutable implements ImmutableCollectionInterface { /** * Return the geography family. diff --git a/lib/Types/Dimension2/Geography/LineString.php b/lib/Types/Dimension2/Geography/LineStringImmutable.php similarity index 78% rename from lib/Types/Dimension2/Geography/LineString.php rename to lib/Types/Dimension2/Geography/LineStringImmutable.php index 15fc505..a5b081c 100644 --- a/lib/Types/Dimension2/Geography/LineString.php +++ b/lib/Types/Dimension2/Geography/LineStringImmutable.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension2\Geography; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\AbstractLineString; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Types\Dimension2\AbstractLineStringImmutable; -class LineString extends AbstractLineString implements LineStringInterface +final class LineStringImmutable extends AbstractLineStringImmutable implements ImmutableLineStringInterface { /** * Define the family. diff --git a/lib/Types/Dimension2/Geography/MultiLineString.php b/lib/Types/Dimension2/Geography/MultiLineStringImmutable.php similarity index 76% rename from lib/Types/Dimension2/Geography/MultiLineString.php rename to lib/Types/Dimension2/Geography/MultiLineStringImmutable.php index 07a07d8..625c5de 100644 --- a/lib/Types/Dimension2/Geography/MultiLineString.php +++ b/lib/Types/Dimension2/Geography/MultiLineStringImmutable.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension2\Geography; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiLineStringInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\AbstractMultiLineString; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiLineStringInterface; +use LongitudeOne\SpatialTypes\Types\Dimension2\AbstractMultiLineStringImmutable; -class MultiLineString extends AbstractMultiLineString implements MultiLineStringInterface +final class MultiLineStringImmutable extends AbstractMultiLineStringImmutable implements ImmutableMultiLineStringInterface { /** * Initialize the family of the object. diff --git a/lib/Types/Dimension2/Geography/MultiPoint.php b/lib/Types/Dimension2/Geography/MultiPointImmutable.php similarity index 78% rename from lib/Types/Dimension2/Geography/MultiPoint.php rename to lib/Types/Dimension2/Geography/MultiPointImmutable.php index 6d7ecca..beda6ba 100644 --- a/lib/Types/Dimension2/Geography/MultiPoint.php +++ b/lib/Types/Dimension2/Geography/MultiPointImmutable.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension2\Geography; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiPointInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\AbstractMultiPoint; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPointInterface; +use LongitudeOne\SpatialTypes\Types\Dimension2\AbstractMultiPointImmutable; -class MultiPoint extends AbstractMultiPoint implements MultiPointInterface +final class MultiPointImmutable extends AbstractMultiPointImmutable implements ImmutableMultiPointInterface { /** * Define the family. diff --git a/lib/Types/Dimension2/Geography/MultiPolygon.php b/lib/Types/Dimension2/Geography/MultiPolygonImmutable.php similarity index 80% rename from lib/Types/Dimension2/Geography/MultiPolygon.php rename to lib/Types/Dimension2/Geography/MultiPolygonImmutable.php index 3773a82..4007be8 100644 --- a/lib/Types/Dimension2/Geography/MultiPolygon.php +++ b/lib/Types/Dimension2/Geography/MultiPolygonImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiPolygonInterface; -use LongitudeOne\SpatialTypes\Types\AbstractMultiPolygon; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPolygonInterface; +use LongitudeOne\SpatialTypes\Types\AbstractMultiPolygonImmutable; -class MultiPolygon extends AbstractMultiPolygon implements MultiPolygonInterface +final class MultiPolygonImmutable extends AbstractMultiPolygonImmutable implements ImmutableMultiPolygonInterface { /** * Initialize the dimension of the object. diff --git a/lib/Types/Dimension2/Geography/Point.php b/lib/Types/Dimension2/Geography/PointImmutable.php similarity index 93% rename from lib/Types/Dimension2/Geography/Point.php rename to lib/Types/Dimension2/Geography/PointImmutable.php index 73b8917..d7f0d0f 100644 --- a/lib/Types/Dimension2/Geography/Point.php +++ b/lib/Types/Dimension2/Geography/PointImmutable.php @@ -21,14 +21,14 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Exception\BadMethodCallException; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\AbstractPoint; +use LongitudeOne\SpatialTypes\Types\AbstractPointImmutable; /** * Geographic point. */ -class Point extends AbstractPoint implements PointInterface +final class PointImmutable extends AbstractPointImmutable implements ImmutablePointInterface { /** * New point constructor. diff --git a/lib/Types/Dimension2/Geography/Polygon.php b/lib/Types/Dimension2/Geography/PolygonImmutable.php similarity index 82% rename from lib/Types/Dimension2/Geography/Polygon.php rename to lib/Types/Dimension2/Geography/PolygonImmutable.php index 73a8c4a..24e9836 100644 --- a/lib/Types/Dimension2/Geography/Polygon.php +++ b/lib/Types/Dimension2/Geography/PolygonImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface; -use LongitudeOne\SpatialTypes\Types\AbstractPolygon; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolygonInterface; +use LongitudeOne\SpatialTypes\Types\AbstractPolygonImmutable; -class Polygon extends AbstractPolygon implements PolygonInterface +final class PolygonImmutable extends AbstractPolygonImmutable implements ImmutablePolygonInterface { /** * Initialize the dimension of the object. diff --git a/lib/Types/Dimension2/Geography/Triangle.php b/lib/Types/Dimension2/Geography/TriangleImmutable.php similarity index 82% rename from lib/Types/Dimension2/Geography/Triangle.php rename to lib/Types/Dimension2/Geography/TriangleImmutable.php index 7677424..e512e0f 100644 --- a/lib/Types/Dimension2/Geography/Triangle.php +++ b/lib/Types/Dimension2/Geography/TriangleImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\TriangleInterface; -use LongitudeOne\SpatialTypes\Types\AbstractTriangle; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableTriangleInterface; +use LongitudeOne\SpatialTypes\Types\AbstractTriangleImmutable; -class Triangle extends AbstractTriangle implements TriangleInterface +final class TriangleImmutable extends AbstractTriangleImmutable implements ImmutableTriangleInterface { /** * Initialize the dimension of the object. diff --git a/lib/Types/Dimension2/Geometry/CircularString.php b/lib/Types/Dimension2/Geometry/CircularStringImmutable.php similarity index 85% rename from lib/Types/Dimension2/Geometry/CircularString.php rename to lib/Types/Dimension2/Geometry/CircularStringImmutable.php index 9c43bc4..34e5fc1 100644 --- a/lib/Types/Dimension2/Geometry/CircularString.php +++ b/lib/Types/Dimension2/Geometry/CircularStringImmutable.php @@ -18,10 +18,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Types\AbstractCircularString; +use LongitudeOne\SpatialTypes\Types\AbstractCircularStringImmutable; /** Circular string with XY coordinates in the Geometry family. */ -class CircularString extends AbstractCircularString +final class CircularStringImmutable extends AbstractCircularStringImmutable { /** Return the coordinate layout. */ public function getDimension(): CoordinateDimensionEnum diff --git a/lib/Types/Dimension2/Geometry/CompoundCurve.php b/lib/Types/Dimension2/Geometry/CompoundCurveImmutable.php similarity index 86% rename from lib/Types/Dimension2/Geometry/CompoundCurve.php rename to lib/Types/Dimension2/Geometry/CompoundCurveImmutable.php index 0abe8d8..af8da1e 100644 --- a/lib/Types/Dimension2/Geometry/CompoundCurve.php +++ b/lib/Types/Dimension2/Geometry/CompoundCurveImmutable.php @@ -18,10 +18,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Types\AbstractCompoundCurve; +use LongitudeOne\SpatialTypes\Types\AbstractCompoundCurveImmutable; /** Compound curve with XY coordinates in the Geometry family. */ -class CompoundCurve extends AbstractCompoundCurve +final class CompoundCurveImmutable extends AbstractCompoundCurveImmutable { /** Return the coordinate layout. */ public function getDimension(): CoordinateDimensionEnum diff --git a/lib/Types/Dimension2/Geometry/GeometryCollection.php b/lib/Types/Dimension2/Geometry/GeometryCollectionImmutable.php similarity index 77% rename from lib/Types/Dimension2/Geometry/GeometryCollection.php rename to lib/Types/Dimension2/Geometry/GeometryCollectionImmutable.php index 5ddaee6..313a9da 100644 --- a/lib/Types/Dimension2/Geometry/GeometryCollection.php +++ b/lib/Types/Dimension2/Geometry/GeometryCollectionImmutable.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension2\Geometry; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\CollectionInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\AbstractCollection; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableCollectionInterface; +use LongitudeOne\SpatialTypes\Types\Dimension2\AbstractCollectionImmutable; -class GeometryCollection extends AbstractCollection implements CollectionInterface +final class GeometryCollectionImmutable extends AbstractCollectionImmutable implements ImmutableCollectionInterface { /** * Return the geometry family. diff --git a/lib/Types/Dimension2/Geometry/LineString.php b/lib/Types/Dimension2/Geometry/LineStringImmutable.php similarity index 78% rename from lib/Types/Dimension2/Geometry/LineString.php rename to lib/Types/Dimension2/Geometry/LineStringImmutable.php index 19f6f68..95cfc2f 100644 --- a/lib/Types/Dimension2/Geometry/LineString.php +++ b/lib/Types/Dimension2/Geometry/LineStringImmutable.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension2\Geometry; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\AbstractLineString; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Types\Dimension2\AbstractLineStringImmutable; -class LineString extends AbstractLineString implements LineStringInterface +final class LineStringImmutable extends AbstractLineStringImmutable implements ImmutableLineStringInterface { /** * Define the family. diff --git a/lib/Types/Dimension2/Geometry/MultiLineString.php b/lib/Types/Dimension2/Geometry/MultiLineStringImmutable.php similarity index 76% rename from lib/Types/Dimension2/Geometry/MultiLineString.php rename to lib/Types/Dimension2/Geometry/MultiLineStringImmutable.php index 101a03c..8680076 100644 --- a/lib/Types/Dimension2/Geometry/MultiLineString.php +++ b/lib/Types/Dimension2/Geometry/MultiLineStringImmutable.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension2\Geometry; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiLineStringInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\AbstractMultiLineString; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiLineStringInterface; +use LongitudeOne\SpatialTypes\Types\Dimension2\AbstractMultiLineStringImmutable; -class MultiLineString extends AbstractMultiLineString implements MultiLineStringInterface +final class MultiLineStringImmutable extends AbstractMultiLineStringImmutable implements ImmutableMultiLineStringInterface { /** * Initialize the family of the object. diff --git a/lib/Types/Dimension2/Geometry/MultiPoint.php b/lib/Types/Dimension2/Geometry/MultiPointImmutable.php similarity index 78% rename from lib/Types/Dimension2/Geometry/MultiPoint.php rename to lib/Types/Dimension2/Geometry/MultiPointImmutable.php index f6e7498..4a8a452 100644 --- a/lib/Types/Dimension2/Geometry/MultiPoint.php +++ b/lib/Types/Dimension2/Geometry/MultiPointImmutable.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension2\Geometry; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiPointInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\AbstractMultiPoint; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPointInterface; +use LongitudeOne\SpatialTypes\Types\Dimension2\AbstractMultiPointImmutable; -class MultiPoint extends AbstractMultiPoint implements MultiPointInterface +final class MultiPointImmutable extends AbstractMultiPointImmutable implements ImmutableMultiPointInterface { /** * Define the family. diff --git a/lib/Types/Dimension2/Geometry/MultiPolygon.php b/lib/Types/Dimension2/Geometry/MultiPolygonImmutable.php similarity index 80% rename from lib/Types/Dimension2/Geometry/MultiPolygon.php rename to lib/Types/Dimension2/Geometry/MultiPolygonImmutable.php index 5d80953..9655879 100644 --- a/lib/Types/Dimension2/Geometry/MultiPolygon.php +++ b/lib/Types/Dimension2/Geometry/MultiPolygonImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiPolygonInterface; -use LongitudeOne\SpatialTypes\Types\AbstractMultiPolygon; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPolygonInterface; +use LongitudeOne\SpatialTypes\Types\AbstractMultiPolygonImmutable; -class MultiPolygon extends AbstractMultiPolygon implements MultiPolygonInterface +final class MultiPolygonImmutable extends AbstractMultiPolygonImmutable implements ImmutableMultiPolygonInterface { /** * Initialize the dimension of the object. diff --git a/lib/Types/Dimension2/Geometry/Point.php b/lib/Types/Dimension2/Geometry/PointImmutable.php similarity index 93% rename from lib/Types/Dimension2/Geometry/Point.php rename to lib/Types/Dimension2/Geometry/PointImmutable.php index 412ff56..c634305 100644 --- a/lib/Types/Dimension2/Geometry/Point.php +++ b/lib/Types/Dimension2/Geometry/PointImmutable.php @@ -21,14 +21,14 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Exception\BadMethodCallException; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\AbstractPoint; +use LongitudeOne\SpatialTypes\Types\AbstractPointImmutable; /** * Geometric point. */ -class Point extends AbstractPoint implements PointInterface +final class PointImmutable extends AbstractPointImmutable implements ImmutablePointInterface { /** * New point constructor. diff --git a/lib/Types/Dimension2/Geometry/Polygon.php b/lib/Types/Dimension2/Geometry/PolygonImmutable.php similarity index 82% rename from lib/Types/Dimension2/Geometry/Polygon.php rename to lib/Types/Dimension2/Geometry/PolygonImmutable.php index a8aa526..2cce7c4 100644 --- a/lib/Types/Dimension2/Geometry/Polygon.php +++ b/lib/Types/Dimension2/Geometry/PolygonImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface; -use LongitudeOne\SpatialTypes\Types\AbstractPolygon; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolygonInterface; +use LongitudeOne\SpatialTypes\Types\AbstractPolygonImmutable; -class Polygon extends AbstractPolygon implements PolygonInterface +final class PolygonImmutable extends AbstractPolygonImmutable implements ImmutablePolygonInterface { /** * Declare the dimension of the object. diff --git a/lib/Types/Dimension2/Geometry/Triangle.php b/lib/Types/Dimension2/Geometry/TriangleImmutable.php similarity index 81% rename from lib/Types/Dimension2/Geometry/Triangle.php rename to lib/Types/Dimension2/Geometry/TriangleImmutable.php index ee3b5aa..01495c4 100644 --- a/lib/Types/Dimension2/Geometry/Triangle.php +++ b/lib/Types/Dimension2/Geometry/TriangleImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\TriangleInterface; -use LongitudeOne\SpatialTypes\Types\AbstractTriangle; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableTriangleInterface; +use LongitudeOne\SpatialTypes\Types\AbstractTriangleImmutable; -class Triangle extends AbstractTriangle implements TriangleInterface +final class TriangleImmutable extends AbstractTriangleImmutable implements ImmutableTriangleInterface { /** * Declare the dimension of the object. diff --git a/lib/Types/Dimension3m/AbstractLineString.php b/lib/Types/Dimension3m/AbstractLineStringImmutable.php similarity index 77% rename from lib/Types/Dimension3m/AbstractLineString.php rename to lib/Types/Dimension3m/AbstractLineStringImmutable.php index 747a88c..950637a 100644 --- a/lib/Types/Dimension3m/AbstractLineString.php +++ b/lib/Types/Dimension3m/AbstractLineStringImmutable.php @@ -21,19 +21,19 @@ use LongitudeOne\SpatialTypes\Exception\InvalidDimensionException; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\MissingValueException; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\AbstractLineString as ParentLineString; +use LongitudeOne\SpatialTypes\Types\AbstractLineStringImmutable as ParentLineString; /** * Base class for three-dimensional line strings with a measure coordinate. */ -abstract class AbstractLineString extends ParentLineString implements LineStringInterface +abstract class AbstractLineStringImmutable extends ParentLineString implements ImmutableLineStringInterface { /** - * @param (array{0: null|float|int|string, 1: null|float|int|string, 2: null|float|int}|PointInterface)[] $points points of the line string - * @param int|SpatialReference $srid Spatial Reference Identifier + * @param (array{0: null|float|int|string, 1: null|float|int|string, 2: null|float|int}|ImmutablePointInterface)[] $points points of the line string + * @param int|SpatialReference $srid Spatial Reference Identifier * * @throws InvalidDimensionException when a point dimension is incompatible * @throws InvalidValueException when point coordinates are invalid diff --git a/lib/Types/Dimension3m/AbstractMultiLineString.php b/lib/Types/Dimension3m/AbstractMultiLineStringImmutable.php similarity index 75% rename from lib/Types/Dimension3m/AbstractMultiLineString.php rename to lib/Types/Dimension3m/AbstractMultiLineStringImmutable.php index 7c561e0..1288662 100644 --- a/lib/Types/Dimension3m/AbstractMultiLineString.php +++ b/lib/Types/Dimension3m/AbstractMultiLineStringImmutable.php @@ -18,13 +18,13 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiLineStringInterface; -use LongitudeOne\SpatialTypes\Types\AbstractMultiLineString as ParentMultiLineString; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiLineStringInterface; +use LongitudeOne\SpatialTypes\Types\AbstractMultiLineStringImmutable as ParentMultiLineString; /** * Base class for multi-line strings using the XYM layout. */ -abstract class AbstractMultiLineString extends ParentMultiLineString implements MultiLineStringInterface +abstract class AbstractMultiLineStringImmutable extends ParentMultiLineString implements ImmutableMultiLineStringInterface { /** * Return the XYM dimension. diff --git a/lib/Types/Dimension3m/AbstractMultiPoint.php b/lib/Types/Dimension3m/AbstractMultiPointImmutable.php similarity index 76% rename from lib/Types/Dimension3m/AbstractMultiPoint.php rename to lib/Types/Dimension3m/AbstractMultiPointImmutable.php index c2fb438..86d3c4d 100644 --- a/lib/Types/Dimension3m/AbstractMultiPoint.php +++ b/lib/Types/Dimension3m/AbstractMultiPointImmutable.php @@ -21,19 +21,19 @@ use LongitudeOne\SpatialTypes\Exception\InvalidDimensionException; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\MissingValueException; -use LongitudeOne\SpatialTypes\Interfaces\MultiPointInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\AbstractMultiPoint as ParentMultiPoint; +use LongitudeOne\SpatialTypes\Types\AbstractMultiPointImmutable as ParentMultiPoint; /** * Base class for multi-points using the XYM layout. */ -abstract class AbstractMultiPoint extends ParentMultiPoint implements MultiPointInterface +abstract class AbstractMultiPointImmutable extends ParentMultiPoint implements ImmutableMultiPointInterface { /** - * @param (array{0: null|float|int|string, 1: null|float|int|string, 2: null|float|int}|PointInterface)[] $points points of the multipoint - * @param int|SpatialReference $srid Spatial Reference Identifier + * @param (array{0: null|float|int|string, 1: null|float|int|string, 2: null|float|int}|ImmutablePointInterface)[] $points points of the multipoint + * @param int|SpatialReference $srid Spatial Reference Identifier * * @throws InvalidDimensionException when a point dimension is incompatible * @throws InvalidValueException when point coordinates are invalid diff --git a/lib/Types/Dimension3m/Geography/CircularString.php b/lib/Types/Dimension3m/Geography/CircularStringImmutable.php similarity index 86% rename from lib/Types/Dimension3m/Geography/CircularString.php rename to lib/Types/Dimension3m/Geography/CircularStringImmutable.php index 6545923..cf17f43 100644 --- a/lib/Types/Dimension3m/Geography/CircularString.php +++ b/lib/Types/Dimension3m/Geography/CircularStringImmutable.php @@ -18,10 +18,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Types\AbstractCircularString; +use LongitudeOne\SpatialTypes\Types\AbstractCircularStringImmutable; /** Circular string with XYM coordinates in the Geography family. */ -class CircularString extends AbstractCircularString +final class CircularStringImmutable extends AbstractCircularStringImmutable { /** Return the coordinate layout. */ public function getDimension(): CoordinateDimensionEnum diff --git a/lib/Types/Dimension3m/Geography/CompoundCurve.php b/lib/Types/Dimension3m/Geography/CompoundCurveImmutable.php similarity index 86% rename from lib/Types/Dimension3m/Geography/CompoundCurve.php rename to lib/Types/Dimension3m/Geography/CompoundCurveImmutable.php index a43862a..6bbc2ad 100644 --- a/lib/Types/Dimension3m/Geography/CompoundCurve.php +++ b/lib/Types/Dimension3m/Geography/CompoundCurveImmutable.php @@ -18,10 +18,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Types\AbstractCompoundCurve; +use LongitudeOne\SpatialTypes\Types\AbstractCompoundCurveImmutable; /** Compound curve with XYM coordinates in the Geography family. */ -class CompoundCurve extends AbstractCompoundCurve +final class CompoundCurveImmutable extends AbstractCompoundCurveImmutable { /** Return the coordinate layout. */ public function getDimension(): CoordinateDimensionEnum diff --git a/lib/Types/Dimension3m/Geography/GeographyCollection.php b/lib/Types/Dimension3m/Geography/GeographyCollectionImmutable.php similarity index 81% rename from lib/Types/Dimension3m/Geography/GeographyCollection.php rename to lib/Types/Dimension3m/Geography/GeographyCollectionImmutable.php index 6c6b8a0..aa173ca 100644 --- a/lib/Types/Dimension3m/Geography/GeographyCollection.php +++ b/lib/Types/Dimension3m/Geography/GeographyCollectionImmutable.php @@ -19,13 +19,13 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\CollectionInterface; -use LongitudeOne\SpatialTypes\Types\AbstractCollection; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableCollectionInterface; +use LongitudeOne\SpatialTypes\Types\AbstractCollectionImmutable; /** * Geographic collection using the XYM layout. */ -class GeographyCollection extends AbstractCollection implements CollectionInterface +final class GeographyCollectionImmutable extends AbstractCollectionImmutable implements ImmutableCollectionInterface { /** * Return the XYM dimension. diff --git a/lib/Types/Dimension3m/Geography/LineString.php b/lib/Types/Dimension3m/Geography/LineStringImmutable.php similarity index 79% rename from lib/Types/Dimension3m/Geography/LineString.php rename to lib/Types/Dimension3m/Geography/LineStringImmutable.php index 261cbf3..6ac6e5f 100644 --- a/lib/Types/Dimension3m/Geography/LineString.php +++ b/lib/Types/Dimension3m/Geography/LineStringImmutable.php @@ -17,13 +17,13 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension3m\Geography; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Types\Dimension3m\AbstractLineString; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Types\Dimension3m\AbstractLineStringImmutable; /** * Geographic line string using the XYM layout. */ -class LineString extends AbstractLineString implements LineStringInterface +final class LineStringImmutable extends AbstractLineStringImmutable implements ImmutableLineStringInterface { /** * Return the geography family. diff --git a/lib/Types/Dimension3m/Geography/MultiLineString.php b/lib/Types/Dimension3m/Geography/MultiLineStringImmutable.php similarity index 77% rename from lib/Types/Dimension3m/Geography/MultiLineString.php rename to lib/Types/Dimension3m/Geography/MultiLineStringImmutable.php index 8889235..ad31ae2 100644 --- a/lib/Types/Dimension3m/Geography/MultiLineString.php +++ b/lib/Types/Dimension3m/Geography/MultiLineStringImmutable.php @@ -17,13 +17,13 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension3m\Geography; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiLineStringInterface; -use LongitudeOne\SpatialTypes\Types\Dimension3m\AbstractMultiLineString; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiLineStringInterface; +use LongitudeOne\SpatialTypes\Types\Dimension3m\AbstractMultiLineStringImmutable; /** * Geographic multi-line string using the XYM layout. */ -class MultiLineString extends AbstractMultiLineString implements MultiLineStringInterface +final class MultiLineStringImmutable extends AbstractMultiLineStringImmutable implements ImmutableMultiLineStringInterface { /** * Return the geography family. diff --git a/lib/Types/Dimension3m/Geography/MultiPoint.php b/lib/Types/Dimension3m/Geography/MultiPointImmutable.php similarity index 79% rename from lib/Types/Dimension3m/Geography/MultiPoint.php rename to lib/Types/Dimension3m/Geography/MultiPointImmutable.php index 49d03d3..1727526 100644 --- a/lib/Types/Dimension3m/Geography/MultiPoint.php +++ b/lib/Types/Dimension3m/Geography/MultiPointImmutable.php @@ -17,13 +17,13 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension3m\Geography; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiPointInterface; -use LongitudeOne\SpatialTypes\Types\Dimension3m\AbstractMultiPoint; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPointInterface; +use LongitudeOne\SpatialTypes\Types\Dimension3m\AbstractMultiPointImmutable; /** * Geographic multi-point using the XYM layout. */ -class MultiPoint extends AbstractMultiPoint implements MultiPointInterface +final class MultiPointImmutable extends AbstractMultiPointImmutable implements ImmutableMultiPointInterface { /** * Return the geography family. diff --git a/lib/Types/Dimension3m/Geography/MultiPolygon.php b/lib/Types/Dimension3m/Geography/MultiPolygonImmutable.php similarity index 81% rename from lib/Types/Dimension3m/Geography/MultiPolygon.php rename to lib/Types/Dimension3m/Geography/MultiPolygonImmutable.php index 1ddf90e..f4263fc 100644 --- a/lib/Types/Dimension3m/Geography/MultiPolygon.php +++ b/lib/Types/Dimension3m/Geography/MultiPolygonImmutable.php @@ -19,13 +19,13 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiPolygonInterface; -use LongitudeOne\SpatialTypes\Types\AbstractMultiPolygon; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPolygonInterface; +use LongitudeOne\SpatialTypes\Types\AbstractMultiPolygonImmutable; /** * Geographic multi-polygon using the XYM layout. */ -class MultiPolygon extends AbstractMultiPolygon implements MultiPolygonInterface +final class MultiPolygonImmutable extends AbstractMultiPolygonImmutable implements ImmutableMultiPolygonInterface { /** * Return the XYM dimension. diff --git a/lib/Types/Dimension3m/Geography/Point.php b/lib/Types/Dimension3m/Geography/PointImmutable.php similarity index 93% rename from lib/Types/Dimension3m/Geography/Point.php rename to lib/Types/Dimension3m/Geography/PointImmutable.php index f9a067f..90ffa6a 100644 --- a/lib/Types/Dimension3m/Geography/Point.php +++ b/lib/Types/Dimension3m/Geography/PointImmutable.php @@ -21,14 +21,14 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Exception\BadMethodCallException; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\AbstractPoint; +use LongitudeOne\SpatialTypes\Types\AbstractPointImmutable; /** * Three-dimensional geographic point with a measure coordinate. */ -class Point extends AbstractPoint implements PointInterface +final class PointImmutable extends AbstractPointImmutable implements ImmutablePointInterface { /** * The M coordinate. diff --git a/lib/Types/Dimension3m/Geography/Polygon.php b/lib/Types/Dimension3m/Geography/PolygonImmutable.php similarity index 82% rename from lib/Types/Dimension3m/Geography/Polygon.php rename to lib/Types/Dimension3m/Geography/PolygonImmutable.php index a8ca9b6..e31c1e5 100644 --- a/lib/Types/Dimension3m/Geography/Polygon.php +++ b/lib/Types/Dimension3m/Geography/PolygonImmutable.php @@ -19,13 +19,13 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface; -use LongitudeOne\SpatialTypes\Types\AbstractPolygon; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolygonInterface; +use LongitudeOne\SpatialTypes\Types\AbstractPolygonImmutable; /** * Geographic polygon using the XYM layout. */ -class Polygon extends AbstractPolygon implements PolygonInterface +final class PolygonImmutable extends AbstractPolygonImmutable implements ImmutablePolygonInterface { /** * Return the XYM dimension. diff --git a/lib/Types/Dimension3m/Geography/Triangle.php b/lib/Types/Dimension3m/Geography/TriangleImmutable.php similarity index 82% rename from lib/Types/Dimension3m/Geography/Triangle.php rename to lib/Types/Dimension3m/Geography/TriangleImmutable.php index c59efe1..2cdf89b 100644 --- a/lib/Types/Dimension3m/Geography/Triangle.php +++ b/lib/Types/Dimension3m/Geography/TriangleImmutable.php @@ -19,13 +19,13 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\TriangleInterface; -use LongitudeOne\SpatialTypes\Types\AbstractTriangle; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableTriangleInterface; +use LongitudeOne\SpatialTypes\Types\AbstractTriangleImmutable; /** * Geographic polygon using the XYM layout. */ -class Triangle extends AbstractTriangle implements TriangleInterface +final class TriangleImmutable extends AbstractTriangleImmutable implements ImmutableTriangleInterface { /** * Return the XYM dimension. diff --git a/lib/Types/Dimension3m/Geometry/CircularString.php b/lib/Types/Dimension3m/Geometry/CircularStringImmutable.php similarity index 86% rename from lib/Types/Dimension3m/Geometry/CircularString.php rename to lib/Types/Dimension3m/Geometry/CircularStringImmutable.php index ca9575b..072497b 100644 --- a/lib/Types/Dimension3m/Geometry/CircularString.php +++ b/lib/Types/Dimension3m/Geometry/CircularStringImmutable.php @@ -18,10 +18,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Types\AbstractCircularString; +use LongitudeOne\SpatialTypes\Types\AbstractCircularStringImmutable; /** Circular string with XYM coordinates in the Geometry family. */ -class CircularString extends AbstractCircularString +final class CircularStringImmutable extends AbstractCircularStringImmutable { /** Return the coordinate layout. */ public function getDimension(): CoordinateDimensionEnum diff --git a/lib/Types/Dimension3m/Geometry/CompoundCurve.php b/lib/Types/Dimension3m/Geometry/CompoundCurveImmutable.php similarity index 86% rename from lib/Types/Dimension3m/Geometry/CompoundCurve.php rename to lib/Types/Dimension3m/Geometry/CompoundCurveImmutable.php index 7d2d709..78490f5 100644 --- a/lib/Types/Dimension3m/Geometry/CompoundCurve.php +++ b/lib/Types/Dimension3m/Geometry/CompoundCurveImmutable.php @@ -18,10 +18,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Types\AbstractCompoundCurve; +use LongitudeOne\SpatialTypes\Types\AbstractCompoundCurveImmutable; /** Compound curve with XYM coordinates in the Geometry family. */ -class CompoundCurve extends AbstractCompoundCurve +final class CompoundCurveImmutable extends AbstractCompoundCurveImmutable { /** Return the coordinate layout. */ public function getDimension(): CoordinateDimensionEnum diff --git a/lib/Types/Dimension3m/Geometry/GeometryCollection.php b/lib/Types/Dimension3m/Geometry/GeometryCollectionImmutable.php similarity index 81% rename from lib/Types/Dimension3m/Geometry/GeometryCollection.php rename to lib/Types/Dimension3m/Geometry/GeometryCollectionImmutable.php index e2d5481..89a6849 100644 --- a/lib/Types/Dimension3m/Geometry/GeometryCollection.php +++ b/lib/Types/Dimension3m/Geometry/GeometryCollectionImmutable.php @@ -19,13 +19,13 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\CollectionInterface; -use LongitudeOne\SpatialTypes\Types\AbstractCollection; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableCollectionInterface; +use LongitudeOne\SpatialTypes\Types\AbstractCollectionImmutable; /** * Geometric collection using the XYM layout. */ -class GeometryCollection extends AbstractCollection implements CollectionInterface +final class GeometryCollectionImmutable extends AbstractCollectionImmutable implements ImmutableCollectionInterface { /** * Return the XYM dimension. diff --git a/lib/Types/Dimension3m/Geometry/LineString.php b/lib/Types/Dimension3m/Geometry/LineStringImmutable.php similarity index 79% rename from lib/Types/Dimension3m/Geometry/LineString.php rename to lib/Types/Dimension3m/Geometry/LineStringImmutable.php index 73d8a8f..580c9b8 100644 --- a/lib/Types/Dimension3m/Geometry/LineString.php +++ b/lib/Types/Dimension3m/Geometry/LineStringImmutable.php @@ -17,13 +17,13 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Types\Dimension3m\AbstractLineString; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Types\Dimension3m\AbstractLineStringImmutable; /** * Geometric line string using the XYM layout. */ -class LineString extends AbstractLineString implements LineStringInterface +final class LineStringImmutable extends AbstractLineStringImmutable implements ImmutableLineStringInterface { /** * Return the geometry family. diff --git a/lib/Types/Dimension3m/Geometry/MultiLineString.php b/lib/Types/Dimension3m/Geometry/MultiLineStringImmutable.php similarity index 77% rename from lib/Types/Dimension3m/Geometry/MultiLineString.php rename to lib/Types/Dimension3m/Geometry/MultiLineStringImmutable.php index 02b2d62..33a09bf 100644 --- a/lib/Types/Dimension3m/Geometry/MultiLineString.php +++ b/lib/Types/Dimension3m/Geometry/MultiLineStringImmutable.php @@ -17,13 +17,13 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiLineStringInterface; -use LongitudeOne\SpatialTypes\Types\Dimension3m\AbstractMultiLineString; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiLineStringInterface; +use LongitudeOne\SpatialTypes\Types\Dimension3m\AbstractMultiLineStringImmutable; /** * Geometric multi-line string using the XYM layout. */ -class MultiLineString extends AbstractMultiLineString implements MultiLineStringInterface +final class MultiLineStringImmutable extends AbstractMultiLineStringImmutable implements ImmutableMultiLineStringInterface { /** * Return the geometry family. diff --git a/lib/Types/Dimension3m/Geometry/MultiPoint.php b/lib/Types/Dimension3m/Geometry/MultiPointImmutable.php similarity index 79% rename from lib/Types/Dimension3m/Geometry/MultiPoint.php rename to lib/Types/Dimension3m/Geometry/MultiPointImmutable.php index e4557bd..f7036a3 100644 --- a/lib/Types/Dimension3m/Geometry/MultiPoint.php +++ b/lib/Types/Dimension3m/Geometry/MultiPointImmutable.php @@ -17,13 +17,13 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiPointInterface; -use LongitudeOne\SpatialTypes\Types\Dimension3m\AbstractMultiPoint; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPointInterface; +use LongitudeOne\SpatialTypes\Types\Dimension3m\AbstractMultiPointImmutable; /** * Geometric multi-point using the XYM layout. */ -class MultiPoint extends AbstractMultiPoint implements MultiPointInterface +final class MultiPointImmutable extends AbstractMultiPointImmutable implements ImmutableMultiPointInterface { /** * Return the geometry family. diff --git a/lib/Types/Dimension3m/Geometry/MultiPolygon.php b/lib/Types/Dimension3m/Geometry/MultiPolygonImmutable.php similarity index 81% rename from lib/Types/Dimension3m/Geometry/MultiPolygon.php rename to lib/Types/Dimension3m/Geometry/MultiPolygonImmutable.php index ca4dd56..86dd2db 100644 --- a/lib/Types/Dimension3m/Geometry/MultiPolygon.php +++ b/lib/Types/Dimension3m/Geometry/MultiPolygonImmutable.php @@ -19,13 +19,13 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiPolygonInterface; -use LongitudeOne\SpatialTypes\Types\AbstractMultiPolygon; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPolygonInterface; +use LongitudeOne\SpatialTypes\Types\AbstractMultiPolygonImmutable; /** * Geometric multi-polygon using the XYM layout. */ -class MultiPolygon extends AbstractMultiPolygon implements MultiPolygonInterface +final class MultiPolygonImmutable extends AbstractMultiPolygonImmutable implements ImmutableMultiPolygonInterface { /** * Return the XYM dimension. diff --git a/lib/Types/Dimension3m/Geometry/Point.php b/lib/Types/Dimension3m/Geometry/PointImmutable.php similarity index 93% rename from lib/Types/Dimension3m/Geometry/Point.php rename to lib/Types/Dimension3m/Geometry/PointImmutable.php index 52558e4..8db4eab 100644 --- a/lib/Types/Dimension3m/Geometry/Point.php +++ b/lib/Types/Dimension3m/Geometry/PointImmutable.php @@ -21,14 +21,14 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Exception\BadMethodCallException; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\AbstractPoint; +use LongitudeOne\SpatialTypes\Types\AbstractPointImmutable; /** * Three-dimensional geometric point with a measure coordinate. */ -class Point extends AbstractPoint implements PointInterface +final class PointImmutable extends AbstractPointImmutable implements ImmutablePointInterface { /** * The M coordinate. diff --git a/lib/Types/Dimension3m/Geometry/Polygon.php b/lib/Types/Dimension3m/Geometry/PolygonImmutable.php similarity index 82% rename from lib/Types/Dimension3m/Geometry/Polygon.php rename to lib/Types/Dimension3m/Geometry/PolygonImmutable.php index 309530d..286c232 100644 --- a/lib/Types/Dimension3m/Geometry/Polygon.php +++ b/lib/Types/Dimension3m/Geometry/PolygonImmutable.php @@ -19,13 +19,13 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface; -use LongitudeOne\SpatialTypes\Types\AbstractPolygon; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolygonInterface; +use LongitudeOne\SpatialTypes\Types\AbstractPolygonImmutable; /** * Geometric polygon using the XYM layout. */ -class Polygon extends AbstractPolygon implements PolygonInterface +final class PolygonImmutable extends AbstractPolygonImmutable implements ImmutablePolygonInterface { /** * Return the XYM dimension. diff --git a/lib/Types/Dimension3m/Geometry/Triangle.php b/lib/Types/Dimension3m/Geometry/TriangleImmutable.php similarity index 82% rename from lib/Types/Dimension3m/Geometry/Triangle.php rename to lib/Types/Dimension3m/Geometry/TriangleImmutable.php index 6151ada..270adbb 100644 --- a/lib/Types/Dimension3m/Geometry/Triangle.php +++ b/lib/Types/Dimension3m/Geometry/TriangleImmutable.php @@ -19,13 +19,13 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\TriangleInterface; -use LongitudeOne\SpatialTypes\Types\AbstractTriangle; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableTriangleInterface; +use LongitudeOne\SpatialTypes\Types\AbstractTriangleImmutable; /** * Geometric polygon using the XYM layout. */ -class Triangle extends AbstractTriangle implements TriangleInterface +final class TriangleImmutable extends AbstractTriangleImmutable implements ImmutableTriangleInterface { /** * Return the XYM dimension. diff --git a/lib/Types/Dimension3z/AbstractLineString.php b/lib/Types/Dimension3z/AbstractLineStringImmutable.php similarity index 74% rename from lib/Types/Dimension3z/AbstractLineString.php rename to lib/Types/Dimension3z/AbstractLineStringImmutable.php index 671b34b..d290e16 100644 --- a/lib/Types/Dimension3z/AbstractLineString.php +++ b/lib/Types/Dimension3z/AbstractLineStringImmutable.php @@ -21,18 +21,18 @@ use LongitudeOne\SpatialTypes\Exception\InvalidDimensionException; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\MissingValueException; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\AbstractLineString as ParentLineString; +use LongitudeOne\SpatialTypes\Types\AbstractLineStringImmutable as ParentLineString; -abstract class AbstractLineString extends ParentLineString implements LineStringInterface +abstract class AbstractLineStringImmutable extends ParentLineString implements ImmutableLineStringInterface { /** - * AbstractLineString constructor. + * AbstractLineStringImmutable constructor. * - * @param (array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int}|PointInterface)[] $points points of the line string - * @param int|SpatialReference $srid Spatial Reference Identifier + * @param (array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int}|ImmutablePointInterface)[] $points points of the line string + * @param int|SpatialReference $srid Spatial Reference Identifier * * @throws InvalidDimensionException when a coordinate tuple does not match the line string dimension * @throws InvalidValueException when coordinates of the point are invalid diff --git a/lib/Types/Dimension3z/AbstractMultiLineString.php b/lib/Types/Dimension3z/AbstractMultiLineStringImmutable.php similarity index 74% rename from lib/Types/Dimension3z/AbstractMultiLineString.php rename to lib/Types/Dimension3z/AbstractMultiLineStringImmutable.php index e2477a3..c4fb9fd 100644 --- a/lib/Types/Dimension3z/AbstractMultiLineString.php +++ b/lib/Types/Dimension3z/AbstractMultiLineStringImmutable.php @@ -18,10 +18,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiLineStringInterface; -use LongitudeOne\SpatialTypes\Types\AbstractMultiLineString as ParentMultiLineString; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiLineStringInterface; +use LongitudeOne\SpatialTypes\Types\AbstractMultiLineStringImmutable as ParentMultiLineString; -abstract class AbstractMultiLineString extends ParentMultiLineString implements MultiLineStringInterface +abstract class AbstractMultiLineStringImmutable extends ParentMultiLineString implements ImmutableMultiLineStringInterface { /** * Initialize the dimension of the object. diff --git a/lib/Types/Dimension3z/AbstractMultiPoint.php b/lib/Types/Dimension3z/AbstractMultiPointImmutable.php similarity index 76% rename from lib/Types/Dimension3z/AbstractMultiPoint.php rename to lib/Types/Dimension3z/AbstractMultiPointImmutable.php index f822e7c..a11d67f 100644 --- a/lib/Types/Dimension3z/AbstractMultiPoint.php +++ b/lib/Types/Dimension3z/AbstractMultiPointImmutable.php @@ -21,18 +21,18 @@ use LongitudeOne\SpatialTypes\Exception\InvalidDimensionException; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\MissingValueException; -use LongitudeOne\SpatialTypes\Interfaces\MultiPointInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\AbstractMultiPoint as ParentMultiPoint; +use LongitudeOne\SpatialTypes\Types\AbstractMultiPointImmutable as ParentMultiPoint; -abstract class AbstractMultiPoint extends ParentMultiPoint implements MultiPointInterface +abstract class AbstractMultiPointImmutable extends ParentMultiPoint implements ImmutableMultiPointInterface { /** - * AbstractMultiPoint constructor. + * AbstractMultiPointImmutable constructor. * - * @param (array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}|PointInterface)[] $points points of the multipoint - * @param int|SpatialReference $srid Spatial Reference Identifier + * @param (array{0: null|float|int|string, 1: null|float|int|string, 2 ?: null|float|int, 3 ?: null|float|int}|ImmutablePointInterface)[] $points points of the multipoint + * @param int|SpatialReference $srid Spatial Reference Identifier * * @throws InvalidDimensionException when the point dimension is not compatible with the multipoint dimension * @throws InvalidValueException when coordinates of the point are invalid diff --git a/lib/Types/Dimension3z/Geography/CircularString.php b/lib/Types/Dimension3z/Geography/CircularStringImmutable.php similarity index 86% rename from lib/Types/Dimension3z/Geography/CircularString.php rename to lib/Types/Dimension3z/Geography/CircularStringImmutable.php index ba9846b..de39912 100644 --- a/lib/Types/Dimension3z/Geography/CircularString.php +++ b/lib/Types/Dimension3z/Geography/CircularStringImmutable.php @@ -18,10 +18,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Types\AbstractCircularString; +use LongitudeOne\SpatialTypes\Types\AbstractCircularStringImmutable; /** Circular string with XYZ coordinates in the Geography family. */ -class CircularString extends AbstractCircularString +final class CircularStringImmutable extends AbstractCircularStringImmutable { /** Return the coordinate layout. */ public function getDimension(): CoordinateDimensionEnum diff --git a/lib/Types/Dimension3z/Geography/CompoundCurve.php b/lib/Types/Dimension3z/Geography/CompoundCurveImmutable.php similarity index 86% rename from lib/Types/Dimension3z/Geography/CompoundCurve.php rename to lib/Types/Dimension3z/Geography/CompoundCurveImmutable.php index eff2f14..5792d45 100644 --- a/lib/Types/Dimension3z/Geography/CompoundCurve.php +++ b/lib/Types/Dimension3z/Geography/CompoundCurveImmutable.php @@ -18,10 +18,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Types\AbstractCompoundCurve; +use LongitudeOne\SpatialTypes\Types\AbstractCompoundCurveImmutable; /** Compound curve with XYZ coordinates in the Geography family. */ -class CompoundCurve extends AbstractCompoundCurve +final class CompoundCurveImmutable extends AbstractCompoundCurveImmutable { /** Return the coordinate layout. */ public function getDimension(): CoordinateDimensionEnum diff --git a/lib/Types/Dimension3z/Geography/GeographyCollection.php b/lib/Types/Dimension3z/Geography/GeographyCollectionImmutable.php similarity index 81% rename from lib/Types/Dimension3z/Geography/GeographyCollection.php rename to lib/Types/Dimension3z/Geography/GeographyCollectionImmutable.php index 888b075..99f5ddf 100644 --- a/lib/Types/Dimension3z/Geography/GeographyCollection.php +++ b/lib/Types/Dimension3z/Geography/GeographyCollectionImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\CollectionInterface; -use LongitudeOne\SpatialTypes\Types\AbstractCollection; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableCollectionInterface; +use LongitudeOne\SpatialTypes\Types\AbstractCollectionImmutable; -class GeographyCollection extends AbstractCollection implements CollectionInterface +final class GeographyCollectionImmutable extends AbstractCollectionImmutable implements ImmutableCollectionInterface { /** * Return the three-dimensional coordinate layout. diff --git a/lib/Types/Dimension3z/Geography/LineString.php b/lib/Types/Dimension3z/Geography/LineStringImmutable.php similarity index 78% rename from lib/Types/Dimension3z/Geography/LineString.php rename to lib/Types/Dimension3z/Geography/LineStringImmutable.php index 2eee926..c282261 100644 --- a/lib/Types/Dimension3z/Geography/LineString.php +++ b/lib/Types/Dimension3z/Geography/LineStringImmutable.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension3z\Geography; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Types\Dimension3z\AbstractLineString; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Types\Dimension3z\AbstractLineStringImmutable; -class LineString extends AbstractLineString implements LineStringInterface +final class LineStringImmutable extends AbstractLineStringImmutable implements ImmutableLineStringInterface { /** * Define the family. diff --git a/lib/Types/Dimension3z/Geography/MultiLineString.php b/lib/Types/Dimension3z/Geography/MultiLineStringImmutable.php similarity index 76% rename from lib/Types/Dimension3z/Geography/MultiLineString.php rename to lib/Types/Dimension3z/Geography/MultiLineStringImmutable.php index 31ae9a5..9c89894 100644 --- a/lib/Types/Dimension3z/Geography/MultiLineString.php +++ b/lib/Types/Dimension3z/Geography/MultiLineStringImmutable.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension3z\Geography; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiLineStringInterface; -use LongitudeOne\SpatialTypes\Types\Dimension3z\AbstractMultiLineString; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiLineStringInterface; +use LongitudeOne\SpatialTypes\Types\Dimension3z\AbstractMultiLineStringImmutable; -class MultiLineString extends AbstractMultiLineString implements MultiLineStringInterface +final class MultiLineStringImmutable extends AbstractMultiLineStringImmutable implements ImmutableMultiLineStringInterface { /** * Initialize the family of the object. diff --git a/lib/Types/Dimension3z/Geography/MultiPoint.php b/lib/Types/Dimension3z/Geography/MultiPointImmutable.php similarity index 78% rename from lib/Types/Dimension3z/Geography/MultiPoint.php rename to lib/Types/Dimension3z/Geography/MultiPointImmutable.php index 5903b6d..fd565a0 100644 --- a/lib/Types/Dimension3z/Geography/MultiPoint.php +++ b/lib/Types/Dimension3z/Geography/MultiPointImmutable.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension3z\Geography; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiPointInterface; -use LongitudeOne\SpatialTypes\Types\Dimension3z\AbstractMultiPoint; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPointInterface; +use LongitudeOne\SpatialTypes\Types\Dimension3z\AbstractMultiPointImmutable; -class MultiPoint extends AbstractMultiPoint implements MultiPointInterface +final class MultiPointImmutable extends AbstractMultiPointImmutable implements ImmutableMultiPointInterface { /** * Define the family. diff --git a/lib/Types/Dimension3z/Geography/MultiPolygon.php b/lib/Types/Dimension3z/Geography/MultiPolygonImmutable.php similarity index 80% rename from lib/Types/Dimension3z/Geography/MultiPolygon.php rename to lib/Types/Dimension3z/Geography/MultiPolygonImmutable.php index 5e68604..767e120 100644 --- a/lib/Types/Dimension3z/Geography/MultiPolygon.php +++ b/lib/Types/Dimension3z/Geography/MultiPolygonImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiPolygonInterface; -use LongitudeOne\SpatialTypes\Types\AbstractMultiPolygon; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPolygonInterface; +use LongitudeOne\SpatialTypes\Types\AbstractMultiPolygonImmutable; -class MultiPolygon extends AbstractMultiPolygon implements MultiPolygonInterface +final class MultiPolygonImmutable extends AbstractMultiPolygonImmutable implements ImmutableMultiPolygonInterface { /** * Initialize the dimension of the object. diff --git a/lib/Types/Dimension3z/Geography/Point.php b/lib/Types/Dimension3z/Geography/PointImmutable.php similarity index 94% rename from lib/Types/Dimension3z/Geography/Point.php rename to lib/Types/Dimension3z/Geography/PointImmutable.php index 96abae1..516749b 100644 --- a/lib/Types/Dimension3z/Geography/Point.php +++ b/lib/Types/Dimension3z/Geography/PointImmutable.php @@ -21,14 +21,14 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Exception\BadMethodCallException; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\AbstractPoint; +use LongitudeOne\SpatialTypes\Types\AbstractPointImmutable; /** * Three-dimensional geographic point. */ -class Point extends AbstractPoint implements PointInterface +final class PointImmutable extends AbstractPointImmutable implements ImmutablePointInterface { /** * The Z coordinate (altitude or elevation). @@ -131,8 +131,6 @@ public function toArray(): array * Set the Z coordinate. In geography, the Z coordinate is the elevation. * * @param null|float|int $z Z coordinate - * - * @throws InvalidValueException when y is not valid */ protected function initializeZ(float|int|null $z): static { diff --git a/lib/Types/Dimension3z/Geography/Polygon.php b/lib/Types/Dimension3z/Geography/PolygonImmutable.php similarity index 82% rename from lib/Types/Dimension3z/Geography/Polygon.php rename to lib/Types/Dimension3z/Geography/PolygonImmutable.php index 2555059..d0b6404 100644 --- a/lib/Types/Dimension3z/Geography/Polygon.php +++ b/lib/Types/Dimension3z/Geography/PolygonImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface; -use LongitudeOne\SpatialTypes\Types\AbstractPolygon; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolygonInterface; +use LongitudeOne\SpatialTypes\Types\AbstractPolygonImmutable; -class Polygon extends AbstractPolygon implements PolygonInterface +final class PolygonImmutable extends AbstractPolygonImmutable implements ImmutablePolygonInterface { /** * Initialize the dimension of the object. diff --git a/lib/Types/Dimension3z/Geography/PolyhedralSurface.php b/lib/Types/Dimension3z/Geography/PolyhedralSurfaceImmutable.php similarity index 79% rename from lib/Types/Dimension3z/Geography/PolyhedralSurface.php rename to lib/Types/Dimension3z/Geography/PolyhedralSurfaceImmutable.php index 620a433..4f90137 100644 --- a/lib/Types/Dimension3z/Geography/PolyhedralSurface.php +++ b/lib/Types/Dimension3z/Geography/PolyhedralSurfaceImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\PolyhedralSurfaceInterface; -use LongitudeOne\SpatialTypes\Types\AbstractPolyhedralSurface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolyhedralSurfaceInterface; +use LongitudeOne\SpatialTypes\Types\AbstractPolyhedralSurfaceImmutable; -class PolyhedralSurface extends AbstractPolyhedralSurface implements PolyhedralSurfaceInterface +final class PolyhedralSurfaceImmutable extends AbstractPolyhedralSurfaceImmutable implements ImmutablePolyhedralSurfaceInterface { /** * Initialize the dimension of the object. diff --git a/lib/Types/Dimension3z/Geography/Triangle.php b/lib/Types/Dimension3z/Geography/TriangleImmutable.php similarity index 82% rename from lib/Types/Dimension3z/Geography/Triangle.php rename to lib/Types/Dimension3z/Geography/TriangleImmutable.php index fa8b610..6265fce 100644 --- a/lib/Types/Dimension3z/Geography/Triangle.php +++ b/lib/Types/Dimension3z/Geography/TriangleImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\TriangleInterface; -use LongitudeOne\SpatialTypes\Types\AbstractTriangle; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableTriangleInterface; +use LongitudeOne\SpatialTypes\Types\AbstractTriangleImmutable; -class Triangle extends AbstractTriangle implements TriangleInterface +final class TriangleImmutable extends AbstractTriangleImmutable implements ImmutableTriangleInterface { /** * Initialize the dimension of the object. diff --git a/lib/Types/Dimension3z/Geometry/CircularString.php b/lib/Types/Dimension3z/Geometry/CircularStringImmutable.php similarity index 86% rename from lib/Types/Dimension3z/Geometry/CircularString.php rename to lib/Types/Dimension3z/Geometry/CircularStringImmutable.php index 0f8fcd7..14083c2 100644 --- a/lib/Types/Dimension3z/Geometry/CircularString.php +++ b/lib/Types/Dimension3z/Geometry/CircularStringImmutable.php @@ -18,10 +18,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Types\AbstractCircularString; +use LongitudeOne\SpatialTypes\Types\AbstractCircularStringImmutable; /** Circular string with XYZ coordinates in the Geometry family. */ -class CircularString extends AbstractCircularString +final class CircularStringImmutable extends AbstractCircularStringImmutable { /** Return the coordinate layout. */ public function getDimension(): CoordinateDimensionEnum diff --git a/lib/Types/Dimension3z/Geometry/CompoundCurve.php b/lib/Types/Dimension3z/Geometry/CompoundCurveImmutable.php similarity index 86% rename from lib/Types/Dimension3z/Geometry/CompoundCurve.php rename to lib/Types/Dimension3z/Geometry/CompoundCurveImmutable.php index c9eef91..6b7604a 100644 --- a/lib/Types/Dimension3z/Geometry/CompoundCurve.php +++ b/lib/Types/Dimension3z/Geometry/CompoundCurveImmutable.php @@ -18,10 +18,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Types\AbstractCompoundCurve; +use LongitudeOne\SpatialTypes\Types\AbstractCompoundCurveImmutable; /** Compound curve with XYZ coordinates in the Geometry family. */ -class CompoundCurve extends AbstractCompoundCurve +final class CompoundCurveImmutable extends AbstractCompoundCurveImmutable { /** Return the coordinate layout. */ public function getDimension(): CoordinateDimensionEnum diff --git a/lib/Types/Dimension3z/Geometry/GeometryCollection.php b/lib/Types/Dimension3z/Geometry/GeometryCollectionImmutable.php similarity index 81% rename from lib/Types/Dimension3z/Geometry/GeometryCollection.php rename to lib/Types/Dimension3z/Geometry/GeometryCollectionImmutable.php index d7420e7..8edfc7a 100644 --- a/lib/Types/Dimension3z/Geometry/GeometryCollection.php +++ b/lib/Types/Dimension3z/Geometry/GeometryCollectionImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\CollectionInterface; -use LongitudeOne\SpatialTypes\Types\AbstractCollection; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableCollectionInterface; +use LongitudeOne\SpatialTypes\Types\AbstractCollectionImmutable; -class GeometryCollection extends AbstractCollection implements CollectionInterface +final class GeometryCollectionImmutable extends AbstractCollectionImmutable implements ImmutableCollectionInterface { /** * Return the three-dimensional coordinate layout. diff --git a/lib/Types/Dimension3z/Geometry/LineString.php b/lib/Types/Dimension3z/Geometry/LineStringImmutable.php similarity index 77% rename from lib/Types/Dimension3z/Geometry/LineString.php rename to lib/Types/Dimension3z/Geometry/LineStringImmutable.php index f1dff1c..945b48c 100644 --- a/lib/Types/Dimension3z/Geometry/LineString.php +++ b/lib/Types/Dimension3z/Geometry/LineStringImmutable.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Types\Dimension3z\AbstractLineString; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Types\Dimension3z\AbstractLineStringImmutable; -class LineString extends AbstractLineString implements LineStringInterface +final class LineStringImmutable extends AbstractLineStringImmutable implements ImmutableLineStringInterface { /** * Define the family. diff --git a/lib/Types/Dimension3z/Geometry/MultiLineString.php b/lib/Types/Dimension3z/Geometry/MultiLineStringImmutable.php similarity index 76% rename from lib/Types/Dimension3z/Geometry/MultiLineString.php rename to lib/Types/Dimension3z/Geometry/MultiLineStringImmutable.php index 01397f9..55c4c90 100644 --- a/lib/Types/Dimension3z/Geometry/MultiLineString.php +++ b/lib/Types/Dimension3z/Geometry/MultiLineStringImmutable.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiLineStringInterface; -use LongitudeOne\SpatialTypes\Types\Dimension3z\AbstractMultiLineString; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiLineStringInterface; +use LongitudeOne\SpatialTypes\Types\Dimension3z\AbstractMultiLineStringImmutable; -class MultiLineString extends AbstractMultiLineString implements MultiLineStringInterface +final class MultiLineStringImmutable extends AbstractMultiLineStringImmutable implements ImmutableMultiLineStringInterface { /** * Initialize the family of the object. diff --git a/lib/Types/Dimension3z/Geometry/MultiPoint.php b/lib/Types/Dimension3z/Geometry/MultiPointImmutable.php similarity index 77% rename from lib/Types/Dimension3z/Geometry/MultiPoint.php rename to lib/Types/Dimension3z/Geometry/MultiPointImmutable.php index 5e127c2..757a0b9 100644 --- a/lib/Types/Dimension3z/Geometry/MultiPoint.php +++ b/lib/Types/Dimension3z/Geometry/MultiPointImmutable.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiPointInterface; -use LongitudeOne\SpatialTypes\Types\Dimension3z\AbstractMultiPoint; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPointInterface; +use LongitudeOne\SpatialTypes\Types\Dimension3z\AbstractMultiPointImmutable; -class MultiPoint extends AbstractMultiPoint implements MultiPointInterface +final class MultiPointImmutable extends AbstractMultiPointImmutable implements ImmutableMultiPointInterface { /** * Define the family. diff --git a/lib/Types/Dimension3z/Geometry/MultiPolygon.php b/lib/Types/Dimension3z/Geometry/MultiPolygonImmutable.php similarity index 80% rename from lib/Types/Dimension3z/Geometry/MultiPolygon.php rename to lib/Types/Dimension3z/Geometry/MultiPolygonImmutable.php index 48c46bc..2fca0fb 100644 --- a/lib/Types/Dimension3z/Geometry/MultiPolygon.php +++ b/lib/Types/Dimension3z/Geometry/MultiPolygonImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiPolygonInterface; -use LongitudeOne\SpatialTypes\Types\AbstractMultiPolygon; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPolygonInterface; +use LongitudeOne\SpatialTypes\Types\AbstractMultiPolygonImmutable; -class MultiPolygon extends AbstractMultiPolygon implements MultiPolygonInterface +final class MultiPolygonImmutable extends AbstractMultiPolygonImmutable implements ImmutableMultiPolygonInterface { /** * Initialize the dimension of the object. diff --git a/lib/Types/Dimension3z/Geometry/Point.php b/lib/Types/Dimension3z/Geometry/PointImmutable.php similarity index 94% rename from lib/Types/Dimension3z/Geometry/Point.php rename to lib/Types/Dimension3z/Geometry/PointImmutable.php index 79b22ac..673336a 100644 --- a/lib/Types/Dimension3z/Geometry/Point.php +++ b/lib/Types/Dimension3z/Geometry/PointImmutable.php @@ -21,14 +21,14 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Exception\BadMethodCallException; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\AbstractPoint; +use LongitudeOne\SpatialTypes\Types\AbstractPointImmutable; /** * Three-dimensional geometric point. */ -class Point extends AbstractPoint implements PointInterface +final class PointImmutable extends AbstractPointImmutable implements ImmutablePointInterface { /** * The Z coordinate or the elevation. diff --git a/lib/Types/Dimension3z/Geometry/Polygon.php b/lib/Types/Dimension3z/Geometry/PolygonImmutable.php similarity index 82% rename from lib/Types/Dimension3z/Geometry/Polygon.php rename to lib/Types/Dimension3z/Geometry/PolygonImmutable.php index ab64d3f..e0cbaa2 100644 --- a/lib/Types/Dimension3z/Geometry/Polygon.php +++ b/lib/Types/Dimension3z/Geometry/PolygonImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface; -use LongitudeOne\SpatialTypes\Types\AbstractPolygon; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolygonInterface; +use LongitudeOne\SpatialTypes\Types\AbstractPolygonImmutable; -class Polygon extends AbstractPolygon implements PolygonInterface +final class PolygonImmutable extends AbstractPolygonImmutable implements ImmutablePolygonInterface { /** * Declare the dimension of the object. diff --git a/lib/Types/Dimension3z/Geometry/PolyhedralSurface.php b/lib/Types/Dimension3z/Geometry/PolyhedralSurfaceImmutable.php similarity index 79% rename from lib/Types/Dimension3z/Geometry/PolyhedralSurface.php rename to lib/Types/Dimension3z/Geometry/PolyhedralSurfaceImmutable.php index cf710d6..96e8585 100644 --- a/lib/Types/Dimension3z/Geometry/PolyhedralSurface.php +++ b/lib/Types/Dimension3z/Geometry/PolyhedralSurfaceImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\PolyhedralSurfaceInterface; -use LongitudeOne\SpatialTypes\Types\AbstractPolyhedralSurface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolyhedralSurfaceInterface; +use LongitudeOne\SpatialTypes\Types\AbstractPolyhedralSurfaceImmutable; -class PolyhedralSurface extends AbstractPolyhedralSurface implements PolyhedralSurfaceInterface +final class PolyhedralSurfaceImmutable extends AbstractPolyhedralSurfaceImmutable implements ImmutablePolyhedralSurfaceInterface { /** * Initialize the dimension of the object. diff --git a/lib/Types/Dimension3z/Geometry/Triangle.php b/lib/Types/Dimension3z/Geometry/TriangleImmutable.php similarity index 81% rename from lib/Types/Dimension3z/Geometry/Triangle.php rename to lib/Types/Dimension3z/Geometry/TriangleImmutable.php index d8b8887..8725d43 100644 --- a/lib/Types/Dimension3z/Geometry/Triangle.php +++ b/lib/Types/Dimension3z/Geometry/TriangleImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\TriangleInterface; -use LongitudeOne\SpatialTypes\Types\AbstractTriangle; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableTriangleInterface; +use LongitudeOne\SpatialTypes\Types\AbstractTriangleImmutable; -class Triangle extends AbstractTriangle implements TriangleInterface +final class TriangleImmutable extends AbstractTriangleImmutable implements ImmutableTriangleInterface { /** * Declare the dimension of the object. diff --git a/lib/Types/Dimension4zm/AbstractLineString.php b/lib/Types/Dimension4zm/AbstractLineStringImmutable.php similarity index 72% rename from lib/Types/Dimension4zm/AbstractLineString.php rename to lib/Types/Dimension4zm/AbstractLineStringImmutable.php index 12e55fb..13953cc 100644 --- a/lib/Types/Dimension4zm/AbstractLineString.php +++ b/lib/Types/Dimension4zm/AbstractLineStringImmutable.php @@ -18,16 +18,16 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\AbstractLineString as ParentLineString; +use LongitudeOne\SpatialTypes\Types\AbstractLineStringImmutable as ParentLineString; -abstract class AbstractLineString extends ParentLineString implements LineStringInterface +abstract class AbstractLineStringImmutable extends ParentLineString implements ImmutableLineStringInterface { /** - * @param (array{0: null|float|int|string, 1: null|float|int|string, 2: null|float|int, 3: null|float|int}|PointInterface)[] $points points of the line string - * @param int|SpatialReference $srid Spatial Reference Identifier + * @param (array{0: null|float|int|string, 1: null|float|int|string, 2: null|float|int, 3: null|float|int}|ImmutablePointInterface)[] $points points of the line string + * @param int|SpatialReference $srid Spatial Reference Identifier */ public function __construct(array $points, int|SpatialReference $srid = 0) { diff --git a/lib/Types/Dimension4zm/AbstractMultiLineString.php b/lib/Types/Dimension4zm/AbstractMultiLineStringImmutable.php similarity index 74% rename from lib/Types/Dimension4zm/AbstractMultiLineString.php rename to lib/Types/Dimension4zm/AbstractMultiLineStringImmutable.php index d383b82..06fe7d1 100644 --- a/lib/Types/Dimension4zm/AbstractMultiLineString.php +++ b/lib/Types/Dimension4zm/AbstractMultiLineStringImmutable.php @@ -18,10 +18,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiLineStringInterface; -use LongitudeOne\SpatialTypes\Types\AbstractMultiLineString as ParentMultiLineString; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiLineStringInterface; +use LongitudeOne\SpatialTypes\Types\AbstractMultiLineStringImmutable as ParentMultiLineString; -abstract class AbstractMultiLineString extends ParentMultiLineString implements MultiLineStringInterface +abstract class AbstractMultiLineStringImmutable extends ParentMultiLineString implements ImmutableMultiLineStringInterface { /** * Define the four-dimensional XYZM coordinate layout. diff --git a/lib/Types/Dimension4zm/AbstractMultiPoint.php b/lib/Types/Dimension4zm/AbstractMultiPointImmutable.php similarity index 78% rename from lib/Types/Dimension4zm/AbstractMultiPoint.php rename to lib/Types/Dimension4zm/AbstractMultiPointImmutable.php index 6a50d3a..1d829b4 100644 --- a/lib/Types/Dimension4zm/AbstractMultiPoint.php +++ b/lib/Types/Dimension4zm/AbstractMultiPointImmutable.php @@ -21,18 +21,18 @@ use LongitudeOne\SpatialTypes\Exception\InvalidDimensionException; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\MissingValueException; -use LongitudeOne\SpatialTypes\Interfaces\MultiPointInterface; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\AbstractMultiPoint as ParentMultiPoint; +use LongitudeOne\SpatialTypes\Types\AbstractMultiPointImmutable as ParentMultiPoint; -abstract class AbstractMultiPoint extends ParentMultiPoint implements MultiPointInterface +abstract class AbstractMultiPointImmutable extends ParentMultiPoint implements ImmutableMultiPointInterface { /** * Create a multipoint from XYZM coordinate arrays or point instances. * - * @param (array{0: null|float|int|string, 1: null|float|int|string, 2: null|float|int, 3: null|float|int}|PointInterface)[] $points points of the multipoint - * @param int|SpatialReference $srid Spatial Reference Identifier + * @param (array{0: null|float|int|string, 1: null|float|int|string, 2: null|float|int, 3: null|float|int}|ImmutablePointInterface)[] $points points of the multipoint + * @param int|SpatialReference $srid Spatial Reference Identifier * * @throws InvalidDimensionException when a point has an incompatible dimension * @throws InvalidValueException when point coordinates are invalid diff --git a/lib/Types/Dimension4zm/Geography/CircularString.php b/lib/Types/Dimension4zm/Geography/CircularStringImmutable.php similarity index 86% rename from lib/Types/Dimension4zm/Geography/CircularString.php rename to lib/Types/Dimension4zm/Geography/CircularStringImmutable.php index be827fc..b5d1ffc 100644 --- a/lib/Types/Dimension4zm/Geography/CircularString.php +++ b/lib/Types/Dimension4zm/Geography/CircularStringImmutable.php @@ -18,10 +18,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Types\AbstractCircularString; +use LongitudeOne\SpatialTypes\Types\AbstractCircularStringImmutable; /** Circular string with XYZM coordinates in the Geography family. */ -class CircularString extends AbstractCircularString +final class CircularStringImmutable extends AbstractCircularStringImmutable { /** Return the coordinate layout. */ public function getDimension(): CoordinateDimensionEnum diff --git a/lib/Types/Dimension4zm/Geography/CompoundCurve.php b/lib/Types/Dimension4zm/Geography/CompoundCurveImmutable.php similarity index 86% rename from lib/Types/Dimension4zm/Geography/CompoundCurve.php rename to lib/Types/Dimension4zm/Geography/CompoundCurveImmutable.php index 755e7cd..80a1f86 100644 --- a/lib/Types/Dimension4zm/Geography/CompoundCurve.php +++ b/lib/Types/Dimension4zm/Geography/CompoundCurveImmutable.php @@ -18,10 +18,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Types\AbstractCompoundCurve; +use LongitudeOne\SpatialTypes\Types\AbstractCompoundCurveImmutable; /** Compound curve with XYZM coordinates in the Geography family. */ -class CompoundCurve extends AbstractCompoundCurve +final class CompoundCurveImmutable extends AbstractCompoundCurveImmutable { /** Return the coordinate layout. */ public function getDimension(): CoordinateDimensionEnum diff --git a/lib/Types/Dimension4zm/Geography/GeographyCollection.php b/lib/Types/Dimension4zm/Geography/GeographyCollectionImmutable.php similarity index 81% rename from lib/Types/Dimension4zm/Geography/GeographyCollection.php rename to lib/Types/Dimension4zm/Geography/GeographyCollectionImmutable.php index e9853ed..00d062b 100644 --- a/lib/Types/Dimension4zm/Geography/GeographyCollection.php +++ b/lib/Types/Dimension4zm/Geography/GeographyCollectionImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\CollectionInterface; -use LongitudeOne\SpatialTypes\Types\AbstractCollection; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableCollectionInterface; +use LongitudeOne\SpatialTypes\Types\AbstractCollectionImmutable; -class GeographyCollection extends AbstractCollection implements CollectionInterface +final class GeographyCollectionImmutable extends AbstractCollectionImmutable implements ImmutableCollectionInterface { /** * Return the four-dimensional XYZM coordinate layout. diff --git a/lib/Types/Dimension4zm/Geography/LineString.php b/lib/Types/Dimension4zm/Geography/LineStringImmutable.php similarity index 78% rename from lib/Types/Dimension4zm/Geography/LineString.php rename to lib/Types/Dimension4zm/Geography/LineStringImmutable.php index a54c0c2..cf79c11 100644 --- a/lib/Types/Dimension4zm/Geography/LineString.php +++ b/lib/Types/Dimension4zm/Geography/LineStringImmutable.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\AbstractLineString; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\AbstractLineStringImmutable; -class LineString extends AbstractLineString implements LineStringInterface +final class LineStringImmutable extends AbstractLineStringImmutable implements ImmutableLineStringInterface { /** * Return the geography family. diff --git a/lib/Types/Dimension4zm/Geography/MultiLineString.php b/lib/Types/Dimension4zm/Geography/MultiLineStringImmutable.php similarity index 76% rename from lib/Types/Dimension4zm/Geography/MultiLineString.php rename to lib/Types/Dimension4zm/Geography/MultiLineStringImmutable.php index 460e6d5..703fdfd 100644 --- a/lib/Types/Dimension4zm/Geography/MultiLineString.php +++ b/lib/Types/Dimension4zm/Geography/MultiLineStringImmutable.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiLineStringInterface; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\AbstractMultiLineString; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiLineStringInterface; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\AbstractMultiLineStringImmutable; -class MultiLineString extends AbstractMultiLineString implements MultiLineStringInterface +final class MultiLineStringImmutable extends AbstractMultiLineStringImmutable implements ImmutableMultiLineStringInterface { /** * Return the geography family. diff --git a/lib/Types/Dimension4zm/Geography/MultiPoint.php b/lib/Types/Dimension4zm/Geography/MultiPointImmutable.php similarity index 78% rename from lib/Types/Dimension4zm/Geography/MultiPoint.php rename to lib/Types/Dimension4zm/Geography/MultiPointImmutable.php index 0f62fd1..0550f7e 100644 --- a/lib/Types/Dimension4zm/Geography/MultiPoint.php +++ b/lib/Types/Dimension4zm/Geography/MultiPointImmutable.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiPointInterface; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\AbstractMultiPoint; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPointInterface; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\AbstractMultiPointImmutable; -class MultiPoint extends AbstractMultiPoint implements MultiPointInterface +final class MultiPointImmutable extends AbstractMultiPointImmutable implements ImmutableMultiPointInterface { /** * Return the geography family. diff --git a/lib/Types/Dimension4zm/Geography/MultiPolygon.php b/lib/Types/Dimension4zm/Geography/MultiPolygonImmutable.php similarity index 80% rename from lib/Types/Dimension4zm/Geography/MultiPolygon.php rename to lib/Types/Dimension4zm/Geography/MultiPolygonImmutable.php index 1ab633d..95970a6 100644 --- a/lib/Types/Dimension4zm/Geography/MultiPolygon.php +++ b/lib/Types/Dimension4zm/Geography/MultiPolygonImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiPolygonInterface; -use LongitudeOne\SpatialTypes\Types\AbstractMultiPolygon; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPolygonInterface; +use LongitudeOne\SpatialTypes\Types\AbstractMultiPolygonImmutable; -class MultiPolygon extends AbstractMultiPolygon implements MultiPolygonInterface +final class MultiPolygonImmutable extends AbstractMultiPolygonImmutable implements ImmutableMultiPolygonInterface { /** * Return the four-dimensional XYZM coordinate layout. diff --git a/lib/Types/Dimension4zm/Geography/Point.php b/lib/Types/Dimension4zm/Geography/PointImmutable.php similarity index 94% rename from lib/Types/Dimension4zm/Geography/Point.php rename to lib/Types/Dimension4zm/Geography/PointImmutable.php index 2155513..2120766 100644 --- a/lib/Types/Dimension4zm/Geography/Point.php +++ b/lib/Types/Dimension4zm/Geography/PointImmutable.php @@ -20,11 +20,11 @@ use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\AbstractPoint; +use LongitudeOne\SpatialTypes\Types\AbstractPointImmutable; -class Point extends AbstractPoint implements PointInterface +final class PointImmutable extends AbstractPointImmutable implements ImmutablePointInterface { protected float|int|null $m = null; diff --git a/lib/Types/Dimension4zm/Geography/Polygon.php b/lib/Types/Dimension4zm/Geography/PolygonImmutable.php similarity index 82% rename from lib/Types/Dimension4zm/Geography/Polygon.php rename to lib/Types/Dimension4zm/Geography/PolygonImmutable.php index 402647b..9dd0cb9 100644 --- a/lib/Types/Dimension4zm/Geography/Polygon.php +++ b/lib/Types/Dimension4zm/Geography/PolygonImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface; -use LongitudeOne\SpatialTypes\Types\AbstractPolygon; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolygonInterface; +use LongitudeOne\SpatialTypes\Types\AbstractPolygonImmutable; -class Polygon extends AbstractPolygon implements PolygonInterface +final class PolygonImmutable extends AbstractPolygonImmutable implements ImmutablePolygonInterface { /** * Return the four-dimensional XYZM coordinate layout. diff --git a/lib/Types/Dimension4zm/Geography/PolyhedralSurface.php b/lib/Types/Dimension4zm/Geography/PolyhedralSurfaceImmutable.php similarity index 79% rename from lib/Types/Dimension4zm/Geography/PolyhedralSurface.php rename to lib/Types/Dimension4zm/Geography/PolyhedralSurfaceImmutable.php index 3a9282a..813df3a 100644 --- a/lib/Types/Dimension4zm/Geography/PolyhedralSurface.php +++ b/lib/Types/Dimension4zm/Geography/PolyhedralSurfaceImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\PolyhedralSurfaceInterface; -use LongitudeOne\SpatialTypes\Types\AbstractPolyhedralSurface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolyhedralSurfaceInterface; +use LongitudeOne\SpatialTypes\Types\AbstractPolyhedralSurfaceImmutable; -class PolyhedralSurface extends AbstractPolyhedralSurface implements PolyhedralSurfaceInterface +final class PolyhedralSurfaceImmutable extends AbstractPolyhedralSurfaceImmutable implements ImmutablePolyhedralSurfaceInterface { /** * Return the four-dimensional XYZM coordinate layout. diff --git a/lib/Types/Dimension4zm/Geography/Triangle.php b/lib/Types/Dimension4zm/Geography/TriangleImmutable.php similarity index 82% rename from lib/Types/Dimension4zm/Geography/Triangle.php rename to lib/Types/Dimension4zm/Geography/TriangleImmutable.php index fa4c596..92f1336 100644 --- a/lib/Types/Dimension4zm/Geography/Triangle.php +++ b/lib/Types/Dimension4zm/Geography/TriangleImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\TriangleInterface; -use LongitudeOne\SpatialTypes\Types\AbstractTriangle; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableTriangleInterface; +use LongitudeOne\SpatialTypes\Types\AbstractTriangleImmutable; -class Triangle extends AbstractTriangle implements TriangleInterface +final class TriangleImmutable extends AbstractTriangleImmutable implements ImmutableTriangleInterface { /** * Return the four-dimensional XYZM coordinate layout. diff --git a/lib/Types/Dimension4zm/Geometry/CircularString.php b/lib/Types/Dimension4zm/Geometry/CircularStringImmutable.php similarity index 86% rename from lib/Types/Dimension4zm/Geometry/CircularString.php rename to lib/Types/Dimension4zm/Geometry/CircularStringImmutable.php index 9775f16..d13567f 100644 --- a/lib/Types/Dimension4zm/Geometry/CircularString.php +++ b/lib/Types/Dimension4zm/Geometry/CircularStringImmutable.php @@ -18,10 +18,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Types\AbstractCircularString; +use LongitudeOne\SpatialTypes\Types\AbstractCircularStringImmutable; /** Circular string with XYZM coordinates in the Geometry family. */ -class CircularString extends AbstractCircularString +final class CircularStringImmutable extends AbstractCircularStringImmutable { /** Return the coordinate layout. */ public function getDimension(): CoordinateDimensionEnum diff --git a/lib/Types/Dimension4zm/Geometry/CompoundCurve.php b/lib/Types/Dimension4zm/Geometry/CompoundCurveImmutable.php similarity index 86% rename from lib/Types/Dimension4zm/Geometry/CompoundCurve.php rename to lib/Types/Dimension4zm/Geometry/CompoundCurveImmutable.php index 594dee2..782c436 100644 --- a/lib/Types/Dimension4zm/Geometry/CompoundCurve.php +++ b/lib/Types/Dimension4zm/Geometry/CompoundCurveImmutable.php @@ -18,10 +18,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Types\AbstractCompoundCurve; +use LongitudeOne\SpatialTypes\Types\AbstractCompoundCurveImmutable; /** Compound curve with XYZM coordinates in the Geometry family. */ -class CompoundCurve extends AbstractCompoundCurve +final class CompoundCurveImmutable extends AbstractCompoundCurveImmutable { /** Return the coordinate layout. */ public function getDimension(): CoordinateDimensionEnum diff --git a/lib/Types/Dimension4zm/Geometry/GeometryCollection.php b/lib/Types/Dimension4zm/Geometry/GeometryCollectionImmutable.php similarity index 81% rename from lib/Types/Dimension4zm/Geometry/GeometryCollection.php rename to lib/Types/Dimension4zm/Geometry/GeometryCollectionImmutable.php index 73e05fa..af3dea9 100644 --- a/lib/Types/Dimension4zm/Geometry/GeometryCollection.php +++ b/lib/Types/Dimension4zm/Geometry/GeometryCollectionImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\CollectionInterface; -use LongitudeOne\SpatialTypes\Types\AbstractCollection; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableCollectionInterface; +use LongitudeOne\SpatialTypes\Types\AbstractCollectionImmutable; -class GeometryCollection extends AbstractCollection implements CollectionInterface +final class GeometryCollectionImmutable extends AbstractCollectionImmutable implements ImmutableCollectionInterface { /** * Return the four-dimensional XYZM coordinate layout. diff --git a/lib/Types/Dimension4zm/Geometry/LineString.php b/lib/Types/Dimension4zm/Geometry/LineStringImmutable.php similarity index 78% rename from lib/Types/Dimension4zm/Geometry/LineString.php rename to lib/Types/Dimension4zm/Geometry/LineStringImmutable.php index 8c7cc61..80cbdef 100644 --- a/lib/Types/Dimension4zm/Geometry/LineString.php +++ b/lib/Types/Dimension4zm/Geometry/LineStringImmutable.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\AbstractLineString; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\AbstractLineStringImmutable; -class LineString extends AbstractLineString implements LineStringInterface +final class LineStringImmutable extends AbstractLineStringImmutable implements ImmutableLineStringInterface { /** * Return the geometry family. diff --git a/lib/Types/Dimension4zm/Geometry/MultiLineString.php b/lib/Types/Dimension4zm/Geometry/MultiLineStringImmutable.php similarity index 75% rename from lib/Types/Dimension4zm/Geometry/MultiLineString.php rename to lib/Types/Dimension4zm/Geometry/MultiLineStringImmutable.php index 525c39c..2fbf2dc 100644 --- a/lib/Types/Dimension4zm/Geometry/MultiLineString.php +++ b/lib/Types/Dimension4zm/Geometry/MultiLineStringImmutable.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiLineStringInterface; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\AbstractMultiLineString; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiLineStringInterface; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\AbstractMultiLineStringImmutable; -class MultiLineString extends AbstractMultiLineString implements MultiLineStringInterface +final class MultiLineStringImmutable extends AbstractMultiLineStringImmutable implements ImmutableMultiLineStringInterface { /** * Return the geometry family. diff --git a/lib/Types/Dimension4zm/Geometry/MultiPoint.php b/lib/Types/Dimension4zm/Geometry/MultiPointImmutable.php similarity index 78% rename from lib/Types/Dimension4zm/Geometry/MultiPoint.php rename to lib/Types/Dimension4zm/Geometry/MultiPointImmutable.php index 9b64499..40915a7 100644 --- a/lib/Types/Dimension4zm/Geometry/MultiPoint.php +++ b/lib/Types/Dimension4zm/Geometry/MultiPointImmutable.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiPointInterface; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\AbstractMultiPoint; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPointInterface; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\AbstractMultiPointImmutable; -class MultiPoint extends AbstractMultiPoint implements MultiPointInterface +final class MultiPointImmutable extends AbstractMultiPointImmutable implements ImmutableMultiPointInterface { /** * Return the geometry family. diff --git a/lib/Types/Dimension4zm/Geometry/MultiPolygon.php b/lib/Types/Dimension4zm/Geometry/MultiPolygonImmutable.php similarity index 80% rename from lib/Types/Dimension4zm/Geometry/MultiPolygon.php rename to lib/Types/Dimension4zm/Geometry/MultiPolygonImmutable.php index 888ea33..25b81f5 100644 --- a/lib/Types/Dimension4zm/Geometry/MultiPolygon.php +++ b/lib/Types/Dimension4zm/Geometry/MultiPolygonImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\MultiPolygonInterface; -use LongitudeOne\SpatialTypes\Types\AbstractMultiPolygon; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableMultiPolygonInterface; +use LongitudeOne\SpatialTypes\Types\AbstractMultiPolygonImmutable; -class MultiPolygon extends AbstractMultiPolygon implements MultiPolygonInterface +final class MultiPolygonImmutable extends AbstractMultiPolygonImmutable implements ImmutableMultiPolygonInterface { /** * Return the four-dimensional XYZM coordinate layout. diff --git a/lib/Types/Dimension4zm/Geometry/Point.php b/lib/Types/Dimension4zm/Geometry/PointImmutable.php similarity index 94% rename from lib/Types/Dimension4zm/Geometry/Point.php rename to lib/Types/Dimension4zm/Geometry/PointImmutable.php index 45c5127..5f1f531 100644 --- a/lib/Types/Dimension4zm/Geometry/Point.php +++ b/lib/Types/Dimension4zm/Geometry/PointImmutable.php @@ -20,11 +20,11 @@ use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\AbstractPoint; +use LongitudeOne\SpatialTypes\Types\AbstractPointImmutable; -class Point extends AbstractPoint implements PointInterface +final class PointImmutable extends AbstractPointImmutable implements ImmutablePointInterface { protected float|int|null $m = null; diff --git a/lib/Types/Dimension4zm/Geometry/Polygon.php b/lib/Types/Dimension4zm/Geometry/PolygonImmutable.php similarity index 82% rename from lib/Types/Dimension4zm/Geometry/Polygon.php rename to lib/Types/Dimension4zm/Geometry/PolygonImmutable.php index 0717d45..c28be50 100644 --- a/lib/Types/Dimension4zm/Geometry/Polygon.php +++ b/lib/Types/Dimension4zm/Geometry/PolygonImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface; -use LongitudeOne\SpatialTypes\Types\AbstractPolygon; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolygonInterface; +use LongitudeOne\SpatialTypes\Types\AbstractPolygonImmutable; -class Polygon extends AbstractPolygon implements PolygonInterface +final class PolygonImmutable extends AbstractPolygonImmutable implements ImmutablePolygonInterface { /** * Return the four-dimensional XYZM coordinate layout. diff --git a/lib/Types/Dimension4zm/Geometry/PolyhedralSurface.php b/lib/Types/Dimension4zm/Geometry/PolyhedralSurfaceImmutable.php similarity index 79% rename from lib/Types/Dimension4zm/Geometry/PolyhedralSurface.php rename to lib/Types/Dimension4zm/Geometry/PolyhedralSurfaceImmutable.php index 97de060..bf60a80 100644 --- a/lib/Types/Dimension4zm/Geometry/PolyhedralSurface.php +++ b/lib/Types/Dimension4zm/Geometry/PolyhedralSurfaceImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\PolyhedralSurfaceInterface; -use LongitudeOne\SpatialTypes\Types\AbstractPolyhedralSurface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolyhedralSurfaceInterface; +use LongitudeOne\SpatialTypes\Types\AbstractPolyhedralSurfaceImmutable; -class PolyhedralSurface extends AbstractPolyhedralSurface implements PolyhedralSurfaceInterface +final class PolyhedralSurfaceImmutable extends AbstractPolyhedralSurfaceImmutable implements ImmutablePolyhedralSurfaceInterface { /** * Return the four-dimensional XYZM coordinate layout. diff --git a/lib/Types/Dimension4zm/Geometry/Triangle.php b/lib/Types/Dimension4zm/Geometry/TriangleImmutable.php similarity index 82% rename from lib/Types/Dimension4zm/Geometry/Triangle.php rename to lib/Types/Dimension4zm/Geometry/TriangleImmutable.php index 1fefd87..b3f189d 100644 --- a/lib/Types/Dimension4zm/Geometry/Triangle.php +++ b/lib/Types/Dimension4zm/Geometry/TriangleImmutable.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Interfaces\TriangleInterface; -use LongitudeOne\SpatialTypes\Types\AbstractTriangle; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableTriangleInterface; +use LongitudeOne\SpatialTypes\Types\AbstractTriangleImmutable; -class Triangle extends AbstractTriangle implements TriangleInterface +final class TriangleImmutable extends AbstractTriangleImmutable implements ImmutableTriangleInterface { /** * Return the four-dimensional XYZM coordinate layout. diff --git a/lib/Types/ImmutableComponentGuard.php b/lib/Types/ImmutableComponentGuard.php new file mode 100644 index 0000000..eaae1a2 --- /dev/null +++ b/lib/Types/ImmutableComponentGuard.php @@ -0,0 +1,80 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Types; + +use LongitudeOne\SpatialTypes\Exception\InvalidValueException; +use LongitudeOne\SpatialTypes\Interfaces\CircularStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\CollectionInterface; +use LongitudeOne\SpatialTypes\Interfaces\CompoundCurveInterface; +use LongitudeOne\SpatialTypes\Interfaces\CurveInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableSpatialInterface; +use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\MutableSpatialInterface; +use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface; +use LongitudeOne\SpatialTypes\Interfaces\PolyhedralSurfaceInterface; +use LongitudeOne\SpatialTypes\Interfaces\SpatialInterface; + +/** Checks component ownership without checking geometric validity. + * @internal + */ +final class ImmutableComponentGuard +{ + /** Reject mutable components at every aggregate nesting level. + * @param SpatialInterface $component Component to inspect + */ + public static function check(SpatialInterface $component): void + { + $visited = []; + self::inspect($component, $visited); + } + + /** Inspect each component once, including custom aggregate implementations. + * @param SpatialInterface $component Component to inspect + * @param array $visited Already inspected components + */ + private static function inspect(SpatialInterface $component, array &$visited): void + { + if (!$component instanceof ImmutableSpatialInterface || $component instanceof MutableSpatialInterface) { + throw new InvalidValueException('Immutable aggregates require exclusively immutable spatial components.'); + } + if (isset($visited[spl_object_id($component)])) { + return; + } + $visited[spl_object_id($component)] = true; + if ($component instanceof CurveInterface) { + $start = $component->getStartPoint(); + $end = $component->getEndPoint(); + if (null !== $start) { + self::inspect($start, $visited); + } + if (null !== $end) { + self::inspect($end, $visited); + } + } + if ($component instanceof CollectionInterface || $component instanceof LineStringInterface + || $component instanceof CircularStringInterface || $component instanceof CompoundCurveInterface + || $component instanceof PolyhedralSurfaceInterface) { + foreach ($component->getElements() as $child) { + self::inspect($child, $visited); + } + } elseif ($component instanceof PolygonInterface) { + foreach ($component->getRings() as $ring) { + self::inspect($ring, $visited); + } + } + } +} diff --git a/tests/Issue/EmptyMultiLineStringDimension2Test.php b/tests/Issue/EmptyMultiLineStringDimension2Test.php index 48fbe09..55176fc 100644 --- a/tests/Issue/EmptyMultiLineStringDimension2Test.php +++ b/tests/Issue/EmptyMultiLineStringDimension2Test.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Tests\Issue; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\LineString as GeographicLineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiLineString as GeographicMultiLineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiLineString; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\LineStringImmutable as GeographicLineString; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiLineStringImmutable as GeographicMultiLineString; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiLineStringImmutable; use PHPUnit\Framework\TestCase; /** @@ -140,12 +140,12 @@ public function testGeographyReferenceCopies(): void /** Coordinate arrays create empty members in the receiving context. */ public function testGeometryCoordinateArrays(): void { - $mixed = new MultiLineString([[], [[1, 2], [3, 4]], [], [[5, 6], [7, 8]], []], 4326); - $single = new MultiLineString([[]], 4326); + $mixed = new MultiLineStringImmutable([[], [[1, 2], [3, 4]], [], [[5, 6], [7, 8]], []], 4326); + $single = new MultiLineStringImmutable([[]], 4326); static::assertSame([[], [[1, 2], [3, 4]], [], [[5, 6], [7, 8]], []], $mixed->toArray()); static::assertCount(5, $mixed->getElements()); - static::assertInstanceOf(LineString::class, $mixed->getLineString(0)); + static::assertInstanceOf(LineStringImmutable::class, $mixed->getLineString(0)); static::assertSame([], $mixed->getLineString(0)->toArray()); static::assertSame([], $mixed->getLineString(2)->toArray()); static::assertSame([], $mixed->getLineString(4)->toArray()); @@ -159,7 +159,7 @@ public function testGeometryCoordinateArrays(): void /** Replacement keeps untouched empty members and can empty or fill a member. */ public function testGeometryLineStringReplacement(): void { - $original = new MultiLineString([[], [[1, 2], [3, 4]], []], 4326); + $original = new MultiLineStringImmutable([[], [[1, 2], [3, 4]], []], 4326); $emptied = $original->withLineString(1, []); $filled = $original->withLineString(-1, [[1, 2], [3, 4]]); @@ -173,7 +173,7 @@ public function testGeometryLineStringReplacement(): void static::assertNotSame($original->getLineString(2), $emptied->getLineString(2)); static::assertNotSame($original->getLineString(1), $filled->getLineString(1)); static::assertNotSame($original->getLineString(1)->getPoint(0), $filled->getLineString(1)->getPoint(0)); - static::assertInstanceOf(LineString::class, $emptied->getLineString(1)); + static::assertInstanceOf(LineStringImmutable::class, $emptied->getLineString(1)); static::assertSame(4326, $emptied->getLineString(1)->getSrid()); static::assertFalse($emptied->getLineString(1)->hasZ()); static::assertFalse($emptied->getLineString(1)->hasM()); @@ -182,12 +182,12 @@ public function testGeometryLineStringReplacement(): void /** Object members retain their count, order and accessors. */ public function testGeometryObjectMembers(): void { - $empty = new LineString([], 4326); - $line = new LineString([[1, 2], [3, 4]], 4326); - $otherLine = new LineString([[5, 6], [7, 8]], 4326); - $mixed = new MultiLineString([$empty, $line, new LineString([], 4326), $otherLine, $empty], 4326); - $single = new MultiLineString([$empty], 4326); - $zero = new MultiLineString([], 4326); + $empty = new LineStringImmutable([], 4326); + $line = new LineStringImmutable([[1, 2], [3, 4]], 4326); + $otherLine = new LineStringImmutable([[5, 6], [7, 8]], 4326); + $mixed = new MultiLineStringImmutable([$empty, $line, new LineStringImmutable([], 4326), $otherLine, $empty], 4326); + $single = new MultiLineStringImmutable([$empty], 4326); + $zero = new MultiLineStringImmutable([], 4326); static::assertSame([[], [[1, 2], [3, 4]], [], [[5, 6], [7, 8]], []], $mixed->toArray()); static::assertCount(5, $mixed->getElements()); @@ -212,7 +212,7 @@ public function testGeometryObjectMembers(): void /** Reference copies preserve empty positions, ordinates and the source graph. */ public function testGeometryReferenceCopies(): void { - $original = new MultiLineString([[], [[1, 2], [3, 4]], []], 4326); + $original = new MultiLineStringImmutable([[], [[1, 2], [3, 4]], []], 4326); $reference = SpatialReference::epsg(2154); $referenced = $original->withSpatialReference($reference); $renumbered = $original->withSrid(3857); @@ -236,8 +236,8 @@ public function testGeometryReferenceCopies(): void static::assertNotSame($original->getLineString(2), $renumbered->getLineString(2)); static::assertNotSame($original->getLineString(1)->getPoint(0), $referenced->getLineString(1)->getPoint(0)); static::assertNotSame($original->getLineString(1)->getPoint(0), $renumbered->getLineString(1)->getPoint(0)); - static::assertInstanceOf(LineString::class, $referenced->getLineString(0)); - static::assertInstanceOf(LineString::class, $renumbered->getLineString(2)); + static::assertInstanceOf(LineStringImmutable::class, $referenced->getLineString(0)); + static::assertInstanceOf(LineStringImmutable::class, $renumbered->getLineString(2)); static::assertFalse($referenced->getLineString(0)->hasZ()); static::assertFalse($renumbered->getLineString(2)->hasM()); } diff --git a/tests/Issue/EmptyMultiLineStringDimension3mTest.php b/tests/Issue/EmptyMultiLineStringDimension3mTest.php index 1b5aeae..c45ebef 100644 --- a/tests/Issue/EmptyMultiLineStringDimension3mTest.php +++ b/tests/Issue/EmptyMultiLineStringDimension3mTest.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Tests\Issue; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\LineString as GeographicLineString; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiLineString as GeographicMultiLineString; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\LineString; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiLineString; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\LineStringImmutable as GeographicLineString; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiLineStringImmutable as GeographicMultiLineString; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\LineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiLineStringImmutable; use PHPUnit\Framework\TestCase; /** @@ -140,12 +140,12 @@ public function testGeographyReferenceCopies(): void /** Coordinate arrays create empty members in the receiving context. */ public function testGeometryCoordinateArrays(): void { - $mixed = new MultiLineString([[], [[1, 2, 7], [3, 4, 8]], [], [[5, 6, 9], [7, 8, 10]], []], 4326); - $single = new MultiLineString([[]], 4326); + $mixed = new MultiLineStringImmutable([[], [[1, 2, 7], [3, 4, 8]], [], [[5, 6, 9], [7, 8, 10]], []], 4326); + $single = new MultiLineStringImmutable([[]], 4326); static::assertSame([[], [[1, 2, 7], [3, 4, 8]], [], [[5, 6, 9], [7, 8, 10]], []], $mixed->toArray()); static::assertCount(5, $mixed->getElements()); - static::assertInstanceOf(LineString::class, $mixed->getLineString(0)); + static::assertInstanceOf(LineStringImmutable::class, $mixed->getLineString(0)); static::assertSame([], $mixed->getLineString(0)->toArray()); static::assertSame([], $mixed->getLineString(2)->toArray()); static::assertSame([], $mixed->getLineString(4)->toArray()); @@ -159,7 +159,7 @@ public function testGeometryCoordinateArrays(): void /** Replacement keeps untouched empty members and can empty or fill a member. */ public function testGeometryLineStringReplacement(): void { - $original = new MultiLineString([[], [[1, 2, 7], [3, 4, 8]], []], 4326); + $original = new MultiLineStringImmutable([[], [[1, 2, 7], [3, 4, 8]], []], 4326); $emptied = $original->withLineString(1, []); $filled = $original->withLineString(-1, [[1, 2, 7], [3, 4, 8]]); @@ -173,7 +173,7 @@ public function testGeometryLineStringReplacement(): void static::assertNotSame($original->getLineString(2), $emptied->getLineString(2)); static::assertNotSame($original->getLineString(1), $filled->getLineString(1)); static::assertNotSame($original->getLineString(1)->getPoint(0), $filled->getLineString(1)->getPoint(0)); - static::assertInstanceOf(LineString::class, $emptied->getLineString(1)); + static::assertInstanceOf(LineStringImmutable::class, $emptied->getLineString(1)); static::assertSame(4326, $emptied->getLineString(1)->getSrid()); static::assertFalse($emptied->getLineString(1)->hasZ()); static::assertTrue($emptied->getLineString(1)->hasM()); @@ -182,12 +182,12 @@ public function testGeometryLineStringReplacement(): void /** Object members retain their count, order and accessors. */ public function testGeometryObjectMembers(): void { - $empty = new LineString([], 4326); - $line = new LineString([[1, 2, 7], [3, 4, 8]], 4326); - $otherLine = new LineString([[5, 6, 9], [7, 8, 10]], 4326); - $mixed = new MultiLineString([$empty, $line, new LineString([], 4326), $otherLine, $empty], 4326); - $single = new MultiLineString([$empty], 4326); - $zero = new MultiLineString([], 4326); + $empty = new LineStringImmutable([], 4326); + $line = new LineStringImmutable([[1, 2, 7], [3, 4, 8]], 4326); + $otherLine = new LineStringImmutable([[5, 6, 9], [7, 8, 10]], 4326); + $mixed = new MultiLineStringImmutable([$empty, $line, new LineStringImmutable([], 4326), $otherLine, $empty], 4326); + $single = new MultiLineStringImmutable([$empty], 4326); + $zero = new MultiLineStringImmutable([], 4326); static::assertSame([[], [[1, 2, 7], [3, 4, 8]], [], [[5, 6, 9], [7, 8, 10]], []], $mixed->toArray()); static::assertCount(5, $mixed->getElements()); @@ -212,7 +212,7 @@ public function testGeometryObjectMembers(): void /** Reference copies preserve empty positions, ordinates and the source graph. */ public function testGeometryReferenceCopies(): void { - $original = new MultiLineString([[], [[1, 2, 7], [3, 4, 8]], []], 4326); + $original = new MultiLineStringImmutable([[], [[1, 2, 7], [3, 4, 8]], []], 4326); $reference = SpatialReference::epsg(2154); $referenced = $original->withSpatialReference($reference); $renumbered = $original->withSrid(3857); @@ -236,8 +236,8 @@ public function testGeometryReferenceCopies(): void static::assertNotSame($original->getLineString(2), $renumbered->getLineString(2)); static::assertNotSame($original->getLineString(1)->getPoint(0), $referenced->getLineString(1)->getPoint(0)); static::assertNotSame($original->getLineString(1)->getPoint(0), $renumbered->getLineString(1)->getPoint(0)); - static::assertInstanceOf(LineString::class, $referenced->getLineString(0)); - static::assertInstanceOf(LineString::class, $renumbered->getLineString(2)); + static::assertInstanceOf(LineStringImmutable::class, $referenced->getLineString(0)); + static::assertInstanceOf(LineStringImmutable::class, $renumbered->getLineString(2)); static::assertFalse($referenced->getLineString(0)->hasZ()); static::assertTrue($renumbered->getLineString(2)->hasM()); } diff --git a/tests/Issue/EmptyMultiLineStringDimension3zTest.php b/tests/Issue/EmptyMultiLineStringDimension3zTest.php index 37ed256..0557ae1 100644 --- a/tests/Issue/EmptyMultiLineStringDimension3zTest.php +++ b/tests/Issue/EmptyMultiLineStringDimension3zTest.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Tests\Issue; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\LineString as GeographicLineString; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiLineString as GeographicMultiLineString; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\LineString; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiLineString; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\LineStringImmutable as GeographicLineString; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiLineStringImmutable as GeographicMultiLineString; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\LineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiLineStringImmutable; use PHPUnit\Framework\TestCase; /** @@ -140,12 +140,12 @@ public function testGeographyReferenceCopies(): void /** Coordinate arrays create empty members in the receiving context. */ public function testGeometryCoordinateArrays(): void { - $mixed = new MultiLineString([[], [[1, 2, 3], [4, 5, 6]], [], [[7, 8, 9], [10, 11, 12]], []], 4326); - $single = new MultiLineString([[]], 4326); + $mixed = new MultiLineStringImmutable([[], [[1, 2, 3], [4, 5, 6]], [], [[7, 8, 9], [10, 11, 12]], []], 4326); + $single = new MultiLineStringImmutable([[]], 4326); static::assertSame([[], [[1, 2, 3], [4, 5, 6]], [], [[7, 8, 9], [10, 11, 12]], []], $mixed->toArray()); static::assertCount(5, $mixed->getElements()); - static::assertInstanceOf(LineString::class, $mixed->getLineString(0)); + static::assertInstanceOf(LineStringImmutable::class, $mixed->getLineString(0)); static::assertSame([], $mixed->getLineString(0)->toArray()); static::assertSame([], $mixed->getLineString(2)->toArray()); static::assertSame([], $mixed->getLineString(4)->toArray()); @@ -159,7 +159,7 @@ public function testGeometryCoordinateArrays(): void /** Replacement keeps untouched empty members and can empty or fill a member. */ public function testGeometryLineStringReplacement(): void { - $original = new MultiLineString([[], [[1, 2, 3], [4, 5, 6]], []], 4326); + $original = new MultiLineStringImmutable([[], [[1, 2, 3], [4, 5, 6]], []], 4326); $emptied = $original->withLineString(1, []); $filled = $original->withLineString(-1, [[1, 2, 3], [4, 5, 6]]); @@ -173,7 +173,7 @@ public function testGeometryLineStringReplacement(): void static::assertNotSame($original->getLineString(2), $emptied->getLineString(2)); static::assertNotSame($original->getLineString(1), $filled->getLineString(1)); static::assertNotSame($original->getLineString(1)->getPoint(0), $filled->getLineString(1)->getPoint(0)); - static::assertInstanceOf(LineString::class, $emptied->getLineString(1)); + static::assertInstanceOf(LineStringImmutable::class, $emptied->getLineString(1)); static::assertSame(4326, $emptied->getLineString(1)->getSrid()); static::assertTrue($emptied->getLineString(1)->hasZ()); static::assertFalse($emptied->getLineString(1)->hasM()); @@ -182,12 +182,12 @@ public function testGeometryLineStringReplacement(): void /** Object members retain their count, order and accessors. */ public function testGeometryObjectMembers(): void { - $empty = new LineString([], 4326); - $line = new LineString([[1, 2, 3], [4, 5, 6]], 4326); - $otherLine = new LineString([[7, 8, 9], [10, 11, 12]], 4326); - $mixed = new MultiLineString([$empty, $line, new LineString([], 4326), $otherLine, $empty], 4326); - $single = new MultiLineString([$empty], 4326); - $zero = new MultiLineString([], 4326); + $empty = new LineStringImmutable([], 4326); + $line = new LineStringImmutable([[1, 2, 3], [4, 5, 6]], 4326); + $otherLine = new LineStringImmutable([[7, 8, 9], [10, 11, 12]], 4326); + $mixed = new MultiLineStringImmutable([$empty, $line, new LineStringImmutable([], 4326), $otherLine, $empty], 4326); + $single = new MultiLineStringImmutable([$empty], 4326); + $zero = new MultiLineStringImmutable([], 4326); static::assertSame([[], [[1, 2, 3], [4, 5, 6]], [], [[7, 8, 9], [10, 11, 12]], []], $mixed->toArray()); static::assertCount(5, $mixed->getElements()); @@ -212,7 +212,7 @@ public function testGeometryObjectMembers(): void /** Reference copies preserve empty positions, ordinates and the source graph. */ public function testGeometryReferenceCopies(): void { - $original = new MultiLineString([[], [[1, 2, 3], [4, 5, 6]], []], 4326); + $original = new MultiLineStringImmutable([[], [[1, 2, 3], [4, 5, 6]], []], 4326); $reference = SpatialReference::epsg(2154); $referenced = $original->withSpatialReference($reference); $renumbered = $original->withSrid(3857); @@ -236,8 +236,8 @@ public function testGeometryReferenceCopies(): void static::assertNotSame($original->getLineString(2), $renumbered->getLineString(2)); static::assertNotSame($original->getLineString(1)->getPoint(0), $referenced->getLineString(1)->getPoint(0)); static::assertNotSame($original->getLineString(1)->getPoint(0), $renumbered->getLineString(1)->getPoint(0)); - static::assertInstanceOf(LineString::class, $referenced->getLineString(0)); - static::assertInstanceOf(LineString::class, $renumbered->getLineString(2)); + static::assertInstanceOf(LineStringImmutable::class, $referenced->getLineString(0)); + static::assertInstanceOf(LineStringImmutable::class, $renumbered->getLineString(2)); static::assertTrue($referenced->getLineString(0)->hasZ()); static::assertFalse($renumbered->getLineString(2)->hasM()); } diff --git a/tests/Issue/EmptyMultiLineStringDimension4zmTest.php b/tests/Issue/EmptyMultiLineStringDimension4zmTest.php index 5968e4f..ff7ef95 100644 --- a/tests/Issue/EmptyMultiLineStringDimension4zmTest.php +++ b/tests/Issue/EmptyMultiLineStringDimension4zmTest.php @@ -17,10 +17,10 @@ namespace LongitudeOne\SpatialTypes\Tests\Issue; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\LineString as GeographicLineString; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiLineString as GeographicMultiLineString; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\LineString; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiLineString; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\LineStringImmutable as GeographicLineString; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiLineStringImmutable as GeographicMultiLineString; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\LineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiLineStringImmutable; use PHPUnit\Framework\TestCase; /** @@ -140,12 +140,12 @@ public function testGeographyReferenceCopies(): void /** Coordinate arrays create empty members in the receiving context. */ public function testGeometryCoordinateArrays(): void { - $mixed = new MultiLineString([[], [[1, 2, 3, 7], [4, 5, 6, 8]], [], [[7, 8, 9, 10], [11, 12, 13, 14]], []], 4326); - $single = new MultiLineString([[]], 4326); + $mixed = new MultiLineStringImmutable([[], [[1, 2, 3, 7], [4, 5, 6, 8]], [], [[7, 8, 9, 10], [11, 12, 13, 14]], []], 4326); + $single = new MultiLineStringImmutable([[]], 4326); static::assertSame([[], [[1, 2, 3, 7], [4, 5, 6, 8]], [], [[7, 8, 9, 10], [11, 12, 13, 14]], []], $mixed->toArray()); static::assertCount(5, $mixed->getElements()); - static::assertInstanceOf(LineString::class, $mixed->getLineString(0)); + static::assertInstanceOf(LineStringImmutable::class, $mixed->getLineString(0)); static::assertSame([], $mixed->getLineString(0)->toArray()); static::assertSame([], $mixed->getLineString(2)->toArray()); static::assertSame([], $mixed->getLineString(4)->toArray()); @@ -159,7 +159,7 @@ public function testGeometryCoordinateArrays(): void /** Replacement keeps untouched empty members and can empty or fill a member. */ public function testGeometryLineStringReplacement(): void { - $original = new MultiLineString([[], [[1, 2, 3, 7], [4, 5, 6, 8]], []], 4326); + $original = new MultiLineStringImmutable([[], [[1, 2, 3, 7], [4, 5, 6, 8]], []], 4326); $emptied = $original->withLineString(1, []); $filled = $original->withLineString(-1, [[1, 2, 3, 7], [4, 5, 6, 8]]); @@ -173,7 +173,7 @@ public function testGeometryLineStringReplacement(): void static::assertNotSame($original->getLineString(2), $emptied->getLineString(2)); static::assertNotSame($original->getLineString(1), $filled->getLineString(1)); static::assertNotSame($original->getLineString(1)->getPoint(0), $filled->getLineString(1)->getPoint(0)); - static::assertInstanceOf(LineString::class, $emptied->getLineString(1)); + static::assertInstanceOf(LineStringImmutable::class, $emptied->getLineString(1)); static::assertSame(4326, $emptied->getLineString(1)->getSrid()); static::assertTrue($emptied->getLineString(1)->hasZ()); static::assertTrue($emptied->getLineString(1)->hasM()); @@ -182,12 +182,12 @@ public function testGeometryLineStringReplacement(): void /** Object members retain their count, order and accessors. */ public function testGeometryObjectMembers(): void { - $empty = new LineString([], 4326); - $line = new LineString([[1, 2, 3, 7], [4, 5, 6, 8]], 4326); - $otherLine = new LineString([[7, 8, 9, 10], [11, 12, 13, 14]], 4326); - $mixed = new MultiLineString([$empty, $line, new LineString([], 4326), $otherLine, $empty], 4326); - $single = new MultiLineString([$empty], 4326); - $zero = new MultiLineString([], 4326); + $empty = new LineStringImmutable([], 4326); + $line = new LineStringImmutable([[1, 2, 3, 7], [4, 5, 6, 8]], 4326); + $otherLine = new LineStringImmutable([[7, 8, 9, 10], [11, 12, 13, 14]], 4326); + $mixed = new MultiLineStringImmutable([$empty, $line, new LineStringImmutable([], 4326), $otherLine, $empty], 4326); + $single = new MultiLineStringImmutable([$empty], 4326); + $zero = new MultiLineStringImmutable([], 4326); static::assertSame([[], [[1, 2, 3, 7], [4, 5, 6, 8]], [], [[7, 8, 9, 10], [11, 12, 13, 14]], []], $mixed->toArray()); static::assertCount(5, $mixed->getElements()); @@ -212,7 +212,7 @@ public function testGeometryObjectMembers(): void /** Reference copies preserve empty positions, ordinates and the source graph. */ public function testGeometryReferenceCopies(): void { - $original = new MultiLineString([[], [[1, 2, 3, 7], [4, 5, 6, 8]], []], 4326); + $original = new MultiLineStringImmutable([[], [[1, 2, 3, 7], [4, 5, 6, 8]], []], 4326); $reference = SpatialReference::epsg(2154); $referenced = $original->withSpatialReference($reference); $renumbered = $original->withSrid(3857); @@ -236,8 +236,8 @@ public function testGeometryReferenceCopies(): void static::assertNotSame($original->getLineString(2), $renumbered->getLineString(2)); static::assertNotSame($original->getLineString(1)->getPoint(0), $referenced->getLineString(1)->getPoint(0)); static::assertNotSame($original->getLineString(1)->getPoint(0), $renumbered->getLineString(1)->getPoint(0)); - static::assertInstanceOf(LineString::class, $referenced->getLineString(0)); - static::assertInstanceOf(LineString::class, $renumbered->getLineString(2)); + static::assertInstanceOf(LineStringImmutable::class, $referenced->getLineString(0)); + static::assertInstanceOf(LineStringImmutable::class, $renumbered->getLineString(2)); static::assertTrue($referenced->getLineString(0)->hasZ()); static::assertTrue($renumbered->getLineString(2)->hasM()); } diff --git a/tests/Issue/EmptyMultiLineStringValidationTest.php b/tests/Issue/EmptyMultiLineStringValidationTest.php index 369c6fe..de0756d 100644 --- a/tests/Issue/EmptyMultiLineStringValidationTest.php +++ b/tests/Issue/EmptyMultiLineStringValidationTest.php @@ -18,8 +18,8 @@ use LongitudeOne\SpatialTypes\Exception\OutOfBoundsException; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiLineString; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiLineStringImmutable; use PHPUnit\Framework\TestCase; /** @@ -34,8 +34,8 @@ class EmptyMultiLineStringValidationTest extends TestCase /** A zero-member collection and a single empty member survive reference copies. */ public function testReferenceCopiesDistinguishZeroAndOneMember(): void { - $zero = new MultiLineString([], 4326); - $single = new MultiLineString([new LineString([], 4326)], 4326); + $zero = new MultiLineStringImmutable([], 4326); + $single = new MultiLineStringImmutable([new LineStringImmutable([], 4326)], 4326); $reference = SpatialReference::epsg(2154); static::assertSame([], $zero->withSpatialReference($reference)->getElements()); @@ -49,7 +49,7 @@ public function testReferenceCopiesDistinguishZeroAndOneMember(): void public function testReplacementPreservesReferenceAuthority(): void { $reference = SpatialReference::epsg(4326); - $original = new MultiLineString([[], [[1, 2], [3, 4]], []], $reference); + $original = new MultiLineStringImmutable([[], [[1, 2], [3, 4]], []], $reference); $replacement = $original->withLineString(1, []); static::assertSame([[], [], []], $replacement->toArray()); @@ -65,7 +65,7 @@ public function testReplacementPreservesReferenceAuthority(): void /** There is no indexed member in a zero-member collection. */ public function testZeroMemberAccessIsRejected(): void { - $zero = new MultiLineString([]); + $zero = new MultiLineStringImmutable([]); $this->expectException(OutOfBoundsException::class); $zero->getLineString(0); @@ -74,7 +74,7 @@ public function testZeroMemberAccessIsRejected(): void /** Replacing a member cannot append to a zero-member collection. */ public function testZeroMemberReplacementIsRejected(): void { - $zero = new MultiLineString([]); + $zero = new MultiLineStringImmutable([]); $this->expectException(OutOfBoundsException::class); $zero->withLineString(0, []); diff --git a/tests/Issue/EmptyMultiPointMembersTest.php b/tests/Issue/EmptyMultiPointMembersTest.php index 9c4c2d6..c8ed6e4 100644 --- a/tests/Issue/EmptyMultiPointMembersTest.php +++ b/tests/Issue/EmptyMultiPointMembersTest.php @@ -17,8 +17,8 @@ namespace LongitudeOne\SpatialTypes\Tests\Issue; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPoint; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPointImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\TestCase; @@ -34,11 +34,11 @@ class EmptyMultiPointMembersTest extends TestCase /** Preserve empty members in Dimension2 Geography. */ public function testDimension2GeographyPreservesEmptyMembers(): void { - $empty = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Point(srid: 4326); - $point = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Point(1, 2, srid: 4326); - $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiPoint([$empty, $point, new \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Point(srid: 4326), $point, $empty], 4326); - $single = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiPoint([$empty], 4326); - $zero = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiPoint([], 4326); + $empty = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PointImmutable(srid: 4326); + $point = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PointImmutable(1, 2, srid: 4326); + $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiPointImmutable([$empty, $point, new \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PointImmutable(srid: 4326), $point, $empty], 4326); + $single = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiPointImmutable([$empty], 4326); + $zero = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiPointImmutable([], 4326); static::assertSame([[], [1, 2], [], [1, 2], []], $multiPoint->toArray()); static::assertCount(5, $multiPoint->getElements()); @@ -59,11 +59,11 @@ public function testDimension2GeographyPreservesEmptyMembers(): void /** Preserve empty members in Dimension2 Geometry. */ public function testDimension2GeometryPreservesEmptyMembers(): void { - $empty = new Point(srid: 4326); - $point = new Point(1, 2, srid: 4326); - $multiPoint = new MultiPoint([$empty, $point, new Point(srid: 4326), $point, $empty], 4326); - $single = new MultiPoint([$empty], 4326); - $zero = new MultiPoint([], 4326); + $empty = new PointImmutable(srid: 4326); + $point = new PointImmutable(1, 2, srid: 4326); + $multiPoint = new MultiPointImmutable([$empty, $point, new PointImmutable(srid: 4326), $point, $empty], 4326); + $single = new MultiPointImmutable([$empty], 4326); + $zero = new MultiPointImmutable([], 4326); static::assertSame([[], [1, 2], [], [1, 2], []], $multiPoint->toArray()); static::assertCount(5, $multiPoint->getElements()); @@ -84,11 +84,11 @@ public function testDimension2GeometryPreservesEmptyMembers(): void /** Preserve empty members in Dimension3m Geography. */ public function testDimension3mGeographyPreservesEmptyMembers(): void { - $empty = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Point(srid: 4326); - $point = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Point(1, 2, 4, srid: 4326); - $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPoint([$empty, $point, new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Point(srid: 4326), $point, $empty], 4326); - $single = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPoint([$empty], 4326); - $zero = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPoint([], 4326); + $empty = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\PointImmutable(srid: 4326); + $point = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\PointImmutable(1, 2, 4, srid: 4326); + $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPointImmutable([$empty, $point, new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\PointImmutable(srid: 4326), $point, $empty], 4326); + $single = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPointImmutable([$empty], 4326); + $zero = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPointImmutable([], 4326); static::assertSame([[], [1, 2, 4], [], [1, 2, 4], []], $multiPoint->toArray()); static::assertCount(5, $multiPoint->getElements()); @@ -109,11 +109,11 @@ public function testDimension3mGeographyPreservesEmptyMembers(): void /** Preserve empty members in Dimension3m Geometry. */ public function testDimension3mGeometryPreservesEmptyMembers(): void { - $empty = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Point(srid: 4326); - $point = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Point(1, 2, 4, srid: 4326); - $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPoint([$empty, $point, new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Point(srid: 4326), $point, $empty], 4326); - $single = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPoint([$empty], 4326); - $zero = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPoint([], 4326); + $empty = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\PointImmutable(srid: 4326); + $point = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\PointImmutable(1, 2, 4, srid: 4326); + $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPointImmutable([$empty, $point, new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\PointImmutable(srid: 4326), $point, $empty], 4326); + $single = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPointImmutable([$empty], 4326); + $zero = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPointImmutable([], 4326); static::assertSame([[], [1, 2, 4], [], [1, 2, 4], []], $multiPoint->toArray()); static::assertCount(5, $multiPoint->getElements()); @@ -134,11 +134,11 @@ public function testDimension3mGeometryPreservesEmptyMembers(): void /** Preserve empty members in Dimension3z Geography. */ public function testDimension3zGeographyPreservesEmptyMembers(): void { - $empty = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point(srid: 4326); - $point = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point(1, 2, 3, srid: 4326); - $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPoint([$empty, $point, new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point(srid: 4326), $point, $empty], 4326); - $single = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPoint([$empty], 4326); - $zero = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPoint([], 4326); + $empty = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PointImmutable(srid: 4326); + $point = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PointImmutable(1, 2, 3, srid: 4326); + $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPointImmutable([$empty, $point, new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PointImmutable(srid: 4326), $point, $empty], 4326); + $single = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPointImmutable([$empty], 4326); + $zero = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPointImmutable([], 4326); static::assertSame([[], [1, 2, 3], [], [1, 2, 3], []], $multiPoint->toArray()); static::assertCount(5, $multiPoint->getElements()); @@ -159,11 +159,11 @@ public function testDimension3zGeographyPreservesEmptyMembers(): void /** Preserve empty members in Dimension3z Geometry. */ public function testDimension3zGeometryPreservesEmptyMembers(): void { - $empty = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point(srid: 4326); - $point = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point(1, 2, 3, srid: 4326); - $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPoint([$empty, $point, new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point(srid: 4326), $point, $empty], 4326); - $single = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPoint([$empty], 4326); - $zero = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPoint([], 4326); + $empty = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PointImmutable(srid: 4326); + $point = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PointImmutable(1, 2, 3, srid: 4326); + $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPointImmutable([$empty, $point, new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PointImmutable(srid: 4326), $point, $empty], 4326); + $single = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPointImmutable([$empty], 4326); + $zero = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPointImmutable([], 4326); static::assertSame([[], [1, 2, 3], [], [1, 2, 3], []], $multiPoint->toArray()); static::assertCount(5, $multiPoint->getElements()); @@ -184,11 +184,11 @@ public function testDimension3zGeometryPreservesEmptyMembers(): void /** Preserve empty members in Dimension4zm Geography. */ public function testDimension4zmGeographyPreservesEmptyMembers(): void { - $empty = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Point(srid: 4326); - $point = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Point(1, 2, 3, 4, srid: 4326); - $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiPoint([$empty, $point, new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Point(srid: 4326), $point, $empty], 4326); - $single = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiPoint([$empty], 4326); - $zero = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiPoint([], 4326); + $empty = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PointImmutable(srid: 4326); + $point = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PointImmutable(1, 2, 3, 4, srid: 4326); + $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiPointImmutable([$empty, $point, new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PointImmutable(srid: 4326), $point, $empty], 4326); + $single = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiPointImmutable([$empty], 4326); + $zero = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiPointImmutable([], 4326); static::assertSame([[], [1, 2, 3, 4], [], [1, 2, 3, 4], []], $multiPoint->toArray()); static::assertCount(5, $multiPoint->getElements()); @@ -209,11 +209,11 @@ public function testDimension4zmGeographyPreservesEmptyMembers(): void /** Preserve empty members in Dimension4zm Geometry. */ public function testDimension4zmGeometryPreservesEmptyMembers(): void { - $empty = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Point(srid: 4326); - $point = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Point(1, 2, 3, 4, srid: 4326); - $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiPoint([$empty, $point, new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Point(srid: 4326), $point, $empty], 4326); - $single = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiPoint([$empty], 4326); - $zero = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiPoint([], 4326); + $empty = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\PointImmutable(srid: 4326); + $point = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\PointImmutable(1, 2, 3, 4, srid: 4326); + $multiPoint = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiPointImmutable([$empty, $point, new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\PointImmutable(srid: 4326), $point, $empty], 4326); + $single = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiPointImmutable([$empty], 4326); + $zero = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiPointImmutable([], 4326); static::assertSame([[], [1, 2, 3, 4], [], [1, 2, 3, 4], []], $multiPoint->toArray()); static::assertCount(5, $multiPoint->getElements()); @@ -234,7 +234,7 @@ public function testDimension4zmGeometryPreservesEmptyMembers(): void /** Immutable copies preserve empty members and the original. */ public function testImmutableCopiesPreserveEmptyMembers(): void { - $original = new MultiPoint([new Point(srid: 4326), new Point(1, 2, 4326), new Point(srid: 4326)], 4326); + $original = new MultiPointImmutable([new PointImmutable(srid: 4326), new PointImmutable(1, 2, 4326), new PointImmutable(srid: 4326)], 4326); $reference = SpatialReference::epsg(2154); $declared = $original->withSpatialReference($reference); $renumbered = $original->withSrid(2154); @@ -256,10 +256,10 @@ public function testImmutableCopiesPreserveEmptyMembers(): void /** The library JSON export retains member positions. */ public function testJsonSerializationPreservesEmptyMembers(): void { - $multiPoint = new MultiPoint([new Point(srid: 4326), new Point(1, 2, 4326), new Point(srid: 4326)], 4326); + $multiPoint = new MultiPointImmutable([new PointImmutable(srid: 4326), new PointImmutable(1, 2, 4326), new PointImmutable(srid: 4326)], 4326); static::assertSame('{"type":"MultiPoint","coordinates":[[],[1,2],[]],"srid":4326}', json_encode($multiPoint)); - static::assertSame('{"type":"MultiPoint","coordinates":[[]],"srid":0}', json_encode(new MultiPoint([new Point()]))); - static::assertSame('{"type":"MultiPoint","coordinates":[],"srid":0}', json_encode(new MultiPoint([]))); + static::assertSame('{"type":"MultiPoint","coordinates":[[]],"srid":0}', json_encode(new MultiPointImmutable([new PointImmutable()]))); + static::assertSame('{"type":"MultiPoint","coordinates":[],"srid":0}', json_encode(new MultiPointImmutable([]))); } } diff --git a/tests/Issue/EmptyMultiPolygonDimension2Test.php b/tests/Issue/EmptyMultiPolygonDimension2Test.php index e012d39..1d43898 100644 --- a/tests/Issue/EmptyMultiPolygonDimension2Test.php +++ b/tests/Issue/EmptyMultiPolygonDimension2Test.php @@ -16,10 +16,10 @@ namespace LongitudeOne\SpatialTypes\Tests\Issue; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiPolygon as GeographicMultiPolygon; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Polygon as GeographicPolygon; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPolygon; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Polygon; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiPolygonImmutable as GeographicMultiPolygon; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PolygonImmutable as GeographicPolygon; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPolygonImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PolygonImmutable; use PHPUnit\Framework\TestCase; /** @@ -81,13 +81,13 @@ public function testGeographyObjectMember(): void /** Coordinate arrays preserve empty members before, between and after polygons. */ public function testGeometryCoordinateArrays(): void { - $single = new MultiPolygon([[]], 4326); - $mixed = new MultiPolygon([[], [[[0, 0], [4, 0], [4, 3], [0, 0]]], [], [[[10, 0], [14, 0], [14, 3], [10, 0]]], []], 4326); + $single = new MultiPolygonImmutable([[]], 4326); + $mixed = new MultiPolygonImmutable([[], [[[0, 0], [4, 0], [4, 3], [0, 0]]], [], [[[10, 0], [14, 0], [14, 3], [10, 0]]], []], 4326); static::assertCount(1, $single->getElements()); static::assertSame([$single->getPolygon(0)], $single->getElements()); static::assertSame([$single->getPolygon(0)], $single->getPolygons()); - static::assertInstanceOf(Polygon::class, $single->getPolygon(0)); + static::assertInstanceOf(PolygonImmutable::class, $single->getPolygon(0)); static::assertTrue($single->getPolygon(0)->isEmpty()); static::assertFalse($single->isEmpty()); static::assertSame([[]], $single->toArray()); @@ -105,9 +105,9 @@ public function testGeometryCoordinateArrays(): void /** An empty polygon remains one member, distinct from a zero-member collection. */ public function testGeometryObjectMember(): void { - $polygon = new Polygon([], 4326); - $single = new MultiPolygon([$polygon], 4326); - $zero = new MultiPolygon([], 4326); + $polygon = new PolygonImmutable([], 4326); + $single = new MultiPolygonImmutable([$polygon], 4326); + $zero = new MultiPolygonImmutable([], 4326); static::assertCount(1, $single->getElements()); static::assertSame([$polygon], $single->getElements()); diff --git a/tests/Issue/EmptyMultiPolygonDimension3mTest.php b/tests/Issue/EmptyMultiPolygonDimension3mTest.php index 6d94051..8432eff 100644 --- a/tests/Issue/EmptyMultiPolygonDimension3mTest.php +++ b/tests/Issue/EmptyMultiPolygonDimension3mTest.php @@ -16,10 +16,10 @@ namespace LongitudeOne\SpatialTypes\Tests\Issue; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPolygon as GeographicMultiPolygon; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Polygon as GeographicPolygon; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPolygon; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Polygon; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPolygonImmutable as GeographicMultiPolygon; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\PolygonImmutable as GeographicPolygon; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPolygonImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\PolygonImmutable; use PHPUnit\Framework\TestCase; /** @@ -81,13 +81,13 @@ public function testGeographyObjectMember(): void /** Coordinate arrays preserve empty members before, between and after polygons. */ public function testGeometryCoordinateArrays(): void { - $single = new MultiPolygon([[]], 4326); - $mixed = new MultiPolygon([[], [[[0, 0, 2], [4, 0, 2], [4, 3, 2], [0, 0, 2]]], [], [[[10, 0, 2], [14, 0, 2], [14, 3, 2], [10, 0, 2]]], []], 4326); + $single = new MultiPolygonImmutable([[]], 4326); + $mixed = new MultiPolygonImmutable([[], [[[0, 0, 2], [4, 0, 2], [4, 3, 2], [0, 0, 2]]], [], [[[10, 0, 2], [14, 0, 2], [14, 3, 2], [10, 0, 2]]], []], 4326); static::assertCount(1, $single->getElements()); static::assertSame([$single->getPolygon(0)], $single->getElements()); static::assertSame([$single->getPolygon(0)], $single->getPolygons()); - static::assertInstanceOf(Polygon::class, $single->getPolygon(0)); + static::assertInstanceOf(PolygonImmutable::class, $single->getPolygon(0)); static::assertTrue($single->getPolygon(0)->isEmpty()); static::assertFalse($single->isEmpty()); static::assertSame([[]], $single->toArray()); @@ -105,9 +105,9 @@ public function testGeometryCoordinateArrays(): void /** An empty polygon remains one member, distinct from a zero-member collection. */ public function testGeometryObjectMember(): void { - $polygon = new Polygon([], 4326); - $single = new MultiPolygon([$polygon], 4326); - $zero = new MultiPolygon([], 4326); + $polygon = new PolygonImmutable([], 4326); + $single = new MultiPolygonImmutable([$polygon], 4326); + $zero = new MultiPolygonImmutable([], 4326); static::assertCount(1, $single->getElements()); static::assertSame([$polygon], $single->getElements()); diff --git a/tests/Issue/EmptyMultiPolygonDimension3zTest.php b/tests/Issue/EmptyMultiPolygonDimension3zTest.php index 8ac9912..cb68591 100644 --- a/tests/Issue/EmptyMultiPolygonDimension3zTest.php +++ b/tests/Issue/EmptyMultiPolygonDimension3zTest.php @@ -16,10 +16,10 @@ namespace LongitudeOne\SpatialTypes\Tests\Issue; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPolygon as GeographicMultiPolygon; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Polygon as GeographicPolygon; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPolygon; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Polygon; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPolygonImmutable as GeographicMultiPolygon; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PolygonImmutable as GeographicPolygon; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPolygonImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PolygonImmutable; use PHPUnit\Framework\TestCase; /** @@ -81,13 +81,13 @@ public function testGeographyObjectMember(): void /** Coordinate arrays preserve empty members before, between and after polygons. */ public function testGeometryCoordinateArrays(): void { - $single = new MultiPolygon([[]], 4326); - $mixed = new MultiPolygon([[], [[[0, 0, 1], [4, 0, 1], [4, 3, 1], [0, 0, 1]]], [], [[[10, 0, 1], [14, 0, 1], [14, 3, 1], [10, 0, 1]]], []], 4326); + $single = new MultiPolygonImmutable([[]], 4326); + $mixed = new MultiPolygonImmutable([[], [[[0, 0, 1], [4, 0, 1], [4, 3, 1], [0, 0, 1]]], [], [[[10, 0, 1], [14, 0, 1], [14, 3, 1], [10, 0, 1]]], []], 4326); static::assertCount(1, $single->getElements()); static::assertSame([$single->getPolygon(0)], $single->getElements()); static::assertSame([$single->getPolygon(0)], $single->getPolygons()); - static::assertInstanceOf(Polygon::class, $single->getPolygon(0)); + static::assertInstanceOf(PolygonImmutable::class, $single->getPolygon(0)); static::assertTrue($single->getPolygon(0)->isEmpty()); static::assertFalse($single->isEmpty()); static::assertSame([[]], $single->toArray()); @@ -105,9 +105,9 @@ public function testGeometryCoordinateArrays(): void /** An empty polygon remains one member, distinct from a zero-member collection. */ public function testGeometryObjectMember(): void { - $polygon = new Polygon([], 4326); - $single = new MultiPolygon([$polygon], 4326); - $zero = new MultiPolygon([], 4326); + $polygon = new PolygonImmutable([], 4326); + $single = new MultiPolygonImmutable([$polygon], 4326); + $zero = new MultiPolygonImmutable([], 4326); static::assertCount(1, $single->getElements()); static::assertSame([$polygon], $single->getElements()); diff --git a/tests/Issue/EmptyMultiPolygonDimension4zmTest.php b/tests/Issue/EmptyMultiPolygonDimension4zmTest.php index 811d44c..b56d866 100644 --- a/tests/Issue/EmptyMultiPolygonDimension4zmTest.php +++ b/tests/Issue/EmptyMultiPolygonDimension4zmTest.php @@ -16,10 +16,10 @@ namespace LongitudeOne\SpatialTypes\Tests\Issue; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiPolygon as GeographicMultiPolygon; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Polygon as GeographicPolygon; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiPolygon; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Polygon; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiPolygonImmutable as GeographicMultiPolygon; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PolygonImmutable as GeographicPolygon; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiPolygonImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\PolygonImmutable; use PHPUnit\Framework\TestCase; /** @@ -81,13 +81,13 @@ public function testGeographyObjectMember(): void /** Coordinate arrays preserve empty members before, between and after polygons. */ public function testGeometryCoordinateArrays(): void { - $single = new MultiPolygon([[]], 4326); - $mixed = new MultiPolygon([[], [[[0, 0, 1, 2], [4, 0, 1, 2], [4, 3, 1, 2], [0, 0, 1, 2]]], [], [[[10, 0, 1, 2], [14, 0, 1, 2], [14, 3, 1, 2], [10, 0, 1, 2]]], []], 4326); + $single = new MultiPolygonImmutable([[]], 4326); + $mixed = new MultiPolygonImmutable([[], [[[0, 0, 1, 2], [4, 0, 1, 2], [4, 3, 1, 2], [0, 0, 1, 2]]], [], [[[10, 0, 1, 2], [14, 0, 1, 2], [14, 3, 1, 2], [10, 0, 1, 2]]], []], 4326); static::assertCount(1, $single->getElements()); static::assertSame([$single->getPolygon(0)], $single->getElements()); static::assertSame([$single->getPolygon(0)], $single->getPolygons()); - static::assertInstanceOf(Polygon::class, $single->getPolygon(0)); + static::assertInstanceOf(PolygonImmutable::class, $single->getPolygon(0)); static::assertTrue($single->getPolygon(0)->isEmpty()); static::assertFalse($single->isEmpty()); static::assertSame([[]], $single->toArray()); @@ -105,9 +105,9 @@ public function testGeometryCoordinateArrays(): void /** An empty polygon remains one member, distinct from a zero-member collection. */ public function testGeometryObjectMember(): void { - $polygon = new Polygon([], 4326); - $single = new MultiPolygon([$polygon], 4326); - $zero = new MultiPolygon([], 4326); + $polygon = new PolygonImmutable([], 4326); + $single = new MultiPolygonImmutable([$polygon], 4326); + $zero = new MultiPolygonImmutable([], 4326); static::assertCount(1, $single->getElements()); static::assertSame([$polygon], $single->getElements()); diff --git a/tests/Issue/Issue1/CollectionTest.php b/tests/Issue/Issue1/CollectionTest.php index 8089012..fa0cac3 100644 --- a/tests/Issue/Issue1/CollectionTest.php +++ b/tests/Issue/Issue1/CollectionTest.php @@ -16,8 +16,8 @@ namespace LongitudeOne\SpatialTypes\Tests\Issue\Issue1; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollection; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollectionImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; use PHPUnit\Framework\TestCase; /** @@ -25,8 +25,8 @@ * * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractCollection - * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollection + * @covers \LongitudeOne\SpatialTypes\Types\AbstractCollectionImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollectionImmutable */ class CollectionTest extends TestCase { @@ -37,9 +37,9 @@ class CollectionTest extends TestCase */ public function testCollectionCanContainAnotherCollection(): void { - $point = new Point(1, 2, 4326); - $nestedCollection = new GeometryCollection(4326, [$point]); - $collection = new GeometryCollection(4326, [$nestedCollection]); + $point = new PointImmutable(1, 2, 4326); + $nestedCollection = new GeometryCollectionImmutable(4326, [$point]); + $collection = new GeometryCollectionImmutable(4326, [$nestedCollection]); static::assertSame([$nestedCollection], $collection->getElements()); static::assertSame([$point], $nestedCollection->getElements()); diff --git a/tests/Issue/Issue2/PointTest.php b/tests/Issue/Issue2/PointTest.php index 6d7a898..28132b4 100644 --- a/tests/Issue/Issue2/PointTest.php +++ b/tests/Issue/Issue2/PointTest.php @@ -16,7 +16,7 @@ namespace LongitudeOne\SpatialTypes\Tests\Issue\Issue2; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PointImmutable; use PHPUnit\Framework\TestCase; /** @@ -24,9 +24,9 @@ * * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractPoint - * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialType - * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Point + * @covers \LongitudeOne\SpatialTypes\Types\AbstractPointImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialTypeImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PointImmutable */ class PointTest extends TestCase { @@ -35,7 +35,7 @@ class PointTest extends TestCase */ public function testConstructsNegativeSouthLatitude(): void { - static::assertSame(-40, (new Point(0, '-40S'))->getLatitude()); + static::assertSame(-40, (new PointImmutable(0, '-40S'))->getLatitude()); } /** @@ -43,6 +43,6 @@ public function testConstructsNegativeSouthLatitude(): void */ public function testConstructsNegativeWestLongitude(): void { - static::assertSame(-40, (new Point('-40W', 0))->getLongitude()); + static::assertSame(-40, (new PointImmutable('-40W', 0))->getLongitude()); } } diff --git a/tests/Issue/PartiallyNullCompoundCurveTest.php b/tests/Issue/PartiallyNullCompoundCurveTest.php index 90dc9e0..06233f4 100644 --- a/tests/Issue/PartiallyNullCompoundCurveTest.php +++ b/tests/Issue/PartiallyNullCompoundCurveTest.php @@ -19,9 +19,9 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\CompoundCurve; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\LineString; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\CompoundCurveImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\LineStringImmutable; use PHPUnit\Framework\TestCase; /** @@ -29,16 +29,16 @@ * * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractCompoundCurve + * @covers \LongitudeOne\SpatialTypes\Types\AbstractCompoundCurveImmutable */ class PartiallyNullCompoundCurveTest extends TestCase { /** Null ordinates survive construction, access and independent reference copies. */ public function testElevationGeographyComponentsPreserveNullOrdinates(): void { - $line = new LineString([[0, null, null], [null, 2, 3.5]], 4326); - $circular = new CircularString([[null, 2, 3.5], [1.5, null, 4], [0, 5, null]], 4326); - $compound = new CompoundCurve([$line, $circular], 4326); + $line = new LineStringImmutable([[0, null, null], [null, 2, 3.5]], 4326); + $circular = new CircularStringImmutable([[null, 2, 3.5], [1.5, null, 4], [0, 5, null]], 4326); + $compound = new CompoundCurveImmutable([$line, $circular], 4326); $copy = $compound->withSpatialReference(SpatialReference::epsg(3857)); $legacyCopy = $compound->withSrid(2154); @@ -54,9 +54,9 @@ public function testElevationGeographyComponentsPreserveNullOrdinates(): void static::assertNotSame($line, $copy->getCurve(0)); static::assertNotSame($line->getPoint(0), $copy->getStartPoint()); static::assertNotSame($circular, $copy->getCurve(1)); - static::assertSame(CompoundCurve::class, $copy::class); - static::assertSame(LineString::class, $copy->getCurve(0)::class); - static::assertSame(CircularString::class, $copy->getCurve(1)::class); + static::assertSame(CompoundCurveImmutable::class, (new \ReflectionClass($copy))->getName()); + static::assertSame(LineStringImmutable::class, $copy->getCurve(0)::class); + static::assertSame(CircularStringImmutable::class, $copy->getCurve(1)::class); static::assertSame(4326, $compound->getSrid()); static::assertSame(4326, $line->getPoint(0)->getSrid()); static::assertSame(3857, $copy->getSrid()); @@ -68,9 +68,9 @@ public function testElevationGeographyComponentsPreserveNullOrdinates(): void /** Null ordinates survive construction, access and independent reference copies. */ public function testElevationGeometryComponentsPreserveNullOrdinates(): void { - $line = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\LineString([[0, null, null], [null, 2, 3.5]], 4326); - $circular = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\CircularString([[null, 2, 3.5], [1.5, null, 4], [0, 5, null]], 4326); - $compound = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\CompoundCurve([$line, $circular], 4326); + $line = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\LineStringImmutable([[0, null, null], [null, 2, 3.5]], 4326); + $circular = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\CircularStringImmutable([[null, 2, 3.5], [1.5, null, 4], [0, 5, null]], 4326); + $compound = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\CompoundCurveImmutable([$line, $circular], 4326); $copy = $compound->withSpatialReference(SpatialReference::epsg(3857)); $legacyCopy = $compound->withSrid(2154); @@ -86,9 +86,9 @@ public function testElevationGeometryComponentsPreserveNullOrdinates(): void static::assertNotSame($line, $copy->getCurve(0)); static::assertNotSame($line->getPoint(0), $copy->getStartPoint()); static::assertNotSame($circular, $copy->getCurve(1)); - static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\CompoundCurve::class, $copy::class); - static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\LineString::class, $copy->getCurve(0)::class); - static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\CircularString::class, $copy->getCurve(1)::class); + static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\CompoundCurveImmutable::class, (new \ReflectionClass($copy))->getName()); + static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\LineStringImmutable::class, $copy->getCurve(0)::class); + static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\CircularStringImmutable::class, $copy->getCurve(1)::class); static::assertSame(4326, $compound->getSrid()); static::assertSame(4326, $line->getPoint(0)->getSrid()); static::assertSame(3857, $copy->getSrid()); @@ -100,8 +100,8 @@ public function testElevationGeometryComponentsPreserveNullOrdinates(): void /** An EMPTY member keeps its empty tuple beside a partially supplied point. */ public function testEmptyPointMemberRemainsEmptyDuringReferenceCopy(): void { - $line = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\LineString([[0, null, 3], [null, null, null]], 4326); - $compound = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\CompoundCurve([$line], 4326); + $line = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\LineStringImmutable([[0, null, 3], [null, null, null]], 4326); + $compound = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\CompoundCurveImmutable([$line], 4326); $copy = $compound->withSpatialReference(SpatialReference::epsg(3857)); static::assertFalse($compound->isEmpty()); @@ -118,9 +118,9 @@ public function testEmptyPointMemberRemainsEmptyDuringReferenceCopy(): void /** Null ordinates survive construction, access and independent reference copies. */ public function testFourDimensionalGeographyComponentsPreserveNullOrdinates(): void { - $line = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\LineString([[0, null, 3.5, null], [null, 2, null, 4]], 4326); - $circular = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\CircularString([[null, 2, null, 4], [1.5, null, 3, null], [0, 5, null, null]], 4326); - $compound = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\CompoundCurve([$line, $circular], 4326); + $line = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\LineStringImmutable([[0, null, 3.5, null], [null, 2, null, 4]], 4326); + $circular = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\CircularStringImmutable([[null, 2, null, 4], [1.5, null, 3, null], [0, 5, null, null]], 4326); + $compound = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\CompoundCurveImmutable([$line, $circular], 4326); $copy = $compound->withSpatialReference(SpatialReference::epsg(3857)); $legacyCopy = $compound->withSrid(2154); @@ -136,9 +136,9 @@ public function testFourDimensionalGeographyComponentsPreserveNullOrdinates(): v static::assertNotSame($line, $copy->getCurve(0)); static::assertNotSame($line->getPoint(0), $copy->getStartPoint()); static::assertNotSame($circular, $copy->getCurve(1)); - static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\CompoundCurve::class, $copy::class); - static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\LineString::class, $copy->getCurve(0)::class); - static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\CircularString::class, $copy->getCurve(1)::class); + static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\CompoundCurveImmutable::class, (new \ReflectionClass($copy))->getName()); + static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\LineStringImmutable::class, $copy->getCurve(0)::class); + static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\CircularStringImmutable::class, $copy->getCurve(1)::class); static::assertSame(4326, $compound->getSrid()); static::assertSame(4326, $line->getPoint(0)->getSrid()); static::assertSame(3857, $copy->getSrid()); @@ -150,9 +150,9 @@ public function testFourDimensionalGeographyComponentsPreserveNullOrdinates(): v /** Null ordinates survive construction, access and independent reference copies. */ public function testFourDimensionalGeometryComponentsPreserveNullOrdinates(): void { - $line = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\LineString([[0, null, 3.5, null], [null, 2, null, 4]], 4326); - $circular = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\CircularString([[null, 2, null, 4], [1.5, null, 3, null], [0, 5, null, null]], 4326); - $compound = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\CompoundCurve([$line, $circular], 4326); + $line = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\LineStringImmutable([[0, null, 3.5, null], [null, 2, null, 4]], 4326); + $circular = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\CircularStringImmutable([[null, 2, null, 4], [1.5, null, 3, null], [0, 5, null, null]], 4326); + $compound = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\CompoundCurveImmutable([$line, $circular], 4326); $copy = $compound->withSpatialReference(SpatialReference::epsg(3857)); $legacyCopy = $compound->withSrid(2154); @@ -168,9 +168,9 @@ public function testFourDimensionalGeometryComponentsPreserveNullOrdinates(): vo static::assertNotSame($line, $copy->getCurve(0)); static::assertNotSame($line->getPoint(0), $copy->getStartPoint()); static::assertNotSame($circular, $copy->getCurve(1)); - static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\CompoundCurve::class, $copy::class); - static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\LineString::class, $copy->getCurve(0)::class); - static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\CircularString::class, $copy->getCurve(1)::class); + static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\CompoundCurveImmutable::class, (new \ReflectionClass($copy))->getName()); + static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\LineStringImmutable::class, $copy->getCurve(0)::class); + static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\CircularStringImmutable::class, $copy->getCurve(1)::class); static::assertSame(4326, $compound->getSrid()); static::assertSame(4326, $line->getPoint(0)->getSrid()); static::assertSame(3857, $copy->getSrid()); @@ -182,9 +182,9 @@ public function testFourDimensionalGeometryComponentsPreserveNullOrdinates(): vo /** Null ordinates survive construction, access and independent reference copies. */ public function testMeasureGeographyComponentsPreserveNullOrdinates(): void { - $line = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\LineString([[0, null, null], [null, 2, 3.5]], 4326); - $circular = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\CircularString([[null, 2, 3.5], [1.5, null, 4], [0, 5, null]], 4326); - $compound = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\CompoundCurve([$line, $circular], 4326); + $line = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\LineStringImmutable([[0, null, null], [null, 2, 3.5]], 4326); + $circular = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\CircularStringImmutable([[null, 2, 3.5], [1.5, null, 4], [0, 5, null]], 4326); + $compound = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\CompoundCurveImmutable([$line, $circular], 4326); $copy = $compound->withSpatialReference(SpatialReference::epsg(3857)); $legacyCopy = $compound->withSrid(2154); @@ -200,9 +200,9 @@ public function testMeasureGeographyComponentsPreserveNullOrdinates(): void static::assertNotSame($line, $copy->getCurve(0)); static::assertNotSame($line->getPoint(0), $copy->getStartPoint()); static::assertNotSame($circular, $copy->getCurve(1)); - static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\CompoundCurve::class, $copy::class); - static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\LineString::class, $copy->getCurve(0)::class); - static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\CircularString::class, $copy->getCurve(1)::class); + static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\CompoundCurveImmutable::class, (new \ReflectionClass($copy))->getName()); + static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\LineStringImmutable::class, $copy->getCurve(0)::class); + static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\CircularStringImmutable::class, $copy->getCurve(1)::class); static::assertSame(4326, $compound->getSrid()); static::assertSame(4326, $line->getPoint(0)->getSrid()); static::assertSame(3857, $copy->getSrid()); @@ -214,9 +214,9 @@ public function testMeasureGeographyComponentsPreserveNullOrdinates(): void /** Null ordinates survive construction, access and independent reference copies. */ public function testMeasureGeometryComponentsPreserveNullOrdinates(): void { - $line = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\LineString([[0, null, null], [null, 2, 3.5]], 4326); - $circular = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\CircularString([[null, 2, 3.5], [1.5, null, 4], [0, 5, null]], 4326); - $compound = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\CompoundCurve([$line, $circular], 4326); + $line = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\LineStringImmutable([[0, null, null], [null, 2, 3.5]], 4326); + $circular = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\CircularStringImmutable([[null, 2, 3.5], [1.5, null, 4], [0, 5, null]], 4326); + $compound = new \LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\CompoundCurveImmutable([$line, $circular], 4326); $copy = $compound->withSpatialReference(SpatialReference::epsg(3857)); $legacyCopy = $compound->withSrid(2154); @@ -232,9 +232,9 @@ public function testMeasureGeometryComponentsPreserveNullOrdinates(): void static::assertNotSame($line, $copy->getCurve(0)); static::assertNotSame($line->getPoint(0), $copy->getStartPoint()); static::assertNotSame($circular, $copy->getCurve(1)); - static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\CompoundCurve::class, $copy::class); - static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\LineString::class, $copy->getCurve(0)::class); - static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\CircularString::class, $copy->getCurve(1)::class); + static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\CompoundCurveImmutable::class, (new \ReflectionClass($copy))->getName()); + static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\LineStringImmutable::class, $copy->getCurve(0)::class); + static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\CircularStringImmutable::class, $copy->getCurve(1)::class); static::assertSame(4326, $compound->getSrid()); static::assertSame(4326, $line->getPoint(0)->getSrid()); static::assertSame(3857, $copy->getSrid()); @@ -246,9 +246,9 @@ public function testMeasureGeometryComponentsPreserveNullOrdinates(): void /** Null ordinates survive construction, access and independent reference copies. */ public function testPlanarGeographyComponentsPreserveNullOrdinates(): void { - $line = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\LineString([[0, null], [null, 2]], 4326); - $circular = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\CircularString([[null, 2], [1.5, null], [0, null]], 4326); - $compound = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\CompoundCurve([$line, $circular], 4326); + $line = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\LineStringImmutable([[0, null], [null, 2]], 4326); + $circular = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\CircularStringImmutable([[null, 2], [1.5, null], [0, null]], 4326); + $compound = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\CompoundCurveImmutable([$line, $circular], 4326); $copy = $compound->withSpatialReference(SpatialReference::epsg(3857)); $legacyCopy = $compound->withSrid(2154); @@ -264,9 +264,9 @@ public function testPlanarGeographyComponentsPreserveNullOrdinates(): void static::assertNotSame($line, $copy->getCurve(0)); static::assertNotSame($line->getPoint(0), $copy->getStartPoint()); static::assertNotSame($circular, $copy->getCurve(1)); - static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension2\Geography\CompoundCurve::class, $copy::class); - static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension2\Geography\LineString::class, $copy->getCurve(0)::class); - static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension2\Geography\CircularString::class, $copy->getCurve(1)::class); + static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension2\Geography\CompoundCurveImmutable::class, (new \ReflectionClass($copy))->getName()); + static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension2\Geography\LineStringImmutable::class, $copy->getCurve(0)::class); + static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension2\Geography\CircularStringImmutable::class, $copy->getCurve(1)::class); static::assertSame(4326, $compound->getSrid()); static::assertSame(4326, $line->getPoint(0)->getSrid()); static::assertSame(3857, $copy->getSrid()); @@ -278,9 +278,9 @@ public function testPlanarGeographyComponentsPreserveNullOrdinates(): void /** Null ordinates survive construction, access and independent reference copies. */ public function testPlanarGeometryComponentsPreserveNullOrdinates(): void { - $line = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString([[0, null], [null, 2]], 4326); - $circular = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularString([[null, 2], [1.5, null], [0, null]], 4326); - $compound = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CompoundCurve([$line, $circular], 4326); + $line = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable([[0, null], [null, 2]], 4326); + $circular = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularStringImmutable([[null, 2], [1.5, null], [0, null]], 4326); + $compound = new \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CompoundCurveImmutable([$line, $circular], 4326); $copy = $compound->withSpatialReference(SpatialReference::epsg(3857)); $legacyCopy = $compound->withSrid(2154); @@ -296,9 +296,9 @@ public function testPlanarGeometryComponentsPreserveNullOrdinates(): void static::assertNotSame($line, $copy->getCurve(0)); static::assertNotSame($line->getPoint(0), $copy->getStartPoint()); static::assertNotSame($circular, $copy->getCurve(1)); - static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CompoundCurve::class, $copy::class); - static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString::class, $copy->getCurve(0)::class); - static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularString::class, $copy->getCurve(1)::class); + static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CompoundCurveImmutable::class, (new \ReflectionClass($copy))->getName()); + static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable::class, $copy->getCurve(0)::class); + static::assertSame(\LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularStringImmutable::class, $copy->getCurve(1)::class); static::assertSame(4326, $compound->getSrid()); static::assertSame(4326, $line->getPoint(0)->getSrid()); static::assertSame(3857, $copy->getSrid()); diff --git a/tests/Issue/PartiallyNullXYMPointTest.php b/tests/Issue/PartiallyNullXYMPointTest.php index b4e9a42..7ded374 100644 --- a/tests/Issue/PartiallyNullXYMPointTest.php +++ b/tests/Issue/PartiallyNullXYMPointTest.php @@ -19,10 +19,10 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Factory\FromIndexedArrayFactory; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\LineString; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPoint; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Point as GeographyPoint; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Point as GeometryPoint; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\LineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPointImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\PointImmutable as GeographyPoint; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\PointImmutable as GeometryPoint; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\TestCase; @@ -31,7 +31,7 @@ * * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractPoint + * @covers \LongitudeOne\SpatialTypes\Types\AbstractPointImmutable */ class PartiallyNullXYMPointTest extends TestCase { @@ -142,9 +142,9 @@ public function testGeographyAbscissaOrdinateNullMeasure(): void /** Shared aggregate constructors and replacements preserve null ordinates. */ public function testGeographyAggregatePathsPreserveNullOrdinates(): void { - $line = new LineString([[0, null, 3], [null, 2, null]], 4326); + $line = new LineStringImmutable([[0, null, 3], [null, 2, null]], 4326); $replacement = $line->withPoint(1, Coordinates::xym(null, null, 4)); - $multiPoint = new MultiPoint([[0, null, 3], [null, 2, null]], 4326); + $multiPoint = new MultiPointImmutable([[0, null, 3], [null, 2, null]], 4326); static::assertSame([[0, null, 3], [null, 2, null]], $line->toArray()); static::assertSame([[0, null, 3], [null, null, 4]], $replacement->toArray()); diff --git a/tests/Issue/PartiallyNullXYPointTest.php b/tests/Issue/PartiallyNullXYPointTest.php index 32a3883..c921612 100644 --- a/tests/Issue/PartiallyNullXYPointTest.php +++ b/tests/Issue/PartiallyNullXYPointTest.php @@ -19,8 +19,8 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Factory\FromIndexedArrayFactory; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Point as GeographyPoint; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point as GeometryPoint; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PointImmutable as GeographyPoint; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable as GeometryPoint; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\TestCase; @@ -29,7 +29,7 @@ * * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractPoint + * @covers \LongitudeOne\SpatialTypes\Types\AbstractPointImmutable */ class PartiallyNullXYPointTest extends TestCase { diff --git a/tests/Issue/PartiallyNullXYZMPointTest.php b/tests/Issue/PartiallyNullXYZMPointTest.php index 9caa198..4d28e99 100644 --- a/tests/Issue/PartiallyNullXYZMPointTest.php +++ b/tests/Issue/PartiallyNullXYZMPointTest.php @@ -19,9 +19,9 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Factory\FromIndexedArrayFactory; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Point as GeographyPoint; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Point as GeometryPoint; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Polygon; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PointImmutable as GeographyPoint; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\PointImmutable as GeometryPoint; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\PolygonImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\TestCase; @@ -30,7 +30,7 @@ * * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractPoint + * @covers \LongitudeOne\SpatialTypes\Types\AbstractPointImmutable */ class PartiallyNullXYZMPointTest extends TestCase { @@ -901,7 +901,7 @@ public function testGeometryNullAbscissaOrdinateNullElevationNullMeasure(): void /** Shared polygon hydration and replacement preserve partially supplied points. */ public function testGeometryPolygonPathsPreserveNullOrdinates(): void { - $polygon = new Polygon([[[0, null, 3, null], [null, 2, null, 4], [0, null, 3, null]]], 3857); + $polygon = new PolygonImmutable([[[0, null, 3, null], [null, 2, null, 4], [0, null, 3, null]]], 3857); $replacement = $polygon->withPoint(0, 1, Coordinates::xyzm(null, null, 5, null)); static::assertSame([[[0, null, 3, null], [null, 2, null, 4], [0, null, 3, null]]], $polygon->toArray()); diff --git a/tests/Issue/PartiallyNullXYZPointTest.php b/tests/Issue/PartiallyNullXYZPointTest.php index 70475bd..123904e 100644 --- a/tests/Issue/PartiallyNullXYZPointTest.php +++ b/tests/Issue/PartiallyNullXYZPointTest.php @@ -19,8 +19,8 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Factory\FromIndexedArrayFactory; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point as GeographyPoint; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point as GeometryPoint; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PointImmutable as GeographyPoint; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PointImmutable as GeometryPoint; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\TestCase; @@ -29,7 +29,7 @@ * * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractPoint + * @covers \LongitudeOne\SpatialTypes\Types\AbstractPointImmutable */ class PartiallyNullXYZPointTest extends TestCase { diff --git a/tests/Unit/Exception/DiagnosticMessagesTest.php b/tests/Unit/Exception/DiagnosticMessagesTest.php index f875142..5f9fe55 100644 --- a/tests/Unit/Exception/DiagnosticMessagesTest.php +++ b/tests/Unit/Exception/DiagnosticMessagesTest.php @@ -19,7 +19,7 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\SpatialTypes\Exception\BadMethodCallException; use LongitudeOne\SpatialTypes\Exception\SpatialTypeExceptionInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; @@ -40,7 +40,7 @@ class DiagnosticMessagesTest extends TestCase public function testCoordinate(string $value, string $expected): void { try { - new Point($value, 0); + new PointImmutable($value, 0); static::fail('An invalid coordinate must be rejected.'); } catch (SpatialTypeExceptionInterface $exception) { static::assertSame('Invalid coordinate value, got "'.$expected.'".', $exception->getMessage()); @@ -88,7 +88,7 @@ public static function valueProvider(): iterable public function testRange(string $value, string $expected, bool $geographic): void { try { - $pointClass = $geographic ? \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Point::class : Point::class; + $pointClass = $geographic ? \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PointImmutable::class : PointImmutable::class; new $pointClass($value, 0); static::fail('An out-of-range coordinate must be rejected.'); } catch (SpatialTypeExceptionInterface $exception) { diff --git a/tests/Unit/Factory/FactoryPipelineTest.php b/tests/Unit/Factory/FactoryPipelineTest.php index 1deb7e0..93459e6 100644 --- a/tests/Unit/Factory/FactoryPipelineTest.php +++ b/tests/Unit/Factory/FactoryPipelineTest.php @@ -34,8 +34,8 @@ use LongitudeOne\SpatialTypes\Factory\SpatialContext; use LongitudeOne\SpatialTypes\Factory\SpatialFactory; use LongitudeOne\SpatialTypes\Factory\SpatialFactoryRegistry; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; @@ -195,14 +195,14 @@ public static function provideInvalidFactoryOperations(): \Generator static function (SpatialFactory $factory): void { (new \ReflectionMethod($factory, 'createLineString'))->invoke($factory, [new \stdClass()], new SpatialContext()); }, - 'objects implementing PointInterface', + 'objects implementing ImmutablePointInterface', ]; yield 'polygon contains an unsupported typed value' => [ static function (SpatialFactory $factory): void { (new \ReflectionMethod($factory, 'createPolygon'))->invoke($factory, [new \stdClass()], new SpatialContext()); }, - 'objects implementing LineStringInterface', + 'objects implementing ImmutableLineStringInterface', ]; } @@ -250,9 +250,9 @@ public function testSpatialFactoryCreatesTypedComponents(): void { $factory = self::createFactory(); $context = new SpatialContext(2154, SpatialModelEnum::GEOMETRY, CoordinateDimensionEnum::XY); - $firstPoint = new Point(0, 0, 2154); - $secondPoint = new Point(1, 1, 2154); - $ring = new LineString([$firstPoint, $secondPoint, new Point(0, 1, 2154), $firstPoint], 2154); + $firstPoint = new PointImmutable(0, 0, 2154); + $secondPoint = new PointImmutable(1, 1, 2154); + $ring = new LineStringImmutable([$firstPoint, $secondPoint, new PointImmutable(0, 1, 2154), $firstPoint], 2154); $point = $factory->createPoint(new Coordinates(2, 3), $context); $lineString = $factory->createLineString([$firstPoint, $secondPoint], $context); diff --git a/tests/Unit/Factory/FromIndexedArrayFactoryTest.php b/tests/Unit/Factory/FromIndexedArrayFactoryTest.php index 5541c1f..f3e7862 100644 --- a/tests/Unit/Factory/FromIndexedArrayFactoryTest.php +++ b/tests/Unit/Factory/FromIndexedArrayFactoryTest.php @@ -22,8 +22,8 @@ use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\MissingValueException; use LongitudeOne\SpatialTypes\Factory\FromIndexedArrayFactory; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString as GeometricLineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point as GeometricPoint; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable as GeometricLineString; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable as GeometricPoint; use PHPUnit\Framework\TestCase; /** @@ -66,7 +66,7 @@ public function testCreateLineStringFromPoints(): void public function testCreateLineStringRejectsInvalidElement(): void { self::expectException(InvalidValueException::class); - self::expectExceptionMessageIsOrContains('The array must contain only objects implementing PointInterface or array of coordinates.'); + self::expectExceptionMessageIsOrContains('The array must contain only objects implementing ImmutablePointInterface or array of coordinates.'); // @phpstan-ignore-next-line FromIndexedArrayFactory::createLineString(['not a point']); @@ -171,7 +171,7 @@ public function testCreatePolygonFromLineStrings(): void public function testCreatePolygonRejectsInvalidElement(): void { self::expectException(InvalidValueException::class); - self::expectExceptionMessageIsOrContains('The array must contain only objects implementing LineStringInterface or array of PointInterface or "array of array of coordinates".'); + self::expectExceptionMessageIsOrContains('The array must contain only objects implementing ImmutableLineStringInterface or array of ImmutablePointInterface or "array of array of coordinates".'); // @phpstan-ignore-next-line FromIndexedArrayFactory::createPolygon(['not a line string']); diff --git a/tests/Unit/Reference/SpatialReferenceTest.php b/tests/Unit/Reference/SpatialReferenceTest.php index 1cabcc5..218a101 100644 --- a/tests/Unit/Reference/SpatialReferenceTest.php +++ b/tests/Unit/Reference/SpatialReferenceTest.php @@ -17,13 +17,13 @@ namespace LongitudeOne\SpatialTypes\Tests\Unit\Reference; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; use PHPUnit\Framework\TestCase; /** * @covers \LongitudeOne\SpatialTypes\Reference\SpatialReference - * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialType + * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialTypeImmutable * * @internal */ @@ -33,9 +33,9 @@ class SpatialReferenceTest extends TestCase public function testEpsgReferenceIsPreservedByAnAggregateAndItsChildren(): void { $reference = SpatialReference::epsg(4326); - $lineString = new LineString([ - new Point(1, 2, $reference), - new Point(3, 4, $reference), + $lineString = new LineStringImmutable([ + new PointImmutable(1, 2, $reference), + new PointImmutable(3, 4, $reference), ], $reference); static::assertSame($reference, $lineString->getSpatialReference()); @@ -47,9 +47,9 @@ public function testWithSpatialReferenceDeeplyRelabelsAnAggregate(): void { $source = SpatialReference::epsg(4326); $target = SpatialReference::epsg(2154); - $lineString = new LineString([ - new Point(1, 2, $source), - new Point(3, 4, $source), + $lineString = new LineStringImmutable([ + new PointImmutable(1, 2, $source), + new PointImmutable(3, 4, $source), ], $source); $copy = $lineString->withSpatialReference($target); diff --git a/tests/Unit/Types/AggregateBoundaryAndValidationTest.php b/tests/Unit/Types/AggregateBoundaryAndValidationTest.php index 812188e..128d0db 100644 --- a/tests/Unit/Types/AggregateBoundaryAndValidationTest.php +++ b/tests/Unit/Types/AggregateBoundaryAndValidationTest.php @@ -18,15 +18,15 @@ use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\OutOfBoundsException; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollection; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiLineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPoint; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPolygon; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Polygon; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPoint as ThreeDimensionalMultiPoint; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point as ThreeDimensionalPoint; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollectionImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiLineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPointImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPolygonImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PolygonImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPointImmutable as ThreeDimensionalMultiPoint; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PointImmutable as ThreeDimensionalPoint; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; @@ -45,24 +45,24 @@ class AggregateBoundaryAndValidationTest extends TestCase */ public function testAggregateAccessorsNormalizePositiveAndNegativeIndexes(): void { - $first = new Point(1, 2); - $second = new Point(3, 4); - $third = new Point(5, 6); - $firstLine = new LineString([$first, $second]); - $secondLine = new LineString([$second, $third]); - $firstPolygon = new Polygon([new LineString([$first, $second, $third, $first])]); - $secondPolygon = new Polygon([new LineString([$second, $third, $first, $second])]); - - $multiLineString = new MultiLineString([$firstLine, $secondLine]); + $first = new PointImmutable(1, 2); + $second = new PointImmutable(3, 4); + $third = new PointImmutable(5, 6); + $firstLine = new LineStringImmutable([$first, $second]); + $secondLine = new LineStringImmutable([$second, $third]); + $firstPolygon = new PolygonImmutable([new LineStringImmutable([$first, $second, $third, $first])]); + $secondPolygon = new PolygonImmutable([new LineStringImmutable([$second, $third, $first, $second])]); + + $multiLineString = new MultiLineStringImmutable([$firstLine, $secondLine]); static::assertSame($firstLine, $multiLineString->getLineString(2)); static::assertSame($secondLine, $multiLineString->getLineString(-1)); - $polygon = new Polygon([$firstPolygon->getRing(0), $secondPolygon->getRing(0)]); + $polygon = new PolygonImmutable([$firstPolygon->getRing(0), $secondPolygon->getRing(0)]); static::assertSame($polygon->getRings(), $polygon->getElements()); static::assertSame($firstPolygon->getRing(0), $polygon->getRing(2)); static::assertSame($secondPolygon->getRing(0), $polygon->getRing(-1)); - $multiPolygon = new MultiPolygon([$firstPolygon, $secondPolygon]); + $multiPolygon = new MultiPolygonImmutable([$firstPolygon, $secondPolygon]); static::assertFalse($multiPolygon->isEmpty()); static::assertSame($firstPolygon, $multiPolygon->getPolygon(2)); static::assertSame($secondPolygon, $multiPolygon->getPolygon(-1)); @@ -74,9 +74,9 @@ public function testAggregateAccessorsNormalizePositiveAndNegativeIndexes(): voi public function testAggregatesRejectInvalidMemberValues(): void { self::expectException(InvalidValueException::class); - self::expectExceptionMessageIsOrContains('objects implementing SpatialInterface'); + self::expectExceptionMessageIsOrContains('objects implementing ImmutableSpatialInterface'); - (new \ReflectionClass(GeometryCollection::class))->newInstance(0, [new \stdClass()]); + (new \ReflectionClass(GeometryCollectionImmutable::class))->newInstance(0, [new \stdClass()]); } /** @@ -96,31 +96,31 @@ public function testEmptyAggregatesRejectReadAndReplacementOperations(\Closure $ */ public static function provideOperationsOnEmptyAggregates(): \Generator { - yield 'line string point replacement' => [static fn () => (new LineString([]))->withPoint(0, Coordinates::xy(1, 2))]; + yield 'line string point replacement' => [static fn () => (new LineStringImmutable([]))->withPoint(0, Coordinates::xy(1, 2))]; - yield 'multi-point point replacement' => [static fn () => (new MultiPoint([]))->withPoint(0, Coordinates::xy(1, 2))]; + yield 'multi-point point replacement' => [static fn () => (new MultiPointImmutable([]))->withPoint(0, Coordinates::xy(1, 2))]; - yield 'multi-line string accessor' => [static fn () => (new MultiLineString([]))->getLineString(0)]; + yield 'multi-line string accessor' => [static fn () => (new MultiLineStringImmutable([]))->getLineString(0)]; - yield 'multi-line string replacement' => [static fn () => (new MultiLineString([]))->withLineString(0, [[1, 2], [3, 4]])]; + yield 'multi-line string replacement' => [static fn () => (new MultiLineStringImmutable([]))->withLineString(0, [[1, 2], [3, 4]])]; - yield 'multi-line string point replacement' => [static fn () => (new MultiLineString([]))->withPoint(0, 0, Coordinates::xy(1, 2))]; + yield 'multi-line string point replacement' => [static fn () => (new MultiLineStringImmutable([]))->withPoint(0, 0, Coordinates::xy(1, 2))]; - yield 'polygon accessor' => [static fn () => (new Polygon([]))->getRing(0)]; + yield 'polygon accessor' => [static fn () => (new PolygonImmutable([]))->getRing(0)]; - yield 'polygon ring replacement' => [static fn () => (new Polygon([]))->withRing(0, [[0, 0], [1, 1], [0, 0]])]; + yield 'polygon ring replacement' => [static fn () => (new PolygonImmutable([]))->withRing(0, [[0, 0], [1, 1], [0, 0]])]; - yield 'polygon point replacement' => [static fn () => (new Polygon([]))->withPoint(0, 0, Coordinates::xy(1, 2))]; + yield 'polygon point replacement' => [static fn () => (new PolygonImmutable([]))->withPoint(0, 0, Coordinates::xy(1, 2))]; - yield 'multi-polygon accessor' => [static fn () => (new MultiPolygon([]))->getPolygon(0)]; + yield 'multi-polygon accessor' => [static fn () => (new MultiPolygonImmutable([]))->getPolygon(0)]; - yield 'multi-polygon replacement' => [static fn () => (new MultiPolygon([]))->withPolygon(0, [[[0, 0], [1, 1], [0, 0]]])]; + yield 'multi-polygon replacement' => [static fn () => (new MultiPolygonImmutable([]))->withPolygon(0, [[[0, 0], [1, 1], [0, 0]]])]; - yield 'multi-polygon ring replacement' => [static fn () => (new MultiPolygon([]))->withRing(0, 0, [[0, 0], [1, 1], [0, 0]])]; + yield 'multi-polygon ring replacement' => [static fn () => (new MultiPolygonImmutable([]))->withRing(0, 0, [[0, 0], [1, 1], [0, 0]])]; - yield 'multi-polygon point replacement' => [static fn () => (new MultiPolygon([]))->withPoint(0, 0, 0, Coordinates::xy(1, 2))]; + yield 'multi-polygon point replacement' => [static fn () => (new MultiPolygonImmutable([]))->withPoint(0, 0, 0, Coordinates::xy(1, 2))]; - yield 'collection element replacement' => [static fn () => (new GeometryCollection())->withElement(0, new Point(1, 2))]; + yield 'collection element replacement' => [static fn () => (new GeometryCollectionImmutable())->withElement(0, new PointImmutable(1, 2))]; } /** @@ -129,9 +129,9 @@ public static function provideOperationsOnEmptyAggregates(): \Generator public function testPolygonRejectsAnInvalidRingValue(): void { self::expectException(InvalidValueException::class); - self::expectExceptionMessageIsOrContains('objects implementing LineStringInterface'); + self::expectExceptionMessageIsOrContains('objects implementing ImmutableLineStringInterface'); - (new \ReflectionClass(Polygon::class))->newInstance([new \stdClass()]); + (new \ReflectionClass(PolygonImmutable::class))->newInstance([new \stdClass()]); } /** @@ -139,7 +139,7 @@ public function testPolygonRejectsAnInvalidRingValue(): void */ public function testPolygonWithPointLeavesClosureEndpointsUntouchedForAnInteriorPoint(): void { - $polygon = new Polygon([[[0, 0], [10, 0], [0, 10], [0, 0]]]); + $polygon = new PolygonImmutable([[[0, 0], [10, 0], [0, 10], [0, 0]]]); $replacement = $polygon->withPoint(0, 1, Coordinates::xy(8, 9)); static::assertSame([[[0, 0], [10, 0], [0, 10], [0, 0]]], $polygon->toArray()); diff --git a/tests/Unit/Types/AggregateImmutabilityTest.php b/tests/Unit/Types/AggregateImmutabilityTest.php index 93aaa41..cc197e3 100644 --- a/tests/Unit/Types/AggregateImmutabilityTest.php +++ b/tests/Unit/Types/AggregateImmutabilityTest.php @@ -17,25 +17,25 @@ namespace LongitudeOne\SpatialTypes\Tests\Unit\Types; use LongitudeOne\SpatialTypes\Interfaces\SpatialInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollection; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiLineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPoint; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPolygon; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Polygon; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollectionImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiLineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPointImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPolygonImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PolygonImmutable; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractCollection - * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiLineString - * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiPolygon - * @covers \LongitudeOne\SpatialTypes\Types\AbstractPolygon - * @covers \LongitudeOne\SpatialTypes\Types\Collection\AbstractLineStringCollection - * @covers \LongitudeOne\SpatialTypes\Types\Collection\AbstractPointCollection + * @covers \LongitudeOne\SpatialTypes\Types\AbstractCollectionImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiLineStringImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiPolygonImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractPolygonImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Collection\AbstractLineStringCollectionImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Collection\AbstractPointCollectionImmutable */ class AggregateImmutabilityTest extends TestCase { @@ -68,21 +68,21 @@ public function testAggregateHasNoPublicMembershipMutator(SpatialInterface $aggr */ public static function provideAggregates(): \Generator { - $lineString = new LineString([[0, 0], [1, 1]]); - $ring = new LineString([[0, 0], [1, 0], [0, 1], [0, 0]]); - $polygon = new Polygon([$ring]); + $lineString = new LineStringImmutable([[0, 0], [1, 1]]); + $ring = new LineStringImmutable([[0, 0], [1, 0], [0, 1], [0, 0]]); + $polygon = new PolygonImmutable([$ring]); yield 'line string' => [$lineString]; - yield 'multi-point' => [new MultiPoint([[0, 0], [1, 1]])]; + yield 'multi-point' => [new MultiPointImmutable([[0, 0], [1, 1]])]; yield 'polygon' => [$polygon]; - yield 'multi-line string' => [new MultiLineString([$lineString])]; + yield 'multi-line string' => [new MultiLineStringImmutable([$lineString])]; - yield 'multi-polygon' => [new MultiPolygon([$polygon])]; + yield 'multi-polygon' => [new MultiPolygonImmutable([$polygon])]; - yield 'collection' => [new GeometryCollection(0, [$lineString, $polygon])]; + yield 'collection' => [new GeometryCollectionImmutable(0, [$lineString, $polygon])]; } /** @@ -90,8 +90,8 @@ public static function provideAggregates(): \Generator */ public function testCollectionReceivesItsElementsAtConstruction(): void { - $point = new Point(1, 2, 2154); - $collection = new GeometryCollection(2154, [$point]); + $point = new PointImmutable(1, 2, 2154); + $collection = new GeometryCollectionImmutable(2154, [$point]); static::assertSame([$point], $collection->getElements()); static::assertSame([[1, 2]], $collection->toArray()); diff --git a/tests/Unit/Types/CircularStringImmutabilityTest.php b/tests/Unit/Types/CircularStringImmutabilityTest.php index 2685c5e..4d47bdc 100644 --- a/tests/Unit/Types/CircularStringImmutabilityTest.php +++ b/tests/Unit/Types/CircularStringImmutabilityTest.php @@ -19,8 +19,7 @@ use LongitudeOne\SpatialTypes\Exception\InvalidDimensionException; use LongitudeOne\SpatialTypes\Exception\OutOfBoundsException; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularStringImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\TestCase; @@ -37,13 +36,13 @@ class CircularStringImmutabilityTest extends TestCase public function testRejectEmptyPointReplacement(): void { $this->expectException(OutOfBoundsException::class); - (new CircularString([]))->withPoint(0, Coordinates::xy(1, 2)); + (new CircularStringImmutable([]))->withPoint(0, Coordinates::xy(1, 2)); } /** Replacement coordinates cannot change the curve layout. */ public function testRejectWrongReplacementDimension(): void { - $curve = new CircularString([[0, 0], [1, 1], [2, 0]]); + $curve = new CircularStringImmutable([[0, 0], [1, 1], [2, 0]]); $this->expectException(InvalidDimensionException::class); try { @@ -56,7 +55,7 @@ public function testRejectWrongReplacementDimension(): void /** Whole replacement supports empty and non-empty values. */ public function testReplaceCoordinates(): void { - $curve = new CircularString([[0, 0], [1, 1], [2, 0]], SpatialReference::epsg(4326)); + $curve = new CircularStringImmutable([[0, 0], [1, 1], [2, 0]], SpatialReference::epsg(4326)); $replacement = $curve->withArrayOfCoordinates([[3, 0], [4, 1], [5, 0]]); $empty = $curve->withArrayOfCoordinates([]); @@ -71,7 +70,7 @@ public function testReplaceCoordinates(): void /** Reference changes retain empty values. */ public function testReplaceEmptyReference(): void { - $curve = new CircularString([], 4326); + $curve = new CircularStringImmutable([], 4326); $replacement = $curve->withSrid(2154); static::assertSame([], $replacement->getPoints()); @@ -82,7 +81,7 @@ public function testReplaceEmptyReference(): void /** Indexed replacement copies points and retains the full reference identity. */ public function testReplacePoint(): void { - $curve = new CircularString([[0, 0], [1, 1], [2, 0]], SpatialReference::epsg(4326)); + $curve = new CircularStringImmutable([[0, 0], [1, 1], [2, 0]], SpatialReference::epsg(4326)); $replacement = $curve->withPoint(-2, Coordinates::xy(1, 2)); static::assertNotSame($curve, $replacement); @@ -97,7 +96,7 @@ public function testReplacePoint(): void /** A reference edit recursively changes declarations without transforming coordinates. */ public function testReplaceSpatialReference(): void { - $curve = new CircularString([[0, 0], [1, 1], [2, 0]], SpatialReference::epsg(4326)); + $curve = new CircularStringImmutable([[0, 0], [1, 1], [2, 0]], SpatialReference::epsg(4326)); $reference = SpatialReference::epsg(2154); $replacement = $curve->withSpatialReference($reference); @@ -114,7 +113,7 @@ public function testReplaceSpatialReference(): void /** The legacy integer adapter also copies every defining point. */ public function testReplaceSrid(): void { - $curve = new CircularString([[0, 0], [1, 1], [2, 0]], 4326); + $curve = new CircularStringImmutable([[0, 0], [1, 1], [2, 0]], 4326); $replacement = $curve->withSrid(2154); static::assertSame(2154, $replacement->getSrid()); diff --git a/tests/Unit/Types/CircularStringValidationTest.php b/tests/Unit/Types/CircularStringValidationTest.php index bb4f8e8..3a9917e 100644 --- a/tests/Unit/Types/CircularStringValidationTest.php +++ b/tests/Unit/Types/CircularStringValidationTest.php @@ -19,9 +19,9 @@ use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\OutOfBoundsException; use LongitudeOne\SpatialTypes\Interfaces\CurveInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; use PHPUnit\Framework\TestCase; /** @@ -36,7 +36,7 @@ class CircularStringValidationTest extends TestCase /** Collinear defining points remain a valid degenerate arc. */ public function testCollinearArc(): void { - $curve = new CircularString([[0, 0], [1, 0], [2, 0]]); + $curve = new CircularStringImmutable([[0, 0], [1, 0], [2, 0]]); static::assertSame([[0, 0], [1, 0], [2, 0]], $curve->toArray()); } @@ -44,7 +44,7 @@ public function testCollinearArc(): void /** A repeated endpoint defines a complete circle. */ public function testCompleteCircle(): void { - $curve = new CircularString([new Point(1, 0), new Point(-1, 0), new Point(1, 0)]); + $curve = new CircularStringImmutable([new PointImmutable(1, 0), new PointImmutable(-1, 0), new PointImmutable(1, 0)]); static::assertSame([[1, 0], [-1, 0], [1, 0]], $curve->toArray()); static::assertTrue($curve->getPoint(0)->equalsTo($curve->getPoint(-1))); @@ -54,19 +54,19 @@ public function testCompleteCircle(): void public function testEmptyPointAccess(): void { $this->expectException(OutOfBoundsException::class); - (new CircularString([]))->getPoint(0); + (new CircularStringImmutable([]))->getPoint(0); } /** Line strings share the approved curve category. */ public function testLineStringIsCurve(): void { - static::assertContains(CurveInterface::class, class_implements(new LineString([[0, 0], [1, 1]]))); + static::assertContains(CurveInterface::class, class_implements(new LineStringImmutable([[0, 0], [1, 1]]))); } /** Two arcs share their connecting endpoint without duplicating it. */ public function testMultipleArcs(): void { - $curve = new CircularString([[0, 0], [1, 1], [2, 0], [3, -1], [4, 0]]); + $curve = new CircularStringImmutable([[0, 0], [1, 1], [2, 0], [3, -1], [4, 0]]); static::assertSame([[0, 0], [1, 1], [2, 0], [3, -1], [4, 0]], $curve->toArray()); static::assertCount(5, $curve->getPoints()); @@ -76,6 +76,6 @@ public function testMultipleArcs(): void public function testRejectInvalidMember(): void { $this->expectException(InvalidValueException::class); - (new \ReflectionClass(CircularString::class))->newInstance([false, [1, 1], [2, 0]]); + (new \ReflectionClass(CircularStringImmutable::class))->newInstance([false, [1, 1], [2, 0]]); } } diff --git a/tests/Unit/Types/CollectionWithElementTest.php b/tests/Unit/Types/CollectionWithElementTest.php index 6fa7496..af072bb 100644 --- a/tests/Unit/Types/CollectionWithElementTest.php +++ b/tests/Unit/Types/CollectionWithElementTest.php @@ -16,14 +16,14 @@ namespace LongitudeOne\SpatialTypes\Tests\Unit\Types; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollection; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollectionImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; use PHPUnit\Framework\TestCase; /** * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractCollection + * @covers \LongitudeOne\SpatialTypes\Types\AbstractCollectionImmutable */ class CollectionWithElementTest extends TestCase { @@ -32,14 +32,14 @@ class CollectionWithElementTest extends TestCase */ public function testWithElementReturnsAnIndependentCopy(): void { - $firstPoint = new Point(1, 2, 2154); - $secondPoint = new Point(3, 4, 2154); - $collection = new GeometryCollection(2154, [$firstPoint, $secondPoint]); + $firstPoint = new PointImmutable(1, 2, 2154); + $secondPoint = new PointImmutable(3, 4, 2154); + $collection = new GeometryCollectionImmutable(2154, [$firstPoint, $secondPoint]); - $replacement = $collection->withElement(-1, new Point(5, 6, 2154)); + $replacement = $collection->withElement(-1, new PointImmutable(5, 6, 2154)); static::assertNotSame($collection, $replacement); - static::assertSame($collection::class, $replacement::class); + static::assertSame($collection::class, (new \ReflectionClass($replacement))->getName()); static::assertSame(2154, $replacement->getSrid()); static::assertSame([[1, 2], [3, 4]], $collection->toArray()); static::assertSame([[1, 2], [5, 6]], $replacement->toArray()); diff --git a/tests/Unit/Types/CompoundCurveValidationTest.php b/tests/Unit/Types/CompoundCurveValidationTest.php index 8a8ef9a..5228998 100644 --- a/tests/Unit/Types/CompoundCurveValidationTest.php +++ b/tests/Unit/Types/CompoundCurveValidationTest.php @@ -21,12 +21,12 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\OutOfBoundsException; -use LongitudeOne\SpatialTypes\Interfaces\CurveInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableCurveInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CompoundCurve; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CompoundCurveImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; use PHPUnit\Framework\TestCase; /** @@ -41,31 +41,31 @@ class CompoundCurveValidationTest extends TestCase /** Multiple arcs preserve their separate circular-string components. */ public function testCircularComponents(): void { - $compound = new CompoundCurve([ - new CircularString([[0, 0], [1, 1], [2, 0]]), - new CircularString([[2, 0], [3, -1], [4, 0]]), + $compound = new CompoundCurveImmutable([ + new CircularStringImmutable([[0, 0], [1, 1], [2, 0]]), + new CircularStringImmutable([[2, 0], [3, -1], [4, 0]]), ]); static::assertFalse($compound->isClosed()); - static::assertInstanceOf(CircularString::class, $compound->getCurve(0)); - static::assertInstanceOf(CircularString::class, $compound->getCurve(1)); + static::assertInstanceOf(CircularStringImmutable::class, $compound->getCurve(0)); + static::assertInstanceOf(CircularStringImmutable::class, $compound->getCurve(1)); static::assertSame([[[0, 0], [1, 1], [2, 0]], [[2, 0], [3, -1], [4, 0]]], $compound->toArray()); } /** A closed line exposes the same endpoints as its point accessors. */ public function testClosedLineEndpoints(): void { - $line = new LineString([[0, 0], [1, 1], [0, 0]]); + $line = new LineStringImmutable([[0, 0], [1, 1], [0, 0]]); static::assertTrue($line->isClosed()); static::assertSame($line->getPoint(0), $line->getStartPoint()); static::assertSame($line->getPoint(-1), $line->getEndPoint()); } - /** Components need only the common curve contract, not concrete interfaces. */ + /** Components need only the immutable curve contract, not concrete interfaces. */ public function testCommonCurveImplementation(): void { - $component = static::createStub(CurveInterface::class); + $component = static::createStub(ImmutableCurveInterface::class); $component->method('getType')->willReturn(GeometryTypeEnum::LINESTRING); $component->method('getDimension')->willReturn(CoordinateDimensionEnum::XY); $component->method('hasZ')->willReturn(false); @@ -73,10 +73,10 @@ public function testCommonCurveImplementation(): void $component->method('getFamily')->willReturn(SpatialModelEnum::GEOMETRY); $component->method('getSpatialReference')->willReturn(SpatialReference::fromSrid(0)); $component->method('isEmpty')->willReturn(false); - $component->method('getStartPoint')->willReturn(new Point(0, 0)); - $component->method('getEndPoint')->willReturn(new Point(1, 1)); + $component->method('getStartPoint')->willReturn(new PointImmutable(0, 0)); + $component->method('getEndPoint')->willReturn(new PointImmutable(1, 1)); $component->method('toArray')->willReturn([[0, 0], [1, 1]]); - $compound = new CompoundCurve([$component]); + $compound = new CompoundCurveImmutable([$component]); static::assertSame($component, $compound->getCurve(0)); static::assertSame([[[0, 0], [1, 1]]], $compound->toArray()); @@ -86,23 +86,23 @@ public function testCommonCurveImplementation(): void /** Booleans are not normalized into numeric component ordinates. */ public function testComponentRejectsBooleanOrdinate(): void { - $component = static::createStub(CurveInterface::class); + $component = static::createStub(ImmutableCurveInterface::class); $component->method('toArray')->willReturn([[0, false]]); $this->expectException(InvalidValueException::class); $this->expectExceptionMessage('A compound curve component must expose numeric or null ordinates.'); - new CompoundCurve([$component]); + new CompoundCurveImmutable([$component]); } /** Strings remain invalid component ordinates when null is accepted. */ public function testComponentRejectsNumericStringOrdinate(): void { - $component = static::createStub(CurveInterface::class); + $component = static::createStub(ImmutableCurveInterface::class); $component->method('toArray')->willReturn([[0, '2']]); $this->expectException(InvalidValueException::class); $this->expectExceptionMessage('A compound curve component must expose numeric or null ordinates.'); - new CompoundCurve([$component]); + new CompoundCurveImmutable([$component]); } /** Indexed access follows the existing empty-aggregate exception contract. */ @@ -110,13 +110,13 @@ public function testEmptyIndexedAccess(): void { $this->expectException(OutOfBoundsException::class); - (new CompoundCurve())->getCurve(0); + (new CompoundCurveImmutable())->getCurve(0); } /** Nested component coordinates cannot masquerade as point ordinates. */ public function testInvalidComponentOrdinate(): void { - $component = static::createStub(CurveInterface::class); + $component = static::createStub(ImmutableCurveInterface::class); $component->method('getType')->willReturn(GeometryTypeEnum::LINESTRING); $component->method('getDimension')->willReturn(CoordinateDimensionEnum::XY); $component->method('hasZ')->willReturn(false); @@ -124,18 +124,18 @@ public function testInvalidComponentOrdinate(): void $component->method('getFamily')->willReturn(SpatialModelEnum::GEOMETRY); $component->method('getSpatialReference')->willReturn(SpatialReference::fromSrid(0)); $component->method('isEmpty')->willReturn(false); - $component->method('getStartPoint')->willReturn(new Point(0, 0)); - $component->method('getEndPoint')->willReturn(new Point(1, 1)); + $component->method('getStartPoint')->willReturn(new PointImmutable(0, 0)); + $component->method('getEndPoint')->willReturn(new PointImmutable(1, 1)); $component->method('toArray')->willReturn([[[0, 0]], [[1, 1]]]); $this->expectException(InvalidValueException::class); - new CompoundCurve([$component]); + new CompoundCurveImmutable([$component]); } /** A component violating its tuple representation is rejected on construction. */ public function testInvalidComponentTuple(): void { - $component = static::createStub(CurveInterface::class); + $component = static::createStub(ImmutableCurveInterface::class); $component->method('getType')->willReturn(GeometryTypeEnum::LINESTRING); $component->method('getDimension')->willReturn(CoordinateDimensionEnum::XY); $component->method('hasZ')->willReturn(false); @@ -143,18 +143,18 @@ public function testInvalidComponentTuple(): void $component->method('getFamily')->willReturn(SpatialModelEnum::GEOMETRY); $component->method('getSpatialReference')->willReturn(SpatialReference::fromSrid(0)); $component->method('isEmpty')->willReturn(false); - $component->method('getStartPoint')->willReturn(new Point(0, 0)); - $component->method('getEndPoint')->willReturn(new Point(1, 1)); + $component->method('getStartPoint')->willReturn(new PointImmutable(0, 0)); + $component->method('getEndPoint')->willReturn(new PointImmutable(1, 1)); $component->method('toArray')->willReturn([0, 1]); $this->expectException(InvalidValueException::class); - new CompoundCurve([$component]); + new CompoundCurveImmutable([$component]); } /** Legacy reference changes copy both component endpoints. */ public function testLegacyReferenceReplacement(): void { - $compound = new CompoundCurve([new LineString([[0, 0], [1, 1]])]); + $compound = new CompoundCurveImmutable([new LineStringImmutable([[0, 0], [1, 1]])]); $copy = $compound->withSrid(4326); static::assertSame(0, $compound->getSrid()); @@ -172,9 +172,9 @@ public function testLegacyReferenceReplacement(): void /** An ordered sequence of line strings is an open compound curve. */ public function testLinearComponents(): void { - $compound = new CompoundCurve([ - new LineString([[0, 0], [1, 1]]), - new LineString([[1, 1], [2, 0]]), + $compound = new CompoundCurveImmutable([ + new LineStringImmutable([[0, 0], [1, 1]]), + new LineStringImmutable([[1, 1], [2, 0]]), ]); static::assertFalse($compound->isClosed()); @@ -188,7 +188,7 @@ public function testNonCurve(): void { $this->expectException(InvalidValueException::class); - (new \ReflectionClass(CompoundCurve::class))->newInstance([new Point(0, 0)]); + (new \ReflectionClass(CompoundCurveImmutable::class))->newInstance([new PointImmutable(0, 0)]); } /** Coordinate tuples do not implicitly select a component interpolation. */ @@ -196,16 +196,16 @@ public function testRawCoordinates(): void { $this->expectException(InvalidValueException::class); - (new \ReflectionClass(CompoundCurve::class))->newInstance([[[0, 0], [1, 1]]]); + (new \ReflectionClass(CompoundCurveImmutable::class))->newInstance([[[0, 0], [1, 1]]]); } /** Returned membership arrays cannot mutate the compound curve. */ public function testReturnedArrayIsIndependent(): void { - $line = new LineString([[0, 0], [1, 1]]); - $compound = new CompoundCurve([$line]); + $line = new LineStringImmutable([[0, 0], [1, 1]]); + $compound = new CompoundCurveImmutable([$line]); $curves = $compound->getCurves(); - $curves[] = new LineString([[1, 1], [2, 2]]); + $curves[] = new LineStringImmutable([[1, 1], [2, 2]]); static::assertCount(2, $curves); static::assertSame([$line], $compound->getCurves()); @@ -214,8 +214,8 @@ public function testReturnedArrayIsIndependent(): void /** A complete circle forms a closed single-component compound. */ public function testSingleClosedComponent(): void { - $circle = new CircularString([[1, 0], [-1, 0], [1, 0]]); - $compound = new CompoundCurve([$circle]); + $circle = new CircularStringImmutable([[1, 0], [-1, 0], [1, 0]]); + $compound = new CompoundCurveImmutable([$circle]); static::assertTrue($circle->isClosed()); static::assertTrue($compound->isClosed()); diff --git a/tests/Unit/Types/ConcreteTypeContractTest.php b/tests/Unit/Types/ConcreteTypeContractTest.php index 5441911..0ac7de1 100644 --- a/tests/Unit/Types/ConcreteTypeContractTest.php +++ b/tests/Unit/Types/ConcreteTypeContractTest.php @@ -102,14 +102,14 @@ private static function asSpatial(object $spatial): SpatialInterface private static function createSpatialTypes(string $dimension, SpatialModelEnum $family, array $coordinates, array $otherCoordinates): array { $familyNamespace = SpatialModelEnum::GEOMETRY === $family ? 'Geometry' : 'Geography'; - $collectionClass = sprintf('LongitudeOne\SpatialTypes\Types\%s\%s\%sCollection', $dimension, $familyNamespace, $familyNamespace); + $collectionClass = sprintf('LongitudeOne\SpatialTypes\Types\%s\%s\%sCollectionImmutable', $dimension, $familyNamespace, $familyNamespace); $namespace = sprintf('LongitudeOne\SpatialTypes\Types\%s\%s\\', $dimension, $familyNamespace); - $pointClass = $namespace.'Point'; - $lineStringClass = $namespace.'LineString'; - $multiPointClass = $namespace.'MultiPoint'; - $multiLineStringClass = $namespace.'MultiLineString'; - $polygonClass = $namespace.'Polygon'; - $multiPolygonClass = $namespace.'MultiPolygon'; + $pointClass = $namespace.'PointImmutable'; + $lineStringClass = $namespace.'LineStringImmutable'; + $multiPointClass = $namespace.'MultiPointImmutable'; + $multiLineStringClass = $namespace.'MultiLineStringImmutable'; + $polygonClass = $namespace.'PolygonImmutable'; + $multiPolygonClass = $namespace.'MultiPolygonImmutable'; $pointArguments = [...$coordinates, 4326]; $otherPointArguments = [...$otherCoordinates, 4326]; diff --git a/tests/Unit/Types/Dimension2/Geography/CircularStringTest.php b/tests/Unit/Types/Dimension2/Geography/CircularStringTest.php index cafdd8c..8734e56 100644 --- a/tests/Unit/Types/Dimension2/Geography/CircularStringTest.php +++ b/tests/Unit/Types/Dimension2/Geography/CircularStringTest.php @@ -21,8 +21,8 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Interfaces\CircularStringInterface; use LongitudeOne\SpatialTypes\Interfaces\CurveInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PointImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\TestCase; @@ -38,7 +38,7 @@ class CircularStringTest extends TestCase /** Empty values retain their declared layout and reference. */ public function testEmpty(): void { - $curve = new CircularString([], 4326); + $curve = new CircularStringImmutable([], 4326); static::assertTrue($curve->isEmpty()); static::assertSame([], $curve->getPoints()); @@ -51,10 +51,10 @@ public function testEmpty(): void /** Immutable replacement preserves this concrete layout and family. */ public function testReplacePoint(): void { - $curve = new CircularString([[0, 0], [1, 1], [2, 0]], 4326); + $curve = new CircularStringImmutable([[0, 0], [1, 1], [2, 0]], 4326); $replacement = $curve->withPoint(1, Coordinates::xy(1, 2)); - static::assertSame(CircularString::class, $replacement::class); + static::assertSame(CircularStringImmutable::class, (new \ReflectionClass($replacement))->getName()); static::assertSame([[0, 0], [1, 1], [2, 0]], $curve->toArray()); static::assertSame([[0, 0], [1, 2], [2, 0]], $replacement->toArray()); static::assertSame(4326, $replacement->getPoint(1)->getSrid()); @@ -64,7 +64,7 @@ public function testReplacePoint(): void /** Three defining points retain circular interpolation and their ordinates. */ public function testSingleArc(): void { - $curve = new CircularString([[0, 0], [1, 1], [2, 0]], 4326); + $curve = new CircularStringImmutable([[0, 0], [1, 1], [2, 0]], 4326); static::assertContains(CurveInterface::class, class_implements($curve)); static::assertContains(CircularStringInterface::class, class_implements($curve)); @@ -75,7 +75,7 @@ public function testSingleArc(): void static::assertSame([[0, 0], [1, 1], [2, 0]], $curve->toArray()); static::assertCount(3, $curve->getPoints()); static::assertSame($curve->getPoints(), $curve->getElements()); - static::assertInstanceOf(Point::class, $curve->getPoint(0)); + static::assertInstanceOf(PointImmutable::class, $curve->getPoint(0)); static::assertSame(4326, $curve->getPoint(-1)->getSrid()); static::assertSame($curve->getPoint(2), $curve->getPoint(-1)); static::assertSame($curve->getPoint(0), $curve->getPoint(3)); diff --git a/tests/Unit/Types/Dimension2/Geography/CompoundCurveTest.php b/tests/Unit/Types/Dimension2/Geography/CompoundCurveTest.php index 7823e7e..eab5b77 100644 --- a/tests/Unit/Types/Dimension2/Geography/CompoundCurveTest.php +++ b/tests/Unit/Types/Dimension2/Geography/CompoundCurveTest.php @@ -22,9 +22,9 @@ use LongitudeOne\SpatialTypes\Interfaces\CompoundCurveInterface; use LongitudeOne\SpatialTypes\Interfaces\CurveInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\CompoundCurve; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\LineString; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\CompoundCurveImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\LineStringImmutable; use PHPUnit\Framework\TestCase; /** @@ -39,9 +39,9 @@ class CompoundCurveTest extends TestCase /** Empty compounds and component curves expose the common empty contract. */ public function testEmptyCurves(): void { - $compound = new CompoundCurve([], 4326); - $line = new LineString([], 4326); - $circular = new CircularString([], 4326); + $compound = new CompoundCurveImmutable([], 4326); + $line = new LineStringImmutable([], 4326); + $circular = new CircularStringImmutable([], 4326); static::assertTrue($compound->isEmpty()); static::assertNull($compound->getStartPoint()); @@ -63,9 +63,9 @@ public function testEmptyCurves(): void /** Mixed interpolation, order and closure survive through public contracts. */ public function testMixedClosedCurve(): void { - $circular = new CircularString([[0, 0], [1, 1], [2, 0]], 4326); - $line = new LineString([[2, 0], [0, 0]], 4326); - $compound = new CompoundCurve([$circular, $line], 4326); + $circular = new CircularStringImmutable([[0, 0], [1, 1], [2, 0]], 4326); + $line = new LineStringImmutable([[2, 0], [0, 0]], 4326); + $compound = new CompoundCurveImmutable([$circular, $line], 4326); static::assertContains(CompoundCurveInterface::class, class_implements($compound)); static::assertContains(CurveInterface::class, class_implements($compound)); @@ -91,13 +91,13 @@ public function testMixedClosedCurve(): void /** Reference changes deeply copy components and preserve defining ordinates. */ public function testReferenceReplacement(): void { - $compound = new CompoundCurve([ - new CircularString([[0, 0], [1, 1], [2, 0]], SpatialReference::epsg(4326)), - new LineString([[2, 0], [0, 0]], SpatialReference::epsg(4326)), + $compound = new CompoundCurveImmutable([ + new CircularStringImmutable([[0, 0], [1, 1], [2, 0]], SpatialReference::epsg(4326)), + new LineStringImmutable([[2, 0], [0, 0]], SpatialReference::epsg(4326)), ], SpatialReference::epsg(4326)); $copy = $compound->withSpatialReference(SpatialReference::epsg(3857)); - static::assertSame(CompoundCurve::class, $copy::class); + static::assertSame(CompoundCurveImmutable::class, (new \ReflectionClass($copy))->getName()); static::assertSame(4326, $compound->getSrid()); static::assertSame(4326, $compound->getCurve(0)->getSrid()); static::assertSame(3857, $copy->getSrid()); @@ -108,8 +108,8 @@ public function testReferenceReplacement(): void static::assertNotSame($compound->getStartPoint(), $copy->getStartPoint()); static::assertSame([[[0, 0], [1, 1], [2, 0]], [[2, 0], [0, 0]]], $compound->toArray()); static::assertSame([[[0, 0], [1, 1], [2, 0]], [[2, 0], [0, 0]]], $copy->toArray()); - static::assertInstanceOf(CircularString::class, $copy->getCurve(0)); - static::assertInstanceOf(LineString::class, $copy->getCurve(1)); + static::assertInstanceOf(CircularStringImmutable::class, $copy->getCurve(0)); + static::assertInstanceOf(LineStringImmutable::class, $copy->getCurve(1)); static::assertTrue($copy->isClosed()); } } diff --git a/tests/Unit/Types/Dimension2/Geography/GeographyCollectionTest.php b/tests/Unit/Types/Dimension2/Geography/GeographyCollectionTest.php index fa41a59..eceee31 100644 --- a/tests/Unit/Types/Dimension2/Geography/GeographyCollectionTest.php +++ b/tests/Unit/Types/Dimension2/Geography/GeographyCollectionTest.php @@ -17,16 +17,16 @@ namespace LongitudeOne\SpatialTypes\Tests\Unit\Types\Dimension2\Geography; use LongitudeOne\Core\Enum\GeometryTypeEnum; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\GeographyCollection; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Point; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Polygon as GeographicPolygon; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\GeographyCollectionImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PointImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PolygonImmutable as GeographicPolygon; use PHPUnit\Framework\TestCase; /** * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractCollection - * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\GeographyCollection + * @covers \LongitudeOne\SpatialTypes\Types\AbstractCollectionImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\GeographyCollectionImmutable */ class GeographyCollectionTest extends TestCase { @@ -37,8 +37,8 @@ class GeographyCollectionTest extends TestCase */ public function testAddElementWithGeographyCollection(): void { - $nestedCollection = new GeographyCollection(); - $geographyCollection = new GeographyCollection(0, [$nestedCollection]); + $nestedCollection = new GeographyCollectionImmutable(); + $geographyCollection = new GeographyCollectionImmutable(0, [$nestedCollection]); static::assertSame([$nestedCollection], $geographyCollection->getElements()); } @@ -49,7 +49,7 @@ public function testAddElementWithGeographyCollection(): void public function testGetElements(): void { $polygon = new GeographicPolygon([]); - $geographyCollection = new GeographyCollection(0, [$polygon]); + $geographyCollection = new GeographyCollectionImmutable(0, [$polygon]); static::assertSame([$polygon], $geographyCollection->getElements()); } @@ -58,7 +58,7 @@ public function testGetElements(): void */ public function testGetType(): void { - static::assertSame(GeometryTypeEnum::GEOMETRYCOLLECTION, (new GeographyCollection())->getType()); + static::assertSame(GeometryTypeEnum::GEOMETRYCOLLECTION, (new GeographyCollectionImmutable())->getType()); } /** @@ -67,7 +67,7 @@ public function testGetType(): void public function testHasElement(): void { $polygon = new GeographicPolygon([]); - $geographyCollection = new GeographyCollection(0, [$polygon]); + $geographyCollection = new GeographyCollectionImmutable(0, [$polygon]); static::assertTrue($geographyCollection->hasElement($polygon)); } @@ -77,8 +77,8 @@ public function testHasElement(): void public function testIsEmpty(): void { $polygon = new GeographicPolygon([]); - static::assertTrue((new GeographyCollection())->isEmpty()); - $geographyCollection = new GeographyCollection(0, [$polygon]); + static::assertTrue((new GeographyCollectionImmutable())->isEmpty()); + $geographyCollection = new GeographyCollectionImmutable(0, [$polygon]); static::assertFalse($geographyCollection->isEmpty()); } @@ -88,8 +88,8 @@ public function testIsEmpty(): void public function testToArray(): void { $polygon = new GeographicPolygon([], 4326); - static::assertSame([], (new GeographyCollection())->toArray()); - $geographyCollection = new GeographyCollection(4326, [$polygon, new Point(1, 2, 4326)]); + static::assertSame([], (new GeographyCollectionImmutable())->toArray()); + $geographyCollection = new GeographyCollectionImmutable(4326, [$polygon, new PointImmutable(1, 2, 4326)]); static::assertSame([[], [1, 2]], $geographyCollection->toArray()); } } diff --git a/tests/Unit/Types/Dimension2/Geography/LineStringTest.php b/tests/Unit/Types/Dimension2/Geography/LineStringTest.php index f4a2cb2..e1321cf 100644 --- a/tests/Unit/Types/Dimension2/Geography/LineStringTest.php +++ b/tests/Unit/Types/Dimension2/Geography/LineStringTest.php @@ -16,8 +16,8 @@ namespace LongitudeOne\SpatialTypes\Tests\Unit\Types\Dimension2\Geography; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\LineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\LineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PointImmutable; use PHPUnit\Framework\TestCase; /** @@ -25,9 +25,9 @@ * * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractLineString - * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialType - * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\LineString + * @covers \LongitudeOne\SpatialTypes\Types\AbstractLineStringImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialTypeImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\LineStringImmutable */ class LineStringTest extends TestCase { @@ -36,13 +36,13 @@ class LineStringTest extends TestCase */ public function testConstructorWithCartesianPoints(): void { - $lineString = new LineString([new Point(1, 2), new Point(3, 4)]); + $lineString = new LineStringImmutable([new PointImmutable(1, 2), new PointImmutable(3, 4)]); static::assertCount(2, $lineString->getPoints()); static::assertFalse($lineString->isClosed()); static::assertTrue($lineString->isLine()); static::assertEquals([[1, 2], [3, 4]], $lineString->toArray()); - $lineString = new LineString([new Point(1, 2), new Point(3, 4), new Point(1, 2)]); + $lineString = new LineStringImmutable([new PointImmutable(1, 2), new PointImmutable(3, 4), new PointImmutable(1, 2)]); static::assertCount(3, $lineString->getPoints()); static::assertTrue($lineString->isClosed()); static::assertTrue($lineString->isLine()); @@ -54,13 +54,13 @@ public function testConstructorWithCartesianPoints(): void */ public function testConstructorWithGeodesicPoints(): void { - $lineString = new LineString([new Point('40W', '40S', 4326), new Point('45W', '45N', 4326)], 4326); + $lineString = new LineStringImmutable([new PointImmutable('40W', '40S', 4326), new PointImmutable('45W', '45N', 4326)], 4326); static::assertCount(2, $lineString->getPoints()); static::assertFalse($lineString->isClosed()); static::assertTrue($lineString->isLine()); static::assertEquals([[-40, -40], [-45, 45]], $lineString->toArray()); - $lineString = new LineString([new Point('40W', '40S', 4326), new Point('45W', '45N', 4326), new Point('40W', '40S', 4326)], 4326); + $lineString = new LineStringImmutable([new PointImmutable('40W', '40S', 4326), new PointImmutable('45W', '45N', 4326), new PointImmutable('40W', '40S', 4326)], 4326); static::assertCount(3, $lineString->getPoints()); static::assertTrue($lineString->isLine()); static::assertTrue($lineString->isClosed()); @@ -72,7 +72,7 @@ public function testConstructorWithGeodesicPoints(): void */ public function testEmptyConstructor(): void { - $lineString = new LineString([]); + $lineString = new LineStringImmutable([]); static::assertEmpty($lineString->getPoints()); static::assertFalse($lineString->isClosed()); static::assertFalse($lineString->isLine()); diff --git a/tests/Unit/Types/Dimension2/Geography/MultiLineStringTest.php b/tests/Unit/Types/Dimension2/Geography/MultiLineStringTest.php index b2940a3..94c1596 100644 --- a/tests/Unit/Types/Dimension2/Geography/MultiLineStringTest.php +++ b/tests/Unit/Types/Dimension2/Geography/MultiLineStringTest.php @@ -20,7 +20,7 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\SpatialTypeExceptionInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiLineString; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiLineStringImmutable; use PHPUnit\Framework\TestCase; /** @@ -28,10 +28,10 @@ * * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiLineString - * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialType - * @covers \LongitudeOne\SpatialTypes\Types\Collection\AbstractLineStringCollection - * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiLineString + * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiLineStringImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialTypeImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Collection\AbstractLineStringCollectionImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiLineStringImmutable */ class MultiLineStringTest extends TestCase { @@ -44,7 +44,7 @@ public function testConstructorWithGeodesicPoints(): void { self::expectException(InvalidValueException::class); self::expectExceptionMessageIsOrContains('Out of range longitude value, longitude must be between -180 and 180, got "240W".'); - new MultiLineString([[['240W', '340S'], ['45W', '45N'], ['45W', '90N']]]); + new MultiLineStringImmutable([[['240W', '340S'], ['45W', '45N'], ['45W', '90N']]]); } /** @@ -52,7 +52,7 @@ public function testConstructorWithGeodesicPoints(): void */ public function testGetDimension(): void { - $multiLineString = new MultiLineString([[[1, 2], [3, 4], [3, 6], [1, 2]]]); + $multiLineString = new MultiLineStringImmutable([[[1, 2], [3, 4], [3, 6], [1, 2]]]); static::assertFalse($multiLineString->hasZ()); static::assertFalse($multiLineString->hasM()); $ring = $multiLineString->getLineString(0); @@ -70,7 +70,7 @@ public function testGetDimension(): void public function testGetFamily(): void { $expected = SpatialModelEnum::GEOGRAPHY; - $multiLineString = new MultiLineString([[[1, 2], [3, 4], [3, 6], [1, 2]]]); + $multiLineString = new MultiLineStringImmutable([[[1, 2], [3, 4], [3, 6], [1, 2]]]); static::assertSame($expected, $multiLineString->getFamily()); $ring = $multiLineString->getLineString(0); static::assertSame($expected, $ring->getFamily()); @@ -84,7 +84,7 @@ public function testGetFamily(): void */ public function testGetType(): void { - $multiLineString = new MultiLineString([[[1, 2], [3, 4], [3, 6], [1, 2]]]); + $multiLineString = new MultiLineStringImmutable([[[1, 2], [3, 4], [3, 6], [1, 2]]]); static::assertSame(GeometryTypeEnum::MULTILINESTRING, $multiLineString->getType()); } @@ -93,10 +93,10 @@ public function testGetType(): void */ public function testIsEmpty(): void { - $multiLineString = new MultiLineString([]); + $multiLineString = new MultiLineStringImmutable([]); static::assertTrue($multiLineString->isEmpty()); - $multiLineString = new MultiLineString([[[1, 2], [3, 4], [3, 6]]]); + $multiLineString = new MultiLineStringImmutable([[[1, 2], [3, 4], [3, 6]]]); static::assertFalse($multiLineString->isEmpty()); } @@ -105,9 +105,9 @@ public function testIsEmpty(): void */ public function testJsonSerialize(): void { - $multiLineString = new MultiLineString([[[1, 2], [3, 4], [3, 6], [1, 2]]]); + $multiLineString = new MultiLineStringImmutable([[[1, 2], [3, 4], [3, 6], [1, 2]]]); static::assertSame('{"type":"MultiLineString","coordinates":[[[1,2],[3,4],[3,6],[1,2]]],"srid":0}', json_encode($multiLineString)); - $multiLineString = new MultiLineString([[[1, 2], [3, 4], [3, 6], [1, 2]]], 4326); + $multiLineString = new MultiLineStringImmutable([[[1, 2], [3, 4], [3, 6], [1, 2]]], 4326); static::assertSame('{"type":"MultiLineString","coordinates":[[[1,2],[3,4],[3,6],[1,2]]],"srid":4326}', json_encode($multiLineString)); } } diff --git a/tests/Unit/Types/Dimension2/Geography/MultiPointTest.php b/tests/Unit/Types/Dimension2/Geography/MultiPointTest.php index 5ad53b7..730432d 100644 --- a/tests/Unit/Types/Dimension2/Geography/MultiPointTest.php +++ b/tests/Unit/Types/Dimension2/Geography/MultiPointTest.php @@ -16,8 +16,8 @@ namespace LongitudeOne\SpatialTypes\Tests\Unit\Types\Dimension2\Geography; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiPoint; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiPointImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PointImmutable; use PHPUnit\Framework\TestCase; /** @@ -25,9 +25,9 @@ * * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiPoint - * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialType - * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiPoint + * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiPointImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialTypeImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiPointImmutable */ class MultiPointTest extends TestCase { @@ -36,13 +36,13 @@ class MultiPointTest extends TestCase */ public function testConstructorWithCartesianPoints(): void { - $multiPoint = new MultiPoint([new Point(1, 2), new Point(3, 4)]); + $multiPoint = new MultiPointImmutable([new PointImmutable(1, 2), new PointImmutable(3, 4)]); static::assertCount(2, $multiPoint->getPoints()); static::assertTrue($multiPoint->isSimple()); static::assertFalse($multiPoint->isEmpty()); static::assertEquals([[1, 2], [3, 4]], $multiPoint->toArray()); - $multiPoint = new MultiPoint([new Point(1, 2), new Point(3, 4), new Point(1, 2)]); + $multiPoint = new MultiPointImmutable([new PointImmutable(1, 2), new PointImmutable(3, 4), new PointImmutable(1, 2)]); static::assertCount(3, $multiPoint->getPoints()); static::assertFalse($multiPoint->isSimple()); static::assertEquals([[1, 2], [3, 4], [1, 2]], $multiPoint->toArray()); @@ -53,13 +53,13 @@ public function testConstructorWithCartesianPoints(): void */ public function testConstructorWithGeodesicPoints(): void { - $multiPoint = new MultiPoint([new Point('40W', '40S', 4326), new Point('45W', '45N', 4326)], 4326); + $multiPoint = new MultiPointImmutable([new PointImmutable('40W', '40S', 4326), new PointImmutable('45W', '45N', 4326)], 4326); static::assertCount(2, $multiPoint->getPoints()); static::assertFalse($multiPoint->isEmpty()); static::assertTrue($multiPoint->isSimple()); static::assertEquals([[-40, -40], [-45, 45]], $multiPoint->toArray()); - $multiPoint = new MultiPoint([new Point('40W', '40S', 4326), new Point('45W', '45N', 4326), new Point('40W', '40S', 4326)], 4326); + $multiPoint = new MultiPointImmutable([new PointImmutable('40W', '40S', 4326), new PointImmutable('45W', '45N', 4326), new PointImmutable('40W', '40S', 4326)], 4326); static::assertCount(3, $multiPoint->getPoints()); static::assertFalse($multiPoint->isSimple()); static::assertFalse($multiPoint->isEmpty()); @@ -71,7 +71,7 @@ public function testConstructorWithGeodesicPoints(): void */ public function testEmptyConstructor(): void { - $multiPoint = new MultiPoint([]); + $multiPoint = new MultiPointImmutable([]); static::assertEmpty($multiPoint->getPoints()); static::assertTrue($multiPoint->isEmpty()); static::assertTrue($multiPoint->isSimple()); diff --git a/tests/Unit/Types/Dimension2/Geography/MultiPolygonTest.php b/tests/Unit/Types/Dimension2/Geography/MultiPolygonTest.php index 9946c34..64bce14 100644 --- a/tests/Unit/Types/Dimension2/Geography/MultiPolygonTest.php +++ b/tests/Unit/Types/Dimension2/Geography/MultiPolygonTest.php @@ -20,7 +20,7 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\SpatialTypeExceptionInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiPolygon; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiPolygonImmutable; use PHPUnit\Framework\TestCase; /** @@ -28,9 +28,9 @@ * * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiPolygon - * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialType - * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiPolygon + * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiPolygonImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialTypeImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiPolygonImmutable */ class MultiPolygonTest extends TestCase { @@ -43,7 +43,7 @@ public function testConstructorWithGeodesicPoints(): void { self::expectException(InvalidValueException::class); self::expectExceptionMessageIsOrContains('Out of range longitude value, longitude must be between -180 and 180, got "240W".'); - new MultiPolygon([[[['240W', '340S'], ['45W', '45N'], ['45W', '90N'], ['240W', '340S']]]]); + new MultiPolygonImmutable([[[['240W', '340S'], ['45W', '45N'], ['45W', '90N'], ['240W', '340S']]]]); } /** @@ -51,7 +51,7 @@ public function testConstructorWithGeodesicPoints(): void */ public function testGetDimension(): void { - $multiPolygon = new MultiPolygon([[[[1, 2], [3, 4], [3, 6], [1, 2]]]]); + $multiPolygon = new MultiPolygonImmutable([[[[1, 2], [3, 4], [3, 6], [1, 2]]]]); static::assertFalse($multiPolygon->hasZ()); static::assertFalse($multiPolygon->hasM()); $polygon = $multiPolygon->getPolygon(0); @@ -69,7 +69,7 @@ public function testGetDimension(): void public function testGetFamily(): void { $expected = SpatialModelEnum::GEOGRAPHY; - $multiPolygon = new MultiPolygon([[[[1, 2], [3, 4], [3, 6], [1, 2]]]]); + $multiPolygon = new MultiPolygonImmutable([[[[1, 2], [3, 4], [3, 6], [1, 2]]]]); static::assertSame($expected, $multiPolygon->getFamily()); $polygon = $multiPolygon->getPolygon(0); static::assertSame($expected, $polygon->getFamily()); @@ -83,7 +83,7 @@ public function testGetFamily(): void */ public function testGetType(): void { - $multiPolygon = new MultiPolygon([[[[1, 2], [3, 4], [3, 6], [1, 2]]]]); + $multiPolygon = new MultiPolygonImmutable([[[[1, 2], [3, 4], [3, 6], [1, 2]]]]); static::assertSame(GeometryTypeEnum::MULTIPOLYGON, $multiPolygon->getType()); } @@ -92,9 +92,9 @@ public function testGetType(): void */ public function testJsonSerialize(): void { - $multiPolygon = new MultiPolygon([[[[1, 2], [3, 4], [3, 6], [1, 2]]]]); + $multiPolygon = new MultiPolygonImmutable([[[[1, 2], [3, 4], [3, 6], [1, 2]]]]); static::assertSame('{"type":"MultiPolygon","coordinates":[[[[1,2],[3,4],[3,6],[1,2]]]],"srid":0}', json_encode($multiPolygon)); - $multiPolygon = new MultiPolygon([[[[1, 2], [3, 4], [3, 6], [1, 2]]]], 4326); + $multiPolygon = new MultiPolygonImmutable([[[[1, 2], [3, 4], [3, 6], [1, 2]]]], 4326); static::assertSame('{"type":"MultiPolygon","coordinates":[[[[1,2],[3,4],[3,6],[1,2]]]],"srid":4326}', json_encode($multiPolygon)); } } diff --git a/tests/Unit/Types/Dimension2/Geography/PointTest.php b/tests/Unit/Types/Dimension2/Geography/PointTest.php index c0ac603..6cd7890 100644 --- a/tests/Unit/Types/Dimension2/Geography/PointTest.php +++ b/tests/Unit/Types/Dimension2/Geography/PointTest.php @@ -19,7 +19,7 @@ use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Exception\BadMethodCallException; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PointImmutable; use PHPUnit\Framework\TestCase; /** @@ -27,16 +27,16 @@ * * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractPoint - * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialType - * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Point + * @covers \LongitudeOne\SpatialTypes\Types\AbstractPointImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialTypeImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PointImmutable */ class PointTest extends TestCase { /** * Point instance. */ - private Point $point; + private PointImmutable $point; /** * Set up the point instance. @@ -44,7 +44,7 @@ class PointTest extends TestCase protected function setUp(): void { parent::setUp(); - $this->point = new Point('1.1W', '45.1N'); + $this->point = new PointImmutable('1.1W', '45.1N'); } /** @@ -52,7 +52,7 @@ protected function setUp(): void */ public function testConstructsLatitude(): void { - static::assertSame(45.1, (new Point(-1.1, '45.1N'))->getY()); + static::assertSame(45.1, (new PointImmutable(-1.1, '45.1N'))->getY()); } /** @@ -60,7 +60,7 @@ public function testConstructsLatitude(): void */ public function testConstructsLongitude(): void { - static::assertSame(-1.1, (new Point('1.1W', 45.1))->getX()); + static::assertSame(-1.1, (new PointImmutable('1.1W', 45.1))->getX()); } /** @@ -93,7 +93,7 @@ public function testGetLongitude(): void public function testGetM(): void { self::expectException(BadMethodCallException::class); - self::expectExceptionMessageIsOrContains('The method "LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Point::getM" cannot be called with a spatial object with dimensions "XY".'); + self::expectExceptionMessageIsOrContains('The method "LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PointImmutable::getM" cannot be called with a spatial object with dimensions "XY".'); $this->point->getM(); } @@ -127,7 +127,7 @@ public function testGetY(): void public function testGetZ(): void { self::expectException(BadMethodCallException::class); - self::expectExceptionMessageIsOrContains('The method "LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Point::getZ" cannot be called with a spatial object with dimensions "XY".'); + self::expectExceptionMessageIsOrContains('The method "LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PointImmutable::getZ" cannot be called with a spatial object with dimensions "XY".'); $this->point->getZ(); } @@ -153,7 +153,7 @@ public function testHasZ(): void public function testJsonSerialize(): void { static::assertSame('{"type":"Point","coordinates":[-1.1,45.1],"srid":0}', json_encode($this->point)); - $this->point = new Point(-1.1, 45.1, 4326); + $this->point = new PointImmutable(-1.1, 45.1, 4326); static::assertSame('{"type":"Point","coordinates":[-1.1,45.1],"srid":4326}', json_encode($this->point)); } diff --git a/tests/Unit/Types/Dimension2/Geography/PolygonTest.php b/tests/Unit/Types/Dimension2/Geography/PolygonTest.php index 28d1582..b291cc5 100644 --- a/tests/Unit/Types/Dimension2/Geography/PolygonTest.php +++ b/tests/Unit/Types/Dimension2/Geography/PolygonTest.php @@ -20,7 +20,7 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\SpatialTypeExceptionInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Polygon; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PolygonImmutable; use PHPUnit\Framework\TestCase; /** @@ -29,9 +29,9 @@ * @internal * * @covers \LongitudeOne\SpatialTypes\Boundary\PolygonBoundary - * @covers \LongitudeOne\SpatialTypes\Types\AbstractPolygon - * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialType - * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Polygon + * @covers \LongitudeOne\SpatialTypes\Types\AbstractPolygonImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialTypeImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PolygonImmutable */ class PolygonTest extends TestCase { @@ -44,7 +44,7 @@ public function testConstructorWithGeodesicPoints(): void { self::expectException(InvalidValueException::class); self::expectExceptionMessageIsOrContains('g'); - new Polygon([[['240W', '340S'], ['45W', '45N'], ['45W', '90N'], ['240W', '340S']]]); + new PolygonImmutable([[['240W', '340S'], ['45W', '45N'], ['45W', '90N'], ['240W', '340S']]]); } /** @@ -52,7 +52,7 @@ public function testConstructorWithGeodesicPoints(): void */ public function testGetDimension(): void { - $polygon = new Polygon([[[1, 2], [3, 4], [3, 6], [1, 2]]]); + $polygon = new PolygonImmutable([[[1, 2], [3, 4], [3, 6], [1, 2]]]); static::assertFalse($polygon->hasZ()); static::assertFalse($polygon->hasM()); $ring = $polygon->getRing(0); @@ -70,7 +70,7 @@ public function testGetDimension(): void public function testGetFamily(): void { $expected = SpatialModelEnum::GEOGRAPHY; - $polygon = new Polygon([[[1, 2], [3, 4], [3, 6], [1, 2]]]); + $polygon = new PolygonImmutable([[[1, 2], [3, 4], [3, 6], [1, 2]]]); static::assertSame($expected, $polygon->getFamily()); $ring = $polygon->getRing(0); static::assertSame($expected, $ring->getFamily()); @@ -84,7 +84,7 @@ public function testGetFamily(): void */ public function testGetType(): void { - $polygon = new Polygon([[[1, 2], [3, 4], [3, 6], [1, 2]]]); + $polygon = new PolygonImmutable([[[1, 2], [3, 4], [3, 6], [1, 2]]]); static::assertSame(GeometryTypeEnum::POLYGON, $polygon->getType()); } @@ -93,9 +93,9 @@ public function testGetType(): void */ public function testJsonSerialize(): void { - $polygon = new Polygon([[[1, 2], [3, 4], [3, 6], [1, 2]]]); + $polygon = new PolygonImmutable([[[1, 2], [3, 4], [3, 6], [1, 2]]]); static::assertSame('{"type":"Polygon","coordinates":[[[1,2],[3,4],[3,6],[1,2]]],"srid":0}', json_encode($polygon)); - $polygon = new Polygon([[[1, 2], [3, 4], [3, 6], [1, 2]]], 4326); + $polygon = new PolygonImmutable([[[1, 2], [3, 4], [3, 6], [1, 2]]], 4326); static::assertSame('{"type":"Polygon","coordinates":[[[1,2],[3,4],[3,6],[1,2]]],"srid":4326}', json_encode($polygon)); } } diff --git a/tests/Unit/Types/Dimension2/Geometry/CircularStringTest.php b/tests/Unit/Types/Dimension2/Geometry/CircularStringTest.php index 3ad4cc0..44f12e3 100644 --- a/tests/Unit/Types/Dimension2/Geometry/CircularStringTest.php +++ b/tests/Unit/Types/Dimension2/Geometry/CircularStringTest.php @@ -21,8 +21,8 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Interfaces\CircularStringInterface; use LongitudeOne\SpatialTypes\Interfaces\CurveInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\TestCase; @@ -38,7 +38,7 @@ class CircularStringTest extends TestCase /** Empty values retain their declared layout and reference. */ public function testEmpty(): void { - $curve = new CircularString([], 4326); + $curve = new CircularStringImmutable([], 4326); static::assertTrue($curve->isEmpty()); static::assertSame([], $curve->getPoints()); @@ -51,10 +51,10 @@ public function testEmpty(): void /** Immutable replacement preserves this concrete layout and family. */ public function testReplacePoint(): void { - $curve = new CircularString([[0, 0], [1, 1], [2, 0]], 4326); + $curve = new CircularStringImmutable([[0, 0], [1, 1], [2, 0]], 4326); $replacement = $curve->withPoint(1, Coordinates::xy(1, 2)); - static::assertSame(CircularString::class, $replacement::class); + static::assertSame(CircularStringImmutable::class, (new \ReflectionClass($replacement))->getName()); static::assertSame([[0, 0], [1, 1], [2, 0]], $curve->toArray()); static::assertSame([[0, 0], [1, 2], [2, 0]], $replacement->toArray()); static::assertSame(4326, $replacement->getPoint(1)->getSrid()); @@ -64,7 +64,7 @@ public function testReplacePoint(): void /** Three defining points retain circular interpolation and their ordinates. */ public function testSingleArc(): void { - $curve = new CircularString([[0, 0], [1, 1], [2, 0]], 4326); + $curve = new CircularStringImmutable([[0, 0], [1, 1], [2, 0]], 4326); static::assertContains(CurveInterface::class, class_implements($curve)); static::assertContains(CircularStringInterface::class, class_implements($curve)); @@ -75,7 +75,7 @@ public function testSingleArc(): void static::assertSame([[0, 0], [1, 1], [2, 0]], $curve->toArray()); static::assertCount(3, $curve->getPoints()); static::assertSame($curve->getPoints(), $curve->getElements()); - static::assertInstanceOf(Point::class, $curve->getPoint(0)); + static::assertInstanceOf(PointImmutable::class, $curve->getPoint(0)); static::assertSame(4326, $curve->getPoint(-1)->getSrid()); static::assertSame($curve->getPoint(2), $curve->getPoint(-1)); static::assertSame($curve->getPoint(0), $curve->getPoint(3)); diff --git a/tests/Unit/Types/Dimension2/Geometry/CompoundCurveTest.php b/tests/Unit/Types/Dimension2/Geometry/CompoundCurveTest.php index 802495a..3790279 100644 --- a/tests/Unit/Types/Dimension2/Geometry/CompoundCurveTest.php +++ b/tests/Unit/Types/Dimension2/Geometry/CompoundCurveTest.php @@ -22,9 +22,9 @@ use LongitudeOne\SpatialTypes\Interfaces\CompoundCurveInterface; use LongitudeOne\SpatialTypes\Interfaces\CurveInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CompoundCurve; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CompoundCurveImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable; use PHPUnit\Framework\TestCase; /** @@ -39,9 +39,9 @@ class CompoundCurveTest extends TestCase /** Empty compounds and component curves expose the common empty contract. */ public function testEmptyCurves(): void { - $compound = new CompoundCurve([], 4326); - $line = new LineString([], 4326); - $circular = new CircularString([], 4326); + $compound = new CompoundCurveImmutable([], 4326); + $line = new LineStringImmutable([], 4326); + $circular = new CircularStringImmutable([], 4326); static::assertTrue($compound->isEmpty()); static::assertNull($compound->getStartPoint()); @@ -63,9 +63,9 @@ public function testEmptyCurves(): void /** Mixed interpolation, order and closure survive through public contracts. */ public function testMixedClosedCurve(): void { - $circular = new CircularString([[0, 0], [1, 1], [2, 0]], 4326); - $line = new LineString([[2, 0], [0, 0]], 4326); - $compound = new CompoundCurve([$circular, $line], 4326); + $circular = new CircularStringImmutable([[0, 0], [1, 1], [2, 0]], 4326); + $line = new LineStringImmutable([[2, 0], [0, 0]], 4326); + $compound = new CompoundCurveImmutable([$circular, $line], 4326); static::assertContains(CompoundCurveInterface::class, class_implements($compound)); static::assertContains(CurveInterface::class, class_implements($compound)); @@ -91,13 +91,13 @@ public function testMixedClosedCurve(): void /** Reference changes deeply copy components and preserve defining ordinates. */ public function testReferenceReplacement(): void { - $compound = new CompoundCurve([ - new CircularString([[0, 0], [1, 1], [2, 0]], SpatialReference::epsg(4326)), - new LineString([[2, 0], [0, 0]], SpatialReference::epsg(4326)), + $compound = new CompoundCurveImmutable([ + new CircularStringImmutable([[0, 0], [1, 1], [2, 0]], SpatialReference::epsg(4326)), + new LineStringImmutable([[2, 0], [0, 0]], SpatialReference::epsg(4326)), ], SpatialReference::epsg(4326)); $copy = $compound->withSpatialReference(SpatialReference::epsg(3857)); - static::assertSame(CompoundCurve::class, $copy::class); + static::assertSame(CompoundCurveImmutable::class, (new \ReflectionClass($copy))->getName()); static::assertSame(4326, $compound->getSrid()); static::assertSame(4326, $compound->getCurve(0)->getSrid()); static::assertSame(3857, $copy->getSrid()); @@ -108,8 +108,8 @@ public function testReferenceReplacement(): void static::assertNotSame($compound->getStartPoint(), $copy->getStartPoint()); static::assertSame([[[0, 0], [1, 1], [2, 0]], [[2, 0], [0, 0]]], $compound->toArray()); static::assertSame([[[0, 0], [1, 1], [2, 0]], [[2, 0], [0, 0]]], $copy->toArray()); - static::assertInstanceOf(CircularString::class, $copy->getCurve(0)); - static::assertInstanceOf(LineString::class, $copy->getCurve(1)); + static::assertInstanceOf(CircularStringImmutable::class, $copy->getCurve(0)); + static::assertInstanceOf(LineStringImmutable::class, $copy->getCurve(1)); static::assertTrue($copy->isClosed()); } } diff --git a/tests/Unit/Types/Dimension2/Geometry/GeometryCollectionTest.php b/tests/Unit/Types/Dimension2/Geometry/GeometryCollectionTest.php index 4fe8635..84ee361 100644 --- a/tests/Unit/Types/Dimension2/Geometry/GeometryCollectionTest.php +++ b/tests/Unit/Types/Dimension2/Geometry/GeometryCollectionTest.php @@ -17,16 +17,16 @@ namespace LongitudeOne\SpatialTypes\Tests\Unit\Types\Dimension2\Geometry; use LongitudeOne\Core\Enum\GeometryTypeEnum; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollection; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Polygon as GeometricPolygon; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollectionImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PolygonImmutable as GeometricPolygon; use PHPUnit\Framework\TestCase; /** * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractCollection - * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollection + * @covers \LongitudeOne\SpatialTypes\Types\AbstractCollectionImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollectionImmutable */ class GeometryCollectionTest extends TestCase { @@ -37,8 +37,8 @@ class GeometryCollectionTest extends TestCase */ public function testAddElementWithGeometryCollection(): void { - $nestedCollection = new GeometryCollection(); - $geometryCollection = new GeometryCollection(0, [$nestedCollection]); + $nestedCollection = new GeometryCollectionImmutable(); + $geometryCollection = new GeometryCollectionImmutable(0, [$nestedCollection]); static::assertSame([$nestedCollection], $geometryCollection->getElements()); } @@ -49,7 +49,7 @@ public function testAddElementWithGeometryCollection(): void public function testGetElements(): void { $polygon = new GeometricPolygon([]); - $geometryCollection = new GeometryCollection(0, [$polygon]); + $geometryCollection = new GeometryCollectionImmutable(0, [$polygon]); static::assertSame([$polygon], $geometryCollection->getElements()); } @@ -58,7 +58,7 @@ public function testGetElements(): void */ public function testGetType(): void { - static::assertSame(GeometryTypeEnum::GEOMETRYCOLLECTION, (new GeometryCollection())->getType()); + static::assertSame(GeometryTypeEnum::GEOMETRYCOLLECTION, (new GeometryCollectionImmutable())->getType()); } /** @@ -67,7 +67,7 @@ public function testGetType(): void public function testHasElement(): void { $polygon = new GeometricPolygon([]); - $geometryCollection = new GeometryCollection(0, [$polygon]); + $geometryCollection = new GeometryCollectionImmutable(0, [$polygon]); static::assertTrue($geometryCollection->hasElement($polygon)); } @@ -77,8 +77,8 @@ public function testHasElement(): void public function testIsEmpty(): void { $polygon = new GeometricPolygon([]); - static::assertTrue((new GeometryCollection())->isEmpty()); - $geometryCollection = new GeometryCollection(0, [$polygon]); + static::assertTrue((new GeometryCollectionImmutable())->isEmpty()); + $geometryCollection = new GeometryCollectionImmutable(0, [$polygon]); static::assertFalse($geometryCollection->isEmpty()); } @@ -88,8 +88,8 @@ public function testIsEmpty(): void public function testToArray(): void { $polygon = new GeometricPolygon([], 4326); - static::assertSame([], (new GeometryCollection())->toArray()); - $geometryCollection = new GeometryCollection(4326, [$polygon, new Point(1, 2, 4326)]); + static::assertSame([], (new GeometryCollectionImmutable())->toArray()); + $geometryCollection = new GeometryCollectionImmutable(4326, [$polygon, new PointImmutable(1, 2, 4326)]); static::assertSame([[], [1, 2]], $geometryCollection->toArray()); } } diff --git a/tests/Unit/Types/Dimension2/Geometry/LineStringTest.php b/tests/Unit/Types/Dimension2/Geometry/LineStringTest.php index 0816b5b..9b43c69 100644 --- a/tests/Unit/Types/Dimension2/Geometry/LineStringTest.php +++ b/tests/Unit/Types/Dimension2/Geometry/LineStringTest.php @@ -17,8 +17,8 @@ namespace LongitudeOne\SpatialTypes\Tests\Unit\Types\Dimension2\Geometry; use LongitudeOne\SpatialTypes\Exception\OutOfBoundsException; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; use PHPUnit\Framework\TestCase; /** @@ -26,9 +26,9 @@ * * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractLineString - * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialType - * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString + * @covers \LongitudeOne\SpatialTypes\Types\AbstractLineStringImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialTypeImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable */ class LineStringTest extends TestCase { @@ -37,13 +37,13 @@ class LineStringTest extends TestCase */ public function testConstructorWithCartesianPoints(): void { - $lineString = new LineString([new Point(1, 2), new Point(3, 4)]); + $lineString = new LineStringImmutable([new PointImmutable(1, 2), new PointImmutable(3, 4)]); static::assertCount(2, $lineString->getPoints()); static::assertFalse($lineString->isClosed()); static::assertTrue($lineString->isLine()); static::assertEquals([[1, 2], [3, 4]], $lineString->toArray()); - $lineString = new LineString([new Point(1, 2), new Point(3, 4), new Point(1, 2)]); + $lineString = new LineStringImmutable([new PointImmutable(1, 2), new PointImmutable(3, 4), new PointImmutable(1, 2)]); static::assertCount(3, $lineString->getPoints()); static::assertTrue($lineString->isClosed()); static::assertTrue($lineString->isLine()); @@ -55,13 +55,13 @@ public function testConstructorWithCartesianPoints(): void */ public function testConstructorWithGeodesicPoints(): void { - $lineString = new LineString([new Point('40W', '40S', 4326), new Point('45W', '45N', 4326)], 4326); + $lineString = new LineStringImmutable([new PointImmutable('40W', '40S', 4326), new PointImmutable('45W', '45N', 4326)], 4326); static::assertCount(2, $lineString->getPoints()); static::assertFalse($lineString->isClosed()); static::assertTrue($lineString->isLine()); static::assertEquals([[-40, -40], [-45, 45]], $lineString->toArray()); - $lineString = new LineString([new Point('40W', '40S', 4326), new Point('45W', '45N', 4326), new Point('40W', '40S', 4326)], 4326); + $lineString = new LineStringImmutable([new PointImmutable('40W', '40S', 4326), new PointImmutable('45W', '45N', 4326), new PointImmutable('40W', '40S', 4326)], 4326); static::assertCount(3, $lineString->getPoints()); static::assertTrue($lineString->isLine()); static::assertTrue($lineString->isClosed()); @@ -73,7 +73,7 @@ public function testConstructorWithGeodesicPoints(): void */ public function testEmptyConstructor(): void { - $lineString = new LineString([]); + $lineString = new LineStringImmutable([]); static::assertEmpty($lineString->getPoints()); static::assertFalse($lineString->isClosed()); static::assertFalse($lineString->isLine()); @@ -86,7 +86,7 @@ public function testEmptyConstructor(): void */ public function testGetElements(): void { - $lineString = new LineString([new Point(1, 2, 4326), new Point(3, 4, 4326)], 4326); + $lineString = new LineStringImmutable([new PointImmutable(1, 2, 4326), new PointImmutable(3, 4, 4326)], 4326); static::assertSame($lineString->getElements(), $lineString->getPoints()); } @@ -95,7 +95,7 @@ public function testGetElements(): void */ public function testGetPoint(): void { - $lineString = new LineString([new Point(1, 2), new Point(3, 4)]); + $lineString = new LineStringImmutable([new PointImmutable(1, 2), new PointImmutable(3, 4)]); static::assertCount(2, $lineString->getPoints()); static::assertSame(1, $lineString->getPoint(0)->getX()); static::assertSame(3, $lineString->getPoint(1)->getX()); @@ -110,7 +110,7 @@ public function testGetPoint(): void self::expectException(OutOfBoundsException::class); self::expectExceptionMessageIsOrContains('The current collection of points is empty.'); - (new LineString([]))->getPoint(0); + (new LineStringImmutable([]))->getPoint(0); } /** @@ -118,9 +118,9 @@ public function testGetPoint(): void */ public function testJsonSerialize(): void { - $lineString = new LineString([new Point('40W', '40S', 4326), new Point('45W', '45N', 4326)], 4326); + $lineString = new LineStringImmutable([new PointImmutable('40W', '40S', 4326), new PointImmutable('45W', '45N', 4326)], 4326); static::assertSame('{"type":"LineString","coordinates":[[-40,-40],[-45,45]],"srid":4326}', json_encode($lineString)); - $lineString = new LineString([new Point(1, 2), new Point(3, 4)]); + $lineString = new LineStringImmutable([new PointImmutable(1, 2), new PointImmutable(3, 4)]); static::assertSame('{"type":"LineString","coordinates":[[1,2],[3,4]],"srid":0}', json_encode($lineString)); } } diff --git a/tests/Unit/Types/Dimension2/Geometry/MultiPointTest.php b/tests/Unit/Types/Dimension2/Geometry/MultiPointTest.php index b0c762d..fac6266 100644 --- a/tests/Unit/Types/Dimension2/Geometry/MultiPointTest.php +++ b/tests/Unit/Types/Dimension2/Geometry/MultiPointTest.php @@ -17,8 +17,8 @@ namespace LongitudeOne\SpatialTypes\Tests\Unit\Types\Dimension2\Geometry; use LongitudeOne\SpatialTypes\Exception\OutOfBoundsException; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPoint; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPointImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; use PHPUnit\Framework\TestCase; /** @@ -26,9 +26,9 @@ * * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiPoint - * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialType - * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPoint + * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiPointImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialTypeImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPointImmutable */ class MultiPointTest extends TestCase { @@ -37,13 +37,13 @@ class MultiPointTest extends TestCase */ public function testConstructorWithCartesianPoints(): void { - $multiPoint = new MultiPoint([new Point(1, 2), new Point(3, 4)]); + $multiPoint = new MultiPointImmutable([new PointImmutable(1, 2), new PointImmutable(3, 4)]); static::assertCount(2, $multiPoint->getPoints()); static::assertTrue($multiPoint->isSimple()); static::assertFalse($multiPoint->isEmpty()); static::assertEquals([[1, 2], [3, 4]], $multiPoint->toArray()); - $multiPoint = new MultiPoint([new Point(1, 2), new Point(3, 4), new Point(1, 2)]); + $multiPoint = new MultiPointImmutable([new PointImmutable(1, 2), new PointImmutable(3, 4), new PointImmutable(1, 2)]); static::assertCount(3, $multiPoint->getPoints()); static::assertFalse($multiPoint->isSimple()); static::assertFalse($multiPoint->isEmpty()); @@ -55,13 +55,13 @@ public function testConstructorWithCartesianPoints(): void */ public function testConstructorWithGeodesicPoints(): void { - $multiPoint = new MultiPoint([new Point('40W', '40S', 4326), new Point('45W', '45N', 4326)], 4326); + $multiPoint = new MultiPointImmutable([new PointImmutable('40W', '40S', 4326), new PointImmutable('45W', '45N', 4326)], 4326); static::assertCount(2, $multiPoint->getPoints()); static::assertTrue($multiPoint->isSimple()); static::assertFalse($multiPoint->isEmpty()); static::assertEquals([[-40, -40], [-45, 45]], $multiPoint->toArray()); - $multiPoint = new MultiPoint([new Point('40W', '40S', 4326), new Point('45W', '45N', 4326), new Point('40W', '40S', 4326)], 4326); + $multiPoint = new MultiPointImmutable([new PointImmutable('40W', '40S', 4326), new PointImmutable('45W', '45N', 4326), new PointImmutable('40W', '40S', 4326)], 4326); static::assertCount(3, $multiPoint->getPoints()); static::assertFalse($multiPoint->isSimple()); static::assertFalse($multiPoint->isEmpty()); @@ -73,7 +73,7 @@ public function testConstructorWithGeodesicPoints(): void */ public function testEmptyConstructor(): void { - $multiPoint = new MultiPoint([]); + $multiPoint = new MultiPointImmutable([]); static::assertEmpty($multiPoint->getPoints()); static::assertTrue($multiPoint->isSimple()); static::assertTrue($multiPoint->isEmpty()); @@ -86,7 +86,7 @@ public function testEmptyConstructor(): void */ public function testGetElements(): void { - $multiPoint = new MultiPoint([new Point(1, 2, 4326), new Point(3, 4, 4326)], 4326); + $multiPoint = new MultiPointImmutable([new PointImmutable(1, 2, 4326), new PointImmutable(3, 4, 4326)], 4326); static::assertSame($multiPoint->getElements(), $multiPoint->getPoints()); } @@ -95,7 +95,7 @@ public function testGetElements(): void */ public function testGetPoint(): void { - $multiPoint = new MultiPoint([new Point(1, 2), new Point(3, 4)]); + $multiPoint = new MultiPointImmutable([new PointImmutable(1, 2), new PointImmutable(3, 4)]); static::assertCount(2, $multiPoint->getPoints()); static::assertSame(1, $multiPoint->getPoint(0)->getX()); static::assertSame(3, $multiPoint->getPoint(1)->getX()); @@ -110,7 +110,7 @@ public function testGetPoint(): void self::expectException(OutOfBoundsException::class); self::expectExceptionMessageIsOrContains('The current collection of points is empty.'); - (new MultiPoint([]))->getPoint(0); + (new MultiPointImmutable([]))->getPoint(0); } /** @@ -118,9 +118,9 @@ public function testGetPoint(): void */ public function testJsonSerialize(): void { - $multiPoint = new MultiPoint([new Point('40W', '40S', 4326), new Point('45W', '45N', 4326)], 4326); + $multiPoint = new MultiPointImmutable([new PointImmutable('40W', '40S', 4326), new PointImmutable('45W', '45N', 4326)], 4326); static::assertSame('{"type":"MultiPoint","coordinates":[[-40,-40],[-45,45]],"srid":4326}', json_encode($multiPoint)); - $multiPoint = new MultiPoint([new Point(1, 2), new Point(3, 4)]); + $multiPoint = new MultiPointImmutable([new PointImmutable(1, 2), new PointImmutable(3, 4)]); static::assertSame('{"type":"MultiPoint","coordinates":[[1,2],[3,4]],"srid":0}', json_encode($multiPoint)); } } diff --git a/tests/Unit/Types/Dimension2/Geometry/PointTest.php b/tests/Unit/Types/Dimension2/Geometry/PointTest.php index c67ae77..156c2ab 100644 --- a/tests/Unit/Types/Dimension2/Geometry/PointTest.php +++ b/tests/Unit/Types/Dimension2/Geometry/PointTest.php @@ -20,23 +20,23 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Exception\BadMethodCallException; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractPoint - * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialType - * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point + * @covers \LongitudeOne\SpatialTypes\Types\AbstractPointImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialTypeImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable */ class PointTest extends TestCase { /** * Point instance. */ - private Point $point; + private PointImmutable $point; /** * Set up the point instance. @@ -46,7 +46,7 @@ class PointTest extends TestCase protected function setUp(): void { parent::setUp(); - $this->point = new Point(1, 2); + $this->point = new PointImmutable(1, 2); } /** @@ -54,23 +54,23 @@ protected function setUp(): void */ public function testEqualsTo(): void { - $point = new Point(1, 2); + $point = new PointImmutable(1, 2); static::assertTrue($this->point->equalsTo($point)); static::assertTrue($point->equalsTo($this->point)); - $point = new Point(1, 2, 4326); + $point = new PointImmutable(1, 2, 4326); static::assertFalse($this->point->equalsTo($point)); static::assertFalse($point->equalsTo($this->point)); - $this->point = new Point(1, 2, 4326); + $this->point = new PointImmutable(1, 2, 4326); static::assertTrue($this->point->equalsTo($point)); static::assertTrue($point->equalsTo($this->point)); - $point = new Point(3, 2, 4326); + $point = new PointImmutable(3, 2, 4326); static::assertFalse($this->point->equalsTo($point)); static::assertFalse($point->equalsTo($this->point)); - $point = new Point(1, 3, 4326); + $point = new PointImmutable(1, 3, 4326); static::assertFalse($this->point->equalsTo($point)); static::assertFalse($point->equalsTo($this->point)); } @@ -105,7 +105,7 @@ public function testGetLongitude(): void public function testGetM(): void { self::expectException(BadMethodCallException::class); - self::expectExceptionMessageIsOrContains('The method "LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point::getM" cannot be called with a spatial object with dimensions "XY".'); + self::expectExceptionMessageIsOrContains('The method "LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable::getM" cannot be called with a spatial object with dimensions "XY".'); $this->point->getM(); } @@ -139,7 +139,7 @@ public function testGetY(): void public function testGetZ(): void { self::expectException(BadMethodCallException::class); - self::expectExceptionMessageIsOrContains('The method "LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point::getZ" cannot be called with a spatial object with dimensions "XY".'); + self::expectExceptionMessageIsOrContains('The method "LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable::getZ" cannot be called with a spatial object with dimensions "XY".'); $this->point->getZ(); } @@ -165,7 +165,7 @@ public function testHasZ(): void public function testJsonSerialize(): void { static::assertSame('{"type":"Point","coordinates":[1,2],"srid":0}', json_encode($this->point)); - $this->point = new Point(1, 2, 4326); + $this->point = new PointImmutable(1, 2, 4326); static::assertSame('{"type":"Point","coordinates":[1,2],"srid":4326}', json_encode($this->point)); } @@ -182,12 +182,12 @@ public function testJsonSerialize(): void public function testOutOfRange(string $longitude, string $latitude, string $expectedMessage): void { // No exception - new Point(181, 91); - new Point('181', '91'); + new PointImmutable(181, 91); + new PointImmutable('181', '91'); self::expectException(InvalidValueException::class); self::expectExceptionMessageIsOrContains($expectedMessage); - new Point($longitude, $latitude); + new PointImmutable($longitude, $latitude); } /** diff --git a/tests/Unit/Types/Dimension3dz/Geography/MultiLineStringTest.php b/tests/Unit/Types/Dimension3dz/Geography/MultiLineStringTest.php index 2bbba62..ce540be 100644 --- a/tests/Unit/Types/Dimension3dz/Geography/MultiLineStringTest.php +++ b/tests/Unit/Types/Dimension3dz/Geography/MultiLineStringTest.php @@ -20,7 +20,7 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\SpatialTypeExceptionInterface; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiLineString; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiLineStringImmutable; use PHPUnit\Framework\TestCase; /** @@ -28,10 +28,10 @@ * * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiLineString - * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialType - * @covers \LongitudeOne\SpatialTypes\Types\Collection\AbstractLineStringCollection - * @covers \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiLineString + * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiLineStringImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialTypeImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Collection\AbstractLineStringCollectionImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiLineStringImmutable */ class MultiLineStringTest extends TestCase { @@ -44,7 +44,7 @@ public function testConstructorWithGeodesicPoints(): void { self::expectException(InvalidValueException::class); self::expectExceptionMessageIsOrContains('Out of range longitude value, longitude must be between -180 and 180, got "240W".'); - new MultiLineString([[['240W', '340S', 0], ['45W', '45N', -1], ['45W', '90N', 42.195]]]); + new MultiLineStringImmutable([[['240W', '340S', 0], ['45W', '45N', -1], ['45W', '90N', 42.195]]]); } /** @@ -52,7 +52,7 @@ public function testConstructorWithGeodesicPoints(): void */ public function testGetDimension(): void { - $multiLineString = new MultiLineString([[[1, 2, -3], [3, 4, 5], [3, 6, 42.195], [1, 2, -3]]]); + $multiLineString = new MultiLineStringImmutable([[[1, 2, -3], [3, 4, 5], [3, 6, 42.195], [1, 2, -3]]]); static::assertTrue($multiLineString->hasZ()); static::assertFalse($multiLineString->hasM()); $ring = $multiLineString->getLineString(0); @@ -70,7 +70,7 @@ public function testGetDimension(): void public function testGetFamily(): void { $expected = SpatialModelEnum::GEOGRAPHY; - $multiLineString = new MultiLineString([[[1, 2, -3], [3, 4, 5], [3, 6, 42.195], [1, 2, -3]]]); + $multiLineString = new MultiLineStringImmutable([[[1, 2, -3], [3, 4, 5], [3, 6, 42.195], [1, 2, -3]]]); static::assertSame($expected, $multiLineString->getFamily()); $ring = $multiLineString->getLineString(0); static::assertSame($expected, $ring->getFamily()); @@ -84,7 +84,7 @@ public function testGetFamily(): void */ public function testGetType(): void { - $multiLineString = new MultiLineString([[[1, 2, -3], [3, 4, 5], [3, 6, 42.195], [1, 2, -3]]]); + $multiLineString = new MultiLineStringImmutable([[[1, 2, -3], [3, 4, 5], [3, 6, 42.195], [1, 2, -3]]]); static::assertSame(GeometryTypeEnum::MULTILINESTRING, $multiLineString->getType()); } @@ -93,10 +93,10 @@ public function testGetType(): void */ public function testIsEmpty(): void { - $multiLineString = new MultiLineString([]); + $multiLineString = new MultiLineStringImmutable([]); static::assertTrue($multiLineString->isEmpty()); - $multiLineString = new MultiLineString([[[1, 2, -3], [3, 4, 5], [3, 6, 42.195], [1, 2, -3]]]); + $multiLineString = new MultiLineStringImmutable([[[1, 2, -3], [3, 4, 5], [3, 6, 42.195], [1, 2, -3]]]); static::assertFalse($multiLineString->isEmpty()); } @@ -105,9 +105,9 @@ public function testIsEmpty(): void */ public function testJsonSerialize(): void { - $multiLineString = new MultiLineString([[[1, 2, -3], [3, 4, 5], [3, 6, 42.195], [1, 2, -3]]]); + $multiLineString = new MultiLineStringImmutable([[[1, 2, -3], [3, 4, 5], [3, 6, 42.195], [1, 2, -3]]]); static::assertSame('{"type":"MultiLineString","coordinates":[[[1,2,-3],[3,4,5],[3,6,42.195],[1,2,-3]]],"srid":0}', json_encode($multiLineString)); - $multiLineString = new MultiLineString([[[1, 2, -3], [3, 4, 5], [3, 6, 42.195], [1, 2, -3]]], 4326); + $multiLineString = new MultiLineStringImmutable([[[1, 2, -3], [3, 4, 5], [3, 6, 42.195], [1, 2, -3]]], 4326); static::assertSame('{"type":"MultiLineString","coordinates":[[[1,2,-3],[3,4,5],[3,6,42.195],[1,2,-3]]],"srid":4326}', json_encode($multiLineString)); } } diff --git a/tests/Unit/Types/Dimension3dz/Geography/MultiPolygonTest.php b/tests/Unit/Types/Dimension3dz/Geography/MultiPolygonTest.php index bdbf7ce..6587868 100644 --- a/tests/Unit/Types/Dimension3dz/Geography/MultiPolygonTest.php +++ b/tests/Unit/Types/Dimension3dz/Geography/MultiPolygonTest.php @@ -20,7 +20,7 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\SpatialTypeExceptionInterface; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPolygon; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPolygonImmutable; use PHPUnit\Framework\TestCase; /** @@ -28,9 +28,9 @@ * * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiPolygon - * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialType - * @covers \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPolygon + * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiPolygonImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialTypeImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPolygonImmutable */ class MultiPolygonTest extends TestCase { @@ -45,7 +45,7 @@ public function testConstructorWithGeodesicPoints(): void { self::expectException(InvalidValueException::class); self::expectExceptionMessageIsOrContains('Out of range longitude value, longitude must be between -180 and 180, got "240W".'); - new MultiPolygon([[[['240W', '340S', 3], ['45W', '45N', 4], ['45W', '90N', 42.195], ['240W', '340S']]]]); + new MultiPolygonImmutable([[[['240W', '340S', 3], ['45W', '45N', 4], ['45W', '90N', 42.195], ['240W', '340S']]]]); } /** @@ -53,7 +53,7 @@ public function testConstructorWithGeodesicPoints(): void */ public function testGetDimension(): void { - $multiPolygon = new MultiPolygon(self::DEFAULT_COORDINATE); + $multiPolygon = new MultiPolygonImmutable(self::DEFAULT_COORDINATE); static::assertTrue($multiPolygon->hasZ()); static::assertFalse($multiPolygon->hasM()); $polygon = $multiPolygon->getPolygon(0); @@ -71,7 +71,7 @@ public function testGetDimension(): void public function testGetFamily(): void { $expected = SpatialModelEnum::GEOGRAPHY; - $multiPolygon = new MultiPolygon(self::DEFAULT_COORDINATE); + $multiPolygon = new MultiPolygonImmutable(self::DEFAULT_COORDINATE); static::assertSame($expected, $multiPolygon->getFamily()); $polygon = $multiPolygon->getPolygon(0); static::assertSame($expected, $polygon->getFamily()); @@ -85,7 +85,7 @@ public function testGetFamily(): void */ public function testGetType(): void { - $multiPolygon = new MultiPolygon(self::DEFAULT_COORDINATE); + $multiPolygon = new MultiPolygonImmutable(self::DEFAULT_COORDINATE); static::assertSame(GeometryTypeEnum::MULTIPOLYGON, $multiPolygon->getType()); } @@ -94,9 +94,9 @@ public function testGetType(): void */ public function testJsonSerialize(): void { - $multiPolygon = new MultiPolygon(self::DEFAULT_COORDINATE); + $multiPolygon = new MultiPolygonImmutable(self::DEFAULT_COORDINATE); static::assertSame('{"type":"MultiPolygon","coordinates":[[[[1,2,3],[3,4,5],[3,6,42.195],[1,2,3]]]],"srid":0}', json_encode($multiPolygon)); - $multiPolygon = new MultiPolygon(self::DEFAULT_COORDINATE, 4326); + $multiPolygon = new MultiPolygonImmutable(self::DEFAULT_COORDINATE, 4326); static::assertSame('{"type":"MultiPolygon","coordinates":[[[[1,2,3],[3,4,5],[3,6,42.195],[1,2,3]]]],"srid":4326}', json_encode($multiPolygon)); } } diff --git a/tests/Unit/Types/Dimension3dz/Geography/PointTest.php b/tests/Unit/Types/Dimension3dz/Geography/PointTest.php index b57fb41..429678b 100644 --- a/tests/Unit/Types/Dimension3dz/Geography/PointTest.php +++ b/tests/Unit/Types/Dimension3dz/Geography/PointTest.php @@ -19,7 +19,7 @@ use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Exception\BadMethodCallException; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PointImmutable; use PHPUnit\Framework\TestCase; /** @@ -27,16 +27,16 @@ * * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractPoint - * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialType - * @covers \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point + * @covers \LongitudeOne\SpatialTypes\Types\AbstractPointImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialTypeImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PointImmutable */ class PointTest extends TestCase { /** * Point instance. */ - private Point $point; + private PointImmutable $point; /** * Set up the point instance. @@ -44,7 +44,7 @@ class PointTest extends TestCase protected function setUp(): void { parent::setUp(); - $this->point = new Point('1.1W', '45.1N', 42.195); + $this->point = new PointImmutable('1.1W', '45.1N', 42.195); } /** @@ -52,7 +52,7 @@ protected function setUp(): void */ public function testConstructsLatitude(): void { - static::assertSame(45.1, (new Point(-1.1, '45.1N', 42.195))->getY()); + static::assertSame(45.1, (new PointImmutable(-1.1, '45.1N', 42.195))->getY()); } /** @@ -60,7 +60,7 @@ public function testConstructsLatitude(): void */ public function testConstructsLongitude(): void { - static::assertSame(-1.1, (new Point('1.1W', 45.1, 42.195))->getX()); + static::assertSame(-1.1, (new PointImmutable('1.1W', 45.1, 42.195))->getX()); } /** @@ -93,7 +93,7 @@ public function testGetLongitude(): void public function testGetM(): void { self::expectException(BadMethodCallException::class); - self::expectExceptionMessageIsOrContains('The method "LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point::getM" cannot be called with a spatial object with dimensions "XYZ".'); + self::expectExceptionMessageIsOrContains('The method "LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PointImmutable::getM" cannot be called with a spatial object with dimensions "XYZ".'); $this->point->getM(); } @@ -152,7 +152,7 @@ public function testHasZ(): void public function testJsonSerialize(): void { static::assertSame('{"type":"Point","coordinates":[-1.1,45.1,42.195],"srid":0}', json_encode($this->point)); - $this->point = new Point(-1.1, 45.1, 42.195, 4326); + $this->point = new PointImmutable(-1.1, 45.1, 42.195, 4326); static::assertSame('{"type":"Point","coordinates":[-1.1,45.1,42.195],"srid":4326}', json_encode($this->point)); } diff --git a/tests/Unit/Types/Dimension3dz/Geography/PolygonTest.php b/tests/Unit/Types/Dimension3dz/Geography/PolygonTest.php index 952491c..c1968ee 100644 --- a/tests/Unit/Types/Dimension3dz/Geography/PolygonTest.php +++ b/tests/Unit/Types/Dimension3dz/Geography/PolygonTest.php @@ -20,7 +20,7 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Exception\SpatialTypeExceptionInterface; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Polygon; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PolygonImmutable; use PHPUnit\Framework\TestCase; /** @@ -29,9 +29,9 @@ * @internal * * @covers \LongitudeOne\SpatialTypes\Boundary\PolygonBoundary - * @covers \LongitudeOne\SpatialTypes\Types\AbstractPolygon - * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialType - * @covers \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Polygon + * @covers \LongitudeOne\SpatialTypes\Types\AbstractPolygonImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialTypeImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PolygonImmutable */ class PolygonTest extends TestCase { @@ -46,7 +46,7 @@ public function testConstructorWithGeodesicPoints(): void { self::expectException(InvalidValueException::class); self::expectExceptionMessageIsOrContains('g'); - new Polygon([[['240W', '340S', -3], ['45W', '45N', 5], ['45W', '90N', 0], ['240W', '340S', -3]]]); + new PolygonImmutable([[['240W', '340S', -3], ['45W', '45N', 5], ['45W', '90N', 0], ['240W', '340S', -3]]]); } /** @@ -54,7 +54,7 @@ public function testConstructorWithGeodesicPoints(): void */ public function testGetDimension(): void { - $polygon = new Polygon(self::DEFAULT_COORDINATES); + $polygon = new PolygonImmutable(self::DEFAULT_COORDINATES); static::assertTrue($polygon->hasZ()); static::assertFalse($polygon->hasM()); $ring = $polygon->getRing(0); @@ -72,7 +72,7 @@ public function testGetDimension(): void public function testGetFamily(): void { $expected = SpatialModelEnum::GEOGRAPHY; - $polygon = new Polygon(self::DEFAULT_COORDINATES); + $polygon = new PolygonImmutable(self::DEFAULT_COORDINATES); static::assertSame($expected, $polygon->getFamily()); $ring = $polygon->getRing(0); static::assertSame($expected, $ring->getFamily()); @@ -86,7 +86,7 @@ public function testGetFamily(): void */ public function testGetType(): void { - $polygon = new Polygon(self::DEFAULT_COORDINATES); + $polygon = new PolygonImmutable(self::DEFAULT_COORDINATES); static::assertSame(GeometryTypeEnum::POLYGON, $polygon->getType()); } @@ -95,9 +95,9 @@ public function testGetType(): void */ public function testJsonSerialize(): void { - $polygon = new Polygon(self::DEFAULT_COORDINATES); + $polygon = new PolygonImmutable(self::DEFAULT_COORDINATES); static::assertSame('{"type":"Polygon","coordinates":[[[1,2,-3],[3,4,5],[3,6,42.195],[1,2,-3]]],"srid":0}', json_encode($polygon)); - $polygon = new Polygon(self::DEFAULT_COORDINATES, 4326); + $polygon = new PolygonImmutable(self::DEFAULT_COORDINATES, 4326); static::assertSame('{"type":"Polygon","coordinates":[[[1,2,-3],[3,4,5],[3,6,42.195],[1,2,-3]]],"srid":4326}', json_encode($polygon)); } } diff --git a/tests/Unit/Types/Dimension3dz/Geometry/PointTest.php b/tests/Unit/Types/Dimension3dz/Geometry/PointTest.php index fa8abc7..f8911f6 100644 --- a/tests/Unit/Types/Dimension3dz/Geometry/PointTest.php +++ b/tests/Unit/Types/Dimension3dz/Geometry/PointTest.php @@ -20,23 +20,23 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Exception\BadMethodCallException; use LongitudeOne\SpatialTypes\Exception\InvalidValueException; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PointImmutable; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractPoint - * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialType - * @covers \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point + * @covers \LongitudeOne\SpatialTypes\Types\AbstractPointImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialTypeImmutable + * @covers \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PointImmutable */ class PointTest extends TestCase { /** * Point instance. */ - private Point $point; + private PointImmutable $point; /** * Set up the point instance. @@ -46,7 +46,7 @@ class PointTest extends TestCase protected function setUp(): void { parent::setUp(); - $this->point = new Point(1, 2, 3); + $this->point = new PointImmutable(1, 2, 3); } /** @@ -54,23 +54,23 @@ protected function setUp(): void */ public function testEqualsTo(): void { - $point = new Point(1, 2, 3); + $point = new PointImmutable(1, 2, 3); static::assertTrue($this->point->equalsTo($point)); static::assertTrue($point->equalsTo($this->point)); - $point = new Point(1, 2, 3, 4326); + $point = new PointImmutable(1, 2, 3, 4326); static::assertFalse($this->point->equalsTo($point)); static::assertFalse($point->equalsTo($this->point)); - $this->point = new Point(1, 2, 3, 4326); + $this->point = new PointImmutable(1, 2, 3, 4326); static::assertTrue($this->point->equalsTo($point)); static::assertTrue($point->equalsTo($this->point)); - $point = new Point(3, 2, 3, 4326); + $point = new PointImmutable(3, 2, 3, 4326); static::assertFalse($this->point->equalsTo($point)); static::assertFalse($point->equalsTo($this->point)); - $point = new Point(1, 3, 3, 4326); + $point = new PointImmutable(1, 3, 3, 4326); static::assertFalse($this->point->equalsTo($point)); static::assertFalse($point->equalsTo($this->point)); } @@ -105,7 +105,7 @@ public function testGetLongitude(): void public function testGetM(): void { self::expectException(BadMethodCallException::class); - self::expectExceptionMessageIsOrContains('The method "LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point::getM" cannot be called with a spatial object with dimensions "XYZ".'); + self::expectExceptionMessageIsOrContains('The method "LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PointImmutable::getM" cannot be called with a spatial object with dimensions "XYZ".'); $this->point->getM(); } @@ -163,7 +163,7 @@ public function testHasZ(): void public function testJsonSerialize(): void { static::assertSame('{"type":"Point","coordinates":[1,2,3],"srid":0}', json_encode($this->point)); - $this->point = new Point(1, 2, 3, 4326); + $this->point = new PointImmutable(1, 2, 3, 4326); static::assertSame('{"type":"Point","coordinates":[1,2,3],"srid":4326}', json_encode($this->point)); } @@ -180,12 +180,12 @@ public function testJsonSerialize(): void public function testOutOfRange(string $longitude, string $latitude, string $expectedMessage): void { // No exception - new Point(181, 91, 0); - new Point('181', '91', 0); + new PointImmutable(181, 91, 0); + new PointImmutable('181', '91', 0); self::expectException(InvalidValueException::class); self::expectExceptionMessageIsOrContains($expectedMessage); - new Point($longitude, $latitude, 0); + new PointImmutable($longitude, $latitude, 0); } /** diff --git a/tests/Unit/Types/Dimension3m/Geography/CircularStringTest.php b/tests/Unit/Types/Dimension3m/Geography/CircularStringTest.php index d6429b9..f639f70 100644 --- a/tests/Unit/Types/Dimension3m/Geography/CircularStringTest.php +++ b/tests/Unit/Types/Dimension3m/Geography/CircularStringTest.php @@ -21,8 +21,8 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Interfaces\CircularStringInterface; use LongitudeOne\SpatialTypes\Interfaces\CurveInterface; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Point; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\PointImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\TestCase; @@ -38,7 +38,7 @@ class CircularStringTest extends TestCase /** Empty values retain their declared layout and reference. */ public function testEmpty(): void { - $curve = new CircularString([], 4326); + $curve = new CircularStringImmutable([], 4326); static::assertTrue($curve->isEmpty()); static::assertSame([], $curve->getPoints()); @@ -51,10 +51,10 @@ public function testEmpty(): void /** Immutable replacement preserves this concrete layout and family. */ public function testReplacePoint(): void { - $curve = new CircularString([[0, 0, 3], [1, 1, 4], [2, 0, 5]], 4326); + $curve = new CircularStringImmutable([[0, 0, 3], [1, 1, 4], [2, 0, 5]], 4326); $replacement = $curve->withPoint(1, Coordinates::xym(1, 2, 8)); - static::assertSame(CircularString::class, $replacement::class); + static::assertSame(CircularStringImmutable::class, (new \ReflectionClass($replacement))->getName()); static::assertSame([[0, 0, 3], [1, 1, 4], [2, 0, 5]], $curve->toArray()); static::assertSame([[0, 0, 3], [1, 2, 8], [2, 0, 5]], $replacement->toArray()); static::assertSame(4326, $replacement->getPoint(1)->getSrid()); @@ -64,7 +64,7 @@ public function testReplacePoint(): void /** Three defining points retain circular interpolation and their ordinates. */ public function testSingleArc(): void { - $curve = new CircularString([[0, 0, 3], [1, 1, 4], [2, 0, 5]], 4326); + $curve = new CircularStringImmutable([[0, 0, 3], [1, 1, 4], [2, 0, 5]], 4326); static::assertContains(CurveInterface::class, class_implements($curve)); static::assertContains(CircularStringInterface::class, class_implements($curve)); @@ -75,7 +75,7 @@ public function testSingleArc(): void static::assertSame([[0, 0, 3], [1, 1, 4], [2, 0, 5]], $curve->toArray()); static::assertCount(3, $curve->getPoints()); static::assertSame($curve->getPoints(), $curve->getElements()); - static::assertInstanceOf(Point::class, $curve->getPoint(0)); + static::assertInstanceOf(PointImmutable::class, $curve->getPoint(0)); static::assertSame(4326, $curve->getPoint(-1)->getSrid()); static::assertSame($curve->getPoint(2), $curve->getPoint(-1)); static::assertSame($curve->getPoint(0), $curve->getPoint(3)); diff --git a/tests/Unit/Types/Dimension3m/Geography/CompoundCurveTest.php b/tests/Unit/Types/Dimension3m/Geography/CompoundCurveTest.php index 814f491..24de59c 100644 --- a/tests/Unit/Types/Dimension3m/Geography/CompoundCurveTest.php +++ b/tests/Unit/Types/Dimension3m/Geography/CompoundCurveTest.php @@ -22,9 +22,9 @@ use LongitudeOne\SpatialTypes\Interfaces\CompoundCurveInterface; use LongitudeOne\SpatialTypes\Interfaces\CurveInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\CompoundCurve; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\LineString; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\CompoundCurveImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\LineStringImmutable; use PHPUnit\Framework\TestCase; /** @@ -39,9 +39,9 @@ class CompoundCurveTest extends TestCase /** Empty compounds and component curves expose the common empty contract. */ public function testEmptyCurves(): void { - $compound = new CompoundCurve([], 4326); - $line = new LineString([], 4326); - $circular = new CircularString([], 4326); + $compound = new CompoundCurveImmutable([], 4326); + $line = new LineStringImmutable([], 4326); + $circular = new CircularStringImmutable([], 4326); static::assertTrue($compound->isEmpty()); static::assertNull($compound->getStartPoint()); @@ -63,9 +63,9 @@ public function testEmptyCurves(): void /** Mixed interpolation, order and closure survive through public contracts. */ public function testMixedClosedCurve(): void { - $circular = new CircularString([[0, 0, 6], [1, 1, 7], [2, 0, 8]], 4326); - $line = new LineString([[2, 0, 8], [0, 0, 6]], 4326); - $compound = new CompoundCurve([$circular, $line], 4326); + $circular = new CircularStringImmutable([[0, 0, 6], [1, 1, 7], [2, 0, 8]], 4326); + $line = new LineStringImmutable([[2, 0, 8], [0, 0, 6]], 4326); + $compound = new CompoundCurveImmutable([$circular, $line], 4326); static::assertContains(CompoundCurveInterface::class, class_implements($compound)); static::assertContains(CurveInterface::class, class_implements($compound)); @@ -91,13 +91,13 @@ public function testMixedClosedCurve(): void /** Reference changes deeply copy components and preserve defining ordinates. */ public function testReferenceReplacement(): void { - $compound = new CompoundCurve([ - new CircularString([[0, 0, 6], [1, 1, 7], [2, 0, 8]], SpatialReference::epsg(4326)), - new LineString([[2, 0, 8], [0, 0, 6]], SpatialReference::epsg(4326)), + $compound = new CompoundCurveImmutable([ + new CircularStringImmutable([[0, 0, 6], [1, 1, 7], [2, 0, 8]], SpatialReference::epsg(4326)), + new LineStringImmutable([[2, 0, 8], [0, 0, 6]], SpatialReference::epsg(4326)), ], SpatialReference::epsg(4326)); $copy = $compound->withSpatialReference(SpatialReference::epsg(3857)); - static::assertSame(CompoundCurve::class, $copy::class); + static::assertSame(CompoundCurveImmutable::class, (new \ReflectionClass($copy))->getName()); static::assertSame(4326, $compound->getSrid()); static::assertSame(4326, $compound->getCurve(0)->getSrid()); static::assertSame(3857, $copy->getSrid()); @@ -108,8 +108,8 @@ public function testReferenceReplacement(): void static::assertNotSame($compound->getStartPoint(), $copy->getStartPoint()); static::assertSame([[[0, 0, 6], [1, 1, 7], [2, 0, 8]], [[2, 0, 8], [0, 0, 6]]], $compound->toArray()); static::assertSame([[[0, 0, 6], [1, 1, 7], [2, 0, 8]], [[2, 0, 8], [0, 0, 6]]], $copy->toArray()); - static::assertInstanceOf(CircularString::class, $copy->getCurve(0)); - static::assertInstanceOf(LineString::class, $copy->getCurve(1)); + static::assertInstanceOf(CircularStringImmutable::class, $copy->getCurve(0)); + static::assertInstanceOf(LineStringImmutable::class, $copy->getCurve(1)); static::assertTrue($copy->isClosed()); } } diff --git a/tests/Unit/Types/Dimension3m/Geometry/CircularStringTest.php b/tests/Unit/Types/Dimension3m/Geometry/CircularStringTest.php index ec5e874..264d375 100644 --- a/tests/Unit/Types/Dimension3m/Geometry/CircularStringTest.php +++ b/tests/Unit/Types/Dimension3m/Geometry/CircularStringTest.php @@ -21,8 +21,8 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Interfaces\CircularStringInterface; use LongitudeOne\SpatialTypes\Interfaces\CurveInterface; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\PointImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\TestCase; @@ -38,7 +38,7 @@ class CircularStringTest extends TestCase /** Empty values retain their declared layout and reference. */ public function testEmpty(): void { - $curve = new CircularString([], 4326); + $curve = new CircularStringImmutable([], 4326); static::assertTrue($curve->isEmpty()); static::assertSame([], $curve->getPoints()); @@ -51,10 +51,10 @@ public function testEmpty(): void /** Immutable replacement preserves this concrete layout and family. */ public function testReplacePoint(): void { - $curve = new CircularString([[0, 0, 3], [1, 1, 4], [2, 0, 5]], 4326); + $curve = new CircularStringImmutable([[0, 0, 3], [1, 1, 4], [2, 0, 5]], 4326); $replacement = $curve->withPoint(1, Coordinates::xym(1, 2, 8)); - static::assertSame(CircularString::class, $replacement::class); + static::assertSame(CircularStringImmutable::class, (new \ReflectionClass($replacement))->getName()); static::assertSame([[0, 0, 3], [1, 1, 4], [2, 0, 5]], $curve->toArray()); static::assertSame([[0, 0, 3], [1, 2, 8], [2, 0, 5]], $replacement->toArray()); static::assertSame(4326, $replacement->getPoint(1)->getSrid()); @@ -64,7 +64,7 @@ public function testReplacePoint(): void /** Three defining points retain circular interpolation and their ordinates. */ public function testSingleArc(): void { - $curve = new CircularString([[0, 0, 3], [1, 1, 4], [2, 0, 5]], 4326); + $curve = new CircularStringImmutable([[0, 0, 3], [1, 1, 4], [2, 0, 5]], 4326); static::assertContains(CurveInterface::class, class_implements($curve)); static::assertContains(CircularStringInterface::class, class_implements($curve)); @@ -75,7 +75,7 @@ public function testSingleArc(): void static::assertSame([[0, 0, 3], [1, 1, 4], [2, 0, 5]], $curve->toArray()); static::assertCount(3, $curve->getPoints()); static::assertSame($curve->getPoints(), $curve->getElements()); - static::assertInstanceOf(Point::class, $curve->getPoint(0)); + static::assertInstanceOf(PointImmutable::class, $curve->getPoint(0)); static::assertSame(4326, $curve->getPoint(-1)->getSrid()); static::assertSame($curve->getPoint(2), $curve->getPoint(-1)); static::assertSame($curve->getPoint(0), $curve->getPoint(3)); diff --git a/tests/Unit/Types/Dimension3m/Geometry/CompoundCurveTest.php b/tests/Unit/Types/Dimension3m/Geometry/CompoundCurveTest.php index 85999f9..cd5daaf 100644 --- a/tests/Unit/Types/Dimension3m/Geometry/CompoundCurveTest.php +++ b/tests/Unit/Types/Dimension3m/Geometry/CompoundCurveTest.php @@ -22,9 +22,9 @@ use LongitudeOne\SpatialTypes\Interfaces\CompoundCurveInterface; use LongitudeOne\SpatialTypes\Interfaces\CurveInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\CompoundCurve; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\LineString; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\CompoundCurveImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\LineStringImmutable; use PHPUnit\Framework\TestCase; /** @@ -39,9 +39,9 @@ class CompoundCurveTest extends TestCase /** Empty compounds and component curves expose the common empty contract. */ public function testEmptyCurves(): void { - $compound = new CompoundCurve([], 4326); - $line = new LineString([], 4326); - $circular = new CircularString([], 4326); + $compound = new CompoundCurveImmutable([], 4326); + $line = new LineStringImmutable([], 4326); + $circular = new CircularStringImmutable([], 4326); static::assertTrue($compound->isEmpty()); static::assertNull($compound->getStartPoint()); @@ -63,9 +63,9 @@ public function testEmptyCurves(): void /** Mixed interpolation, order and closure survive through public contracts. */ public function testMixedClosedCurve(): void { - $circular = new CircularString([[0, 0, 6], [1, 1, 7], [2, 0, 8]], 4326); - $line = new LineString([[2, 0, 8], [0, 0, 6]], 4326); - $compound = new CompoundCurve([$circular, $line], 4326); + $circular = new CircularStringImmutable([[0, 0, 6], [1, 1, 7], [2, 0, 8]], 4326); + $line = new LineStringImmutable([[2, 0, 8], [0, 0, 6]], 4326); + $compound = new CompoundCurveImmutable([$circular, $line], 4326); static::assertContains(CompoundCurveInterface::class, class_implements($compound)); static::assertContains(CurveInterface::class, class_implements($compound)); @@ -91,13 +91,13 @@ public function testMixedClosedCurve(): void /** Reference changes deeply copy components and preserve defining ordinates. */ public function testReferenceReplacement(): void { - $compound = new CompoundCurve([ - new CircularString([[0, 0, 6], [1, 1, 7], [2, 0, 8]], SpatialReference::epsg(4326)), - new LineString([[2, 0, 8], [0, 0, 6]], SpatialReference::epsg(4326)), + $compound = new CompoundCurveImmutable([ + new CircularStringImmutable([[0, 0, 6], [1, 1, 7], [2, 0, 8]], SpatialReference::epsg(4326)), + new LineStringImmutable([[2, 0, 8], [0, 0, 6]], SpatialReference::epsg(4326)), ], SpatialReference::epsg(4326)); $copy = $compound->withSpatialReference(SpatialReference::epsg(3857)); - static::assertSame(CompoundCurve::class, $copy::class); + static::assertSame(CompoundCurveImmutable::class, (new \ReflectionClass($copy))->getName()); static::assertSame(4326, $compound->getSrid()); static::assertSame(4326, $compound->getCurve(0)->getSrid()); static::assertSame(3857, $copy->getSrid()); @@ -108,8 +108,8 @@ public function testReferenceReplacement(): void static::assertNotSame($compound->getStartPoint(), $copy->getStartPoint()); static::assertSame([[[0, 0, 6], [1, 1, 7], [2, 0, 8]], [[2, 0, 8], [0, 0, 6]]], $compound->toArray()); static::assertSame([[[0, 0, 6], [1, 1, 7], [2, 0, 8]], [[2, 0, 8], [0, 0, 6]]], $copy->toArray()); - static::assertInstanceOf(CircularString::class, $copy->getCurve(0)); - static::assertInstanceOf(LineString::class, $copy->getCurve(1)); + static::assertInstanceOf(CircularStringImmutable::class, $copy->getCurve(0)); + static::assertInstanceOf(LineStringImmutable::class, $copy->getCurve(1)); static::assertTrue($copy->isClosed()); } } diff --git a/tests/Unit/Types/Dimension3m/SpatialTypesTest.php b/tests/Unit/Types/Dimension3m/SpatialTypesTest.php index 10de1a4..525fa16 100644 --- a/tests/Unit/Types/Dimension3m/SpatialTypesTest.php +++ b/tests/Unit/Types/Dimension3m/SpatialTypesTest.php @@ -18,20 +18,20 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Exception\BadMethodCallException; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\GeographyCollection; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\LineString as GeographicLineString; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiLineString as GeographicMultiLineString; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPoint as GeographicMultiPoint; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPolygon as GeographicMultiPolygon; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Point as GeographicPoint; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Polygon as GeographicPolygon; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\GeometryCollection; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\LineString as GeometricLineString; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiLineString as GeometricMultiLineString; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPoint as GeometricMultiPoint; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPolygon as GeometricMultiPolygon; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Point as GeometricPoint; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Polygon as GeometricPolygon; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\GeographyCollectionImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\LineStringImmutable as GeographicLineString; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiLineStringImmutable as GeographicMultiLineString; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPointImmutable as GeographicMultiPoint; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPolygonImmutable as GeographicMultiPolygon; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\PointImmutable as GeographicPoint; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\PolygonImmutable as GeographicPolygon; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\GeometryCollectionImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\LineStringImmutable as GeometricLineString; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiLineStringImmutable as GeometricMultiLineString; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPointImmutable as GeometricMultiPoint; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPolygonImmutable as GeometricMultiPolygon; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\PointImmutable as GeometricPoint; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\PolygonImmutable as GeometricPolygon; use PHPUnit\Framework\TestCase; /** @@ -61,7 +61,7 @@ public function testGeographicXymTypes(): void static::assertSame([$lineString], (new GeographicMultiLineString([$lineString]))->getElements()); static::assertSame([$polygon], (new GeographicMultiPolygon([$polygon]))->getElements()); - $collection = new GeographyCollection(0, [$polygon]); + $collection = new GeographyCollectionImmutable(0, [$polygon]); static::assertSame([$polygon], $collection->getElements()); } @@ -85,7 +85,7 @@ public function testGeometricXymTypes(): void static::assertSame([$lineString], (new GeometricMultiLineString([$lineString]))->getElements()); static::assertSame([$polygon], (new GeometricMultiPolygon([$polygon]))->getElements()); - $collection = new GeometryCollection(0, [$polygon]); + $collection = new GeometryCollectionImmutable(0, [$polygon]); static::assertSame([$polygon], $collection->getElements()); } diff --git a/tests/Unit/Types/Dimension3m/XymContractTest.php b/tests/Unit/Types/Dimension3m/XymContractTest.php index e870688..1cfcd39 100644 --- a/tests/Unit/Types/Dimension3m/XymContractTest.php +++ b/tests/Unit/Types/Dimension3m/XymContractTest.php @@ -16,8 +16,8 @@ namespace LongitudeOne\SpatialTypes\Tests\Unit\Types\Dimension3m; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Point as GeographicPoint; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Point as GeometricPoint; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\PointImmutable as GeographicPoint; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\PointImmutable as GeometricPoint; use PHPUnit\Framework\TestCase; /** diff --git a/tests/Unit/Types/Dimension3z/Geography/CircularStringTest.php b/tests/Unit/Types/Dimension3z/Geography/CircularStringTest.php index 7e17c14..12f85e2 100644 --- a/tests/Unit/Types/Dimension3z/Geography/CircularStringTest.php +++ b/tests/Unit/Types/Dimension3z/Geography/CircularStringTest.php @@ -21,8 +21,8 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Interfaces\CircularStringInterface; use LongitudeOne\SpatialTypes\Interfaces\CurveInterface; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PointImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\TestCase; @@ -38,7 +38,7 @@ class CircularStringTest extends TestCase /** Empty values retain their declared layout and reference. */ public function testEmpty(): void { - $curve = new CircularString([], 4326); + $curve = new CircularStringImmutable([], 4326); static::assertTrue($curve->isEmpty()); static::assertSame([], $curve->getPoints()); @@ -51,10 +51,10 @@ public function testEmpty(): void /** Immutable replacement preserves this concrete layout and family. */ public function testReplacePoint(): void { - $curve = new CircularString([[0, 0, 3], [1, 1, 4], [2, 0, 5]], 4326); + $curve = new CircularStringImmutable([[0, 0, 3], [1, 1, 4], [2, 0, 5]], 4326); $replacement = $curve->withPoint(1, Coordinates::xyz(1, 2, 8)); - static::assertSame(CircularString::class, $replacement::class); + static::assertSame(CircularStringImmutable::class, (new \ReflectionClass($replacement))->getName()); static::assertSame([[0, 0, 3], [1, 1, 4], [2, 0, 5]], $curve->toArray()); static::assertSame([[0, 0, 3], [1, 2, 8], [2, 0, 5]], $replacement->toArray()); static::assertSame(4326, $replacement->getPoint(1)->getSrid()); @@ -64,7 +64,7 @@ public function testReplacePoint(): void /** Three defining points retain circular interpolation and their ordinates. */ public function testSingleArc(): void { - $curve = new CircularString([[0, 0, 3], [1, 1, 4], [2, 0, 5]], 4326); + $curve = new CircularStringImmutable([[0, 0, 3], [1, 1, 4], [2, 0, 5]], 4326); static::assertContains(CurveInterface::class, class_implements($curve)); static::assertContains(CircularStringInterface::class, class_implements($curve)); @@ -75,7 +75,7 @@ public function testSingleArc(): void static::assertSame([[0, 0, 3], [1, 1, 4], [2, 0, 5]], $curve->toArray()); static::assertCount(3, $curve->getPoints()); static::assertSame($curve->getPoints(), $curve->getElements()); - static::assertInstanceOf(Point::class, $curve->getPoint(0)); + static::assertInstanceOf(PointImmutable::class, $curve->getPoint(0)); static::assertSame(4326, $curve->getPoint(-1)->getSrid()); static::assertSame($curve->getPoint(2), $curve->getPoint(-1)); static::assertSame($curve->getPoint(0), $curve->getPoint(3)); diff --git a/tests/Unit/Types/Dimension3z/Geography/CompoundCurveTest.php b/tests/Unit/Types/Dimension3z/Geography/CompoundCurveTest.php index ff9c796..db2f76c 100644 --- a/tests/Unit/Types/Dimension3z/Geography/CompoundCurveTest.php +++ b/tests/Unit/Types/Dimension3z/Geography/CompoundCurveTest.php @@ -22,9 +22,9 @@ use LongitudeOne\SpatialTypes\Interfaces\CompoundCurveInterface; use LongitudeOne\SpatialTypes\Interfaces\CurveInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\CompoundCurve; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\LineString; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\CompoundCurveImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\LineStringImmutable; use PHPUnit\Framework\TestCase; /** @@ -39,9 +39,9 @@ class CompoundCurveTest extends TestCase /** Empty compounds and component curves expose the common empty contract. */ public function testEmptyCurves(): void { - $compound = new CompoundCurve([], 4326); - $line = new LineString([], 4326); - $circular = new CircularString([], 4326); + $compound = new CompoundCurveImmutable([], 4326); + $line = new LineStringImmutable([], 4326); + $circular = new CircularStringImmutable([], 4326); static::assertTrue($compound->isEmpty()); static::assertNull($compound->getStartPoint()); @@ -63,9 +63,9 @@ public function testEmptyCurves(): void /** Mixed interpolation, order and closure survive through public contracts. */ public function testMixedClosedCurve(): void { - $circular = new CircularString([[0, 0, 3], [1, 1, 4], [2, 0, 5]], 4326); - $line = new LineString([[2, 0, 5], [0, 0, 3]], 4326); - $compound = new CompoundCurve([$circular, $line], 4326); + $circular = new CircularStringImmutable([[0, 0, 3], [1, 1, 4], [2, 0, 5]], 4326); + $line = new LineStringImmutable([[2, 0, 5], [0, 0, 3]], 4326); + $compound = new CompoundCurveImmutable([$circular, $line], 4326); static::assertContains(CompoundCurveInterface::class, class_implements($compound)); static::assertContains(CurveInterface::class, class_implements($compound)); @@ -91,13 +91,13 @@ public function testMixedClosedCurve(): void /** Reference changes deeply copy components and preserve defining ordinates. */ public function testReferenceReplacement(): void { - $compound = new CompoundCurve([ - new CircularString([[0, 0, 3], [1, 1, 4], [2, 0, 5]], SpatialReference::epsg(4326)), - new LineString([[2, 0, 5], [0, 0, 3]], SpatialReference::epsg(4326)), + $compound = new CompoundCurveImmutable([ + new CircularStringImmutable([[0, 0, 3], [1, 1, 4], [2, 0, 5]], SpatialReference::epsg(4326)), + new LineStringImmutable([[2, 0, 5], [0, 0, 3]], SpatialReference::epsg(4326)), ], SpatialReference::epsg(4326)); $copy = $compound->withSpatialReference(SpatialReference::epsg(3857)); - static::assertSame(CompoundCurve::class, $copy::class); + static::assertSame(CompoundCurveImmutable::class, (new \ReflectionClass($copy))->getName()); static::assertSame(4326, $compound->getSrid()); static::assertSame(4326, $compound->getCurve(0)->getSrid()); static::assertSame(3857, $copy->getSrid()); @@ -108,8 +108,8 @@ public function testReferenceReplacement(): void static::assertNotSame($compound->getStartPoint(), $copy->getStartPoint()); static::assertSame([[[0, 0, 3], [1, 1, 4], [2, 0, 5]], [[2, 0, 5], [0, 0, 3]]], $compound->toArray()); static::assertSame([[[0, 0, 3], [1, 1, 4], [2, 0, 5]], [[2, 0, 5], [0, 0, 3]]], $copy->toArray()); - static::assertInstanceOf(CircularString::class, $copy->getCurve(0)); - static::assertInstanceOf(LineString::class, $copy->getCurve(1)); + static::assertInstanceOf(CircularStringImmutable::class, $copy->getCurve(0)); + static::assertInstanceOf(LineStringImmutable::class, $copy->getCurve(1)); static::assertTrue($copy->isClosed()); } } diff --git a/tests/Unit/Types/Dimension3z/Geometry/CircularStringTest.php b/tests/Unit/Types/Dimension3z/Geometry/CircularStringTest.php index 11bd104..65d9f7c 100644 --- a/tests/Unit/Types/Dimension3z/Geometry/CircularStringTest.php +++ b/tests/Unit/Types/Dimension3z/Geometry/CircularStringTest.php @@ -21,8 +21,8 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Interfaces\CircularStringInterface; use LongitudeOne\SpatialTypes\Interfaces\CurveInterface; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PointImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\TestCase; @@ -38,7 +38,7 @@ class CircularStringTest extends TestCase /** Empty values retain their declared layout and reference. */ public function testEmpty(): void { - $curve = new CircularString([], 4326); + $curve = new CircularStringImmutable([], 4326); static::assertTrue($curve->isEmpty()); static::assertSame([], $curve->getPoints()); @@ -51,10 +51,10 @@ public function testEmpty(): void /** Immutable replacement preserves this concrete layout and family. */ public function testReplacePoint(): void { - $curve = new CircularString([[0, 0, 3], [1, 1, 4], [2, 0, 5]], 4326); + $curve = new CircularStringImmutable([[0, 0, 3], [1, 1, 4], [2, 0, 5]], 4326); $replacement = $curve->withPoint(1, Coordinates::xyz(1, 2, 8)); - static::assertSame(CircularString::class, $replacement::class); + static::assertSame(CircularStringImmutable::class, (new \ReflectionClass($replacement))->getName()); static::assertSame([[0, 0, 3], [1, 1, 4], [2, 0, 5]], $curve->toArray()); static::assertSame([[0, 0, 3], [1, 2, 8], [2, 0, 5]], $replacement->toArray()); static::assertSame(4326, $replacement->getPoint(1)->getSrid()); @@ -64,7 +64,7 @@ public function testReplacePoint(): void /** Three defining points retain circular interpolation and their ordinates. */ public function testSingleArc(): void { - $curve = new CircularString([[0, 0, 3], [1, 1, 4], [2, 0, 5]], 4326); + $curve = new CircularStringImmutable([[0, 0, 3], [1, 1, 4], [2, 0, 5]], 4326); static::assertContains(CurveInterface::class, class_implements($curve)); static::assertContains(CircularStringInterface::class, class_implements($curve)); @@ -75,7 +75,7 @@ public function testSingleArc(): void static::assertSame([[0, 0, 3], [1, 1, 4], [2, 0, 5]], $curve->toArray()); static::assertCount(3, $curve->getPoints()); static::assertSame($curve->getPoints(), $curve->getElements()); - static::assertInstanceOf(Point::class, $curve->getPoint(0)); + static::assertInstanceOf(PointImmutable::class, $curve->getPoint(0)); static::assertSame(4326, $curve->getPoint(-1)->getSrid()); static::assertSame($curve->getPoint(2), $curve->getPoint(-1)); static::assertSame($curve->getPoint(0), $curve->getPoint(3)); diff --git a/tests/Unit/Types/Dimension3z/Geometry/CompoundCurveTest.php b/tests/Unit/Types/Dimension3z/Geometry/CompoundCurveTest.php index 07948a4..4b86b91 100644 --- a/tests/Unit/Types/Dimension3z/Geometry/CompoundCurveTest.php +++ b/tests/Unit/Types/Dimension3z/Geometry/CompoundCurveTest.php @@ -22,9 +22,9 @@ use LongitudeOne\SpatialTypes\Interfaces\CompoundCurveInterface; use LongitudeOne\SpatialTypes\Interfaces\CurveInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\CompoundCurve; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\LineString; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\CompoundCurveImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\LineStringImmutable; use PHPUnit\Framework\TestCase; /** @@ -39,9 +39,9 @@ class CompoundCurveTest extends TestCase /** Empty compounds and component curves expose the common empty contract. */ public function testEmptyCurves(): void { - $compound = new CompoundCurve([], 4326); - $line = new LineString([], 4326); - $circular = new CircularString([], 4326); + $compound = new CompoundCurveImmutable([], 4326); + $line = new LineStringImmutable([], 4326); + $circular = new CircularStringImmutable([], 4326); static::assertTrue($compound->isEmpty()); static::assertNull($compound->getStartPoint()); @@ -63,9 +63,9 @@ public function testEmptyCurves(): void /** Mixed interpolation, order and closure survive through public contracts. */ public function testMixedClosedCurve(): void { - $circular = new CircularString([[0, 0, 3], [1, 1, 4], [2, 0, 5]], 4326); - $line = new LineString([[2, 0, 5], [0, 0, 3]], 4326); - $compound = new CompoundCurve([$circular, $line], 4326); + $circular = new CircularStringImmutable([[0, 0, 3], [1, 1, 4], [2, 0, 5]], 4326); + $line = new LineStringImmutable([[2, 0, 5], [0, 0, 3]], 4326); + $compound = new CompoundCurveImmutable([$circular, $line], 4326); static::assertContains(CompoundCurveInterface::class, class_implements($compound)); static::assertContains(CurveInterface::class, class_implements($compound)); @@ -91,13 +91,13 @@ public function testMixedClosedCurve(): void /** Reference changes deeply copy components and preserve defining ordinates. */ public function testReferenceReplacement(): void { - $compound = new CompoundCurve([ - new CircularString([[0, 0, 3], [1, 1, 4], [2, 0, 5]], SpatialReference::epsg(4326)), - new LineString([[2, 0, 5], [0, 0, 3]], SpatialReference::epsg(4326)), + $compound = new CompoundCurveImmutable([ + new CircularStringImmutable([[0, 0, 3], [1, 1, 4], [2, 0, 5]], SpatialReference::epsg(4326)), + new LineStringImmutable([[2, 0, 5], [0, 0, 3]], SpatialReference::epsg(4326)), ], SpatialReference::epsg(4326)); $copy = $compound->withSpatialReference(SpatialReference::epsg(3857)); - static::assertSame(CompoundCurve::class, $copy::class); + static::assertSame(CompoundCurveImmutable::class, (new \ReflectionClass($copy))->getName()); static::assertSame(4326, $compound->getSrid()); static::assertSame(4326, $compound->getCurve(0)->getSrid()); static::assertSame(3857, $copy->getSrid()); @@ -108,8 +108,8 @@ public function testReferenceReplacement(): void static::assertNotSame($compound->getStartPoint(), $copy->getStartPoint()); static::assertSame([[[0, 0, 3], [1, 1, 4], [2, 0, 5]], [[2, 0, 5], [0, 0, 3]]], $compound->toArray()); static::assertSame([[[0, 0, 3], [1, 1, 4], [2, 0, 5]], [[2, 0, 5], [0, 0, 3]]], $copy->toArray()); - static::assertInstanceOf(CircularString::class, $copy->getCurve(0)); - static::assertInstanceOf(LineString::class, $copy->getCurve(1)); + static::assertInstanceOf(CircularStringImmutable::class, $copy->getCurve(0)); + static::assertInstanceOf(LineStringImmutable::class, $copy->getCurve(1)); static::assertTrue($copy->isClosed()); } } diff --git a/tests/Unit/Types/Dimension4zm/Geography/CircularStringTest.php b/tests/Unit/Types/Dimension4zm/Geography/CircularStringTest.php index ac486f7..8b5ef5c 100644 --- a/tests/Unit/Types/Dimension4zm/Geography/CircularStringTest.php +++ b/tests/Unit/Types/Dimension4zm/Geography/CircularStringTest.php @@ -21,8 +21,8 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Interfaces\CircularStringInterface; use LongitudeOne\SpatialTypes\Interfaces\CurveInterface; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Point; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PointImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\TestCase; @@ -38,7 +38,7 @@ class CircularStringTest extends TestCase /** Empty values retain their declared layout and reference. */ public function testEmpty(): void { - $curve = new CircularString([], 4326); + $curve = new CircularStringImmutable([], 4326); static::assertTrue($curve->isEmpty()); static::assertSame([], $curve->getPoints()); @@ -51,10 +51,10 @@ public function testEmpty(): void /** Immutable replacement preserves this concrete layout and family. */ public function testReplacePoint(): void { - $curve = new CircularString([[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], 4326); + $curve = new CircularStringImmutable([[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], 4326); $replacement = $curve->withPoint(1, Coordinates::xyzm(1, 2, 8, 9)); - static::assertSame(CircularString::class, $replacement::class); + static::assertSame(CircularStringImmutable::class, (new \ReflectionClass($replacement))->getName()); static::assertSame([[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], $curve->toArray()); static::assertSame([[0, 0, 3, 6], [1, 2, 8, 9], [2, 0, 5, 8]], $replacement->toArray()); static::assertSame(4326, $replacement->getPoint(1)->getSrid()); @@ -64,7 +64,7 @@ public function testReplacePoint(): void /** Three defining points retain circular interpolation and their ordinates. */ public function testSingleArc(): void { - $curve = new CircularString([[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], 4326); + $curve = new CircularStringImmutable([[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], 4326); static::assertContains(CurveInterface::class, class_implements($curve)); static::assertContains(CircularStringInterface::class, class_implements($curve)); @@ -75,7 +75,7 @@ public function testSingleArc(): void static::assertSame([[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], $curve->toArray()); static::assertCount(3, $curve->getPoints()); static::assertSame($curve->getPoints(), $curve->getElements()); - static::assertInstanceOf(Point::class, $curve->getPoint(0)); + static::assertInstanceOf(PointImmutable::class, $curve->getPoint(0)); static::assertSame(4326, $curve->getPoint(-1)->getSrid()); static::assertSame($curve->getPoint(2), $curve->getPoint(-1)); static::assertSame($curve->getPoint(0), $curve->getPoint(3)); diff --git a/tests/Unit/Types/Dimension4zm/Geography/CompoundCurveTest.php b/tests/Unit/Types/Dimension4zm/Geography/CompoundCurveTest.php index be3a679..c2679b7 100644 --- a/tests/Unit/Types/Dimension4zm/Geography/CompoundCurveTest.php +++ b/tests/Unit/Types/Dimension4zm/Geography/CompoundCurveTest.php @@ -22,9 +22,9 @@ use LongitudeOne\SpatialTypes\Interfaces\CompoundCurveInterface; use LongitudeOne\SpatialTypes\Interfaces\CurveInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\CompoundCurve; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\LineString; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\CompoundCurveImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\LineStringImmutable; use PHPUnit\Framework\TestCase; /** @@ -39,9 +39,9 @@ class CompoundCurveTest extends TestCase /** Empty compounds and component curves expose the common empty contract. */ public function testEmptyCurves(): void { - $compound = new CompoundCurve([], 4326); - $line = new LineString([], 4326); - $circular = new CircularString([], 4326); + $compound = new CompoundCurveImmutable([], 4326); + $line = new LineStringImmutable([], 4326); + $circular = new CircularStringImmutable([], 4326); static::assertTrue($compound->isEmpty()); static::assertNull($compound->getStartPoint()); @@ -63,9 +63,9 @@ public function testEmptyCurves(): void /** Mixed interpolation, order and closure survive through public contracts. */ public function testMixedClosedCurve(): void { - $circular = new CircularString([[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], 4326); - $line = new LineString([[2, 0, 5, 8], [0, 0, 3, 6]], 4326); - $compound = new CompoundCurve([$circular, $line], 4326); + $circular = new CircularStringImmutable([[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], 4326); + $line = new LineStringImmutable([[2, 0, 5, 8], [0, 0, 3, 6]], 4326); + $compound = new CompoundCurveImmutable([$circular, $line], 4326); static::assertContains(CompoundCurveInterface::class, class_implements($compound)); static::assertContains(CurveInterface::class, class_implements($compound)); @@ -91,13 +91,13 @@ public function testMixedClosedCurve(): void /** Reference changes deeply copy components and preserve defining ordinates. */ public function testReferenceReplacement(): void { - $compound = new CompoundCurve([ - new CircularString([[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], SpatialReference::epsg(4326)), - new LineString([[2, 0, 5, 8], [0, 0, 3, 6]], SpatialReference::epsg(4326)), + $compound = new CompoundCurveImmutable([ + new CircularStringImmutable([[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], SpatialReference::epsg(4326)), + new LineStringImmutable([[2, 0, 5, 8], [0, 0, 3, 6]], SpatialReference::epsg(4326)), ], SpatialReference::epsg(4326)); $copy = $compound->withSpatialReference(SpatialReference::epsg(3857)); - static::assertSame(CompoundCurve::class, $copy::class); + static::assertSame(CompoundCurveImmutable::class, (new \ReflectionClass($copy))->getName()); static::assertSame(4326, $compound->getSrid()); static::assertSame(4326, $compound->getCurve(0)->getSrid()); static::assertSame(3857, $copy->getSrid()); @@ -108,8 +108,8 @@ public function testReferenceReplacement(): void static::assertNotSame($compound->getStartPoint(), $copy->getStartPoint()); static::assertSame([[[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], [[2, 0, 5, 8], [0, 0, 3, 6]]], $compound->toArray()); static::assertSame([[[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], [[2, 0, 5, 8], [0, 0, 3, 6]]], $copy->toArray()); - static::assertInstanceOf(CircularString::class, $copy->getCurve(0)); - static::assertInstanceOf(LineString::class, $copy->getCurve(1)); + static::assertInstanceOf(CircularStringImmutable::class, $copy->getCurve(0)); + static::assertInstanceOf(LineStringImmutable::class, $copy->getCurve(1)); static::assertTrue($copy->isClosed()); } } diff --git a/tests/Unit/Types/Dimension4zm/Geometry/CircularStringTest.php b/tests/Unit/Types/Dimension4zm/Geometry/CircularStringTest.php index 97ddb6e..f52cf2a 100644 --- a/tests/Unit/Types/Dimension4zm/Geometry/CircularStringTest.php +++ b/tests/Unit/Types/Dimension4zm/Geometry/CircularStringTest.php @@ -21,8 +21,8 @@ use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Interfaces\CircularStringInterface; use LongitudeOne\SpatialTypes\Interfaces\CurveInterface; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\PointImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\TestCase; @@ -38,7 +38,7 @@ class CircularStringTest extends TestCase /** Empty values retain their declared layout and reference. */ public function testEmpty(): void { - $curve = new CircularString([], 4326); + $curve = new CircularStringImmutable([], 4326); static::assertTrue($curve->isEmpty()); static::assertSame([], $curve->getPoints()); @@ -51,10 +51,10 @@ public function testEmpty(): void /** Immutable replacement preserves this concrete layout and family. */ public function testReplacePoint(): void { - $curve = new CircularString([[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], 4326); + $curve = new CircularStringImmutable([[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], 4326); $replacement = $curve->withPoint(1, Coordinates::xyzm(1, 2, 8, 9)); - static::assertSame(CircularString::class, $replacement::class); + static::assertSame(CircularStringImmutable::class, (new \ReflectionClass($replacement))->getName()); static::assertSame([[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], $curve->toArray()); static::assertSame([[0, 0, 3, 6], [1, 2, 8, 9], [2, 0, 5, 8]], $replacement->toArray()); static::assertSame(4326, $replacement->getPoint(1)->getSrid()); @@ -64,7 +64,7 @@ public function testReplacePoint(): void /** Three defining points retain circular interpolation and their ordinates. */ public function testSingleArc(): void { - $curve = new CircularString([[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], 4326); + $curve = new CircularStringImmutable([[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], 4326); static::assertContains(CurveInterface::class, class_implements($curve)); static::assertContains(CircularStringInterface::class, class_implements($curve)); @@ -75,7 +75,7 @@ public function testSingleArc(): void static::assertSame([[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], $curve->toArray()); static::assertCount(3, $curve->getPoints()); static::assertSame($curve->getPoints(), $curve->getElements()); - static::assertInstanceOf(Point::class, $curve->getPoint(0)); + static::assertInstanceOf(PointImmutable::class, $curve->getPoint(0)); static::assertSame(4326, $curve->getPoint(-1)->getSrid()); static::assertSame($curve->getPoint(2), $curve->getPoint(-1)); static::assertSame($curve->getPoint(0), $curve->getPoint(3)); diff --git a/tests/Unit/Types/Dimension4zm/Geometry/CompoundCurveTest.php b/tests/Unit/Types/Dimension4zm/Geometry/CompoundCurveTest.php index c8fdc7b..dc4d527 100644 --- a/tests/Unit/Types/Dimension4zm/Geometry/CompoundCurveTest.php +++ b/tests/Unit/Types/Dimension4zm/Geometry/CompoundCurveTest.php @@ -22,9 +22,9 @@ use LongitudeOne\SpatialTypes\Interfaces\CompoundCurveInterface; use LongitudeOne\SpatialTypes\Interfaces\CurveInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\CompoundCurve; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\LineString; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\CompoundCurveImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\LineStringImmutable; use PHPUnit\Framework\TestCase; /** @@ -39,9 +39,9 @@ class CompoundCurveTest extends TestCase /** Empty compounds and component curves expose the common empty contract. */ public function testEmptyCurves(): void { - $compound = new CompoundCurve([], 4326); - $line = new LineString([], 4326); - $circular = new CircularString([], 4326); + $compound = new CompoundCurveImmutable([], 4326); + $line = new LineStringImmutable([], 4326); + $circular = new CircularStringImmutable([], 4326); static::assertTrue($compound->isEmpty()); static::assertNull($compound->getStartPoint()); @@ -63,9 +63,9 @@ public function testEmptyCurves(): void /** Mixed interpolation, order and closure survive through public contracts. */ public function testMixedClosedCurve(): void { - $circular = new CircularString([[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], 4326); - $line = new LineString([[2, 0, 5, 8], [0, 0, 3, 6]], 4326); - $compound = new CompoundCurve([$circular, $line], 4326); + $circular = new CircularStringImmutable([[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], 4326); + $line = new LineStringImmutable([[2, 0, 5, 8], [0, 0, 3, 6]], 4326); + $compound = new CompoundCurveImmutable([$circular, $line], 4326); static::assertContains(CompoundCurveInterface::class, class_implements($compound)); static::assertContains(CurveInterface::class, class_implements($compound)); @@ -91,13 +91,13 @@ public function testMixedClosedCurve(): void /** Reference changes deeply copy components and preserve defining ordinates. */ public function testReferenceReplacement(): void { - $compound = new CompoundCurve([ - new CircularString([[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], SpatialReference::epsg(4326)), - new LineString([[2, 0, 5, 8], [0, 0, 3, 6]], SpatialReference::epsg(4326)), + $compound = new CompoundCurveImmutable([ + new CircularStringImmutable([[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], SpatialReference::epsg(4326)), + new LineStringImmutable([[2, 0, 5, 8], [0, 0, 3, 6]], SpatialReference::epsg(4326)), ], SpatialReference::epsg(4326)); $copy = $compound->withSpatialReference(SpatialReference::epsg(3857)); - static::assertSame(CompoundCurve::class, $copy::class); + static::assertSame(CompoundCurveImmutable::class, (new \ReflectionClass($copy))->getName()); static::assertSame(4326, $compound->getSrid()); static::assertSame(4326, $compound->getCurve(0)->getSrid()); static::assertSame(3857, $copy->getSrid()); @@ -108,8 +108,8 @@ public function testReferenceReplacement(): void static::assertNotSame($compound->getStartPoint(), $copy->getStartPoint()); static::assertSame([[[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], [[2, 0, 5, 8], [0, 0, 3, 6]]], $compound->toArray()); static::assertSame([[[0, 0, 3, 6], [1, 1, 4, 7], [2, 0, 5, 8]], [[2, 0, 5, 8], [0, 0, 3, 6]]], $copy->toArray()); - static::assertInstanceOf(CircularString::class, $copy->getCurve(0)); - static::assertInstanceOf(LineString::class, $copy->getCurve(1)); + static::assertInstanceOf(CircularStringImmutable::class, $copy->getCurve(0)); + static::assertInstanceOf(LineStringImmutable::class, $copy->getCurve(1)); static::assertTrue($copy->isClosed()); } } diff --git a/tests/Unit/Types/Dimension4zm/SpatialTypesTest.php b/tests/Unit/Types/Dimension4zm/SpatialTypesTest.php index dc20302..a0aa819 100644 --- a/tests/Unit/Types/Dimension4zm/SpatialTypesTest.php +++ b/tests/Unit/Types/Dimension4zm/SpatialTypesTest.php @@ -17,20 +17,20 @@ namespace LongitudeOne\SpatialTypes\Tests\Unit\Types\Dimension4zm; use LongitudeOne\Core\Enum\SpatialModelEnum; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\GeographyCollection; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\LineString as GeographicLineString; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiLineString as GeographicMultiLineString; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiPoint as GeographicMultiPoint; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiPolygon as GeographicMultiPolygon; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Point as GeographicPoint; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Polygon as GeographicPolygon; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\GeometryCollection; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\LineString as GeometricLineString; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiLineString as GeometricMultiLineString; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiPoint as GeometricMultiPoint; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiPolygon as GeometricMultiPolygon; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Point as GeometricPoint; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Polygon as GeometricPolygon; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\GeographyCollectionImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\LineStringImmutable as GeographicLineString; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiLineStringImmutable as GeographicMultiLineString; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiPointImmutable as GeographicMultiPoint; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiPolygonImmutable as GeographicMultiPolygon; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PointImmutable as GeographicPoint; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PolygonImmutable as GeographicPolygon; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\GeometryCollectionImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\LineStringImmutable as GeometricLineString; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiLineStringImmutable as GeometricMultiLineString; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiPointImmutable as GeometricMultiPoint; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiPolygonImmutable as GeometricMultiPolygon; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\PointImmutable as GeometricPoint; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\PolygonImmutable as GeometricPolygon; use PHPUnit\Framework\TestCase; /** @@ -59,7 +59,7 @@ public function testGeographicXyzmTypes(): void static::assertSame([$lineString], (new GeographicMultiLineString([$lineString]))->getElements()); static::assertSame([$polygon], (new GeographicMultiPolygon([$polygon]))->getElements()); - $collection = new GeographyCollection(0, [$polygon]); + $collection = new GeographyCollectionImmutable(0, [$polygon]); static::assertSame([$polygon], $collection->getElements()); } @@ -84,7 +84,7 @@ public function testGeometricXyzmTypes(): void static::assertSame([$lineString], (new GeometricMultiLineString([$lineString]))->getElements()); static::assertSame([$polygon], (new GeometricMultiPolygon([$polygon]))->getElements()); - $collection = new GeometryCollection(0, [$polygon]); + $collection = new GeometryCollectionImmutable(0, [$polygon]); static::assertSame([$polygon], $collection->getElements()); } } diff --git a/tests/Unit/Types/EmptyGeometryTest.php b/tests/Unit/Types/EmptyGeometryTest.php index 0271e9b..d896633 100644 --- a/tests/Unit/Types/EmptyGeometryTest.php +++ b/tests/Unit/Types/EmptyGeometryTest.php @@ -54,19 +54,19 @@ public static function provideEmptyGeometries(): \Generator foreach (['Dimension2', 'Dimension3m', 'Dimension3z', 'Dimension4zm'] as $dimension) { $namespace = sprintf('LongitudeOne\SpatialTypes\Types\%s\Geometry\\', $dimension); - yield $dimension.' Point' => [new ($namespace.'Point')(), GeometryTypeEnum::POINT]; + yield $dimension.' Point' => [new ($namespace.'PointImmutable')(), GeometryTypeEnum::POINT]; - yield $dimension.' LineString' => [new ($namespace.'LineString')([]), GeometryTypeEnum::LINESTRING]; + yield $dimension.' LineString' => [new ($namespace.'LineStringImmutable')([]), GeometryTypeEnum::LINESTRING]; - yield $dimension.' Polygon' => [new ($namespace.'Polygon')([]), GeometryTypeEnum::POLYGON]; + yield $dimension.' Polygon' => [new ($namespace.'PolygonImmutable')([]), GeometryTypeEnum::POLYGON]; - yield $dimension.' MultiPoint' => [new ($namespace.'MultiPoint')([]), GeometryTypeEnum::MULTIPOINT]; + yield $dimension.' MultiPoint' => [new ($namespace.'MultiPointImmutable')([]), GeometryTypeEnum::MULTIPOINT]; - yield $dimension.' MultiLineString' => [new ($namespace.'MultiLineString')([]), GeometryTypeEnum::MULTILINESTRING]; + yield $dimension.' MultiLineString' => [new ($namespace.'MultiLineStringImmutable')([]), GeometryTypeEnum::MULTILINESTRING]; - yield $dimension.' MultiPolygon' => [new ($namespace.'MultiPolygon')([]), GeometryTypeEnum::MULTIPOLYGON]; + yield $dimension.' MultiPolygon' => [new ($namespace.'MultiPolygonImmutable')([]), GeometryTypeEnum::MULTIPOLYGON]; - yield $dimension.' GeometryCollection' => [new ($namespace.'GeometryCollection')(), GeometryTypeEnum::GEOMETRYCOLLECTION]; + yield $dimension.' GeometryCollection' => [new ($namespace.'GeometryCollectionImmutable')(), GeometryTypeEnum::GEOMETRYCOLLECTION]; } } } diff --git a/tests/Unit/Types/EmptyPointTest.php b/tests/Unit/Types/EmptyPointTest.php index 3822bc8..c38fee3 100644 --- a/tests/Unit/Types/EmptyPointTest.php +++ b/tests/Unit/Types/EmptyPointTest.php @@ -19,8 +19,8 @@ use LongitudeOne\Core\Enum\CoordinateDimensionEnum; use LongitudeOne\Core\Enum\SpatialModelEnum; use LongitudeOne\SpatialTypes\Factory\FromIndexedArrayFactory; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point as GeometryPoint; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable as GeometryPoint; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; @@ -30,30 +30,30 @@ * * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractPoint + * @covers \LongitudeOne\SpatialTypes\Types\AbstractPointImmutable */ class EmptyPointTest extends TestCase { /** * @param object $point Configured point instance * - * @throws \LogicException when a configured concrete class does not implement PointInterface + * @throws \LogicException when a configured concrete class does not implement ImmutablePointInterface */ - private static function asPoint(object $point): PointInterface + private static function asPoint(object $point): ImmutablePointInterface { - if (!$point instanceof PointInterface) { - throw new \LogicException('Configured point class does not implement PointInterface.'); + if (!$point instanceof ImmutablePointInterface) { + throw new \LogicException('Configured point class does not implement ImmutablePointInterface.'); } return $point; } /** - * @param PointInterface $point Configured point + * @param ImmutablePointInterface $point Configured point * * @throws \LogicException when a configured concrete class does not expose a known dimension */ - private static function dimensionFromPoint(PointInterface $point): CoordinateDimensionEnum + private static function dimensionFromPoint(ImmutablePointInterface $point): CoordinateDimensionEnum { return match ([$point->hasZ(), $point->hasM()]) { [false, false] => CoordinateDimensionEnum::XY, @@ -94,10 +94,10 @@ private static function familiesAndDimensions(): array /** * Empty points preserve their dimension, family, and spatial reference. * - * @param PointInterface $point Empty point + * @param ImmutablePointInterface $point Empty point */ #[DataProvider('provideEmptyPoints')] - public function testEmptyPointCanBeCreated(PointInterface $point): void + public function testEmptyPointCanBeCreated(ImmutablePointInterface $point): void { static::assertTrue($point->isEmpty()); static::assertSame(4326, $point->getSrid()); @@ -118,13 +118,13 @@ public function testEmptyPointCanBeCreated(PointInterface $point): void } /** - * @return \Generator + * @return \Generator */ public static function provideEmptyPoints(): \Generator { foreach (self::familiesAndDimensions() as $name => [$family, $dimension]) { $familyNamespace = SpatialModelEnum::GEOMETRY === $family ? 'Geometry' : 'Geography'; - $class = sprintf('LongitudeOne\SpatialTypes\Types\%s\%s\Point', self::dimensionNamespace($dimension), $familyNamespace); + $class = sprintf('LongitudeOne\SpatialTypes\Types\%s\%s\PointImmutable', self::dimensionNamespace($dimension), $familyNamespace); yield $name => [self::asPoint(new $class(srid: 4326))]; } @@ -168,11 +168,11 @@ public function testPointConstructorPreservesPartialCoordinates(): void /** * A coordinate tuple produces a non-empty copy of an empty point. * - * @param PointInterface $point Empty point - * @param Coordinates $coordinates Replacement coordinates + * @param ImmutablePointInterface $point Empty point + * @param Coordinates $coordinates Replacement coordinates */ #[DataProvider('provideEmptyPointsAndCoordinates')] - public function testWithCoordinatesCreatesNonEmptyPoint(PointInterface $point, Coordinates $coordinates): void + public function testWithCoordinatesCreatesNonEmptyPoint(ImmutablePointInterface $point, Coordinates $coordinates): void { $replacement = $point->withCoordinates($coordinates); @@ -182,7 +182,7 @@ public function testWithCoordinatesCreatesNonEmptyPoint(PointInterface $point, C } /** - * @return \Generator + * @return \Generator */ public static function provideEmptyPointsAndCoordinates(): \Generator { diff --git a/tests/Unit/Types/ImmutableComponentContractTest.php b/tests/Unit/Types/ImmutableComponentContractTest.php new file mode 100644 index 0000000..246e25b --- /dev/null +++ b/tests/Unit/Types/ImmutableComponentContractTest.php @@ -0,0 +1,195 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Tests\Unit\Types; + +use LongitudeOne\SpatialTypes\Exception\InvalidValueException; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableCollectionInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableSpatialInterface; +use LongitudeOne\SpatialTypes\Interfaces\MutableCurveInterface; +use LongitudeOne\SpatialTypes\Interfaces\MutableLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\MutablePointInterface; +use LongitudeOne\SpatialTypes\Interfaces\MutablePolygonInterface; +use LongitudeOne\SpatialTypes\Reference\SpatialReference; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CompoundCurveImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollectionImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiLineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPointImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPolygonImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PolygonImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\TriangleImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PolyhedralSurfaceImmutable; +use PHPUnit\Framework\TestCase; + +/** Mutable components never become part of an immutable aggregate. + * @internal + * + * @coversNothing + */ +class ImmutableComponentContractTest extends TestCase +{ + /** CircularString rejects mutable input without conversion. */ + public function testCircularStringRejectsMutableComponents(): void + { + $mutable = static::createStub(MutablePointInterface::class); + $this->expectException(InvalidValueException::class); + + (new \ReflectionClass(CircularStringImmutable::class))->newInstance([$mutable]); + } + + /** Collection rejects mutable input without conversion. */ + public function testCollectionRejectsMutableComponents(): void + { + $mutable = static::createStub(MutablePointInterface::class); + $this->expectException(InvalidValueException::class); + + (new \ReflectionClass(GeometryCollectionImmutable::class))->newInstance(0, [$mutable]); + } + + /** CompoundCurve rejects mutable input without conversion. */ + public function testCompoundCurveRejectsMutableComponents(): void + { + $mutable = static::createStub(MutableCurveInterface::class); + $this->expectException(InvalidValueException::class); + + (new \ReflectionClass(CompoundCurveImmutable::class))->newInstance([$mutable]); + } + + /** XY tuples produce immutable points while preserving partial nulls. */ + public function testCoordinateTuplesCreateImmutableDescendants(): void + { + $source = new MultiPolygonImmutable([[[[0, null], [2, 3]]]], 4326); + $copy = $source->withSpatialReference(SpatialReference::epsg(2154)); + + static::assertTrue(is_a((new \ReflectionClass($copy->getPolygon(0)))->getName(), ImmutableSpatialInterface::class, true)); + static::assertTrue(is_a((new \ReflectionClass($copy->getPolygon(0)->getRing(0)))->getName(), ImmutableSpatialInterface::class, true)); + static::assertTrue(is_a((new \ReflectionClass($copy->getPolygon(0)->getRing(0)->getPoint(0)))->getName(), ImmutableSpatialInterface::class, true)); + static::assertSame([[[[0, null], [2, 3]]]], $copy->toArray()); + static::assertSame(2154, $copy->getPolygon(0)->getRing(0)->getPoint(0)->getSrid()); + static::assertSame(4326, $source->getPolygon(0)->getRing(0)->getPoint(0)->getSrid()); + static::assertNotSame($source->getPolygon(0), $copy->getPolygon(0)); + static::assertNotSame($source->getPolygon(0)->getRing(0), $copy->getPolygon(0)->getRing(0)); + static::assertNotSame($source->getPolygon(0)->getRing(0)->getPoint(0), $copy->getPolygon(0)->getRing(0)->getPoint(0)); + } + + /** LineString rejects mutable input without conversion. */ + public function testLineStringRejectsMutableComponents(): void + { + $mutable = static::createStub(MutablePointInterface::class); + $this->expectException(InvalidValueException::class); + + (new \ReflectionClass(LineStringImmutable::class))->newInstance([$mutable]); + } + + /** MultiLineString rejects mutable input without conversion. */ + public function testMultiLineStringRejectsMutableComponents(): void + { + $mutable = static::createStub(MutableLineStringInterface::class); + $this->expectException(\TypeError::class); + + (new \ReflectionClass(MultiLineStringImmutable::class))->newInstance([$mutable]); + } + + /** MultiPoint rejects mutable input without conversion. */ + public function testMultiPointRejectsMutableComponents(): void + { + $mutable = static::createStub(MutablePointInterface::class); + $this->expectException(InvalidValueException::class); + + (new \ReflectionClass(MultiPointImmutable::class))->newInstance([$mutable]); + } + + /** MultiPolygon rejects mutable input without conversion. */ + public function testMultiPolygonRejectsMutableComponents(): void + { + $mutable = static::createStub(MutablePolygonInterface::class); + $this->expectException(\TypeError::class); + + (new \ReflectionClass(MultiPolygonImmutable::class))->newInstance([$mutable]); + } + + /** A marker cannot hide mutable descendants of a custom collection. */ + public function testNestedMutableComponentIsRejected(): void + { + $mutable = static::createStub(MutablePointInterface::class); + $nested = static::createStub(ImmutableCollectionInterface::class); + $nested->method('getElements')->willReturn([$mutable]); + $this->expectException(InvalidValueException::class); + $this->expectExceptionMessage('Immutable aggregates require exclusively immutable spatial components.'); + + new GeometryCollectionImmutable(0, [$nested]); + } + + /** NestedPointArray rejects mutable input without conversion. */ + public function testNestedPointArrayRejectsMutableComponents(): void + { + $mutable = static::createStub(MutablePointInterface::class); + $this->expectException(InvalidValueException::class); + + (new \ReflectionClass(PolygonImmutable::class))->newInstance([[$mutable]]); + } + + /** Polygon rejects mutable input without conversion. */ + public function testPolygonRejectsMutableComponents(): void + { + $mutable = static::createStub(MutableLineStringInterface::class); + $this->expectException(InvalidValueException::class); + + (new \ReflectionClass(PolygonImmutable::class))->newInstance([$mutable]); + } + + /** PolyhedralSurface rejects mutable input without conversion. */ + public function testPolyhedralSurfaceRejectsMutableComponents(): void + { + $mutable = static::createStub(MutablePolygonInterface::class); + $this->expectException(\TypeError::class); + + (new \ReflectionClass(PolyhedralSurfaceImmutable::class))->newInstance([$mutable]); + } + + /** A rejected replacement preserves source membership and supplied objects. */ + public function testRejectedReplacementDoesNotChangeTheSource(): void + { + $point = new PointImmutable(0, null, 4326); + $source = new GeometryCollectionImmutable(4326, [$point]); + $mutable = static::createStub(MutablePointInterface::class); + $mutable->method('getX')->willReturn(7); + $nested = static::createStub(ImmutableCollectionInterface::class); + $nested->method('getElements')->willReturn([$mutable]); + $this->expectException(InvalidValueException::class); + + try { + $source->withElement(0, $nested); + } finally { + static::assertSame([$point], $source->getElements()); + static::assertSame([[0, null]], $source->toArray()); + static::assertSame(4326, $source->getSrid()); + static::assertSame(7, $mutable->getX()); + } + } + + /** Triangle rejects mutable input without conversion. */ + public function testTriangleRejectsMutableComponents(): void + { + $mutable = static::createStub(MutableLineStringInterface::class); + $this->expectException(InvalidValueException::class); + + (new \ReflectionClass(TriangleImmutable::class))->newInstance([$mutable]); + } +} diff --git a/tests/Unit/Types/LineStringWithSridTest.php b/tests/Unit/Types/LineStringWithSridTest.php index 32efccf..a08cbd6 100644 --- a/tests/Unit/Types/LineStringWithSridTest.php +++ b/tests/Unit/Types/LineStringWithSridTest.php @@ -16,33 +16,33 @@ namespace LongitudeOne\SpatialTypes\Tests\Unit\Types; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\LineString as GeographyLineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Point as GeographyPoint; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString as GeometryLineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point as GeometryPoint; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\LineStringImmutable as GeographyLineString; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PointImmutable as GeographyPoint; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable as GeometryLineString; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable as GeometryPoint; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractLineString + * @covers \LongitudeOne\SpatialTypes\Types\AbstractLineStringImmutable */ class LineStringWithSridTest extends TestCase { /** * Verify that withSrid copies the line string and every one of its points. * - * @param LineStringInterface $lineString line string to copy + * @param ImmutableLineStringInterface $lineString line string to copy */ #[DataProvider('provideLineStrings')] - public function testWithSridPreservesInternalSridConsistency(LineStringInterface $lineString): void + public function testWithSridPreservesInternalSridConsistency(ImmutableLineStringInterface $lineString): void { $lineStringWithSrid = $lineString->withSrid(2154); static::assertNotSame($lineString, $lineStringWithSrid); - static::assertSame($lineString::class, $lineStringWithSrid::class); + static::assertSame($lineString::class, (new \ReflectionClass($lineStringWithSrid))->getName()); static::assertSame($lineString->toArray(), $lineStringWithSrid->toArray()); static::assertSame(4326, $lineString->getSrid()); static::assertSame(2154, $lineStringWithSrid->getSrid()); @@ -57,7 +57,7 @@ public function testWithSridPreservesInternalSridConsistency(LineStringInterface } /** - * @return \Generator + * @return \Generator */ public static function provideLineStrings(): \Generator { diff --git a/tests/Unit/Types/MultiLineStringWithPointTest.php b/tests/Unit/Types/MultiLineStringWithPointTest.php index 004b573..5d22435 100644 --- a/tests/Unit/Types/MultiLineStringWithPointTest.php +++ b/tests/Unit/Types/MultiLineStringWithPointTest.php @@ -16,14 +16,14 @@ namespace LongitudeOne\SpatialTypes\Tests\Unit\Types; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiLineString; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiLineStringImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\TestCase; /** * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiLineString + * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiLineStringImmutable */ class MultiLineStringWithPointTest extends TestCase { @@ -32,14 +32,14 @@ class MultiLineStringWithPointTest extends TestCase */ public function testWithPointReturnsAnIndependentCopy(): void { - $multiLineString = new MultiLineString([ + $multiLineString = new MultiLineStringImmutable([ [[0, 0], [1, 1]], [[2, 2], [3, 3]], ], 2154); $replacement = $multiLineString->withPoint(-1, -1, Coordinates::xy(4, 4)); static::assertNotSame($multiLineString, $replacement); - static::assertSame($multiLineString::class, $replacement::class); + static::assertSame($multiLineString::class, (new \ReflectionClass($replacement))->getName()); static::assertSame(2154, $replacement->getSrid()); static::assertSame([[[0, 0], [1, 1]], [[2, 2], [3, 3]]], $multiLineString->toArray()); static::assertSame([[[0, 0], [1, 1]], [[2, 2], [4, 4]]], $replacement->toArray()); diff --git a/tests/Unit/Types/MultiPointWithPointTest.php b/tests/Unit/Types/MultiPointWithPointTest.php index 55cfd74..20b54c5 100644 --- a/tests/Unit/Types/MultiPointWithPointTest.php +++ b/tests/Unit/Types/MultiPointWithPointTest.php @@ -17,14 +17,14 @@ namespace LongitudeOne\SpatialTypes\Tests\Unit\Types; use LongitudeOne\SpatialTypes\Exception\InvalidDimensionException; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPoint; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPointImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\TestCase; /** * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiPoint + * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiPointImmutable */ class MultiPointWithPointTest extends TestCase { @@ -33,7 +33,7 @@ class MultiPointWithPointTest extends TestCase */ public function testWithPointRejectsAnotherDimension(): void { - $multiPoint = new MultiPoint([[1, 2, 3]], 2154); + $multiPoint = new MultiPointImmutable([[1, 2, 3]], 2154); self::expectException(InvalidDimensionException::class); @@ -45,11 +45,11 @@ public function testWithPointRejectsAnotherDimension(): void */ public function testWithPointReturnsAnIndependentCopy(): void { - $multiPoint = new MultiPoint([[1, 2, 3], [4, 5, 6]], 2154); + $multiPoint = new MultiPointImmutable([[1, 2, 3], [4, 5, 6]], 2154); $replacement = $multiPoint->withPoint(-1, Coordinates::xym(7, 8, 9)); static::assertNotSame($multiPoint, $replacement); - static::assertSame($multiPoint::class, $replacement::class); + static::assertSame($multiPoint::class, (new \ReflectionClass($replacement))->getName()); static::assertSame(2154, $replacement->getSrid()); static::assertTrue($replacement->hasM()); static::assertFalse($replacement->hasZ()); diff --git a/tests/Unit/Types/MultiPolygonWithReplacementTest.php b/tests/Unit/Types/MultiPolygonWithReplacementTest.php index 0fed8df..d9ca7db 100644 --- a/tests/Unit/Types/MultiPolygonWithReplacementTest.php +++ b/tests/Unit/Types/MultiPolygonWithReplacementTest.php @@ -16,23 +16,23 @@ namespace LongitudeOne\SpatialTypes\Tests\Unit\Types; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPolygon; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPolygonImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\TestCase; /** * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiPolygon + * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiPolygonImmutable */ class MultiPolygonWithReplacementTest extends TestCase { /** * Create a valid two-dimensional multi-polygon with an exterior ring and a contained hole. */ - private static function createMultiPolygon(): MultiPolygon + private static function createMultiPolygon(): MultiPolygonImmutable { - return new MultiPolygon([ + return new MultiPolygonImmutable([ [ [[0, 0], [10, 0], [0, 10], [0, 0]], [[1, 1], [2, 1], [1, 2], [1, 1]], @@ -52,7 +52,7 @@ public function testWithPointReturnsAnIndependentCopy(): void $replacement = $multiPolygon->withPoint(0, 0, 0, Coordinates::xy(-1, -1)); static::assertNotSame($multiPolygon, $replacement); - static::assertSame($multiPolygon::class, $replacement::class); + static::assertSame($multiPolygon::class, (new \ReflectionClass($replacement))->getName()); static::assertSame(2154, $replacement->getSrid()); static::assertSame([[[[0, 0], [10, 0], [0, 10], [0, 0]], [[1, 1], [2, 1], [1, 2], [1, 1]]], [[[20, 0], [30, 0], [20, 10], [20, 0]]]], $multiPolygon->toArray()); static::assertSame([[[[-1, -1], [10, 0], [0, 10], [-1, -1]], [[1, 1], [2, 1], [1, 2], [1, 1]]], [[[20, 0], [30, 0], [20, 10], [20, 0]]]], $replacement->toArray()); diff --git a/tests/Unit/Types/PointWithCoordinatesTest.php b/tests/Unit/Types/PointWithCoordinatesTest.php index 5f47d29..2c84658 100644 --- a/tests/Unit/Types/PointWithCoordinatesTest.php +++ b/tests/Unit/Types/PointWithCoordinatesTest.php @@ -18,15 +18,15 @@ use LongitudeOne\SpatialTypes\Exception\BadMethodCallException; use LongitudeOne\SpatialTypes\Exception\InvalidDimensionException; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Point as GeographyPoint2D; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point as GeometryPoint2D; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Point as GeographyPoint3Dm; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Point as GeometryPoint3Dm; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point as GeographyPoint3Dz; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point as GeometryPoint3Dz; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Point as GeographyPoint4Dzm; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Point as GeometryPoint4Dzm; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PointImmutable as GeographyPoint2D; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable as GeometryPoint2D; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\PointImmutable as GeographyPoint3Dm; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\PointImmutable as GeometryPoint3Dm; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PointImmutable as GeographyPoint3Dz; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PointImmutable as GeometryPoint3Dz; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PointImmutable as GeographyPoint4Dzm; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\PointImmutable as GeometryPoint4Dzm; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; @@ -34,7 +34,7 @@ /** * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractPoint + * @covers \LongitudeOne\SpatialTypes\Types\AbstractPointImmutable */ class PointWithCoordinatesTest extends TestCase { @@ -57,17 +57,17 @@ public function testEqualsToRejectsDifferentMeasureOrElevation(): void /** * Verify that withCoordinates returns a distinct point with the same SRID and type. * - * @param Coordinates $coordinates replacement coordinates - * @param PointInterface $point point to copy + * @param Coordinates $coordinates replacement coordinates + * @param ImmutablePointInterface $point point to copy */ #[DataProvider('providePointsAndCoordinates')] - public function testWithCoordinates(Coordinates $coordinates, PointInterface $point): void + public function testWithCoordinates(Coordinates $coordinates, ImmutablePointInterface $point): void { $originalCoordinates = $point->getCoordinates(); $pointWithCoordinates = $point->withCoordinates($coordinates); static::assertNotSame($point, $pointWithCoordinates); - static::assertSame($point::class, $pointWithCoordinates::class); + static::assertSame($point::class, (new \ReflectionClass($pointWithCoordinates))->getName()); static::assertSame(4326, $point->getSrid()); static::assertSame(4326, $pointWithCoordinates->getSrid()); static::assertEquals($originalCoordinates, $point->getCoordinates()); @@ -75,7 +75,7 @@ public function testWithCoordinates(Coordinates $coordinates, PointInterface $po } /** - * @return \Generator + * @return \Generator */ public static function providePointsAndCoordinates(): \Generator { diff --git a/tests/Unit/Types/PointWithSridTest.php b/tests/Unit/Types/PointWithSridTest.php index 644c0d6..4bad63e 100644 --- a/tests/Unit/Types/PointWithSridTest.php +++ b/tests/Unit/Types/PointWithSridTest.php @@ -16,44 +16,44 @@ namespace LongitudeOne\SpatialTypes\Tests\Unit\Types; -use LongitudeOne\SpatialTypes\Interfaces\PointInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Point as GeographyPoint2D; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point as GeometryPoint2D; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Point as GeographyPoint3Dm; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Point as GeometryPoint3Dm; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point as GeographyPoint3Dz; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point as GeometryPoint3Dz; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Point as GeographyPoint4Dzm; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Point as GeometryPoint4Dzm; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePointInterface; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PointImmutable as GeographyPoint2D; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable as GeometryPoint2D; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\PointImmutable as GeographyPoint3Dm; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\PointImmutable as GeometryPoint3Dm; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PointImmutable as GeographyPoint3Dz; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PointImmutable as GeometryPoint3Dz; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PointImmutable as GeographyPoint4Dzm; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\PointImmutable as GeometryPoint4Dzm; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractPoint + * @covers \LongitudeOne\SpatialTypes\Types\AbstractPointImmutable */ class PointWithSridTest extends TestCase { /** * Verify that withSrid returns a distinct point without changing its ordinates. * - * @param PointInterface $point Point to copy + * @param ImmutablePointInterface $point Point to copy */ #[DataProvider('providePoints')] - public function testWithSrid(PointInterface $point): void + public function testWithSrid(ImmutablePointInterface $point): void { $pointWithSrid = $point->withSrid(2154); static::assertNotSame($point, $pointWithSrid); - static::assertSame($point::class, $pointWithSrid::class); + static::assertSame($point::class, (new \ReflectionClass($pointWithSrid))->getName()); static::assertSame($point->toArray(), $pointWithSrid->toArray()); static::assertSame(4326, $point->getSrid()); static::assertSame(2154, $pointWithSrid->getSrid()); } /** - * @return \Generator + * @return \Generator */ public static function providePoints(): \Generator { diff --git a/tests/Unit/Types/PolyhedralSurfaceTest.php b/tests/Unit/Types/PolyhedralSurfaceTest.php index b54f610..b628902 100644 --- a/tests/Unit/Types/PolyhedralSurfaceTest.php +++ b/tests/Unit/Types/PolyhedralSurfaceTest.php @@ -19,8 +19,8 @@ use LongitudeOne\Core\Enum\GeometryTypeEnum; use LongitudeOne\SpatialTypes\Exception\OutOfBoundsException; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\AbstractPolyhedralSurface; -use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PolyhedralSurface; +use LongitudeOne\SpatialTypes\Types\AbstractPolyhedralSurfaceImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PolyhedralSurfaceImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; @@ -28,7 +28,7 @@ /** * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractPolyhedralSurface + * @covers \LongitudeOne\SpatialTypes\Types\AbstractPolyhedralSurfaceImmutable * * @phpstan-type Position array{int, int, int, 3?: int} * @phpstan-type Patches list>> @@ -60,7 +60,7 @@ private static function coordinates(string $class): array /** * @param string $class Surface class * - * @phpstan-param class-string $class + * @phpstan-param class-string $class */ #[DataProvider('surfaces')] public function testEmptySurface(string $class): void @@ -73,7 +73,7 @@ public function testEmptySurface(string $class): void static::assertSame([], $surface->toArray()); static::assertSame(['type' => 'PolyhedralSurface', 'coordinates' => [], 'srid' => 0], $surface->jsonSerialize()); $copy = $surface->withSpatialReference(SpatialReference::epsg(4326)); - static::assertSame($class, $copy::class); + static::assertSame($class, (new \ReflectionClass($copy))->getName()); static::assertTrue($copy->isEmpty()); static::assertSame(4326, $copy->getSrid()); static::assertSame(0, $surface->getSrid()); @@ -85,7 +85,7 @@ public function testEmptySurface(string $class): void /** * @param string $class Surface class * - * @phpstan-param class-string $class + * @phpstan-param class-string $class */ #[DataProvider('surfaces')] public function testEmptySurfaceCannotReplacePatch(string $class): void @@ -98,7 +98,7 @@ public function testEmptySurfaceCannotReplacePatch(string $class): void /** * @param string $class Surface class * - * @phpstan-param class-string $class + * @phpstan-param class-string $class */ #[DataProvider('surfaces')] public function testOpenSurfaceAndIndependentCopies(string $class): void @@ -120,7 +120,7 @@ public function testOpenSurfaceAndIndependentCopies(string $class): void $surface->withSpatialReference(SpatialReference::epsg(4326)), ]; foreach ($copies as $copy) { - static::assertSame($class, $copy::class); + static::assertSame($class, (new \ReflectionClass($copy))->getName()); static::assertSame($surface->getFamily(), $copy->getFamily()); static::assertTrue($surface->hasSameDimension($copy)); static::assertSame($coordinates, $copy->toArray()); @@ -141,7 +141,7 @@ public function testOpenSurfaceAndIndependentCopies(string $class): void /** * @param string $class Surface class * - * @phpstan-param class-string $class + * @phpstan-param class-string $class */ #[DataProvider('surfaces')] public function testPointReplacementAndSinglePatch(string $class): void @@ -150,7 +150,7 @@ public function testPointReplacementAndSinglePatch(string $class): void $surface = new $class([$coordinates[0]], 4326); $point = $surface->hasM() ? Coordinates::xyzm(-1, 0, 0, 7) : Coordinates::xyz(-1, 0, 0); $copy = $surface->withPoint(0, -1, 0, $point); - static::assertSame($class, $copy::class); + static::assertSame($class, (new \ReflectionClass($copy))->getName()); static::assertSame([$coordinates[0]], $surface->toArray()); static::assertSame(-1, $copy->getPatch(0)->getRing(0)->getPoint(0)->getX()); static::assertSame(-1, $copy->getPatch(0)->getRing(0)->getPoint(-1)->getX()); @@ -160,7 +160,7 @@ public function testPointReplacementAndSinglePatch(string $class): void /** * @param string $class Surface class * - * @phpstan-param class-string $class + * @phpstan-param class-string $class */ #[DataProvider('surfaces')] public function testReplacementsPreserveReferenceAuthority(string $class): void @@ -176,15 +176,15 @@ public function testReplacementsPreserveReferenceAuthority(string $class): void } } - /** @return iterable}> */ + /** @return iterable}> */ public static function surfaces(): iterable { - yield 'Dimension3z Geometry' => [PolyhedralSurface::class]; + yield 'Dimension3z Geometry' => [PolyhedralSurfaceImmutable::class]; - yield 'Dimension3z Geography' => [\LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PolyhedralSurface::class]; + yield 'Dimension3z Geography' => [\LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PolyhedralSurfaceImmutable::class]; - yield 'Dimension4zm Geometry' => [\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\PolyhedralSurface::class]; + yield 'Dimension4zm Geometry' => [\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\PolyhedralSurfaceImmutable::class]; - yield 'Dimension4zm Geography' => [\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PolyhedralSurface::class]; + yield 'Dimension4zm Geography' => [\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PolyhedralSurfaceImmutable::class]; } } diff --git a/tests/Unit/Types/RepresentationWithoutValidationTest.php b/tests/Unit/Types/RepresentationWithoutValidationTest.php index 367ff68..eaa62b4 100644 --- a/tests/Unit/Types/RepresentationWithoutValidationTest.php +++ b/tests/Unit/Types/RepresentationWithoutValidationTest.php @@ -18,14 +18,14 @@ use LongitudeOne\SpatialTypes\Exception\OutOfBoundsException; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CompoundCurve; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollection; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Polygon; -use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Triangle; -use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PolyhedralSurface; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CompoundCurveImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollectionImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PolygonImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\TriangleImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PolyhedralSurfaceImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\TestCase; @@ -39,7 +39,7 @@ final class RepresentationWithoutValidationTest extends TestCase /** Circular string stores incomplete arcs and empty members. */ public function testCircularStringStoresIncompleteArcsAndEmptyMembers(): void { - $curve = new CircularString([new Point(), new Point(1, 1)]); + $curve = new CircularStringImmutable([new PointImmutable(), new PointImmutable(1, 1)]); $copy = $curve->withArrayOfCoordinates([[2, 2]]); self::assertSame([[], [1, 1]], $curve->toArray()); @@ -49,10 +49,10 @@ public function testCircularStringStoresIncompleteArcsAndEmptyMembers(): void /** Compound curve stores disconnected and empty components. */ public function testCompoundCurveStoresDisconnectedAndEmptyComponents(): void { - $curve = new CompoundCurve([ - new LineString([[0, 0], [1, 1]]), - new CircularString([[5, 5]]), - new LineString([]), + $curve = new CompoundCurveImmutable([ + new LineStringImmutable([[0, 0], [1, 1]]), + new CircularStringImmutable([[5, 5]]), + new LineStringImmutable([]), ]); $copy = $curve->withSrid(4326); @@ -66,7 +66,7 @@ public function testCompoundCurveStoresDisconnectedAndEmptyComponents(): void /** Empty ring still rejects indexed replacement. */ public function testEmptyRingStillRejectsIndexedReplacement(): void { - $polygon = new Polygon([[]]); + $polygon = new PolygonImmutable([[]]); $this->expectException(OutOfBoundsException::class); $polygon->withPoint(0, 0, Coordinates::xy(1, 2)); @@ -75,22 +75,22 @@ public function testEmptyRingStillRejectsIndexedReplacement(): void /** Membership does not enforce family dimension or reference. */ public function testMembershipDoesNotEnforceFamilyDimensionOrReference(): void { - $member = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point(1, 2, 3, SpatialReference::epsg(4326)); - $collection = new GeometryCollection(2154, [$member, new GeometryCollection()]); - $copy = $collection->withElement(1, new Point(4, 5, 3857)); + $member = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PointImmutable(1, 2, 3, SpatialReference::epsg(4326)); + $collection = new GeometryCollectionImmutable(2154, [$member, new GeometryCollectionImmutable()]); + $copy = $collection->withElement(1, new PointImmutable(4, 5, 3857)); self::assertSame($member, $collection->getElements()[0]); self::assertSame(4326, $collection->getElements()[0]->getSrid()); self::assertSame(2154, $collection->getSrid()); self::assertSame(3857, $copy->getElements()[1]->getSrid()); - self::assertInstanceOf(GeometryCollection::class, $collection->getElements()[1]); + self::assertInstanceOf(GeometryCollectionImmutable::class, $collection->getElements()[1]); } /** Spatial reference retains unvalidated identifiers and authorities. */ public function testSpatialReferenceRetainsUnvalidatedIdentifiersAndAuthorities(): void { $reference = new SpatialReference(-1, ''); - $point = new Point(1, 2, $reference); + $point = new PointImmutable(1, 2, $reference); self::assertSame(-1, $point->getSrid()); self::assertSame('', $point->getSpatialReference()->authority); @@ -100,24 +100,24 @@ public function testSpatialReferenceRetainsUnvalidatedIdentifiersAndAuthorities( /** Xy duplicate replacement preserves original. */ public function testXyDuplicateReplacementPreservesOriginal(): void { - $line = new LineString([[0, 0], [1, 1]], 4326); + $line = new LineStringImmutable([[0, 0], [1, 1]], 4326); $copy = $line->withPoint(1, Coordinates::xy(0, 0)); self::assertSame([[0, 0], [0, 0]], $copy->toArray()); self::assertSame([[0, 0], [1, 1]], $line->toArray()); self::assertSame(4326, $copy->getSrid()); - self::assertSame(LineString::class, $copy::class); + self::assertSame(LineStringImmutable::class, (new \ReflectionClass($copy))->getName()); } /** Xym triangle stores open boundaries and holes. */ public function testXymTriangleStoresOpenBoundariesAndHoles(): void { - $triangle = new Triangle([[[0, 0, 7], [1, 0, 8]], [[2, 2, 9]]]); + $triangle = new TriangleImmutable([[[0, 0, 7], [1, 0, 8]], [[2, 2, 9]]]); $copy = $triangle->withArrayOfCoordinates([[[3, 3, 10]]]); self::assertSame([[[0, 0, 7], [1, 0, 8]], [[2, 2, 9]]], $triangle->toArray()); self::assertSame([[[3, 3, 10]]], $copy->toArray()); - self::assertSame(Triangle::class, $copy::class); + self::assertSame(TriangleImmutable::class, (new \ReflectionClass($copy))->getName()); self::assertTrue($copy->hasM()); self::assertFalse($copy->hasZ()); } @@ -125,7 +125,7 @@ public function testXymTriangleStoresOpenBoundariesAndHoles(): void /** Xyz geography stores numeric ranges without validation. */ public function testXyzGeographyStoresNumericRangesWithoutValidation(): void { - $point = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point(181, 91, 5, 4326); + $point = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PointImmutable(181, 91, 5, 4326); $copy = $point->withCoordinates(Coordinates::xyz(-181, -91, 6)); self::assertSame([181, 91, 5], $point->toArray()); @@ -136,7 +136,7 @@ public function testXyzGeographyStoresNumericRangesWithoutValidation(): void /** Xyzm geography stores open polygon replacement. */ public function testXyzmGeographyStoresOpenPolygonReplacement(): void { - $polygon = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Polygon([[[181, 91, 5, 7]]], 4326); + $polygon = new \LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PolygonImmutable([[[181, 91, 5, 7]]], 4326); $copy = $polygon->withRing(0, [[182, 92, 6, 8], [183, 93, 7, 9]]); self::assertSame([[[181, 91, 5, 7]]], $polygon->toArray()); @@ -149,7 +149,7 @@ public function testXyzmGeographyStoresOpenPolygonReplacement(): void /** Xyzm surface stores unclosed patch replacement. */ public function testXyzmSurfaceStoresUnclosedPatchReplacement(): void { - $surface = new PolyhedralSurface([[[[0, 0, 0, 7]]]], 4326); + $surface = new PolyhedralSurfaceImmutable([[[[0, 0, 0, 7]]]], 4326); $copy = $surface->withRing(0, 0, [[181, 91, 1, 8], [182, 92, 2, 9]]); self::assertSame([[[[0, 0, 0, 7]]]], $surface->toArray()); @@ -160,7 +160,7 @@ public function testXyzmSurfaceStoresUnclosedPatchReplacement(): void /** Xyz surface stores disconnected and empty patches. */ public function testXyzSurfaceStoresDisconnectedAndEmptyPatches(): void { - $surface = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PolyhedralSurface([ + $surface = new \LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PolyhedralSurfaceImmutable([ [[[0, 0, 0], [1, 0, 0]]], [[[10, 10, 10]]], [], diff --git a/tests/Unit/Types/SpatialVariantContractTest.php b/tests/Unit/Types/SpatialVariantContractTest.php new file mode 100644 index 0000000..cba2779 --- /dev/null +++ b/tests/Unit/Types/SpatialVariantContractTest.php @@ -0,0 +1,321 @@ + 2024-2026 + * Copyright Longitude One 2024-2026 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + */ + +declare(strict_types=1); + +namespace LongitudeOne\SpatialTypes\Tests\Unit\Types; + +use LongitudeOne\SpatialTypes\Interfaces\CircularStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\CollectionInterface; +use LongitudeOne\SpatialTypes\Interfaces\CompoundCurveInterface; +use LongitudeOne\SpatialTypes\Interfaces\CurveInterface; +use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\MultiLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\MultiPointInterface; +use LongitudeOne\SpatialTypes\Interfaces\MultiPolygonInterface; +use LongitudeOne\SpatialTypes\Interfaces\MutableCircularStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\MutableCollectionInterface; +use LongitudeOne\SpatialTypes\Interfaces\MutableCompoundCurveInterface; +use LongitudeOne\SpatialTypes\Interfaces\MutableCurveInterface; +use LongitudeOne\SpatialTypes\Interfaces\MutableLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\MutableMultiLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\MutableMultiPointInterface; +use LongitudeOne\SpatialTypes\Interfaces\MutableMultiPolygonInterface; +use LongitudeOne\SpatialTypes\Interfaces\MutablePointInterface; +use LongitudeOne\SpatialTypes\Interfaces\MutablePolygonInterface; +use LongitudeOne\SpatialTypes\Interfaces\MutablePolyhedralSurfaceInterface; +use LongitudeOne\SpatialTypes\Interfaces\MutableSpatialInterface; +use LongitudeOne\SpatialTypes\Interfaces\MutableTriangleInterface; +use LongitudeOne\SpatialTypes\Interfaces\PointInterface; +use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface; +use LongitudeOne\SpatialTypes\Interfaces\PolyhedralSurfaceInterface; +use LongitudeOne\SpatialTypes\Interfaces\SpatialInterface; +use LongitudeOne\SpatialTypes\Interfaces\TriangleInterface; +use LongitudeOne\SpatialTypes\Types\AbstractSpatialType; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\CircularStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\CompoundCurveImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\GeographyCollectionImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\LineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiLineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiPointImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\MultiPolygonImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PointImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\PolygonImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geography\TriangleImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollectionImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PolyhedralSurfaceImmutable; +use PHPUnit\Framework\TestCase; + +/** Public variant contract boundaries. + * @internal + * + * @coversNothing + */ +class SpatialVariantContractTest extends TestCase +{ + /** The neutral base does not leak immutable replacement operations. */ + public function testCommonBaseExposesReadMethodsOnly(): void + { + foreach ((new \ReflectionClass(AbstractSpatialType::class))->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { + static::assertStringStartsNotWith('with', $method->getName()); + static::assertStringStartsNotWith('set', $method->getName()); + } + } + + /** All Dimension2 Geography concrete immutable types are final. */ + public function testDimension2GeographyClassesAreFinal(): void + { + static::assertTrue((new \ReflectionClass(CircularStringImmutable::class))->isFinal()); + static::assertTrue((new \ReflectionClass(CompoundCurveImmutable::class))->isFinal()); + static::assertTrue((new \ReflectionClass(GeographyCollectionImmutable::class))->isFinal()); + static::assertTrue((new \ReflectionClass(LineStringImmutable::class))->isFinal()); + static::assertTrue((new \ReflectionClass(MultiLineStringImmutable::class))->isFinal()); + static::assertTrue((new \ReflectionClass(MultiPointImmutable::class))->isFinal()); + static::assertTrue((new \ReflectionClass(MultiPolygonImmutable::class))->isFinal()); + static::assertTrue((new \ReflectionClass(PointImmutable::class))->isFinal()); + static::assertTrue((new \ReflectionClass(PolygonImmutable::class))->isFinal()); + static::assertTrue((new \ReflectionClass(TriangleImmutable::class))->isFinal()); + } + + /** All Dimension2 Geometry concrete immutable types are final. */ + public function testDimension2GeometryClassesAreFinal(): void + { + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularStringImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CircularString')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CompoundCurveImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\CompoundCurve')); + static::assertTrue((new \ReflectionClass(GeometryCollectionImmutable::class))->isFinal()); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiLineStringImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiLineString')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPointImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPoint')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPolygonImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPolygon')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PolygonImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Polygon')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\TriangleImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Triangle')); + } + + /** All Dimension3m Geography concrete immutable types are final. */ + public function testDimension3mGeographyClassesAreFinal(): void + { + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\CircularStringImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\CircularString')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\CompoundCurveImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\CompoundCurve')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\GeographyCollectionImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\GeographyCollection')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\LineStringImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\LineString')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiLineStringImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiLineString')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPointImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPoint')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPolygonImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\MultiPolygon')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\PointImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Point')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\PolygonImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Polygon')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\TriangleImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Triangle')); + } + + /** All Dimension3m Geometry concrete immutable types are final. */ + public function testDimension3mGeometryClassesAreFinal(): void + { + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\CircularStringImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\CircularString')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\CompoundCurveImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\CompoundCurve')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\GeometryCollectionImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\GeometryCollection')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\LineStringImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\LineString')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiLineStringImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiLineString')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPointImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPoint')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPolygonImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\MultiPolygon')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\PointImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Point')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\PolygonImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Polygon')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\TriangleImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Triangle')); + } + + /** All Dimension3z Geography concrete immutable types are final. */ + public function testDimension3zGeographyClassesAreFinal(): void + { + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\CircularStringImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\CircularString')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\CompoundCurveImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\CompoundCurve')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\GeographyCollectionImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\GeographyCollection')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\LineStringImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\LineString')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiLineStringImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiLineString')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPointImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPoint')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPolygonImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\MultiPolygon')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PointImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Point')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\PolygonImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Polygon')); + static::assertTrue((new \ReflectionClass(PolyhedralSurfaceImmutable::class))->isFinal()); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\TriangleImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Triangle')); + } + + /** All Dimension3z Geometry concrete immutable types are final. */ + public function testDimension3zGeometryClassesAreFinal(): void + { + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\CircularStringImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\CircularString')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\CompoundCurveImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\CompoundCurve')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\GeometryCollectionImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\GeometryCollection')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\LineStringImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\LineString')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiLineStringImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiLineString')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPointImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPoint')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPolygonImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\MultiPolygon')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PointImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Point')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PolygonImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Polygon')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PolyhedralSurfaceImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\PolyhedralSurface')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\TriangleImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Triangle')); + } + + /** All Dimension4zm Geography concrete immutable types are final. */ + public function testDimension4zmGeographyClassesAreFinal(): void + { + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\CircularStringImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\CircularString')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\CompoundCurveImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\CompoundCurve')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\GeographyCollectionImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\GeographyCollection')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\LineStringImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\LineString')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiLineStringImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiLineString')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiPointImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiPoint')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiPolygonImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\MultiPolygon')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PointImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Point')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PolygonImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Polygon')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PolyhedralSurfaceImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\PolyhedralSurface')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\TriangleImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Triangle')); + } + + /** All Dimension4zm Geometry concrete immutable types are final. */ + public function testDimension4zmGeometryClassesAreFinal(): void + { + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\CircularStringImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\CircularString')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\CompoundCurveImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\CompoundCurve')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\GeometryCollectionImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\GeometryCollection')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\LineStringImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\LineString')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiLineStringImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiLineString')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiPointImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiPoint')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiPolygonImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\MultiPolygon')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\PointImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Point')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\PolygonImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Polygon')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\PolyhedralSurfaceImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\PolyhedralSurface')); + static::assertTrue((new \ReflectionClass(\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\TriangleImmutable::class))->isFinal()); + static::assertFalse(class_exists('LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Triangle')); + } + + /** Mutable metadata setters belong to the mutable spatial contract. */ + public function testMutableMetadataContract(): void + { + $contract = new \ReflectionClass(MutableSpatialInterface::class); + static::assertTrue($contract->hasMethod('setFamily')); + static::assertTrue($contract->hasMethod('setSpatialReference')); + static::assertTrue($contract->hasMethod('setSrid')); + static::assertFalse($contract->hasMethod('setDimension')); + static::assertFalse($contract->hasMethod('withSrid')); + } + + /** Common and mutable contracts expose no copy operations. */ + public function testReadAndMutableContractsExposeNoCopyMethods(): void + { + $contracts = [ + CircularStringInterface::class, + CollectionInterface::class, + CompoundCurveInterface::class, + CurveInterface::class, + LineStringInterface::class, + MultiLineStringInterface::class, + MultiPointInterface::class, + MultiPolygonInterface::class, + MutableCircularStringInterface::class, + MutableCollectionInterface::class, + MutableCompoundCurveInterface::class, + MutableCurveInterface::class, + MutableLineStringInterface::class, + MutableMultiLineStringInterface::class, + MutableMultiPointInterface::class, + MutableMultiPolygonInterface::class, + MutablePointInterface::class, + MutablePolygonInterface::class, + MutablePolyhedralSurfaceInterface::class, + MutableSpatialInterface::class, + MutableTriangleInterface::class, + PointInterface::class, + PolygonInterface::class, + PolyhedralSurfaceInterface::class, + SpatialInterface::class, + TriangleInterface::class, + ]; + foreach ($contracts as $contract) { + foreach ((new \ReflectionClass($contract))->getMethods() as $method) { + static::assertStringStartsNotWith('with', $method->getName()); + static::assertNotSame('setDimension', $method->getName()); + } + } + } +} diff --git a/tests/Unit/Types/SpatialWithArrayOfCoordinatesTest.php b/tests/Unit/Types/SpatialWithArrayOfCoordinatesTest.php index e28ac2c..7943d97 100644 --- a/tests/Unit/Types/SpatialWithArrayOfCoordinatesTest.php +++ b/tests/Unit/Types/SpatialWithArrayOfCoordinatesTest.php @@ -27,8 +27,8 @@ /** * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractLineString - * @covers \LongitudeOne\SpatialTypes\Types\AbstractPolygon + * @covers \LongitudeOne\SpatialTypes\Types\AbstractLineStringImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractPolygonImmutable */ class SpatialWithArrayOfCoordinatesTest extends TestCase { @@ -51,7 +51,7 @@ private static function assertLineStringWasReplaced( CoordinateDimensionEnum $dimension ): void { static::assertNotSame($lineString, $replacement); - static::assertSame($lineString::class, $replacement::class); + static::assertSame($lineString::class, (new \ReflectionClass($replacement))->getName()); static::assertSame($family, $replacement->getFamily()); static::assertSame(4326, $replacement->getSrid()); static::assertSame($dimension->hasM(), $replacement->hasM()); @@ -113,7 +113,7 @@ public function testPolygonWithArrayOfCoordinates( $replacement = $polygon->withArrayOfCoordinates([$replacementCoordinates]); static::assertNotSame($polygon, $replacement); - static::assertSame($polygon::class, $replacement::class); + static::assertSame($polygon::class, (new \ReflectionClass($replacement))->getName()); static::assertSame($family, $replacement->getFamily()); static::assertSame(4326, $replacement->getSrid()); static::assertSame([$initialCoordinates], $polygon->toArray()); @@ -150,13 +150,13 @@ public function testWithArrayOfCoordinatesReturnsIndependentClones(): void $polygonClone = $polygon->withArrayOfCoordinates([[[7, 8, 9], [10, 11, 12], [13, 14, 15], [7, 8, 9]]]); static::assertNotSame($lineString, $lineStringClone); - static::assertSame($lineString::class, $lineStringClone::class); + static::assertSame($lineString::class, (new \ReflectionClass($lineStringClone))->getName()); static::assertSame(2154, $lineStringClone->getSrid()); static::assertNotSame($lineString->getPoint(0), $lineStringClone->getPoint(0)); static::assertSame([[1, 2, 3], [4, 5, 6]], $lineString->toArray()); static::assertNotSame($polygon, $polygonClone); - static::assertSame($polygon::class, $polygonClone::class); + static::assertSame($polygon::class, (new \ReflectionClass($polygonClone))->getName()); static::assertSame(2154, $polygonClone->getSrid()); static::assertNotSame($polygon->getRing(0), $polygonClone->getRing(0)); static::assertNotSame($polygon->getRing(0)->getPoint(0), $polygonClone->getRing(0)->getPoint(0)); diff --git a/tests/Unit/Types/SpatialWithLineStringTest.php b/tests/Unit/Types/SpatialWithLineStringTest.php index 4e27fca..d35b2cd 100644 --- a/tests/Unit/Types/SpatialWithLineStringTest.php +++ b/tests/Unit/Types/SpatialWithLineStringTest.php @@ -17,14 +17,14 @@ namespace LongitudeOne\SpatialTypes\Tests\Unit\Types; use LongitudeOne\SpatialTypes\Factory\FromIndexedArrayFactory; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiLineString; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiLineStringImmutable; use PHPUnit\Framework\TestCase; /** * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiLineString - * @covers \LongitudeOne\SpatialTypes\Types\AbstractPolygon + * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiLineStringImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractPolygonImmutable */ class SpatialWithLineStringTest extends TestCase { @@ -33,14 +33,14 @@ class SpatialWithLineStringTest extends TestCase */ public function testMultiLineStringWithLineStringReturnsAnIndependentCopy(): void { - $multiLineString = new MultiLineString([ + $multiLineString = new MultiLineStringImmutable([ [[0, 0], [1, 1]], [[2, 2], [3, 3]], ], 2154); $replacement = $multiLineString->withLineString(-1, [[4, 4], [5, 5]]); static::assertNotSame($multiLineString, $replacement); - static::assertSame($multiLineString::class, $replacement::class); + static::assertSame($multiLineString::class, (new \ReflectionClass($replacement))->getName()); static::assertSame(2154, $replacement->getSrid()); static::assertSame([[[0, 0], [1, 1]], [[2, 2], [3, 3]]], $multiLineString->toArray()); static::assertSame([[[0, 0], [1, 1]], [[4, 4], [5, 5]]], $replacement->toArray()); @@ -60,7 +60,7 @@ public function testPolygonWithRingReturnsAnIndependentCopy(): void $replacement = $polygon->withRing(0, [[-1, -1], [11, -1], [-1, 11], [-1, -1]]); static::assertNotSame($polygon, $replacement); - static::assertSame($polygon::class, $replacement::class); + static::assertSame($polygon::class, (new \ReflectionClass($replacement))->getName()); static::assertSame(2154, $replacement->getSrid()); static::assertSame([[[0, 0], [10, 0], [0, 10], [0, 0]], [[1, 1], [2, 1], [1, 2], [1, 1]]], $polygon->toArray()); static::assertSame([[[-1, -1], [11, -1], [-1, 11], [-1, -1]], [[1, 1], [2, 1], [1, 2], [1, 1]]], $replacement->toArray()); diff --git a/tests/Unit/Types/SpatialWithPointTest.php b/tests/Unit/Types/SpatialWithPointTest.php index f875d7d..a4760b2 100644 --- a/tests/Unit/Types/SpatialWithPointTest.php +++ b/tests/Unit/Types/SpatialWithPointTest.php @@ -26,8 +26,8 @@ /** * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractLineString - * @covers \LongitudeOne\SpatialTypes\Types\AbstractPolygon + * @covers \LongitudeOne\SpatialTypes\Types\AbstractLineStringImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractPolygonImmutable */ class SpatialWithPointTest extends TestCase { @@ -52,7 +52,7 @@ public function testLineStringWithPointReturnsAnIndependentCopy(): void $replacement = $lineString->withPoint(1, Coordinates::xym(7, 8, 9)); static::assertNotSame($lineString, $replacement); - static::assertSame($lineString::class, $replacement::class); + static::assertSame($lineString::class, (new \ReflectionClass($replacement))->getName()); static::assertSame(2154, $replacement->getSrid()); static::assertSame([[1, 2, 3], [4, 5, 6]], $lineString->toArray()); static::assertSame([[1, 2, 3], [7, 8, 9]], $replacement->toArray()); @@ -72,7 +72,7 @@ public function testPolygonWithPointPreservesExteriorRingClosure(): void $replacement = $polygon->withPoint(0, 0, Coordinates::xy(-1, -1)); static::assertNotSame($polygon, $replacement); - static::assertSame($polygon::class, $replacement::class); + static::assertSame($polygon::class, (new \ReflectionClass($replacement))->getName()); static::assertSame(2154, $replacement->getSrid()); static::assertSame([[[0, 0], [10, 0], [0, 10], [0, 0]], [[1, 1], [2, 1], [1, 2], [1, 1]]], $polygon->toArray()); static::assertSame([[[-1, -1], [10, 0], [0, 10], [-1, -1]], [[1, 1], [2, 1], [1, 2], [1, 1]]], $replacement->toArray()); diff --git a/tests/Unit/Types/SpatialWithSridTest.php b/tests/Unit/Types/SpatialWithSridTest.php index f0a183d..222f591 100644 --- a/tests/Unit/Types/SpatialWithSridTest.php +++ b/tests/Unit/Types/SpatialWithSridTest.php @@ -16,43 +16,43 @@ namespace LongitudeOne\SpatialTypes\Tests\Unit\Types; -use LongitudeOne\SpatialTypes\Interfaces\CollectionInterface; -use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableCollectionInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableLineStringInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutablePolygonInterface; +use LongitudeOne\SpatialTypes\Interfaces\ImmutableSpatialInterface; use LongitudeOne\SpatialTypes\Interfaces\PointInterface; -use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface; -use LongitudeOne\SpatialTypes\Interfaces\SpatialInterface; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollection; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiLineString; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPoint; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPolygon; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Polygon; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\GeometryCollectionImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiLineStringImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPointImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\MultiPolygonImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PolygonImmutable; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractCollection - * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiLineString - * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiPoint - * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiPolygon - * @covers \LongitudeOne\SpatialTypes\Types\AbstractPolygon - * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialType + * @covers \LongitudeOne\SpatialTypes\Types\AbstractCollectionImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiLineStringImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiPointImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractMultiPolygonImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractPolygonImmutable + * @covers \LongitudeOne\SpatialTypes\Types\AbstractSpatialTypeImmutable */ class SpatialWithSridTest extends TestCase { /** * Assert that an aggregate and every descendant were copied with SRID 2154. * - * @param SpatialInterface $source original spatial object - * @param SpatialInterface $copy copied spatial object + * @param ImmutableSpatialInterface $source original spatial object + * @param ImmutableSpatialInterface $copy copied spatial object */ - private static function assertCopiedTree(SpatialInterface $source, SpatialInterface $copy): void + private static function assertCopiedTree(ImmutableSpatialInterface $source, ImmutableSpatialInterface $copy): void { static::assertNotSame($source, $copy); - static::assertSame($source::class, $copy::class); + static::assertSame($source::class, (new \ReflectionClass($copy))->getName()); static::assertSame($source->toArray(), $copy->toArray()); static::assertSame(2154, $copy->getSrid()); @@ -68,17 +68,17 @@ private static function assertCopiedTree(SpatialInterface $source, SpatialInterf /** * Return direct child spatial objects for a spatial aggregate. * - * @param SpatialInterface $spatial spatial object to inspect + * @param ImmutableSpatialInterface $spatial spatial object to inspect * - * @return SpatialInterface[] + * @return ImmutableSpatialInterface[] */ - private static function childrenOf(SpatialInterface $spatial): array + private static function childrenOf(ImmutableSpatialInterface $spatial): array { return match (true) { $spatial instanceof PointInterface => [], - $spatial instanceof LineStringInterface => $spatial->getPoints(), - $spatial instanceof PolygonInterface => $spatial->getRings(), - $spatial instanceof CollectionInterface => $spatial->getElements(), + $spatial instanceof ImmutableLineStringInterface => $spatial->getPoints(), + $spatial instanceof ImmutablePolygonInterface => $spatial->getRings(), + $spatial instanceof ImmutableCollectionInterface => $spatial->getElements(), default => [], }; } @@ -86,34 +86,34 @@ private static function childrenOf(SpatialInterface $spatial): array /** * Create a line string whose points share its spatial reference. */ - private static function createLineString(): LineString + private static function createLineString(): LineStringImmutable { - return new LineString([ - new Point(1, 2, 4326), - new Point(3, 4, 4326), + return new LineStringImmutable([ + new PointImmutable(1, 2, 4326), + new PointImmutable(3, 4, 4326), ], 4326); } /** * Create a polygon whose boundary shares its spatial reference. */ - private static function createPolygon(): Polygon + private static function createPolygon(): PolygonImmutable { - return new Polygon([new LineString([ - new Point(0, 0, 4326), - new Point(1, 0, 4326), - new Point(0, 1, 4326), - new Point(0, 0, 4326), + return new PolygonImmutable([new LineStringImmutable([ + new PointImmutable(0, 0, 4326), + new PointImmutable(1, 0, 4326), + new PointImmutable(0, 1, 4326), + new PointImmutable(0, 0, 4326), ], 4326)], 4326); } /** * Verify that every nested spatial object receives the requested SRID. * - * @param SpatialInterface $spatial spatial object to copy + * @param ImmutableSpatialInterface $spatial spatial object to copy */ #[DataProvider('provideSpatialTypes')] - public function testWithSridCopiesAllNestedSpatialObjects(SpatialInterface $spatial): void + public function testWithSridCopiesAllNestedSpatialObjects(ImmutableSpatialInterface $spatial): void { $spatialWithSrid = $spatial->withSrid(2154); @@ -122,22 +122,22 @@ public function testWithSridCopiesAllNestedSpatialObjects(SpatialInterface $spat } /** - * @return \Generator + * @return \Generator */ public static function provideSpatialTypes(): \Generator { - yield 'multipoint' => [new MultiPoint([ - new Point(1, 2, 4326), - new Point(3, 4, 4326), + yield 'multipoint' => [new MultiPointImmutable([ + new PointImmutable(1, 2, 4326), + new PointImmutable(3, 4, 4326), ], 4326)]; yield 'polygon' => [self::createPolygon()]; - yield 'multi-line string' => [new MultiLineString([self::createLineString()], 4326)]; + yield 'multi-line string' => [new MultiLineStringImmutable([self::createLineString()], 4326)]; - yield 'multi-polygon' => [new MultiPolygon([self::createPolygon()], 4326)]; + yield 'multi-polygon' => [new MultiPolygonImmutable([self::createPolygon()], 4326)]; - $collection = new GeometryCollection(4326, [self::createPolygon()]); + $collection = new GeometryCollectionImmutable(4326, [self::createPolygon()]); yield 'geometry collection' => [$collection]; } diff --git a/tests/Unit/Types/SridDefaultTest.php b/tests/Unit/Types/SridDefaultTest.php index e290143..aee4a16 100644 --- a/tests/Unit/Types/SridDefaultTest.php +++ b/tests/Unit/Types/SridDefaultTest.php @@ -16,7 +16,7 @@ namespace LongitudeOne\SpatialTypes\Tests\Unit\Types; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; use PHPUnit\Framework\TestCase; /** @@ -31,7 +31,7 @@ class SridDefaultTest extends TestCase */ public function testSpatialObjectsUseTheUnnamedReference(): void { - $point = new Point(1, 2); + $point = new PointImmutable(1, 2); static::assertSame(0, $point->getSrid()); static::assertSame(0, $point->getSpatialReference()->srid()); diff --git a/tests/Unit/Types/TriangleTest.php b/tests/Unit/Types/TriangleTest.php index e6d1839..fe77bb4 100644 --- a/tests/Unit/Types/TriangleTest.php +++ b/tests/Unit/Types/TriangleTest.php @@ -20,8 +20,8 @@ use LongitudeOne\SpatialTypes\Exception\InvalidValueException; use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface; use LongitudeOne\SpatialTypes\Reference\SpatialReference; -use LongitudeOne\SpatialTypes\Types\AbstractTriangle; -use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Triangle; +use LongitudeOne\SpatialTypes\Types\AbstractTriangleImmutable; +use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\TriangleImmutable; use LongitudeOne\SpatialTypes\Value\Coordinates; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; @@ -29,7 +29,7 @@ /** * @internal * - * @covers \LongitudeOne\SpatialTypes\Types\AbstractTriangle + * @covers \LongitudeOne\SpatialTypes\Types\AbstractTriangleImmutable */ class TriangleTest extends TestCase { @@ -37,7 +37,7 @@ class TriangleTest extends TestCase * @param string $class Concrete type * @param list $ring Exterior coordinates * - * @phpstan-param class-string $class + * @phpstan-param class-string $class */ #[DataProvider('triangles')] public function testConstructionAndCopies(string $class, array $ring): void @@ -57,7 +57,7 @@ public function testConstructionAndCopies(string $class, array $ring): void $copies = [$triangle->withRing(-1, $ring), $triangle->withArrayOfCoordinates([$ring]), $triangle->withSrid(3857), $triangle->withSpatialReference(SpatialReference::epsg(4326))]; foreach ($copies as $copy) { - static::assertSame($class, $copy::class); + static::assertSame($class, (new \ReflectionClass($copy))->getName()); static::assertSame($triangle->getFamily(), $copy->getFamily()); static::assertTrue($triangle->hasSameDimension($copy)); static::assertSame([$ring], $copy->toArray()); @@ -77,7 +77,7 @@ public function testConstructionAndCopies(string $class, array $ring): void * @param string $class Concrete type * @param list $ring Exterior coordinates * - * @phpstan-param class-string $class + * @phpstan-param class-string $class */ #[DataProvider('triangles')] public function testPointReplacementPreservesClosure(string $class, array $ring): void @@ -92,7 +92,7 @@ public function testPointReplacementPreservesClosure(string $class, array $ring) static::assertInstanceOf(Coordinates::class, $coordinates); foreach ([0, -1] as $index) { $copy = $triangle->withPoint(0, $index, $coordinates); - static::assertSame($class, $copy::class); + static::assertSame($class, (new \ReflectionClass($copy))->getName()); static::assertSame([$replacementRing], $copy->toArray()); static::assertSame([$ring], $triangle->toArray()); static::assertSame(4326, $copy->getSrid()); @@ -105,7 +105,7 @@ public function testPointReplacementPreservesClosure(string $class, array $ring) * @param string $class Concrete type * @param list $ring Exterior coordinates * - * @phpstan-param class-string $class + * @phpstan-param class-string $class */ #[DataProvider('triangles')] public function testRejectsInvalidCoordinates(string $class, array $ring): void @@ -115,23 +115,23 @@ public function testRejectsInvalidCoordinates(string $class, array $ring): void new $class([$ring]); } - /** @return iterable, list}> */ + /** @return iterable, list}> */ public static function triangles(): iterable { - yield 'Dimension2 Geometry' => [Triangle::class, [[0, 0], [4, 0], [0, 4], [0, 0]]]; + yield 'Dimension2 Geometry' => [TriangleImmutable::class, [[0, 0], [4, 0], [0, 4], [0, 0]]]; - yield 'Dimension2 Geography' => [\LongitudeOne\SpatialTypes\Types\Dimension2\Geography\Triangle::class, [[0, 0], [4, 0], [0, 4], [0, 0]]]; + yield 'Dimension2 Geography' => [\LongitudeOne\SpatialTypes\Types\Dimension2\Geography\TriangleImmutable::class, [[0, 0], [4, 0], [0, 4], [0, 0]]]; - yield 'Dimension3m Geometry' => [\LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\Triangle::class, [[0, 0, 7], [4, 0, 7], [0, 4, 7], [0, 0, 7]]]; + yield 'Dimension3m Geometry' => [\LongitudeOne\SpatialTypes\Types\Dimension3m\Geometry\TriangleImmutable::class, [[0, 0, 7], [4, 0, 7], [0, 4, 7], [0, 0, 7]]]; - yield 'Dimension3m Geography' => [\LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\Triangle::class, [[0, 0, 7], [4, 0, 7], [0, 4, 7], [0, 0, 7]]]; + yield 'Dimension3m Geography' => [\LongitudeOne\SpatialTypes\Types\Dimension3m\Geography\TriangleImmutable::class, [[0, 0, 7], [4, 0, 7], [0, 4, 7], [0, 0, 7]]]; - yield 'Dimension3z Geometry' => [\LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\Triangle::class, [[0, 0, 5], [4, 0, 5], [0, 4, 5], [0, 0, 5]]]; + yield 'Dimension3z Geometry' => [\LongitudeOne\SpatialTypes\Types\Dimension3z\Geometry\TriangleImmutable::class, [[0, 0, 5], [4, 0, 5], [0, 4, 5], [0, 0, 5]]]; - yield 'Dimension3z Geography' => [\LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\Triangle::class, [[0, 0, 5], [4, 0, 5], [0, 4, 5], [0, 0, 5]]]; + yield 'Dimension3z Geography' => [\LongitudeOne\SpatialTypes\Types\Dimension3z\Geography\TriangleImmutable::class, [[0, 0, 5], [4, 0, 5], [0, 4, 5], [0, 0, 5]]]; - yield 'Dimension4zm Geometry' => [\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\Triangle::class, [[0, 0, 5, 7], [4, 0, 5, 7], [0, 4, 5, 7], [0, 0, 5, 7]]]; + yield 'Dimension4zm Geometry' => [\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geometry\TriangleImmutable::class, [[0, 0, 5, 7], [4, 0, 5, 7], [0, 4, 5, 7], [0, 0, 5, 7]]]; - yield 'Dimension4zm Geography' => [\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\Triangle::class, [[0, 0, 5, 7], [4, 0, 5, 7], [0, 4, 5, 7], [0, 0, 5, 7]]]; + yield 'Dimension4zm Geography' => [\LongitudeOne\SpatialTypes\Types\Dimension4zm\Geography\TriangleImmutable::class, [[0, 0, 5, 7], [4, 0, 5, 7], [0, 4, 5, 7], [0, 0, 5, 7]]]; } }