• 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

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

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

42
        if (! $points) {
3,640✔
43
            return;
804✔
44
        }
45

46
        CoordinateSystem::check($this, ...$points);
2,850✔
47

48
        $numPoints = count($points);
2,850✔
49

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

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

58
        $this->points = array_values($points);
2,815✔
59
    }
60

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

75
    #[Override]
76
    public function startPoint() : Point
77
    {
78
        if ($this->isEmpty) {
980✔
79
            throw new EmptyGeometryException('The CircularString is empty and has no start point.');
56✔
80
        }
81

82
        return $this->points[0];
924✔
83
    }
84

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

92
        return end($this->points);
574✔
93
    }
94

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

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

116
        return $this->points[$n - 1];
91✔
117
    }
118

119
    /**
120
     * Returns the points that compose this CircularString.
121
     *
122
     * @psalm-return list<Point>
123
     *
124
     * @return Point[]
125
     */
126
    public function points() : array
127
    {
128
        return $this->points;
×
129
    }
130

131
    #[Override]
132
    public function geometryType() : string
133
    {
134
        return 'CircularString';
1,672✔
135
    }
136

137
    #[Override]
138
    public function geometryTypeBinary() : int
139
    {
140
        return Geometry::CIRCULARSTRING;
743✔
141
    }
142

143
    #[Override]
144
    public function getBoundingBox() : BoundingBox
145
    {
NEW
146
        $boundingBox = BoundingBox::new();
×
147

148
        foreach ($this->points as $point) {
×
149
            $boundingBox = $boundingBox->extendedWithPoint($point);
×
150
        }
151

152
        return $boundingBox;
×
153
    }
154

155
    #[Override]
156
    public function toArray() : array
157
    {
158
        $result = [];
448✔
159

160
        foreach ($this->points as $point) {
448✔
161
            $result[] = $point->toArray();
336✔
162
        }
163

164
        return $result;
448✔
165
    }
166

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

179
    /**
180
     * Returns the number of points in this CircularString.
181
     *
182
     * Required by interface Countable.
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
     * Required by interface IteratorAggregate.
194
     *
195
     * @psalm-return ArrayIterator<int, Point>
196
     */
197
    #[Override]
198
    public function getIterator() : ArrayIterator
199
    {
200
        return new ArrayIterator($this->points);
2,052✔
201
    }
202

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