-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBBox.php
More file actions
113 lines (105 loc) · 2.43 KB
/
Copy pathBBox.php
File metadata and controls
113 lines (105 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace Mindee\Geometry;
/**
* Bounding box represented as a set of minimum and maximum values for the x and y axes.
*/
class BBox
{
/**
* @var float Minimum X coordinate.
*/
private float $minX;
/**
* @var float Maximum X coordinate.
*/
private float $maxX;
/**
* @var float Minimum Y coordinate.
*/
private float $minY;
/**
* @var float Maximum Y coordinate.
*/
private float $maxY;
/**
* @param float $minX Input minimum X coordinate.
* @param float $maxX Input maximum X coordinate.
* @param float $minY Input minimum Y coordinate.
* @param float $maxY Input maximum Y coordinate.
*/
public function __construct(
float $minX,
float $maxX,
float $minY,
float $maxY
) {
$this->minX = $minX;
$this->maxX = $maxX;
$this->minY = $minY;
$this->maxY = $maxY;
}
/**
* Retrieves the minimum x coordinate.
*
* @return float
*/
public function getMinX(): float
{
return $this->minX;
}
/**
* Retrieves the maximum x coordinate.
*
* @return float
*/
public function getMaxX(): float
{
return $this->maxX;
}
/**
* Retrieves the minimum y coordinate.
*
* @return float
*/
public function getMinY(): float
{
return $this->minY;
}
/**
* Retrieves the maximum y coordinate.
*
* @return float
*/
public function getMaxY(): float
{
return $this->maxY;
}
/**
* Extends the BBox with the provided points.
*
* @param array|Polygon $points Series of points to add to the BBox.
* @return void
*/
public function extendWith(Polygon|array $points): void
{
if ($points instanceof Polygon) {
$sequence = $points->getCoordinates();
} else {
$sequence = $points;
}
foreach ($sequence as $point) {
if ($this->minX > $point->getX()) {
$this->minX = $point->getX();
}
if ($this->minY > $point->getY()) {
$this->minY = $point->getY();
}
if ($this->maxX < $point->getX()) {
$this->maxX = $point->getX();
}
if ($this->maxY < $point->getY()) {
$this->maxY = $point->getY();
}
}
}
}