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

brick / geo / 13716844819

07 Mar 2025 08:35AM UTC coverage: 47.964% (+3.9%) from 44.086%
13716844819

push

github

BenMorel
Add TypeChecker for engines

8 of 21 new or added lines in 5 files covered. (38.1%)

98 existing lines in 18 files now uncovered.

1684 of 3511 relevant lines covered (47.96%)

944.32 hits per line

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

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

16
/**
17
 * A CircularString is a Curve made of zero or more connected circular arc segments.
18
 *
19
 * A circular arc segment is a curved segment defined by three points in a two-dimensional plane;
20
 * the first point cannot be the same as the third point.
21
 *
22
 * @template-implements \IteratorAggregate<Point>
23
 * @final
24
 */
25
class CircularString extends Curve implements \Countable, \IteratorAggregate
26
{
27
    /**
28
     * The Points that compose this CircularString.
29
     *
30
     * An empty CircularString contains no points.
31
     *
32
     * @var list<Point>
33
     */
34
    protected array $points = [];
35

36
    /**
37
     * @throws InvalidGeometryException  If the number of points is invalid.
38
     * @throws CoordinateSystemException If different coordinate systems are used.
39
     */
40
    public function __construct(CoordinateSystem $cs, Point ...$points)
41
    {
42
        parent::__construct($cs, ! $points);
3,416✔
43

44
        if (! $points) {
3,416✔
45
            return;
748✔
46
        }
47

48
        CoordinateSystem::check($this, ...$points);
2,682✔
49

50
        $numPoints = count($points);
2,682✔
51

52
        if ($numPoints < 3) {
2,682✔
53
            throw new InvalidGeometryException('A CircularString must be made of at least 3 points.');
21✔
54
        }
55

56
        if ($numPoints % 2 === 0) {
2,661✔
57
            throw new InvalidGeometryException('A CircularString must have an odd number of points.');
14✔
58
        }
59

60
        $this->points = array_values($points);
2,647✔
61
    }
62

63
    /**
64
     * Creates a non-empty CircularString composed of the given points.
65
     *
66
     * @param Point    $point1 The first point.
67
     * @param Point ...$pointN The subsequent points.
68
     *
69
     * @throws InvalidGeometryException  If the number of points is invalid.
70
     * @throws CoordinateSystemException If the points use different coordinate systems.
71
     */
72
    public static function of(Point $point1, Point ...$pointN) : CircularString
73
    {
UNCOV
74
        return new CircularString($point1->coordinateSystem(), $point1, ...$pointN);
×
75
    }
76

77
    #[Override]
78
    public function startPoint() : Point
79
    {
80
        if (count($this->points) === 0) {
924✔
81
            throw new EmptyGeometryException('The CircularString is empty and has no start point.');
56✔
82
        }
83

84
        return $this->points[0];
868✔
85
    }
86

87
    #[Override]
88
    public function endPoint() : Point
89
    {
90
        $count = count($this->points);
602✔
91

92
        if ($count === 0) {
602✔
93
            throw new EmptyGeometryException('The CircularString is empty and has no end point.');
56✔
94
        }
95

96
        return $this->points[$count - 1];
546✔
97
    }
98

99
    /**
100
     * Returns the number of Points in this CircularString.
101
     */
102
    public function numPoints() : int
103
    {
104
        return count($this->points);
56✔
105
    }
106

107
    /**
108
     * Returns the specified Point N in this CircularString.
109
     *
110
     * @param int $n The point number, 1-based.
111
     *
112
     * @throws NoSuchGeometryException If there is no Point at this index.
113
     */
114
    public function pointN(int $n) : Point
115
    {
116
        if (! isset($this->points[$n - 1])) {
133✔
117
            throw new NoSuchGeometryException('There is no Point in this CircularString at index ' . $n);
42✔
118
        }
119

120
        return $this->points[$n - 1];
91✔
121
    }
122

123
    /**
124
     * Returns the points that compose this CircularString.
125
     *
126
     * @return list<Point>
127
     */
128
    public function points() : array
129
    {
UNCOV
130
        return $this->points;
×
131
    }
132

133
    #[NoProxy, Override]
134
    public function geometryType() : string
135
    {
136
        return 'CircularString';
1,448✔
137
    }
138

139
    #[NoProxy, Override]
140
    public function geometryTypeBinary() : int
141
    {
142
        return Geometry::CIRCULARSTRING;
743✔
143
    }
144

145
    #[Override]
146
    public function getBoundingBox() : BoundingBox
147
    {
UNCOV
148
        $boundingBox = BoundingBox::new();
×
149

150
        foreach ($this->points as $point) {
×
UNCOV
151
            $boundingBox = $boundingBox->extendedWithPoint($point);
×
152
        }
153

UNCOV
154
        return $boundingBox;
×
155
    }
156

157
    /**
158
     * @return list<list<float>>
159
     */
160
    #[Override]
161
    public function toArray() : array
162
    {
163
        return array_map(
448✔
164
            fn (Point $point) => $point->toArray(),
448✔
165
            $this->points,
448✔
166
        );
448✔
167
    }
168

169
    #[Override]
170
    public function project(Projector $projector): CircularString
171
    {
172
        return new CircularString(
×
173
            $projector->getTargetCoordinateSystem($this->coordinateSystem),
×
174
            ...array_map(
×
175
                fn (Point $point) => $point->project($projector),
×
176
                $this->points,
×
177
            ),
×
UNCOV
178
        );
×
179
    }
180

181
    /**
182
     * Returns the number of points in this CircularString.
183
     */
184
    #[Override]
185
    public function count() : int
186
    {
187
        return count($this->points);
750✔
188
    }
189

190
    /**
191
     * Returns an iterator for the points in this CircularString.
192
     *
193
     * @return ArrayIterator<int<0, max>, Point>
194
     */
195
    #[Override]
196
    public function getIterator() : ArrayIterator
197
    {
198
        return new ArrayIterator($this->points);
1,884✔
199
    }
200

201
    /**
202
     * Returns a copy of this CircularString, with the given points added.
203
     */
204
    public function withAddedPoints(Point ...$points): CircularString
205
    {
206
        return new CircularString($this->coordinateSystem, ...$this->points, ...$points);
42✔
207
    }
208
}
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