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

brick / geo / 13632627167

03 Mar 2025 01:58PM UTC coverage: 47.859% (+0.3%) from 47.546%
13632627167

push

github

BenMorel
Final methods in abstract test classes

1632 of 3410 relevant lines covered (47.86%)

965.73 hits per line

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

96.0
/src/BoundingBox.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Brick\Geo;
6

7
use Brick\Geo\Exception\CoordinateSystemException;
8
use Brick\Geo\Exception\EmptyGeometryException;
9

10
/**
11
 * Represents a 2D or 3D bounding box calculated from a set of points. M coordinates are ignored.
12
 * This class is immutable.
13
 */
14
class BoundingBox
15
{
16
    private ?float $swX = null;
17

18
    private ?float $swY = null;
19

20
    private ?float $swZ = null;
21

22
    private ?float $neX = null;
23

24
    private ?float $neY = null;
25

26
    private ?float $neZ = null;
27

28
    private ?CoordinateSystem $cs = null;
29

30
    /**
31
     * Returns a copy of this BoundingBox extended with the given Point.
32
     *
33
     * @throws CoordinateSystemException
34
     */
35
    public function extendedWithPoint(Point $point) : BoundingBox
36
    {
37
        if ($point->isEmpty()) {
35✔
38
            return $this;
×
39
        }
40

41
        $point = $point->withoutM();
35✔
42

43
        if ($this->cs === null) {
35✔
44
            $cs = $point->coordinateSystem();
35✔
45
        } else {
46
            $cs = $this->cs;
35✔
47
            if (! $cs->isEqualTo($point->coordinateSystem())) {
35✔
48
                throw CoordinateSystemException::dimensionalityMix($cs, $point->coordinateSystem());
14✔
49
            }
50
        }
51

52
        $x = $point->x();
35✔
53
        $y = $point->y();
35✔
54
        $z = $point->z();
35✔
55

56
        $swX = ($this->swX === null) ? $x : min($this->swX, $x);
35✔
57
        $swY = ($this->swY === null) ? $y : min($this->swY, $y);
35✔
58

59
        $neX = ($this->neX === null) ? $x : max($this->neX, $x);
35✔
60
        $neY = ($this->neY === null) ? $y : max($this->neY, $y);
35✔
61

62
        if ($z !== null) {
35✔
63
            $swZ = ($this->swZ === null) ? $z : min($this->swZ, $z);
7✔
64
            $neZ = ($this->neZ === null) ? $z : max($this->neZ, $z);
7✔
65
        } else {
66
            $swZ = null;
28✔
67
            $neZ = null;
28✔
68
        }
69

70
        if (
71
            $swX === $this->swX && $swY === $this->swY && $swZ === $this->swZ &&
35✔
72
            $neX === $this->neX && $neY === $this->neY && $neZ === $this->neZ
35✔
73
        ) {
74
            return $this;
14✔
75
        }
76

77
        $that = new BoundingBox();
35✔
78

79
        $that->cs = $cs;
35✔
80
        $that->swX = $swX;
35✔
81
        $that->swY = $swY;
35✔
82
        $that->swZ = $swZ;
35✔
83
        $that->neX = $neX;
35✔
84
        $that->neY = $neY;
35✔
85
        $that->neZ = $neZ;
35✔
86

87
        return $that;
35✔
88
    }
89

90
    /**
91
     * Returns a copy of this BoundingBox extended with the given BoundingBox.
92
     *
93
     * @throws CoordinateSystemException
94
     */
95
    public function extendedWithBoundingBox(BoundingBox $boundingBox) : BoundingBox
96
    {
97
        if ($boundingBox->isEmpty()) {
7✔
98
            return $this;
×
99
        }
100

101
        return $this
7✔
102
            ->extendedWithPoint($boundingBox->getSouthWest())
7✔
103
            ->extendedWithPoint($boundingBox->getNorthEast());
7✔
104
    }
105

106
    public function isEmpty() : bool
107
    {
108
        return $this->cs === null;
7✔
109
    }
110

111
    /**
112
     * Returns the south-west XY or XYZ point.
113
     *
114
     * @throws EmptyGeometryException
115
     */
116
    public function getSouthWest() : Point
117
    {
118
        if ($this->cs === null) {
28✔
119
            throw new EmptyGeometryException('The bounding box is empty.');
7✔
120
        }
121

122
        if ($this->cs->hasZ()) {
21✔
123
            $coords = [$this->swX, $this->swY, $this->swZ];
7✔
124
        } else {
125
            $coords = [$this->swX, $this->swY];
14✔
126
        }
127

128
        /** @var list<float> $coords */
129
        return new Point($this->cs, ...$coords);
21✔
130
    }
131

132
    /**
133
     * Returns the north-east XY or XYZ point.
134
     *
135
     * @throws EmptyGeometryException
136
     */
137
    public function getNorthEast() : Point
138
    {
139
        if ($this->cs === null) {
28✔
140
            throw new EmptyGeometryException('The bounding box is empty.');
7✔
141
        }
142

143
        if ($this->cs->hasZ()) {
21✔
144
            $coords = [$this->neX, $this->neY, $this->neZ];
7✔
145
        } else {
146
            $coords = [$this->neX, $this->neY];
14✔
147
        }
148

149
        /** @var list<float> $coords */
150
        return new Point($this->cs, ...$coords);
21✔
151
    }
152
}
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