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

brick / geo / 13766209603

09 Mar 2025 10:35PM UTC coverage: 87.414% (+3.3%) from 84.117%
13766209603

push

github

BenMorel
Add Point::isEqualTo() (WIP: finish? keep?)

8 of 8 new or added lines in 2 files covered. (100.0%)

73 existing lines in 16 files now uncovered.

1653 of 1891 relevant lines covered (87.41%)

1946.79 hits per line

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

69.57
/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
 * @template-implements \IteratorAggregate<int<0, max>, LineString|CircularString>
19
 */
20
final readonly class CompoundCurve extends Curve implements \Countable, \IteratorAggregate
21
{
22
    /**
23
     * The Curves that compose this CompoundCurve.
24
     *
25
     * This array can be empty.
26
     *
27
     * @var list<LineString|CircularString>
28
     */
29
    public 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 LineString|CircularString ...$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, LineString|CircularString ...$curves)
42
    {
43
        $isEmpty = (count($curves) === 0);
2,330✔
44
        parent::__construct($cs, $isEmpty);
2,330✔
45

46
        $this->curves = array_values($curves);
2,330✔
47

48
        if ($isEmpty) {
2,330✔
49
            return;
916✔
50
        }
51

52
        CoordinateSystem::check($this, ...$curves);
1,428✔
53

54
        $previousCurve = null;
1,428✔
55

56
        foreach ($curves as $curve) {
1,428✔
57
            if ($previousCurve !== null) {
1,428✔
58
                if (! $curve->startPoint()->isEqualTo($previousCurve->endPoint())) {
1,330✔
59
                    throw new InvalidGeometryException('Incontinuous compound curve.');
7✔
60
                }
61
            }
62

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

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

82
    #[Override]
83
    public function startPoint() : Point
84
    {
85
        if (count($this->curves) === 0) {
112✔
86
            throw new EmptyGeometryException('The CompoundCurve is empty and has no start point.');
56✔
87
        }
88

89
        return $this->curves[0]->startPoint();
56✔
90
    }
91

92
    #[Override]
93
    public function endPoint() : Point
94
    {
95
        $count = count($this->curves);
112✔
96

97
        if ($count === 0) {
112✔
98
            throw new EmptyGeometryException('The CompoundCurve is empty and has no end point.');
56✔
99
        }
100

101
        return $this->curves[$count - 1]->endPoint();
56✔
102
    }
103

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

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

125
        return $this->curves[$n - 1];
105✔
126
    }
127

128
    /**
129
     * Returns the curves that compose this CompoundCurve.
130
     *
131
     * @return list<LineString|CircularString>
132
     *
133
     * @deprecated Use $curves property instead.
134
     */
135
    public function curves() : array
136
    {
UNCOV
137
        return $this->curves;
×
138
    }
139

140
    #[Override]
141
    public function geometryType() : string
142
    {
143
        return 'CompoundCurve';
979✔
144
    }
145

146
    #[Override]
147
    public function geometryTypeBinary() : int
148
    {
149
        return Geometry::COMPOUNDCURVE;
448✔
150
    }
151

152
    #[Override]
153
    public function getBoundingBox() : BoundingBox
154
    {
UNCOV
155
        return array_reduce(
×
156
            $this->curves,
×
UNCOV
157
            fn (BoundingBox $boundingBox, Curve $curve) => $boundingBox->extendedWithBoundingBox($curve->getBoundingBox()),
×
158
            BoundingBox::new(),
×
159
        );
×
160
    }
161

162
    /**
163
     * @return list<list<list<float>>>
164
     */
165
    #[Override]
166
    public function toArray() : array
167
    {
168
        return array_map(
252✔
169
            fn (Curve $curve) => $curve->toArray(),
252✔
170
            $this->curves,
252✔
171
        );
252✔
172
    }
173

174
    #[Override]
175
    public function project(Projector $projector): static
176
    {
UNCOV
177
        return new CompoundCurve(
×
UNCOV
178
            $projector->getTargetCoordinateSystem($this->coordinateSystem),
×
UNCOV
179
            ...array_map(
×
180
                fn (Curve $curve) => $curve->project($projector),
×
181
                $this->curves,
×
182
            ),
×
183
        );
×
184
    }
185

186
    /**
187
     * Returns the number of curves in this CompoundCurve.
188
     */
189
    #[Override]
190
    public function count() : int
191
    {
192
        return count($this->curves);
455✔
193
    }
194

195
    /**
196
     * Returns an iterator for the curves in this CompoundCurve.
197
     *
198
     * @return ArrayIterator<int<0, max>, LineString|CircularString>
199
     */
200
    #[Override]
201
    public function getIterator() : ArrayIterator
202
    {
203
        return new ArrayIterator($this->curves);
1,064✔
204
    }
205

206
    /**
207
     * Returns a copy of this CompoundCurve, with the given curves added.
208
     */
209
    public function withAddedCurves(LineString|CircularString ...$curves): CompoundCurve
210
    {
211
        return new CompoundCurve($this->coordinateSystem, ...$this->curves, ...$curves);
56✔
212
    }
213
}
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