Skip to content

Commit

Permalink
Merge branch 'v0.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Nov 21, 2022
2 parents 47bdb4e + 276c04c commit 8a696d8
Show file tree
Hide file tree
Showing 57 changed files with 3,048 additions and 2,709 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog

## UNRELEASED (0.9.0)

💥 **Breaking changes**

- Proxies are now `@internal` and considered an implementation detail. This means that they are no longer part of the public API and can change at any time. This means that you should *always* type-hint against the base class and not the proxy.
- `Point` constructor now throw an exception when passing NaN or infinite coordinates.
- `GeometryEngine::pointOnSurface()` now returns `Point` instead of `Geometry`.

🐛 **Bug fixes**

- `Geometry::withSRID()` now properly propagates the SRID to all sub-geometries. Previously, only the top-level geometry was updated.
- `Point` constructor would error when destructuring an associative array.

**New features**

- New `Projector` API to reproject geometry coordinates.
- New method: `Polygon::rings()`
- New method: `Geometry::isIdenticalTo()`

**Improvements**

- `GeometryCollection::geometryN()` is now properly documented with generics

## [0.8.1](https://github.com/brick/geo/releases/tag/0.8.1) - 2022-10-14

**Improvements**
Expand Down
6 changes: 3 additions & 3 deletions proxy-generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use Brick\Geo\Attribute\NoProxy;
use Brick\Geo\BoundingBox;
use Brick\Geo\CoordinateSystem;
use Brick\Reflection\ReflectionTools;
Expand Down Expand Up @@ -70,9 +71,7 @@ function removeDuplicateImports(string $proxyCode): string
continue;
}

$docComment = $method->getDocComment();

if ($docComment !== false && str_contains($docComment, '@noproxy')) {
if ($method->getAttributes(NoProxy::class)) {
continue;
}

Expand Down Expand Up @@ -102,6 +101,7 @@ function removeDuplicateImports(string $proxyCode): string
}

$proxyCode = $proxyTemplate;
$proxyCode = str_replace('_FQCN_', $class->getName(), $proxyCode);
$proxyCode = str_replace('_CLASSNAME_', $class->getShortName(), $proxyCode);
$proxyCode = str_replace('// METHODS', $methods, $proxyCode);
$proxyCode = removeDuplicateImports($proxyCode);
Expand Down
3 changes: 3 additions & 0 deletions proxy-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

/**
* Proxy class for _CLASSNAME_.
*
* @internal This class is not part of the public API and can change at any time.
* Please type-hint against _FQCN_ in your projects.
*/
class _CLASSNAME_Proxy extends _CLASSNAME_ implements ProxyInterface
{
Expand Down
108 changes: 14 additions & 94 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,99 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.28.0@52e96bea381e6cb07a672aefec791a5817694a26">
<file src="src/CircularString.php">
<LessSpecificReturnStatement occurrences="3">
<code>new CircularString($cs, ...$geometries)</code>
<code>new CircularString($cs, ...$points)</code>
<code>new CircularString($cs, ...$points)</code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType occurrences="3">
<code>CircularString</code>
<code>CircularString</code>
<code>CircularString</code>
</MoreSpecificReturnType>
</file>
<file src="src/CompoundCurve.php">
<LessSpecificReturnStatement occurrences="3">
<code>new CompoundCurve($cs, ...$curves)</code>
<code>new CompoundCurve($cs, ...$curves)</code>
<code>new CompoundCurve($cs, ...$curves)</code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType occurrences="3">
<code>CompoundCurve</code>
<code>CompoundCurve</code>
<code>CompoundCurve</code>
</MoreSpecificReturnType>
</file>
<file src="src/CurvePolygon.php">
<LessSpecificReturnStatement occurrences="3">
<code>new CurvePolygon($cs, ...$rings)</code>
<code>new CurvePolygon($cs, ...$rings)</code>
<code>new CurvePolygon($cs, ...$rings)</code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType occurrences="3">
<code>CurvePolygon</code>
<code>CurvePolygon</code>
<code>CurvePolygon</code>
</MoreSpecificReturnType>
</file>
<file src="src/GeometryCollection.php">
<LessSpecificReturnStatement occurrences="3">
<code>new GeometryCollection($cs, ...$geometries)</code>
<code>new GeometryCollection($cs, ...$geometries)</code>
<code>new GeometryCollection($cs, ...$geometries)</code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType occurrences="3">
<code>GeometryCollection</code>
<code>GeometryCollection</code>
<code>GeometryCollection</code>
</MoreSpecificReturnType>
</file>
<file src="src/LineString.php">
<LessSpecificReturnStatement occurrences="3">
<code>new LineString($cs, ...$points)</code>
<code>new LineString($cs, ...$points)</code>
<code>new LineString($cs, ...$points)</code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType occurrences="3">
<code>LineString</code>
<code>LineString</code>
<code>LineString</code>
</MoreSpecificReturnType>
</file>
<file src="src/Point.php">
<LessSpecificReturnStatement occurrences="3">
<code>new Point($cs, ...$coords)</code>
<code>new Point($cs, ...$coords)</code>
<code>new Point($cs, ...$coords)</code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType occurrences="3">
<code>Point</code>
<code>Point</code>
<code>Point</code>
</MoreSpecificReturnType>
</file>
<file src="src/Polygon.php">
<LessSpecificReturnStatement occurrences="3">
<code>new Polygon($cs, ...$rings)</code>
<code>new Polygon($cs, ...$rings)</code>
<code>new Polygon($cs, ...$rings)</code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType occurrences="3">
<code>Polygon</code>
<code>Polygon</code>
<code>Polygon</code>
</MoreSpecificReturnType>
</file>
<file src="src/PolyhedralSurface.php">
<LessSpecificReturnStatement occurrences="3">
<code>new PolyhedralSurface($cs, ...$patches)</code>
<code>new PolyhedralSurface($cs, ...$patches)</code>
<code>new PolyhedralSurface($cs, ...$patches)</code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType occurrences="3">
<code>PolyhedralSurface</code>
<code>PolyhedralSurface</code>
<code>PolyhedralSurface</code>
<file src="src/Geometry.php">
<LessSpecificReturnStatement occurrences="5">
<code>$this-&gt;project(new RemoveZMProjector(removeM: true))</code>
<code>$this-&gt;project(new RemoveZMProjector(removeZ: true))</code>
<code>$this-&gt;project(new RemoveZMProjector(removeZ: true, removeM: true))</code>
<code>$this-&gt;project(new SRIDProjector($srid))</code>
<code>$this-&gt;project(new SwapXYProjector())</code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType occurrences="5">
<code>static</code>
<code>static</code>
<code>static</code>
<code>static</code>
<code>static</code>
</MoreSpecificReturnType>
</file>
</files>
15 changes: 15 additions & 0 deletions src/Attribute/NoProxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Brick\Geo\Attribute;

use Attribute;

/**
* Used to tag a method that should not be proxied in Proxy classes.
*/
#[Attribute(Attribute::TARGET_METHOD)]
final class NoProxy
{
}
67 changes: 12 additions & 55 deletions src/CircularString.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
namespace Brick\Geo;

use ArrayIterator;
use Brick\Geo\Attribute\NoProxy;
use Brick\Geo\Exception\CoordinateSystemException;
use Brick\Geo\Exception\EmptyGeometryException;
use Brick\Geo\Exception\InvalidGeometryException;
use Brick\Geo\Exception\NoSuchGeometryException;
use Brick\Geo\Projector\Projector;

/**
* A CircularString is a Curve made of zero or more connected circular arc segments.
Expand Down Expand Up @@ -124,63 +126,18 @@ public function points() : array
return $this->points;
}

/**
* @noproxy
*/
#[NoProxy]
public function geometryType() : string
{
return 'CircularString';
}

/**
* @noproxy
*/
#[NoProxy]
public function geometryTypeBinary() : int
{
return Geometry::CIRCULARSTRING;
}

public function toXY(): CircularString
{
if ($this->coordinateDimension() === 2) {
return $this;
}

$cs = $this->coordinateSystem
->withZ(false)
->withM(false);

$points = array_map(fn(Point $point) => $point->toXY(), $this->points);

return new CircularString($cs, ...$points);
}

public function withoutZ(): CircularString
{
if (! $this->coordinateSystem->hasZ()) {
return $this;
}

$cs = $this->coordinateSystem->withZ(false);

$points = array_map(fn(Point $point) => $point->withoutZ(), $this->points);

return new CircularString($cs, ...$points);
}

public function withoutM(): CircularString
{
if (! $this->coordinateSystem->hasM()) {
return $this;
}

$cs = $this->coordinateSystem->withM(false);

$geometries = array_map(fn(Point $point) => $point->withoutM(), $this->points);

return new CircularString($cs, ...$geometries);
}

public function getBoundingBox() : BoundingBox
{
$boundingBox = new BoundingBox();
Expand All @@ -203,15 +160,15 @@ public function toArray() : array
return $result;
}

public function swapXY() : Geometry
public function project(Projector $projector): CircularString
{
$that = clone $this;

foreach ($that->points as & $point) {
$point = $point->swapXY();
}

return $that;
return new CircularString(
$projector->getTargetCoordinateSystem($this->coordinateSystem),
...array_map(
fn (Point $point) => $point->project($projector),
$this->points,
),
);
}

/**
Expand Down
Loading

0 comments on commit 8a696d8

Please sign in to comment.