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

brick / geo / 13399333180

18 Feb 2025 08:17PM UTC coverage: 83.425%. First build
13399333180

push

github

BenMorel
BoundingBox: readonly + promoted properties

23 of 28 new or added lines in 10 files covered. (82.14%)

1525 of 1828 relevant lines covered (83.42%)

1858.37 hits per line

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

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

3
declare(strict_types=1);
4

5
namespace Brick\Geo;
6

7
use ArrayIterator;
8
use Brick\Geo\Exception\CoordinateSystemException;
9
use Brick\Geo\Exception\EmptyGeometryException;
10
use Brick\Geo\Exception\NoSuchGeometryException;
11
use Brick\Geo\Projector\Projector;
12
use Override;
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
final 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 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;
840✔
50
        }
51

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

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

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

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

81
        return $this->rings[0];
28✔
82
    }
83

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

93
        return count($this->rings) - 1;
35✔
94
    }
95

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

109
        return $this->rings[$n];
56✔
110
    }
111

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

122
    #[Override]
123
    public function geometryType() : string
124
    {
125
        return 'CurvePolygon';
672✔
126
    }
127

128
    #[Override]
129
    public function geometryTypeBinary() : int
130
    {
131
        return Geometry::CURVEPOLYGON;
350✔
132
    }
133

134
    #[Override]
135
    public function getBoundingBox() : BoundingBox
136
    {
NEW
137
        $boundingBox = BoundingBox::new();
×
138

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

143
        return $boundingBox;
×
144
    }
145

146
    #[Override]
147
    public function toArray() : array
148
    {
149
        $result = [];
224✔
150

151
        foreach ($this->rings as $ring) {
224✔
152
            $result[] = $ring->toArray();
112✔
153
        }
154

155
        return $result;
224✔
156
    }
157

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

170
    /**
171
     * Returns the number of rings (exterior + interior) in this CurvePolygon.
172
     *
173
     * Required by interface Countable.
174
     */
175
    #[Override]
176
    public function count() : int
177
    {
178
        return count($this->rings);
350✔
179
    }
180

181
    /**
182
     * Returns an iterator for the rings (exterior + interior) in this CurvePolygon.
183
     *
184
     * Required by interface IteratorAggregate.
185
     *
186
     * @psalm-return ArrayIterator<int, Curve>
187
     */
188
    #[Override]
189
    public function getIterator() : ArrayIterator
190
    {
191
        return new ArrayIterator($this->rings);
686✔
192
    }
193
}
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