• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

brick / geo / 13700983528

06 Mar 2025 02:28PM UTC coverage: 48.121% (+0.6%) from 47.546%
13700983528

Pull #55

github

web-flow
Merge 41526e1ed into 723c55ddf
Pull Request #55: Add LineInterpolatePoint for Postgis

15 of 21 new or added lines in 3 files covered. (71.43%)

54 existing lines in 10 files now uncovered.

1652 of 3433 relevant lines covered (48.12%)

967.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.42
/src/CurvePolygon.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Brick\Geo;
6

7
use ArrayIterator;
8
use Brick\Geo\Attribute\NoProxy;
9
use Brick\Geo\Exception\CoordinateSystemException;
10
use Brick\Geo\Exception\EmptyGeometryException;
11
use Brick\Geo\Exception\NoSuchGeometryException;
12
use Brick\Geo\Projector\Projector;
13

14
/**
15
 * A CurvePolygon is a planar Surface defined by 1 exterior boundary and 0 or more interior boundaries.
16
 *
17
 * A CurvePolygon instance differs from a Polygon instance in that a CurvePolygon instance may contain
18
 * the following circular arc segments: CircularString and CompoundCurve in addition to LineString.
19
 */
20
class CurvePolygon extends Surface
21
{
22
    /**
23
     * The rings that compose this CurvePolygon.
24
     *
25
     * The first one represents the exterior ring, and the
26
     * (optional) other ones represent the interior rings (holes) of the CurvePolygon.
27
     *
28
     * An empty CurvePolygon contains no rings.
29
     *
30
     * @psalm-var list<Curve>
31
     *
32
     * @var Curve[]
33
     */
34
    protected array $rings = [];
35

36
    /**
37
     * The coordinate system of each of the rings must match the one of the CurvePolygon.
38
     *
39
     * @param CoordinateSystem $cs       The coordinate system of the CurvePolygon.
40
     * @param Curve            ...$rings The rings that compose the CurvePolygon.
41
     *
42
     * @throws CoordinateSystemException If different coordinate systems are used.
43
     */
44
    public function __construct(CoordinateSystem $cs, Curve ...$rings)
45
    {
46
        parent::__construct($cs, ! $rings);
1,729✔
47

48
        if (! $rings) {
1,729✔
49
            return;
798✔
50
        }
51

52
        CoordinateSystem::check($this, ...$rings);
945✔
53

54
        $this->rings = array_values($rings);
945✔
55
    }
56

57
    /**
58
     * Creates a non-empty CurvePolygon composed of the given rings.
59
     *
60
     * @psalm-suppress UnsafeInstantiation
61
     *
62
     * @param Curve    $exteriorRing  The exterior ring.
63
     * @param Curve ...$interiorRings The interior rings, if any.
64
     *
65
     * @throws CoordinateSystemException If the rings use different coordinate systems.
66
     */
67
    public static function of(Curve $exteriorRing, Curve ...$interiorRings) :  CurvePolygon
68
    {
69
        return new static($exteriorRing->coordinateSystem(), $exteriorRing, ...$interiorRings);
×
70
    }
71

72
    /**
73
     * Returns the exterior ring of this CurvePolygon.
74
     *
75
     * @throws EmptyGeometryException
76
     */
77
    public function exteriorRing() : Curve
78
    {
79
        if ($this->isEmpty) {
140✔
80
            throw new EmptyGeometryException('An empty CurvePolygon has no exterior ring.');
28✔
81
        }
82

83
        return $this->rings[0];
112✔
84
    }
85

86
    /**
87
     * Returns the number of interior rings in this CurvePolygon.
88
     */
89
    public function numInteriorRings() : int
90
    {
91
        if ($this->isEmpty) {
63✔
92
            return 0;
28✔
93
        }
94

95
        return count($this->rings) - 1;
35✔
96
    }
97

98
    /**
99
     * Returns the specified interior ring N in this CurvePolygon.
100
     *
101
     * @param int $n The ring number, 1-based.
102
     *
103
     * @throws NoSuchGeometryException If there is no interior ring at this index.
104
     */
105
    public function interiorRingN(int $n) : Curve
106
    {
107
        if ($n === 0 || ! isset($this->rings[$n])) {
308✔
108
            throw new NoSuchGeometryException('There is no interior ring in this CurvePolygon at index ' . $n);
252✔
109
        }
110

111
        return $this->rings[$n];
56✔
112
    }
113

114
    /**
115
     * Returns the interior rings in this CurvePolygon.
116
     *
117
     * @return Curve[]
118
     */
119
    public function interiorRings() : array
120
    {
121
        return array_slice($this->rings, 1);
70✔
122
    }
123

124
    #[NoProxy]
125
    public function geometryType() : string
126
    {
127
        return 'CurvePolygon';
672✔
128
    }
129

130
    #[NoProxy]
131
    public function geometryTypeBinary() : int
132
    {
133
        return Geometry::CURVEPOLYGON;
350✔
134
    }
135

136
    public function getBoundingBox() : BoundingBox
137
    {
138
        $boundingBox = new BoundingBox();
×
139

140
        foreach ($this->rings as $ring) {
×
141
            $boundingBox = $boundingBox->extendedWithBoundingBox($ring->getBoundingBox());
×
142
        }
143

144
        return $boundingBox;
×
145
    }
146

147
    public function toArray() : array
148
    {
149
        return array_map(
224✔
150
            fn (Curve $ring) => $ring->toArray(),
224✔
151
            $this->rings,
224✔
152
        );
224✔
153
    }
154

155
    public function project(Projector $projector): CurvePolygon
156
    {
UNCOV
157
        return new CurvePolygon(
×
UNCOV
158
            $projector->getTargetCoordinateSystem($this->coordinateSystem),
×
UNCOV
159
            ...array_map(
×
160
                fn (Curve $ring) => $ring->project($projector),
×
161
                $this->rings,
×
162
            ),
×
163
        );
×
164
    }
165

166
    /**
167
     * Returns the number of rings (exterior + interior) in this CurvePolygon.
168
     *
169
     * Required by interface Countable.
170
     */
171
    public function count() : int
172
    {
173
        return count($this->rings);
350✔
174
    }
175

176
    /**
177
     * Returns an iterator for the rings (exterior + interior) in this CurvePolygon.
178
     *
179
     * Required by interface IteratorAggregate.
180
     *
181
     * @psalm-return ArrayIterator<int, Curve>
182
     */
183
    public function getIterator() : ArrayIterator
184
    {
185
        return new ArrayIterator($this->rings);
742✔
186
    }
187

188
    /**
189
     * Returns a copy of this CurvePolygon, with the exterior ring replaced with the given one.
190
     */
191
    public function withExteriorRing(Curve $exteriorRing) : CurvePolygon
192
    {
193
        return new CurvePolygon($this->coordinateSystem, $exteriorRing, ...$this->interiorRings());
28✔
194
    }
195

196
    /**
197
     * Returns a copy of this CurvePolygon, with the interior rings replaced with the given ones.
198
     */
199
    public function withInteriorRings(Curve ...$interiorRings) : CurvePolygon
200
    {
201
        return new CurvePolygon($this->coordinateSystem, $this->exteriorRing(), ...$interiorRings);
42✔
202
    }
203

204
    /**
205
     * Returns a copy of this CurvePolygon, with the given interior rings added.
206
     */
207
    public function withAddedInteriorRings(Curve ...$interiorRings) : CurvePolygon
208
    {
209
        return new CurvePolygon($this->coordinateSystem, $this->exteriorRing(), ...$this->interiorRings(), ...$interiorRings);
42✔
210
    }
211
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc