@@ -31,106 +31,6 @@ public static function getCentroid(array $vertices): Point
31
31
return new Point ($ xSum / $ verticesSum , $ ySum / $ verticesSum );
32
32
}
33
33
34
- /**
35
- * Retrieves the minimum y coordinate of a Polygon.
36
- *
37
- * @param Polygon $polygon Polygon to get the minimum y coordinate of.
38
- * @return float
39
- * @throws MindeeGeometryException Throws if a minimum y-axis value cannot
40
- * be found, e.g. if the polygon is empty.
41
- */
42
- public static function getMinYCoordinate (Polygon $ polygon ): float
43
- {
44
- $ min = null ;
45
- foreach ($ polygon ->getCoordinates () as $ point ) {
46
- if (!isset ($ min ) || $ min > $ point ->getY ()) {
47
- $ min = $ point ->getY ();
48
- }
49
- }
50
- if (!isset ($ min )) {
51
- throw new MindeeGeometryException (
52
- 'The provided polygon seems to be empty, or the Y coordinates of each point are invalid. '
53
- );
54
- }
55
-
56
- return $ min ;
57
- }
58
-
59
- /**
60
- * Retrieves the minimum x coordinate of a Polygon.
61
- *
62
- * @param Polygon $polygon Polygon to get the minimum y coordinate of.
63
- * @return float
64
- * @throws MindeeGeometryException Throws if a minimum x-axis value cannot be
65
- * found, e.g. if the polygon is empty.
66
- */
67
- public static function getMinXCoordinate (Polygon $ polygon ): float
68
- {
69
- $ min = null ;
70
- foreach ($ polygon ->getCoordinates () as $ point ) {
71
- if (!isset ($ min ) || $ min > $ point ->getX ()) {
72
- $ min = $ point ->getX ();
73
- }
74
- }
75
- if (!isset ($ min )) {
76
- throw new MindeeGeometryException (
77
- 'The provided polygon seems to be empty, or the X coordinates of each point are invalid. '
78
- );
79
- }
80
-
81
- return $ min ;
82
- }
83
-
84
- /**
85
- * Retrieves the maximum y coordinate of a Polygon.
86
- *
87
- * @param Polygon $polygon Polygon to get the minimum y coordinate of.
88
- * @return float
89
- * @throws MindeeGeometryException Throws if a maximum y-axis value cannot be
90
- * found, e.g. if the polygon is empty.
91
- */
92
- public static function getMaxYCoordinate (Polygon $ polygon ): float
93
- {
94
- $ min = null ;
95
- foreach ($ polygon ->getCoordinates () as $ point ) {
96
- if (!isset ($ min ) || $ min < $ point ->getY ()) {
97
- $ min = $ point ->getY ();
98
- }
99
- }
100
- if (!isset ($ min )) {
101
- throw new MindeeGeometryException (
102
- 'The provided polygon seems to be empty, or the Y coordinates of each point are invalid. '
103
- );
104
- }
105
-
106
- return $ min ;
107
- }
108
-
109
- /**
110
- * Retrieves the maximum x coordinate of a Polygon.
111
- *
112
- * @param Polygon $polygon Polygon to get the minimum y coordinate of.
113
- * @return float
114
- * @throws MindeeGeometryException Throws if a maximum x-axis value cannot be
115
- * found, e.g. if the polygon is empty.
116
- */
117
- public static function getMaxXCoordinate (Polygon $ polygon ): float
118
- {
119
- $ min = null ;
120
- foreach ($ polygon ->getCoordinates () as $ point ) {
121
- if (!isset ($ min ) || $ min < $ point ->getX ()) {
122
- $ min = $ point ->getX ();
123
- }
124
- }
125
- if (!isset ($ min )) {
126
- throw new MindeeGeometryException (
127
- 'The provided polygon seems to be empty, or the X coordinates of each point are invalid. '
128
- );
129
- }
130
-
131
- return $ min ;
132
- }
133
-
134
34
/**
135
35
* Compares two polygons on the Y axis. Returns a sort-compliant result (0;-1;1).
136
36
*
@@ -140,11 +40,10 @@ public static function getMaxXCoordinate(Polygon $polygon): float
140
40
*/
141
41
public static function compareOnY (Polygon $ polygon1 , Polygon $ polygon2 ): int
142
42
{
143
- $ sort = self :: getMinYCoordinate ($ polygon1 ) - self :: getMinYCoordinate ( $ polygon2 );
43
+ $ sort = ($ polygon1-> getMinY ( ) - $ polygon2-> getMinY () );
144
44
if ($ sort == 0 ) {
145
45
return 0 ;
146
46
}
147
-
148
47
return $ sort < 0 ? -1 : 1 ;
149
48
}
150
49
@@ -182,10 +81,10 @@ public static function createBoundingBoxFrom(?Polygon $base, ?Polygon $target =
182
81
{
183
82
$ merged = PolygonUtils::merge ($ base , $ target );
184
83
185
- $ topLeft = new Point (self :: getMinXCoordinate ( $ merged ), self :: getMinYCoordinate ( $ merged ));
186
- $ topRight = new Point (self :: getMaxXCoordinate ( $ merged ), self :: getMinYCoordinate ( $ merged ));
187
- $ bottomRight = new Point (self :: getMaxXCoordinate ( $ merged ), self :: getMaxYCoordinate ( $ merged ));
188
- $ bottomLeft = new Point (self :: getMinXCoordinate ( $ merged ), self :: getMaxYCoordinate ( $ merged ));
84
+ $ topLeft = new Point ($ merged-> getMinX ( ), $ merged-> getMinY ( ));
85
+ $ topRight = new Point ($ merged-> getMaxX ( ), $ merged-> getMinY ( ));
86
+ $ bottomRight = new Point ($ merged-> getMaxX ( ), $ merged-> getMaxY ( ));
87
+ $ bottomLeft = new Point ($ merged-> getMinX ( ), $ merged-> getMaxY ( ));
189
88
190
89
return new Polygon ([
191
90
$ topLeft ,
@@ -207,29 +106,7 @@ public static function quadrilateralFromPrediction(array $prediction): Polygon
207
106
if (count ($ prediction ) != 4 ) {
208
107
throw new MindeeGeometryException ('Prediction must have exactly 4 points. ' );
209
108
}
210
-
211
- return new Polygon ([
212
- new Point ($ prediction [0 ][0 ], $ prediction [0 ][1 ]),
213
- new Point ($ prediction [1 ][0 ], $ prediction [1 ][1 ]),
214
- new Point ($ prediction [2 ][0 ], $ prediction [2 ][1 ]),
215
- new Point ($ prediction [3 ][0 ], $ prediction [3 ][1 ]),
216
- ]);
217
- }
218
-
219
- /**
220
- * Generates a Polygon from a given prediction.
221
- *
222
- * @deprecated construct a new Polygon() instead.
223
- * @param array $prediction Raw prediction array.
224
- * @return Polygon
225
- */
226
- public static function polygonFromPrediction (array $ prediction ): Polygon
227
- {
228
- $ points = [];
229
- foreach ($ prediction as $ point ) {
230
- $ points [] = new Point ($ point [0 ], $ point [1 ]);
231
- }
232
- return new Polygon ($ points );
109
+ return new Polygon ($ prediction );
233
110
}
234
111
235
112
/**
@@ -245,20 +122,6 @@ public static function isPointInX(Point $point, float $minX, float $maxX): bool
245
122
return $ point ->getX () >= $ minX && $ point ->getX () <= $ maxX ;
246
123
}
247
124
248
- /**
249
- * Checks whether a point is in a polygon's x-axis range.
250
- *
251
- * @param Point $point Point to check.
252
- * @param Polygon $polygon Polygon.
253
- * @return boolean
254
- */
255
- public static function isPointInPolygonX (Point $ point , Polygon $ polygon ): bool
256
- {
257
- $ minX = MinMaxUtils::getMinMaxX ($ polygon ->getCoordinates ())->getMin ();
258
- $ maxX = MinMaxUtils::getMinMaxX ($ polygon ->getCoordinates ())->getMax ();
259
- return self ::isPointInX ($ point , $ minX , $ maxX );
260
- }
261
-
262
125
/**
263
126
* Checks whether a point is located within a coordinate range on the y-axis.
264
127
*
@@ -271,18 +134,4 @@ public static function isPointInY(Point $point, float $minY, float $maxY): bool
271
134
{
272
135
return $ point ->getY () >= $ minY && $ point ->getY () <= $ maxY ;
273
136
}
274
-
275
- /**
276
- * Checks whether a point is in a polygon's y-axis range.
277
- *
278
- * @param Point $point Point to check.
279
- * @param Polygon $polygon Polygon.
280
- * @return boolean
281
- */
282
- public static function isPointInPolygonY (Point $ point , Polygon $ polygon ): bool
283
- {
284
- $ minY = MinMaxUtils::getMinMaxY ($ polygon ->getCoordinates ())->getMin ();
285
- $ maxY = MinMaxUtils::getMinMaxY ($ polygon ->getCoordinates ())->getMax ();
286
- return self ::isPointInY ($ point , $ minY , $ maxY );
287
- }
288
137
}
0 commit comments