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

brick / geo / 13971277707

20 Mar 2025 02:05PM UTC coverage: 65.568% (+0.1%) from 65.472%
13971277707

push

github

BenMorel
Accept $prettyPrint in AbstractWktWriter constructor

1889 of 2881 relevant lines covered (65.57%)

1480.09 hits per line

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

67.5
/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
use Override;
14

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

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

51
        $this->rings = array_values($rings);
1,976✔
52

53
        if ($isEmpty) {
1,976✔
54
            return;
912✔
55
        }
56

57
        CoordinateSystem::check($this, ...$rings);
1,080✔
58
    }
59

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

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

84
        return $this->rings[0];
128✔
85
    }
86

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

96
        return count($this->rings) - 1;
40✔
97
    }
98

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

112
        return $this->rings[$n];
64✔
113
    }
114

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

125
    #[NoProxy, Override]
126
    public function geometryType() : string
127
    {
128
        return 'CurvePolygon';
768✔
129
    }
130

131
    #[NoProxy, Override]
132
    public function geometryTypeBinary() : int
133
    {
134
        return Geometry::CURVEPOLYGON;
398✔
135
    }
136

137
    #[Override]
138
    public function getBoundingBox() : BoundingBox
139
    {
140
        return array_reduce(
×
141
            $this->rings,
×
142
            fn (BoundingBox $boundingBox, Curve $ring) => $boundingBox->extendedWithBoundingBox($ring->getBoundingBox()),
×
143
            BoundingBox::new(),
×
144
        );
×
145
    }
146

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

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

168
    /**
169
     * Returns the number of rings (exterior + interior) in this CurvePolygon.
170
     */
171
    #[Override]
172
    public function count() : int
173
    {
174
        return count($this->rings);
398✔
175
    }
176

177
    /**
178
     * Returns an iterator for the rings (exterior + interior) in this CurvePolygon.
179
     *
180
     * @return ArrayIterator<int<0, max>, Curve>
181
     */
182
    #[Override]
183
    public function getIterator() : ArrayIterator
184
    {
185
        return new ArrayIterator($this->rings);
846✔
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());
32✔
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);
48✔
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);
48✔
210
    }
211
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc