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

brick / geo / 13700983528

06 Mar 2025 02:28PM UTC coverage: 48.121% (+0.6%) from 47.546%
13700983528

Pull #55

github

web-flow
Merge 41526e1ed into 723c55ddf
Pull Request #55: Add LineInterpolatePoint for Postgis

15 of 21 new or added lines in 3 files covered. (71.43%)

54 existing lines in 10 files now uncovered.

1652 of 3433 relevant lines covered (48.12%)

967.63 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\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

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
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,416✔
41

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

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

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

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

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

58
        $this->points = array_values($points);
2,647✔
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
    public function startPoint() : Point
76
    {
77
        if ($this->isEmpty) {
924✔
78
            throw new EmptyGeometryException('The CircularString is empty and has no start point.');
56✔
79
        }
80

81
        return $this->points[0];
868✔
82
    }
83

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

90
        return end($this->points);
546✔
91
    }
92

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

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

114
        return $this->points[$n - 1];
91✔
115
    }
116

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

129
    #[NoProxy]
130
    public function geometryType() : string
131
    {
132
        return 'CircularString';
1,448✔
133
    }
134

135
    #[NoProxy]
136
    public function geometryTypeBinary() : int
137
    {
138
        return Geometry::CIRCULARSTRING;
743✔
139
    }
140

141
    public function getBoundingBox() : BoundingBox
142
    {
143
        $boundingBox = new BoundingBox();
×
144

145
        foreach ($this->points as $point) {
×
146
            $boundingBox = $boundingBox->extendedWithPoint($point);
×
147
        }
148

149
        return $boundingBox;
×
150
    }
151

152
    public function toArray() : array
153
    {
154
        return array_map(
448✔
155
            fn (Point $point) => $point->toArray(),
448✔
156
            $this->points,
448✔
157
        );
448✔
158
    }
159

160
    public function project(Projector $projector): CircularString
161
    {
UNCOV
162
        return new CircularString(
×
UNCOV
163
            $projector->getTargetCoordinateSystem($this->coordinateSystem),
×
UNCOV
164
            ...array_map(
×
165
                fn (Point $point) => $point->project($projector),
×
166
                $this->points,
×
167
            ),
×
168
        );
×
169
    }
170

171
    /**
172
     * Returns the number of points in this CircularString.
173
     *
174
     * Required by interface Countable.
175
     */
176
    public function count() : int
177
    {
178
        return count($this->points);
750✔
179
    }
180

181
    /**
182
     * Returns an iterator for the points in this CircularString.
183
     *
184
     * Required by interface IteratorAggregate.
185
     *
186
     * @psalm-return ArrayIterator<int, Point>
187
     */
188
    public function getIterator() : ArrayIterator
189
    {
190
        return new ArrayIterator($this->points);
1,884✔
191
    }
192

193
    /**
194
     * Returns a copy of this CircularString, with the given points added.
195
     */
196
    public function withAddedPoints(Point ...$points): CircularString
197
    {
198
        return new CircularString($this->coordinateSystem, ...$this->points, ...$points);
42✔
199
    }
200
}
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