@@ -31,106 +31,6 @@ public static function getCentroid(array $vertices): Point
3131 return new Point ($ xSum / $ verticesSum , $ ySum / $ verticesSum );
3232 }
3333
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-
13434 /**
13535 * Compares two polygons on the Y axis. Returns a sort-compliant result (0;-1;1).
13636 *
@@ -140,11 +40,10 @@ public static function getMaxXCoordinate(Polygon $polygon): float
14040 */
14141 public static function compareOnY (Polygon $ polygon1 , Polygon $ polygon2 ): int
14242 {
143- $ sort = self :: getMinYCoordinate ($ polygon1 ) - self :: getMinYCoordinate ( $ polygon2 );
43+ $ sort = ($ polygon1-> getMinY ( ) - $ polygon2-> getMinY () );
14444 if ($ sort == 0 ) {
14545 return 0 ;
14646 }
147-
14847 return $ sort < 0 ? -1 : 1 ;
14948 }
15049
@@ -182,10 +81,10 @@ public static function createBoundingBoxFrom(?Polygon $base, ?Polygon $target =
18281 {
18382 $ merged = PolygonUtils::merge ($ base , $ target );
18483
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 ( ));
18988
19089 return new Polygon ([
19190 $ topLeft ,
@@ -207,29 +106,7 @@ public static function quadrilateralFromPrediction(array $prediction): Polygon
207106 if (count ($ prediction ) != 4 ) {
208107 throw new MindeeGeometryException ('Prediction must have exactly 4 points. ' );
209108 }
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 );
233110 }
234111
235112 /**
@@ -245,20 +122,6 @@ public static function isPointInX(Point $point, float $minX, float $maxX): bool
245122 return $ point ->getX () >= $ minX && $ point ->getX () <= $ maxX ;
246123 }
247124
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-
262125 /**
263126 * Checks whether a point is located within a coordinate range on the y-axis.
264127 *
@@ -271,18 +134,4 @@ public static function isPointInY(Point $point, float $minY, float $maxY): bool
271134 {
272135 return $ point ->getY () >= $ minY && $ point ->getY () <= $ maxY ;
273136 }
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- }
288137}
0 commit comments