• 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

68.89
/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
 * @template-implements \IteratorAggregate<int<0, max>, Point>
22
 */
23
final readonly class CircularString extends Curve implements \Countable, \IteratorAggregate
24
{
25
    /**
26
     * The Points that compose this CircularString.
27
     *
28
     * An empty CircularString contains no points.
29
     *
30
     * @var list<Point>
31
     */
32
    public 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
        $numPoints = count($points);
3,668✔
41
        $isEmpty = ($numPoints === 0);
3,668✔
42

43
        parent::__construct($cs, $isEmpty);
3,668✔
44

45
        $this->points = array_values($points);
3,668✔
46

47
        if ($isEmpty) {
3,668✔
48
            return;
804✔
49
        }
50

51
        CoordinateSystem::check($this, ...$points);
2,878✔
52

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

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

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

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

83
        return $this->points[0];
945✔
84
    }
85

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

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

95
        return $this->points[$count - 1];
581✔
96
    }
97

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

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

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

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

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

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

146
    #[Override]
147
    public function getBoundingBox() : BoundingBox
148
    {
149
        return array_reduce(
×
UNCOV
150
            $this->points,
×
151
            fn (BoundingBox $boundingBox, Point $point) => $boundingBox->extendedWithPoint($point),
×
152
            BoundingBox::new(),
×
UNCOV
153
        );
×
154
    }
155

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

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

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

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

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