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

brick / geo / 13633473181

03 Mar 2025 02:25PM UTC coverage: 83.61% (+0.2%) from 83.425%
13633473181

push

github

BenMorel
BoundingBox: readonly + promoted properties

21 of 28 new or added lines in 10 files covered. (75.0%)

41 existing lines in 5 files now uncovered.

1561 of 1867 relevant lines covered (83.61%)

1882.91 hits per line

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

71.74
/src/CompoundCurve.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\InvalidGeometryException;
11
use Brick\Geo\Exception\NoSuchGeometryException;
12
use Brick\Geo\Projector\Projector;
13
use Override;
14

15
/**
16
 * A CompoundCurve is a collection of zero or more continuous CircularString or LineString instances.
17
 */
18
final class CompoundCurve extends Curve
19
{
20
    /**
21
     * The Curves that compose this CompoundCurve.
22
     *
23
     * This array can be empty.
24
     *
25
     * @psalm-var list<Curve>
26
     *
27
     * @var Curve[]
28
     */
29
    protected array $curves = [];
30

31
    /**
32
     * The coordinate system of each of the curves must match the one of the CompoundCurve.
33
     *
34
     * @param CoordinateSystem $cs        The coordinate system of the CompoundCurve.
35
     * @param Curve            ...$curves The curves that compose the CompoundCurve.
36
     *
37
     * @throws EmptyGeometryException    If any of the input curves is empty.
38
     * @throws InvalidGeometryException  If the compound curve is not continuous.
39
     * @throws CoordinateSystemException If different coordinate systems are used.
40
     */
41
    public function __construct(CoordinateSystem $cs, Curve ...$curves)
42
    {
43
        parent::__construct($cs, ! $curves);
2,302✔
44

45
        if (! $curves) {
2,302✔
46
            return;
916✔
47
        }
48

49
        CoordinateSystem::check($this, ...$curves);
1,400✔
50

51
        /** @var Curve|null $previousCurve */
52
        $previousCurve = null;
1,400✔
53

54
        foreach ($curves as $curve) {
1,400✔
55
            if ($previousCurve) {
1,400✔
56
                $endPoint = $previousCurve->endPoint();
1,302✔
57
                $startPoint = $curve->startPoint();
1,302✔
58

59
                if ($endPoint != $startPoint) { // on purpose by-value comparison!
1,302✔
60
                    throw new InvalidGeometryException('Incontinuous compound curve.');
7✔
61
                }
62
            }
63

64
            $previousCurve = $curve;
1,400✔
65
        }
66

67
        $this->curves = array_values($curves);
1,393✔
68
    }
69

70
    /**
71
     * Creates a non-empty CompoundCurve composed of the given curves.
72
     *
73
     * @param Curve    $curve1 The first curve.
74
     * @param Curve ...$curveN The subsequent curves, if any.
75
     *
76
     * @throws EmptyGeometryException    If any of the input curves is empty.
77
     * @throws InvalidGeometryException  If the compound curve is not continuous.
78
     * @throws CoordinateSystemException If the curves use different coordinate systems.
79
     */
80
    public static function of(Curve $curve1, Curve ...$curveN) : CompoundCurve
81
    {
82
        return new CompoundCurve($curve1->coordinateSystem(), $curve1, ...$curveN);
×
83
    }
84

85
    #[Override]
86
    public function startPoint() : Point
87
    {
88
        if ($this->isEmpty) {
112✔
89
            throw new EmptyGeometryException('The CompoundCurve is empty and has no start point.');
56✔
90
        }
91

92
        return $this->curves[0]->startPoint();
56✔
93
    }
94

95
    #[Override]
96
    public function endPoint() : Point
97
    {
98
        if ($this->isEmpty) {
112✔
99
            throw new EmptyGeometryException('The CompoundCurve is empty and has no end point.');
56✔
100
        }
101

102
        $count = count($this->curves);
56✔
103

104
        return $this->curves[$count - 1]->endPoint();
56✔
105
    }
106

107
    /**
108
     * Returns the number of Curves in this CompoundCurve.
109
     */
110
    public function numCurves() : int
111
    {
112
        return count($this->curves);
56✔
113
    }
114

115
    /**
116
     * Returns the specified Curve N in this CompoundCurve.
117
     *
118
     * @param int $n The curve number, 1-based.
119
     *
120
     * @throws NoSuchGeometryException If there is no Curve at this index.
121
     */
122
    public function curveN(int $n) : Curve
123
    {
124
        if (! isset($this->curves[$n - 1])) {
329✔
125
            throw new NoSuchGeometryException('There is no Curve in this CompoundCurve at index ' . $n);
224✔
126
        }
127

128
        return $this->curves[$n - 1];
105✔
129
    }
130

131
    /**
132
     * Returns the curves that compose this CompoundCurve.
133
     *
134
     * @psalm-return list<Curve>
135
     *
136
     * @return Curve[]
137
     */
138
    public function curves() : array
139
    {
140
        return $this->curves;
×
141
    }
142

143
    #[Override]
144
    public function geometryType() : string
145
    {
146
        return 'CompoundCurve';
951✔
147
    }
148

149
    #[Override]
150
    public function geometryTypeBinary() : int
151
    {
152
        return Geometry::COMPOUNDCURVE;
448✔
153
    }
154

155
    #[Override]
156
    public function getBoundingBox() : BoundingBox
157
    {
NEW
158
        $boundingBox = BoundingBox::new();
×
159

160
        foreach ($this->curves as $curve) {
×
161
            $boundingBox = $boundingBox->extendedWithBoundingBox($curve->getBoundingBox());
×
162
        }
163

164
        return $boundingBox;
×
165
    }
166

167
    #[Override]
168
    public function toArray() : array
169
    {
170
        $result = [];
252✔
171

172
        foreach ($this->curves as $curve) {
252✔
173
            $result[] = $curve->toArray();
140✔
174
        }
175

176
        return $result;
252✔
177
    }
178

179
    #[Override]
180
    public function project(Projector $projector): CompoundCurve
181
    {
182
        return new CompoundCurve(
×
183
            $projector->getTargetCoordinateSystem($this->coordinateSystem),
×
184
            ...array_map(
×
185
                fn (Curve $curve) => $curve->project($projector),
×
186
                $this->curves,
×
187
            ),
×
188
        );
×
189
    }
190

191
    /**
192
     * Returns the number of curves in this CompoundCurve.
193
     *
194
     * Required by interface Countable.
195
     */
196
    #[Override]
197
    public function count() : int
198
    {
199
        return count($this->curves);
455✔
200
    }
201

202
    /**
203
     * Returns an iterator for the curves in this CompoundCurve.
204
     *
205
     * Required by interface IteratorAggregate.
206
     *
207
     * @psalm-return ArrayIterator<int, Curve>
208
     */
209
    #[Override]
210
    public function getIterator() : ArrayIterator
211
    {
212
        return new ArrayIterator($this->curves);
1,036✔
213
    }
214

215
    /**
216
     * Returns a copy of this CompoundCurve, with the given curves added.
217
     */
218
    public function withAddedCurves(Curve ...$curves): CompoundCurve
219
    {
220
        return new CompoundCurve($this->coordinateSystem, ...$this->curves, ...$curves);
56✔
221
    }
222
}
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