Skip to content

Commit

Permalink
Dimension helper removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre-T committed Aug 8, 2024
1 parent 20b9df5 commit 6c3da7d
Show file tree
Hide file tree
Showing 33 changed files with 441 additions and 236 deletions.
2 changes: 1 addition & 1 deletion lib/LongitudeOne/SpatialTypes/Enum/DimensionEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* Dimension enumeration.
*
* This enumeration is used to define the dimensions of a geometry or a geography instance.
* This enumeration is used to define the dimensions of spatial instances.
*/
enum DimensionEnum: string
{
Expand Down
11 changes: 11 additions & 0 deletions lib/LongitudeOne/SpatialTypes/Enum/FamilyEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@

namespace LongitudeOne\SpatialTypes\Enum;

/**
* Family enumeration.
*
* This enumeration is used to define the family of spatial instances.
*
* Geography instances use by default Longitude and latitude.
* So, coordinates are in degrees and shall respect ranges.
*
* Geometric instances use by default Cartesian coordinates.
* So, coordinates shall not respect any ranges.
*/
enum FamilyEnum: string
{
case GEOGRAPHY = 'Geography';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

/**
* This exception is thrown when mixing objects with non-compatible dimensions.
*
* For example, when you try to add a PointM in a MultiPointZ object, this exception is thrown.
*/
class InvalidDimensionException extends \Exception implements SpatialTypeExceptionInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
namespace LongitudeOne\SpatialTypes\Exception;

/**
* This exception is thrown when mixing objects with non-compatible dimensions.
* This exception is thrown when mixing objects with non-compatible SRID.
*
* For example, when you try to add a Point with SRID 4326 in a MultiPoint with SRID 3857, this exception is thrown.
* But if any of the objects has no SRID, the operation is allowed.
* For example, you can add a Point with SRID 4326 in a MultiPoint without SRID.
* But be careful, after an instance has been associated with another one; the library no more checks the SRID.
* Be aware developers are responsible to check the SRID before any operation and shall not update SRID after association.
*/
class InvalidSridException extends \Exception implements SpatialTypeExceptionInterface
{
Expand Down
21 changes: 0 additions & 21 deletions lib/LongitudeOne/SpatialTypes/Exception/JsonException.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
namespace LongitudeOne\SpatialTypes\Exception;

/**
* This exception is thrown when a developer tries to get a point of an empty linestring.
* This exception is thrown when a developer tries to get an instance point of an empty collection.
*
* For example, when you try to get the first point of an empty linestring, this exception is thrown.
*/
class OutOfBoundsException extends \OutOfBoundsException implements SpatialTypeExceptionInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
use Throwable;

/**
* All exceptions throwable by spatial types must implement this interface.
* All exceptions throwable by longitude-one/spatial-types implement this interface.
*
* So developers can catch all exceptions related to spatial types with this interface.
*/
interface SpatialTypeExceptionInterface extends \Throwable
{
Expand Down
7 changes: 7 additions & 0 deletions lib/LongitudeOne/SpatialTypes/Factory/FactoryLineString.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
use LongitudeOne\SpatialTypes\Types\Geography\LineString as GeographyLineString;
use LongitudeOne\SpatialTypes\Types\Geometry\LineString as GeometryLineString;

/**
* Factory LineString class.
*
* @internal This class is internal. It is used to create a linestring from an array of points or an indexed array.
*
* Developer can use it, but be aware that there is no backward compatibility pledge.
*/
class FactoryLineString
{
/**
Expand Down
14 changes: 9 additions & 5 deletions lib/LongitudeOne/SpatialTypes/Factory/FactoryPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@
use LongitudeOne\SpatialTypes\Exception\InvalidDimensionException;
use LongitudeOne\SpatialTypes\Exception\InvalidValueException;
use LongitudeOne\SpatialTypes\Exception\MissingValueException;
use LongitudeOne\SpatialTypes\Helper\DimensionHelper;
use LongitudeOne\SpatialTypes\Interfaces\PointInterface;
use LongitudeOne\SpatialTypes\Types\Geography\Point as GeographicPoint;
use LongitudeOne\SpatialTypes\Types\Geometry\Point as GeometricPoint;

/**
* Factory Point class.
*
* @internal This class is internal. It is used to create a point from an array of coordinates.
*
* Developer can use it, but be aware that there is no backward compatibility pledge.
*/
class FactoryPoint
{
/**
Expand Down Expand Up @@ -82,8 +88,6 @@ public static function fromIndexedArray(
FamilyEnum $family = FamilyEnum::GEOMETRY,
DimensionEnum $dimension = DimensionEnum::X_Y
): PointInterface {
$dimensionHelper = new DimensionHelper($dimension);

if (count($point) < 2) {
throw new MissingValueException('The array must contain at least two coordinates to create a point.');
}
Expand All @@ -100,11 +104,11 @@ public static function fromIndexedArray(
throw new MissingValueException('The second coordinate of array is missing.');
}

if ($dimensionHelper->hasZ() && !isset($point[2])) {
if (in_array($dimension, [DimensionEnum::X_Y_Z, DimensionEnum::X_Y_Z_M], true) && !isset($point[2])) {
throw new MissingValueException('The third coordinate of array is missing.');
}

if ($dimensionHelper->hasM() && !isset($point[3])) {
if (in_array($dimension, [DimensionEnum::X_Y_M, DimensionEnum::X_Y_Z_M], true) && !isset($point[3])) {
throw new MissingValueException('The fourth coordinate of array is missing.');
}

Expand Down
8 changes: 8 additions & 0 deletions lib/LongitudeOne/SpatialTypes/Factory/FactoryPolygon.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
use LongitudeOne\SpatialTypes\Types\Geography\Polygon as GeographyPolygon;
use LongitudeOne\SpatialTypes\Types\Geometry\Polygon as GeometryPolygon;

/**
* Factory Polygon class.
*
* This class helps
* to create a polygon from an array of lineStrings or a bi-dimensional array of Points or an indexed array.
*
* @internal This class is internal. You can use it, but be aware that there is no backward compatibility pledge.
*/
class FactoryPolygon
{
/**
Expand Down
87 changes: 0 additions & 87 deletions lib/LongitudeOne/SpatialTypes/Helper/DimensionHelper.php

This file was deleted.

45 changes: 0 additions & 45 deletions lib/LongitudeOne/SpatialTypes/Interfaces/DimensionInterface.php

This file was deleted.

5 changes: 5 additions & 0 deletions lib/LongitudeOne/SpatialTypes/Trait/LineStringTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
use LongitudeOne\SpatialTypes\Interfaces\LineStringInterface;
use LongitudeOne\SpatialTypes\Interfaces\PointInterface;

/**
* Line string trait.
*
* @internal trait is used internally to avoid code duplication
*/
trait LineStringTrait
{
/**
Expand Down
2 changes: 2 additions & 0 deletions lib/LongitudeOne/SpatialTypes/Trait/PointTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* This trait helps to manage point in linestring and multipoint classes.
*
* Line string and multipoint are considered as spatial collections of points.
*
* @internal trait is used internally to avoid code duplication
*/
trait PointTrait
{
Expand Down
5 changes: 5 additions & 0 deletions lib/LongitudeOne/SpatialTypes/Types/AbstractCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
use LongitudeOne\SpatialTypes\Types\Geography\GeographyCollection;
use LongitudeOne\SpatialTypes\Types\Geometry\GeometryCollection;

/**
* Abstract Collection class.
*
* @internal This class is internal. It is used to create geometry or geography collection of spatial objects.
*/
abstract class AbstractCollection extends AbstractSpatialType implements CollectionInterface
{
/**
Expand Down
5 changes: 5 additions & 0 deletions lib/LongitudeOne/SpatialTypes/Types/AbstractLineString.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
use LongitudeOne\SpatialTypes\Interfaces\PointInterface;
use LongitudeOne\SpatialTypes\Trait\PointTrait;

/**
* Abstract LineString class.
*
* @internal This class is internal. It is used to create geometry or geography line string of spatial objects.
*/
abstract class AbstractLineString extends AbstractSpatialType implements LineStringInterface
{
use PointTrait;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
use LongitudeOne\SpatialTypes\Interfaces\PointInterface;
use LongitudeOne\SpatialTypes\Trait\LineStringTrait;

/**
* Abstract MultiLineString class.
*
* @internal This class is internal. It is used to create geometry or geography multi line string of spatial objects.
*/
abstract class AbstractMultiLineString extends AbstractSpatialType implements MultiLineStringInterface
{
use LineStringTrait;
Expand Down
5 changes: 5 additions & 0 deletions lib/LongitudeOne/SpatialTypes/Types/AbstractMultiPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
use LongitudeOne\SpatialTypes\Interfaces\PointInterface;
use LongitudeOne\SpatialTypes\Trait\PointTrait;

/**
* Abstract MultiPoint class.
*
* @internal This class is internal. It is used to create geometry or geography multi point of spatial objects.
*/
abstract class AbstractMultiPoint extends AbstractSpatialType implements MultiPointInterface
{
use PointTrait;
Expand Down
4 changes: 3 additions & 1 deletion lib/LongitudeOne/SpatialTypes/Types/AbstractMultiPolygon.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
use LongitudeOne\SpatialTypes\Interfaces\PolygonInterface;

/**
* Multi polygon abstract class.
* Abstract MultiPolygon class.
*
* @internal This class is internal. It is used to create geometry or geography multi polygon of spatial objects.
*/
abstract class AbstractMultiPolygon extends AbstractSpatialType implements MultiPolygonInterface
{
Expand Down
2 changes: 2 additions & 0 deletions lib/LongitudeOne/SpatialTypes/Types/AbstractPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
*
* @see https://stackoverflow.com/questions/7309121/preferred-order-of-writing-latitude-longitude-tuples
* @see https://docs.geotools.org/latest/userguide/library/referencing/order.html
*
* @internal This class is internal. It is used to create geometry or geography point of spatial objects.
*/
abstract class AbstractPoint extends AbstractSpatialType implements PointInterface
{
Expand Down
Loading

0 comments on commit 6c3da7d

Please sign in to comment.