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

brick / geo / 13715696346

06 Mar 2025 05:06PM UTC coverage: 47.295% (-0.8%) from 48.121%
13715696346

push

github

BenMorel
Merge branch 'v0.11'

0 of 60 new or added lines in 14 files covered. (0.0%)

117 existing lines in 6 files now uncovered.

1652 of 3493 relevant lines covered (47.29%)

951.01 hits per line

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

16.16
/src/Proxy/PolygonProxy.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\Polygon;
13

14
/**
15
 * Proxy class for Polygon.
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\Polygon in your projects.
19
 */
20
class PolygonProxy extends Polygon 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 ?Polygon $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;
76✔
50
        $this->isProxyBinary = $isBinary;
76✔
51
        $this->proxySRID     = $srid;
76✔
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
76✔
65
            ? Polygon::fromBinary($this->proxyData, $this->proxySRID)
76✔
66
            : Polygon::fromText($this->proxyData, $this->proxySRID);
×
67
    }
68

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

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

80
        return $this->proxyGeometry;
×
81
    }
82

83
    public function isProxyBinary() : bool
84
    {
85
        return $this->isProxyBinary;
51✔
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) {
58✔
106
            return $this->proxyData;
×
107
        }
108

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

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

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

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

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

129

130
    public function rings(): array
131
    {
132
        if ($this->proxyGeometry === null) {
×
133
            $this->load();
×
134
        }
135

136
        return $this->proxyGeometry->rings();
×
137
    }
138

139
    public function exteriorRing(): \Brick\Geo\LineString
140
    {
141
        if ($this->proxyGeometry === null) {
18✔
142
            $this->load();
18✔
143
        }
144

145
        return $this->proxyGeometry->exteriorRing();
18✔
146
    }
147

148
    public function numInteriorRings(): int
149
    {
150
        if ($this->proxyGeometry === null) {
×
151
            $this->load();
×
152
        }
153

154
        return $this->proxyGeometry->numInteriorRings();
×
155
    }
156

157
    public function interiorRingN(int $n): \Brick\Geo\LineString
158
    {
159
        if ($this->proxyGeometry === null) {
×
160
            $this->load();
×
161
        }
162

163
        return $this->proxyGeometry->interiorRingN($n);
×
164
    }
165

166
    public function interiorRings(): array
167
    {
168
        if ($this->proxyGeometry === null) {
×
169
            $this->load();
×
170
        }
171

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

175
    public function getBoundingBox(): \Brick\Geo\BoundingBox
176
    {
177
        if ($this->proxyGeometry === null) {
×
178
            $this->load();
×
179
        }
180

181
        return $this->proxyGeometry->getBoundingBox();
×
182
    }
183

184
    public function toArray(): array
185
    {
186
        if ($this->proxyGeometry === null) {
×
187
            $this->load();
×
188
        }
189

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

193
    public function project(\Brick\Geo\Projector\Projector $projector): \Brick\Geo\Polygon
194
    {
195
        if ($this->proxyGeometry === null) {
×
196
            $this->load();
×
197
        }
198

199
        return $this->proxyGeometry->project($projector);
×
200
    }
201

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

208
        return $this->proxyGeometry->count();
×
209
    }
210

211
    public function getIterator(): \ArrayIterator
212
    {
213
        if ($this->proxyGeometry === null) {
×
214
            $this->load();
×
215
        }
216

217
        return $this->proxyGeometry->getIterator();
×
218
    }
219

220
    public function withExteriorRing(\Brick\Geo\LineString $exteriorRing): \Brick\Geo\Polygon
221
    {
NEW
222
        if ($this->proxyGeometry === null) {
×
NEW
223
            $this->load();
×
224
        }
225

NEW
226
        return $this->proxyGeometry->withExteriorRing($exteriorRing);
×
227
    }
228

229
    public function withInteriorRings(\Brick\Geo\LineString ...$interiorRings): \Brick\Geo\Polygon
230
    {
NEW
231
        if ($this->proxyGeometry === null) {
×
NEW
232
            $this->load();
×
233
        }
234

NEW
235
        return $this->proxyGeometry->withInteriorRings($interiorRings);
×
236
    }
237

238
    public function withAddedInteriorRings(\Brick\Geo\LineString ...$interiorRings): \Brick\Geo\Polygon
239
    {
NEW
240
        if ($this->proxyGeometry === null) {
×
NEW
241
            $this->load();
×
242
        }
243

NEW
244
        return $this->proxyGeometry->withAddedInteriorRings($interiorRings);
×
245
    }
246

247
    public function coordinateDimension(): int
248
    {
249
        if ($this->proxyGeometry === null) {
×
250
            $this->load();
×
251
        }
252

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

256
    public function spatialDimension(): int
257
    {
258
        if ($this->proxyGeometry === null) {
×
259
            $this->load();
×
260
        }
261

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

265
    public function isEmpty(): bool
266
    {
267
        if ($this->proxyGeometry === null) {
×
268
            $this->load();
×
269
        }
270

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

274
    public function is3D(): bool
275
    {
276
        if ($this->proxyGeometry === null) {
×
277
            $this->load();
×
278
        }
279

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

283
    public function isMeasured(): bool
284
    {
285
        if ($this->proxyGeometry === null) {
×
286
            $this->load();
×
287
        }
288

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

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

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

301
    public function withSRID(int $srid): \Brick\Geo\Geometry
302
    {
303
        if ($this->proxyGeometry === null) {
×
304
            $this->load();
×
305
        }
306

307
        return $this->proxyGeometry->withSRID($srid);
×
308
    }
309

310
    public function toXY(): \Brick\Geo\Geometry
311
    {
312
        if ($this->proxyGeometry === null) {
×
313
            $this->load();
×
314
        }
315

316
        return $this->proxyGeometry->toXY();
×
317
    }
318

319
    public function withoutZ(): \Brick\Geo\Geometry
320
    {
321
        if ($this->proxyGeometry === null) {
×
322
            $this->load();
×
323
        }
324

325
        return $this->proxyGeometry->withoutZ();
×
326
    }
327

328
    public function withoutM(): \Brick\Geo\Geometry
329
    {
330
        if ($this->proxyGeometry === null) {
×
331
            $this->load();
×
332
        }
333

334
        return $this->proxyGeometry->withoutM();
×
335
    }
336

337
    public function swapXY(): \Brick\Geo\Geometry
338
    {
339
        if ($this->proxyGeometry === null) {
×
340
            $this->load();
×
341
        }
342

343
        return $this->proxyGeometry->swapXY();
×
344
    }
345

346
    public function isIdenticalTo(\Brick\Geo\Geometry $that): bool
347
    {
348
        if ($this->proxyGeometry === null) {
×
349
            $this->load();
×
350
        }
351

352
        return $this->proxyGeometry->isIdenticalTo($that);
×
353
    }
354

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