2
2
3
3
namespace Mindee \Geometry ;
4
4
5
+ use Mindee \Error \MindeeGeometryException ;
6
+
5
7
/**
6
8
* Polygon represented as a set of coordinates (vertices/points).
7
9
*/
@@ -12,6 +14,16 @@ class Polygon
12
14
*/
13
15
public ?array $ coordinates ;
14
16
17
+ /**
18
+ * @var MinMax Min and max Y values of the polygon.
19
+ */
20
+ private MinMax $ minMaxY ;
21
+
22
+ /**
23
+ * @var MinMax Min and max X values of the polygon.
24
+ */
25
+ private MinMax $ minMaxX ;
26
+
15
27
/**
16
28
* @param array|null $coordinates Coordinates of the polygon as a set of Points.
17
29
*/
@@ -44,7 +56,10 @@ public function getCentroid(): Point
44
56
*/
45
57
public function getMinMaxY (): MinMax
46
58
{
47
- return MinMaxUtils::getMinMaxY ($ this ->coordinates );
59
+ if (!isset ($ this ->minMaxY )) {
60
+ $ this ->minMaxY = MinMaxUtils::getMinMaxY ($ this ->coordinates );
61
+ }
62
+ return $ this ->minMaxY ;
48
63
}
49
64
50
65
/**
@@ -54,7 +69,10 @@ public function getMinMaxY(): MinMax
54
69
*/
55
70
public function getMinMaxX (): MinMax
56
71
{
57
- return MinMaxUtils::getMinMaxX ($ this ->coordinates );
72
+ if (!isset ($ this ->minMaxX )) {
73
+ $ this ->minMaxX = MinMaxUtils::getMinMaxX ($ this ->coordinates );
74
+ }
75
+ return $ this ->minMaxX ;
58
76
}
59
77
60
78
/**
@@ -81,6 +99,46 @@ public function isPointInX(Point $point): bool
81
99
return PolygonUtils::isPointInX ($ point , $ minMax ->getMin (), $ minMax ->getMax ());
82
100
}
83
101
102
+ /**
103
+ * Retrieves the minimum X coordinate.
104
+ *
105
+ * @return float
106
+ */
107
+ public function getMinX (): float
108
+ {
109
+ return $ this ->getMinMaxX ()->getMin ();
110
+ }
111
+
112
+ /**
113
+ * Retrieves the maximum X coordinate.
114
+ *
115
+ * @return float
116
+ */
117
+ public function getMaxX (): float
118
+ {
119
+ return $ this ->getMinMaxX ()->getMax ();
120
+ }
121
+
122
+ /**
123
+ * Retrieves the minimum Y coordinate.
124
+ *
125
+ * @return float
126
+ */
127
+ public function getMinY (): float
128
+ {
129
+ return $ this ->getMinMaxY ()->getMin ();
130
+ }
131
+
132
+ /**
133
+ * Retrieves the maximum Y coordinate.
134
+ *
135
+ * @return float
136
+ */
137
+ public function getMaxY (): float
138
+ {
139
+ return $ this ->getMinMaxY ()->getMax ();
140
+ }
141
+
84
142
/**
85
143
* Checks whether the Polygon has coordinates.
86
144
*
0 commit comments