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

brick / geo / 13861125046

14 Mar 2025 04:33PM UTC coverage: 48.122% (-2.9%) from 51.017%
13861125046

push

github

BenMorel
Add more tests for spatial equality

This engine method is the foundation for other tests, so we need to ensure that it works fine in more complex cases.

1755 of 3647 relevant lines covered (48.12%)

863.52 hits per line

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

53.09
/src/Proxy/PointProxy.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Brick\Geo\Proxy;
6

7
use Brick\Geo\Exception\GeometryIOException;
8
use Brick\Geo\Exception\CoordinateSystemException;
9
use Brick\Geo\Exception\InvalidGeometryException;
10
use Brick\Geo\Exception\UnexpectedGeometryException;
11
use Brick\Geo\Geometry;
12
use Brick\Geo\Point;
13

14
/**
15
 * Proxy class for Point.
16
 *
17
 * @internal This class is not part of the public API and can change at any time.
18
 *           Please type-hint against Brick\Geo\Point in your projects.
19
 */
20
class PointProxy extends Point implements ProxyInterface
21
{
22
    /**
23
     * The WKT or WKB data.
24
     */
25
    private readonly string $proxyData;
26

27
    /**
28
     * `true` if WKB, `false` if WKT.
29
     */
30
    private readonly bool $isProxyBinary;
31

32
    /**
33
     * The SRID of the underlying geometry.
34
     */
35
    private readonly int $proxySRID;
36

37
    /**
38
     * The underlying geometry, or NULL if not yet loaded.
39
     */
40
    private ?Point $proxyGeometry = null;
41

42
    /**
43
     * @param string $data     The WKT or WKB data.
44
     * @param bool   $isBinary Whether the data is binary (true) or text (false).
45
     * @param int    $srid     The SRID of the geometry.
46
     */
47
    public function __construct(string $data, bool $isBinary, int $srid = 0)
48
    {
49
        $this->proxyData     = $data;
180✔
50
        $this->isProxyBinary = $isBinary;
180✔
51
        $this->proxySRID     = $srid;
180✔
52
    }
53

54
    /**
55
     * Loads the underlying geometry.
56
     *
57
     * @throws GeometryIOException         If the proxy data is not valid.
58
     * @throws CoordinateSystemException   If the resulting geometry contains mixed coordinate systems.
59
     * @throws InvalidGeometryException    If the resulting geometry is not valid.
60
     * @throws UnexpectedGeometryException If the resulting geometry is not an instance of the proxied class.
61
     */
62
    private function load() : void
63
    {
64
        $this->proxyGeometry = $this->isProxyBinary
159✔
65
            ? Point::fromBinary($this->proxyData, $this->proxySRID)
141✔
66
            : Point::fromText($this->proxyData, $this->proxySRID);
18✔
67
    }
68

69
    public function isLoaded() : bool
70
    {
71
        return $this->proxyGeometry !== null;
6✔
72
    }
73

74
    public function getGeometry() : Geometry
75
    {
76
        if ($this->proxyGeometry === null) {
6✔
77
            $this->load();
×
78
        }
79

80
        return $this->proxyGeometry;
6✔
81
    }
82

83
    public function isProxyBinary() : bool
84
    {
85
        return $this->isProxyBinary;
21✔
86
    }
87

88
    public static function fromText(string $wkt, int $srid = 0) : Geometry
89
    {
90
        return new self($wkt, false, $srid);
×
91
    }
92

93
    public static function fromBinary(string $wkb, int $srid = 0) : Geometry
94
    {
95
        return new self($wkb, true, $srid);
×
96
    }
97

98
    public function SRID() : int
99
    {
100
        return $this->proxySRID;
51✔
101
    }
102

103
    public function asText() : string
104
    {
105
        if (! $this->isProxyBinary) {
117✔
106
            return $this->proxyData;
12✔
107
        }
108

109
        if ($this->proxyGeometry === null) {
105✔
110
            $this->load();
93✔
111
        }
112

113
        return $this->proxyGeometry->asText();
105✔
114
    }
115

116
    public function asBinary() : string
117
    {
118
        if ($this->isProxyBinary) {
39✔
119
            return $this->proxyData;
33✔
120
        }
121

122
        if ($this->proxyGeometry === null) {
6✔
123
            $this->load();
×
124
        }
125

126
        return $this->proxyGeometry->asBinary();
6✔
127
    }
128

129

130
    public function x(): ?float
131
    {
132
        if ($this->proxyGeometry === null) {
60✔
133
            $this->load();
36✔
134
        }
135

136
        return $this->proxyGeometry->x();
60✔
137
    }
138

139
    public function y(): ?float
140
    {
141
        if ($this->proxyGeometry === null) {
60✔
142
            $this->load();
×
143
        }
144

145
        return $this->proxyGeometry->y();
60✔
146
    }
147

148
    public function z(): ?float
149
    {
150
        if ($this->proxyGeometry === null) {
24✔
151
            $this->load();
×
152
        }
153

154
        return $this->proxyGeometry->z();
24✔
155
    }
156

157
    public function m(): ?float
158
    {
159
        if ($this->proxyGeometry === null) {
24✔
160
            $this->load();
×
161
        }
162

163
        return $this->proxyGeometry->m();
24✔
164
    }
165

166
    public function getBoundingBox(): \Brick\Geo\BoundingBox
167
    {
168
        if ($this->proxyGeometry === null) {
×
169
            $this->load();
×
170
        }
171

172
        return $this->proxyGeometry->getBoundingBox();
×
173
    }
174

175
    public function toArray(): array
176
    {
177
        if ($this->proxyGeometry === null) {
51✔
178
            $this->load();
6✔
179
        }
180

181
        return $this->proxyGeometry->toArray();
51✔
182
    }
183

184
    public function project(\Brick\Geo\Projector\Projector $projector): \Brick\Geo\Point
185
    {
186
        if ($this->proxyGeometry === null) {
×
187
            $this->load();
×
188
        }
189

190
        return $this->proxyGeometry->project($projector);
×
191
    }
192

193
    public function coordinateDimension(): int
194
    {
195
        if ($this->proxyGeometry === null) {
24✔
196
            $this->load();
×
197
        }
198

199
        return $this->proxyGeometry->coordinateDimension();
24✔
200
    }
201

202
    public function spatialDimension(): int
203
    {
204
        if ($this->proxyGeometry === null) {
24✔
205
            $this->load();
×
206
        }
207

208
        return $this->proxyGeometry->spatialDimension();
24✔
209
    }
210

211
    public function isEmpty(): bool
212
    {
213
        if ($this->proxyGeometry === null) {
24✔
214
            $this->load();
×
215
        }
216

217
        return $this->proxyGeometry->isEmpty();
24✔
218
    }
219

220
    public function is3D(): bool
221
    {
222
        if ($this->proxyGeometry === null) {
30✔
223
            $this->load();
24✔
224
        }
225

226
        return $this->proxyGeometry->is3D();
30✔
227
    }
228

229
    public function isMeasured(): bool
230
    {
231
        if ($this->proxyGeometry === null) {
6✔
232
            $this->load();
×
233
        }
234

235
        return $this->proxyGeometry->isMeasured();
6✔
236
    }
237

238
    public function coordinateSystem(): \Brick\Geo\CoordinateSystem
239
    {
240
        if ($this->proxyGeometry === null) {
×
241
            $this->load();
×
242
        }
243

244
        return $this->proxyGeometry->coordinateSystem();
×
245
    }
246

247
    public function withSRID(int $srid): \Brick\Geo\Geometry
248
    {
249
        if ($this->proxyGeometry === null) {
×
250
            $this->load();
×
251
        }
252

253
        return $this->proxyGeometry->withSRID($srid);
×
254
    }
255

256
    public function toXY(): \Brick\Geo\Geometry
257
    {
258
        if ($this->proxyGeometry === null) {
×
259
            $this->load();
×
260
        }
261

262
        return $this->proxyGeometry->toXY();
×
263
    }
264

265
    public function withoutZ(): \Brick\Geo\Geometry
266
    {
267
        if ($this->proxyGeometry === null) {
×
268
            $this->load();
×
269
        }
270

271
        return $this->proxyGeometry->withoutZ();
×
272
    }
273

274
    public function withoutM(): \Brick\Geo\Geometry
275
    {
276
        if ($this->proxyGeometry === null) {
×
277
            $this->load();
×
278
        }
279

280
        return $this->proxyGeometry->withoutM();
×
281
    }
282

283
    public function swapXY(): \Brick\Geo\Geometry
284
    {
285
        if ($this->proxyGeometry === null) {
×
286
            $this->load();
×
287
        }
288

289
        return $this->proxyGeometry->swapXY();
×
290
    }
291

292
    public function isIdenticalTo(\Brick\Geo\Geometry $that): bool
293
    {
294
        if ($this->proxyGeometry === null) {
×
295
            $this->load();
×
296
        }
297

298
        return $this->proxyGeometry->isIdenticalTo($that);
×
299
    }
300

301
}
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