1 /*
2 * Copyright (C) 2017 Alberto Irurueta Carro (alberto@irurueta.com)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.irurueta.geometry;
18
19 import java.io.Serializable;
20
21 /**
22 * This class defines a 2D rectangle aligned with the horizontal and vertical
23 * axes.
24 * A rectangle is defined by two corners (top-left and bottom-right).
25 * Notice that vertical coordinates are defined from bottom to top, hence,
26 * top is a larger value than bottom.
27 */
28 public class Rectangle implements Serializable {
29
30 /**
31 * Constant defining default threshold value used when none is provided.
32 */
33 public static final double DEFAULT_THRESHOLD = 1e-9;
34
35 /**
36 * Top left coordinate of rectangle.
37 */
38 private Point2D topLeft;
39
40 /**
41 * Bottom right coordinate of rectangle.
42 */
43 private Point2D bottomRight;
44
45 /**
46 * Empty constructor.
47 * Creates a rectangle centered at the origin and having unitary area.
48 */
49 public Rectangle() {
50 topLeft = new InhomogeneousPoint2D(-0.5, -0.5);
51 bottomRight = new InhomogeneousPoint2D(0.5, 0.5);
52 }
53
54 /**
55 * Constructor with boundaries.
56 *
57 * @param topLeft top-left coordinates.
58 * @param bottomRight bottom-right coordinates.
59 */
60 public Rectangle(final Point2D topLeft, final Point2D bottomRight) {
61 setBounds(topLeft, bottomRight);
62 }
63
64 /**
65 * Constructor with boundaries.
66 *
67 * @param left left coordinate.
68 * @param top top coordinate.
69 * @param right right coordinate.
70 * @param bottom bottom coordinate.
71 */
72 public Rectangle(final double left, final double top, final double right, final double bottom) {
73 setBounds(left, top, right, bottom);
74 }
75
76 /**
77 * Constructor from 2D box.
78 *
79 * @param box a 2D box.
80 */
81 public Rectangle(final Box2D box) {
82 fromBox(box);
83 }
84
85 /**
86 * Gets top-left corner.
87 *
88 * @return top-left corner.
89 */
90 public Point2D getTopLeft() {
91 return topLeft;
92 }
93
94 /**
95 * Sets top-left corner.
96 *
97 * @param topLeft top-left corner.
98 */
99 public void setTopLeft(final Point2D topLeft) {
100 this.topLeft = topLeft;
101 }
102
103 /**
104 * Gets bottom-right corner.
105 *
106 * @return bottom-right corner.
107 */
108 public Point2D getBottomRight() {
109 return bottomRight;
110 }
111
112 /**
113 * Sets bottom-right corner.
114 *
115 * @param bottomRight bottom-right corner.
116 */
117 public void setBottomRight(final Point2D bottomRight) {
118 this.bottomRight = bottomRight;
119 }
120
121 /**
122 * Sets rectangle boundaries
123 *
124 * @param topLeft top-left coordinates.
125 * @param bottomRight bottom-right coordinates.
126 */
127 public final void setBounds(final Point2D topLeft, final Point2D bottomRight) {
128 this.topLeft = topLeft;
129 this.bottomRight = bottomRight;
130 }
131
132 /**
133 * Sets rectangle boundaries.
134 *
135 * @param left left coordinate.
136 * @param top top coordinate.
137 * @param right right coordinate.
138 * @param bottom bottom coordinate.
139 */
140 public final void setBounds(final double left, final double top, final double right, final double bottom) {
141 setBounds(new InhomogeneousPoint2D(left, top), new InhomogeneousPoint2D(right, bottom));
142 }
143
144 /**
145 * Gets center of rectangle.
146 *
147 * @param topLeft top-left coordinates.
148 * @param bottomRight bottom-right coordinates.
149 * @param result instance where center of rectangle will be stored.
150 */
151 public static void getCenter(final Point2D topLeft, final Point2D bottomRight, final Point2D result) {
152 getCenter(topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(), bottomRight.getInhomY(), result);
153 }
154
155 /**
156 * Gets center of rectangle.
157 *
158 * @param left left coordinate.
159 * @param top top coordinate
160 * @param right right coordinate.
161 * @param bottom bottom coordinate.
162 * @param result instance where center of rectangle will be stored.
163 */
164 public static void getCenter(
165 final double left, final double top, final double right, final double bottom, final Point2D result) {
166 result.setInhomogeneousCoordinates(0.5 * (left + right), 0.5 * (top + bottom));
167 }
168
169 /**
170 * Gets center of rectangle.
171 *
172 * @param topLeft top-left coordinates.
173 * @param bottomRight bottom-right coordinates.
174 * @return center of rectangle.
175 */
176 public static Point2D getCenter(final Point2D topLeft, final Point2D bottomRight) {
177 final var result = new InhomogeneousPoint2D();
178 getCenter(topLeft, bottomRight, result);
179 return result;
180 }
181
182 /**
183 * Gets center of rectangle.
184 *
185 * @param left left coordinate.
186 * @param top top coordinate.
187 * @param right right coordinate.
188 * @param bottom bottom coordinate.
189 * @return center of rectangle.
190 */
191 public static Point2D getCenter(final double left, final double top, final double right, final double bottom) {
192 final var result = new InhomogeneousPoint2D();
193 getCenter(left, top, right, bottom, result);
194 return result;
195 }
196
197 /**
198 * Gets center of rectangle.
199 *
200 * @param result instance where coordinates of center of rectangle will be
201 * stored.
202 */
203 public void getCenter(final Point2D result) {
204 getCenter(topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(), bottomRight.getInhomY(), result);
205 }
206
207 /**
208 * Gets center of rectangle.
209 *
210 * @return a new point containing center of rectangle.
211 */
212 public Point2D getCenter() {
213 final var result = new InhomogeneousPoint2D();
214 getCenter(result);
215 return result;
216 }
217
218 /**
219 * Sets values of this rectangle from provided 2D box.
220 *
221 * @param box a 2D box containing rectangle boundaries.
222 */
223 public final void fromBox(final Box2D box) {
224 box.toRectangle(this);
225 }
226
227 /**
228 * Creates a 2D box instance equivalent to this rectangle.
229 *
230 * @return a new 2D box instance equivalent to this rectangle.
231 */
232 public Box2D toBox() {
233 final var result = new Box2D();
234 toBox(result);
235 return result;
236 }
237
238 /**
239 * Sets values into provided box instance to make it equivalent to this rectangle.
240 *
241 * @param result instance where values will be stored.
242 */
243 public void toBox(final Box2D result) {
244 result.fromRectangle(this);
245 }
246
247 /**
248 * Gets signed width of a rectangle defined as the difference between
249 * bottom-right and top-left horizontal coordinates.
250 * Signed width will be positive if bottom-right corner is located at the
251 * rightmost position and will be negative otherwise.
252 *
253 * @param topLeft top-left corner.
254 * @param bottomRight bottom-right corner.
255 * @return signed width.
256 */
257 public static double getSignedWidth(final Point2D topLeft, final Point2D bottomRight) {
258 return bottomRight.getInhomX() - topLeft.getInhomX();
259 }
260
261 /**
262 * Gets signed width of this rectangle defined as the difference between
263 * its bottom-right and top-left horizontal coordinates.
264 * Signed width will be positive if bottom-right corner is located at the
265 * rightmost position and will be negative otherwise.
266 *
267 * @return signed width of this rectangle.
268 */
269 public double getSignedWidth() {
270 return getSignedWidth(topLeft, bottomRight);
271 }
272
273 /**
274 * Gets width of a rectangle defined as the absolute difference between
275 * bottom-right and top-left horizontal coordinates.
276 *
277 * @param topLeft top-left corner.
278 * @param bottomRight bottom-right corner.
279 * @return width the rectangle.
280 */
281 public static double getWidth(final Point2D topLeft, final Point2D bottomRight) {
282 return Math.abs(getSignedWidth(topLeft, bottomRight));
283 }
284
285 /**
286 * Gets width of this rectangle defined as the absolute difference between
287 * bottom-right and top-left horizontal coordinates.
288 *
289 * @return width of this rectangle.
290 */
291 public double getWidth() {
292 return getWidth(topLeft, bottomRight);
293 }
294
295 /**
296 * Gets signed height of a rectangle defined as the difference between
297 * its bottom-right and top-left vertical coordinates.
298 * Signed height will be negative if bottom-right corner is located at the
299 * lowest position and will be positive otherwise.
300 *
301 * @param topLeft top-left corner.
302 * @param bottomRight bottom-right corner.
303 * @return signed height.
304 */
305 public static double getSignedHeight(final Point2D topLeft, final Point2D bottomRight) {
306 return bottomRight.getInhomY() - topLeft.getInhomY();
307 }
308
309 /**
310 * Gets signed height of this rectangle defined as the difference between
311 * its bottom-right and top-left vertical coordinates.
312 * Signed height will be negative if bottom right corner is located at the
313 * lowest position and will be positive otherwise.
314 *
315 * @return signed height of this rectangle.
316 */
317 public double getSignedHeight() {
318 return getSignedHeight(topLeft, bottomRight);
319 }
320
321 /**
322 * Gets height of a rectangle defined as the absolute difference between
323 * bottom-right and top-left vertical coordinates.
324 *
325 * @param topLeft top-left corner.
326 * @param bottomRight bottom-right corner.
327 * @return height of the rectangle.
328 */
329 public static double getHeight(final Point2D topLeft, final Point2D bottomRight) {
330 return Math.abs(getSignedHeight(topLeft, bottomRight));
331 }
332
333 /**
334 * Gets height of this rectangle defined as the absolute difference between
335 * bottom-right and top-left vertical coordinates.
336 *
337 * @return height of this rectangle.
338 */
339 public double getHeight() {
340 return getHeight(topLeft, bottomRight);
341 }
342
343 /**
344 * Gets area of the rectangle defined by provided top-left and bottom-right
345 * corners.
346 *
347 * @param topLeft top-left corner.
348 * @param bottomRight bottom-right corner
349 * @return area of rectangle.
350 */
351 public static double getArea(final Point2D topLeft, final Point2D bottomRight) {
352 return getWidth(topLeft, bottomRight) * getHeight(topLeft, bottomRight);
353 }
354
355 /**
356 * Gets area of the rectangle defined by provided corner coordinates.
357 *
358 * @param left left coordinate.
359 * @param top top coordinate.
360 * @param right right coordinate.
361 * @param bottom bottom coordinate.
362 * @return area of rectangle.
363 */
364 public static double getArea(final double left, final double top, final double right, final double bottom) {
365 return getArea(left - right, top - bottom);
366 }
367
368 /**
369 * Gets area of the rectangle having provided width and height values.
370 *
371 * @param width width of rectangle.
372 * @param height height of rectangle.
373 * @return area of rectangle.
374 */
375 public static double getArea(final double width, final double height) {
376 return Math.abs(width) * Math.abs(height);
377 }
378
379 /**
380 * Gets area of this rectangle.
381 *
382 * @return area of this rectangle.
383 */
384 public double getArea() {
385 return getArea(topLeft, bottomRight);
386 }
387
388 /**
389 * Sets the center of this rectangle preserving its width and height.
390 *
391 * @param center new center to be set.
392 */
393 public void setCenter(final Point2D center) {
394 setCenter(center.getInhomX(), center.getInhomY());
395 }
396
397 /**
398 * Sets center of this rectangle preserving its width and height.
399 *
400 * @param centerX x coordinate of new center to be set.
401 * @param centerY y coordinate of new center to be set.
402 */
403 public void setCenter(final double centerX, final double centerY) {
404 final var width = getSignedWidth();
405 final var height = getSignedHeight();
406 setCenterAndSize(centerX, centerY, width, height);
407 }
408
409 /**
410 * Sets center and size (width and height) of this rectangle.
411 *
412 * @param center new center to be set.
413 * @param width new width to be set. (can be signed).
414 * @param height new height to be set. (can be signed).
415 */
416 public void setCenterAndSize(final Point2D center, final double width, final double height) {
417 setCenterAndSize(center.getInhomX(), center.getInhomY(), width, height);
418 }
419
420 /**
421 * Sets center and size of this rectangle.
422 *
423 * @param centerX x coordinate of new center to be set.
424 * @param centerY y coordinate of new center to be set.
425 * @param width new width to be set. (can be signed).
426 * @param height new height to be set. (can be signed).
427 */
428 public void setCenterAndSize(final double centerX, final double centerY, final double width, final double height) {
429 final var halfWidth = width / 2.0;
430 final var halfHeight = height / 2.0;
431 topLeft = new InhomogeneousPoint2D(centerX - halfWidth, centerY - halfHeight);
432 bottomRight = new InhomogeneousPoint2D(centerX + halfWidth, centerY + halfHeight);
433 }
434
435 /**
436 * Gets perimeter of a rectangle having provided width and height.
437 *
438 * @param width width of rectangle.
439 * @param height height of rectangle.
440 * @return perimeter of a rectangle having provided width and height.
441 */
442 public static double getPerimeter(final double width, final double height) {
443 return 2.0 * (width + height);
444 }
445
446 /**
447 * Gets perimeter of a rectangle having provided top-left and bottom-right
448 * corners.
449 *
450 * @param topLeft top-left corner.
451 * @param bottomRight bottom-right corner.
452 * @return perimeter of rectangle.
453 */
454 public static double getPerimeter(final Point2D topLeft, final Point2D bottomRight) {
455 return getPerimeter(topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(), bottomRight.getInhomY());
456 }
457
458 /**
459 * Gets perimeter of a rectangle having provided top-left and bottom-right
460 * corners.
461 *
462 * @param left left coordinate.
463 * @param top top coordinate.
464 * @param right right coordinate.
465 * @param bottom bottom coordinate.
466 * @return perimeter of rectangle.
467 */
468 public static double getPerimeter(final double left, final double top, final double right, final double bottom) {
469 final var width = Math.abs(right - left);
470 final var height = Math.abs(bottom - top);
471 return getPerimeter(width, height);
472 }
473
474 /**
475 * Gets perimeter of this rectangle.
476 *
477 * @return perimeter of this rectangle.
478 */
479 public double getPerimeter() {
480 return getPerimeter(topLeft, bottomRight);
481 }
482
483 /**
484 * Indicates if provided (x,y) coordinates are located inside the
485 * rectangle defined by top-left and bottom-right coordinates up to a
486 * certain threshold.
487 * A positive threshold makes inside area smaller, a negative threshold
488 * increases the inside area.
489 *
490 * @param x x coordinate of point to be checked.
491 * @param y y coordinate of point to be checked.
492 * @param left left coordinate.
493 * @param top top coordinate.
494 * @param right right coordinate.
495 * @param bottom bottom coordinate.
496 * @param threshold threshold to use as a margin to determine whether a
497 * point lies inside or not.
498 * @return true if point is inside, false otherwise.
499 */
500 public static boolean isInside(
501 final double x, final double y, final double left, final double top, final double right,
502 final double bottom, final double threshold) {
503
504 return !isAtLeftSide(x, y, left, top, right, bottom, threshold) &&
505 !isAtTopLeftCorner(x, y, left, top, right, bottom, threshold) &&
506 !isAtTopSide(x, y, left, top, right, bottom, threshold) &&
507 !isAtTopRightCorner(x, y, left, top, right, bottom, threshold) &&
508 !isAtRightSide(x, y, left, top, right, bottom, threshold) &&
509 !isAtBottomRightCorner(x, y, left, top, right, bottom, threshold) &&
510 !isAtBottomSide(x, y, left, top, right, bottom, threshold) &&
511 !isAtBottomLeftCorner(x, y, left, top, right, bottom, threshold);
512 }
513
514 /**
515 * Indicates if provided (x,y) coordinates are located inside the
516 * rectangle defined by top-left and bottom-right coordinates.
517 *
518 * @param x x coordinate of point to be checked.
519 * @param y y coordinate of point to be checked.
520 * @param left left coordinate.
521 * @param top top coordinate.
522 * @param right right coordinate.
523 * @param bottom bottom coordinate.
524 * @return true if point is inside, false otherwise.
525 */
526 public static boolean isInside(
527 final double x, final double y, final double left, final double top, final double right,
528 final double bottom) {
529 return isInside(x, y, left, top, right, bottom, 0.0);
530 }
531
532 /**
533 * Indicates if provided point is located inside the rectangle defined by
534 * top-left and bottom-right coordinates up to a certain threshold.
535 * A positive threshold makes inside area smaller, a negative threshold
536 * increases the inside area.
537 *
538 * @param point point to be checked.
539 * @param left left coordinate.
540 * @param top top coordinate.
541 * @param right right coordinate.
542 * @param bottom bottom coordinate.
543 * @param threshold threshold to use as a margin to determine whether
544 * point lies inside or not.
545 * @return true if point is inside, false otherwise.
546 */
547 public static boolean isInside(
548 final Point2D point, final double left, final double top, final double right, final double bottom,
549 final double threshold) {
550 return isInside(point.getInhomX(), point.getInhomY(), left, top, right, bottom, threshold);
551 }
552
553 /**
554 * Indicates if provided point is located inside the rectangle defined by
555 * top-left and bottom-right coordinates.
556 *
557 * @param point point to be checked.
558 * @param left left coordinate.
559 * @param top top coordinate.
560 * @param right right coordinate.
561 * @param bottom bottom coordinate.
562 * @return true if point is inside, false otherwise.
563 */
564 public static boolean isInside(
565 final Point2D point, final double left, final double top, final double right, final double bottom) {
566 return isInside(point, left, top, right, bottom, 0.0);
567 }
568
569 /**
570 * Indicates if provided point is located inside the rectangle defined by
571 * provided center and size up to a certain threshold.
572 * A positive threshold makes inside area smaller, a negative threshold
573 * increases the inside area.
574 *
575 * @param point point to be checked.
576 * @param center center of rectangle.
577 * @param width width of rectangle.
578 * @param height height of rectangle.
579 * @param threshold threshold to use as a margin to determine whether point
580 * lies inside or not.
581 * @return true if point is inside, false otherwise.
582 */
583 public static boolean isInside(
584 final Point2D point, final Point2D center, final double width, final double height,
585 final double threshold) {
586 final var halfWidth = width / 2.0;
587 final var halfHeight = height / 2.0;
588 return isInside(point, center.getInhomX() - halfWidth, center.getInhomY() - halfHeight,
589 center.getInhomX() + halfWidth, center.getInhomY() + halfHeight, threshold);
590 }
591
592 /**
593 * Indicates if provided point is located inside the rectangle defined by
594 * provided center and size.
595 *
596 * @param point point to be checked.
597 * @param center center of rectangle.
598 * @param width width of rectangle.
599 * @param height height of rectangle.
600 * @return true if point is inside, false otherwise.
601 */
602 public static boolean isInside(
603 final Point2D point, final Point2D center, final double width, final double height) {
604 return isInside(point, center, width, height, 0.0);
605 }
606
607 /**
608 * Indicates if provided point is located inside the rectangle defined by
609 * provided top-left and bottom-right corners up to a certain threshold.
610 * A positive threshold makes inside area smaller, a negative threshold
611 * increases the inside area.
612 *
613 * @param x x coordinate of point to be checked.
614 * @param y y coordinate of point to be checked.
615 * @param topLeft top-left corner.
616 * @param bottomRight bottom-right corner.
617 * @param threshold threshold to use as a margin to determine whether
618 * point lies inside or not.
619 * @return true if point is inside, false otherwise.
620 */
621 public static boolean isInside(
622 final double x, final double y, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
623 return isInside(x, y, topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(),
624 bottomRight.getInhomY(), threshold);
625 }
626
627 /**
628 * Indicates if provided point is located inside the rectangle defined by
629 * provided top-left and bottom-right corners.
630 *
631 * @param x x coordinate of point to be checked.
632 * @param y y coordinate of point to be checked.
633 * @param topLeft top-left corner.
634 * @param bottomRight bottom-right corner.
635 * @return true if point is inside, false otherwise.
636 */
637 public static boolean isInside(final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
638 return isInside(x, y, topLeft, bottomRight, 0.0);
639 }
640
641 /**
642 * Indicates if provided point is located inside the rectangle defined by
643 * provided top-left and bottom-right corners up to a certain threshold.
644 * A positive threshold makes inside area smaller, a negative threshold
645 * increases the inside area.
646 *
647 * @param point point to be checked.
648 * @param topLeft top-left corner.
649 * @param bottomRight bottom-right corner.
650 * @param threshold threshold to use as a margin to determine whether point
651 * lies inside or not.
652 * @return true if point is inside, false otherwise.
653 */
654 public static boolean isInside(
655 final Point2D point, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
656 return isInside(point, topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(),
657 bottomRight.getInhomY(), threshold);
658 }
659
660 /**
661 * Indicates if provided point is located inside the rectangle defined by
662 * provided top-left and bottom-right corners.
663 *
664 * @param point point to be checked.
665 * @param topLeft top-left corner.
666 * @param bottomRight bottom-right corner.
667 * @return true if point is inside, false otherwise.
668 */
669 public static boolean isInside(final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
670 return isInside(point, topLeft, bottomRight, 0.0);
671 }
672
673 /**
674 * Indicates if provided point coordinates are located inside this rectangle
675 * up to a certain threshold.
676 * A positive threshold makes inside area smaller, a negative threshold
677 * increases the inside area.
678 *
679 * @param x x coordinate of point to be checked.
680 * @param y y coordinate of point to be checked.
681 * @param threshold threshold to use as a margin to determine whether point
682 * lies inside or not.
683 * @return true if point is inside, false otherwise.
684 */
685 public boolean isInside(final double x, final double y, final double threshold) {
686 return isInside(x, y, topLeft, bottomRight, threshold);
687 }
688
689 /**
690 * Indicates if provided point coordinates are located inside this
691 * rectangle.
692 *
693 * @param x x coordinate of point to be checked.
694 * @param y y coordinate of point to be checked.
695 * @return true if point is inside, false otherwise.
696 */
697 public boolean isInside(final double x, final double y) {
698 return isInside(x, y, topLeft, bottomRight);
699 }
700
701 /**
702 * Indicates if provided point is located inside this rectangle up to a
703 * certain threshold.
704 * A positive threshold makes inside area smaller, a negative threshold
705 * increases the inside area.
706 *
707 * @param point point to be checked.
708 * @param threshold threshold to use as a margin to determine whether point
709 * lies inside or not.
710 * @return true if point is inside, false otherwise.
711 */
712 public boolean isInside(final Point2D point, final double threshold) {
713 return isInside(point, topLeft, bottomRight, threshold);
714 }
715
716 /**
717 * Indicates if provided point is located inside this rectangle.
718 *
719 * @param point point to be checked.
720 * @return true if point is inside, false otherwise.
721 */
722 public boolean isInside(final Point2D point) {
723 return isInside(point, topLeft, bottomRight);
724 }
725
726 /**
727 * Indicates if point at provided coordinates are located at left side of
728 * rectangle defined by provided top-left and bottom-right corners up to a
729 * certain threshold.
730 * A positive threshold moves left border to the right, a negative threshold
731 * moves left border to the left.
732 *
733 * @param x x coordinate of point to be checked.
734 * @param y y coordinate of point to be checked.
735 * @param left left coordinate of rectangle.
736 * @param top top coordinate of rectangle.
737 * @param right right coordinate of rectangle.
738 * @param bottom bottom coordinate of rectangle.
739 * @param threshold threshold to use as a margin to determine whether point
740 * lies at left side or not.
741 * @return true if point is at left side, false otherwise.
742 */
743 public static boolean isAtLeftSide(
744 final double x, final double y, final double left, final double top, final double right,
745 final double bottom, final double threshold) {
746 // fix values in case that corners are reversed
747 final var left2 = Math.min(left, right);
748 final var top2 = Math.max(top, bottom);
749 final var bottom2 = Math.min(top, bottom);
750
751 return x < (left2 + threshold) && y >= (bottom2 + threshold) && y <= (top2 - threshold);
752 }
753
754 /**
755 * Indicates if point at provided coordinates is located at left side of
756 * rectangle defined by provided top-left and bottom-right corners.
757 *
758 * @param x x coordinate of point to be checked.
759 * @param y y coordinate of point to be checked.
760 * @param left left coordinate of rectangle.
761 * @param top top coordinate of rectangle.
762 * @param right right coordinate of rectangle.
763 * @param bottom bottom coordinate of rectangle.
764 * @return true if point is at left side, false otherwise.
765 */
766 public static boolean isAtLeftSide(
767 final double x, final double y, final double left, final double top, final double right,
768 final double bottom) {
769 return isAtLeftSide(x, y, left, top, right, bottom, 0.0);
770 }
771
772 /**
773 * Indicates if provided point is located at left side of rectangle defined
774 * by provided top-left and bottom-right corners up to a certain threshold.
775 * A positive threshold moves left border to the right, a negative threshold
776 * moves left border to the left.
777 *
778 * @param point point to be checked.
779 * @param left left coordinate of rectangle.
780 * @param top top coordinate of rectangle.
781 * @param right right coordinate of rectangle.
782 * @param bottom bottom coordinate of rectangle.
783 * @param threshold threshold to use as a margin to determine whether point
784 * lies at left side or not.
785 * @return true if point is at left side, false otherwise.
786 */
787 public static boolean isAtLeftSide(
788 final Point2D point, final double left, final double top, final double right, final double bottom,
789 final double threshold) {
790 return isAtLeftSide(point.getInhomX(), point.getInhomY(), left, top, right, bottom, threshold);
791 }
792
793 /**
794 * Indicates if provided point is located at left side of rectangle defined
795 * by provided top-left and bottom-right corners.
796 *
797 * @param point point to be checked.
798 * @param left left coordinate of rectangle.
799 * @param top top coordinate of rectangle.
800 * @param right right coordinate of rectangle.
801 * @param bottom bottom coordinate of rectangle.
802 * @return true if point is at left side, false otherwise.
803 */
804 public static boolean isAtLeftSide(
805 final Point2D point, final double left, final double top, final double right, final double bottom) {
806 return isAtLeftSide(point, left, top, right, bottom, 0.0);
807 }
808
809 /**
810 * Indicates if provided point coordinates are located at left side of
811 * rectangle defined by provided top-left and bottom-right corners up to a
812 * certain threshold.
813 * A positive threshold moves left border to the right, a negative threshold
814 * moves left border to the left.
815 *
816 * @param x x coordinate of point to be checked.
817 * @param y y coordinate of point to be checked.
818 * @param topLeft top-left corner of rectangle.
819 * @param bottomRight bottom-right corner of rectangle.
820 * @param threshold threshold to use as a margin to determine whether point
821 * lies at left side or not.
822 * @return true if point is at left side, false otherwise.
823 */
824 public static boolean isAtLeftSide(
825 final double x, final double y, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
826 return isAtLeftSide(x, y, topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(),
827 bottomRight.getInhomY(), threshold);
828 }
829
830 /**
831 * Indicates if provided point coordinates are located at left side of
832 * rectangle defined by provided top-left and bottom-right corners.
833 *
834 * @param x x coordinate of point to be checked.
835 * @param y y coordinate of point to be checked.
836 * @param topLeft top-left corner of rectangle.
837 * @param bottomRight bottom-right corner of rectangle.
838 * @return true if point is at left side, false otherwise.
839 */
840 public static boolean isAtLeftSide(
841 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
842 return isAtLeftSide(x, y, topLeft, bottomRight, 0.0);
843 }
844
845 /**
846 * Indicates if provided point is located at left side of rectangle defined
847 * by provided top-left and bottom-right corners up to a certain threshold.
848 * A positive threshold moves left border to the right, a negative threshold
849 * moves left border to the left.
850 *
851 * @param point point to be checked.
852 * @param topLeft top-left corner of rectangle.
853 * @param bottomRight bottom-right corner of rectangle.
854 * @param threshold threshold to use as a margin to determine whether point
855 * lies at left side or not.
856 * @return true if point lies at left side, false otherwise.
857 */
858 public static boolean isAtLeftSide(
859 final Point2D point, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
860 return isAtLeftSide(point.getInhomX(), point.getInhomY(), topLeft, bottomRight, threshold);
861 }
862
863 /**
864 * Indicates if provided point is located at left side of rectangle defined
865 * by provided top-left and bottom-right corners.
866 *
867 * @param point point to be checked.
868 * @param topLeft top-left corner of rectangle.
869 * @param bottomRight bottom-right corner of rectangle.
870 * @return true if point lies at left side, false otherwise.
871 */
872 public static boolean isAtLeftSide(final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
873 return isAtLeftSide(point, topLeft, bottomRight, 0.0);
874 }
875
876 /**
877 * Indicates if provided point coordinates are located at left side of
878 * rectangle defined by provided center and size values.
879 * A positive threshold moves left border to the right, a negative threshold
880 * moves border to the left.
881 *
882 * @param x x coordinate of point to be checked.
883 * @param y y coordinate of point to be checked.
884 * @param center center of rectangle.
885 * @param width width of rectangle.
886 * @param height height of rectangle.
887 * @param threshold threshold to use as a margin to determine whether point
888 * lies at left side or not.
889 * @return true if point is at left side, false otherwise.
890 */
891 public static boolean isAtLeftSide(
892 final double x, final double y, final Point2D center, final double width, final double height,
893 final double threshold) {
894 final var halfWidth = width / 2.0;
895 final var halfHeight = height / 2.0;
896 final var centerX = center.getInhomX();
897 final var centerY = center.getInhomY();
898 return isAtLeftSide(x, y, centerX - halfWidth, centerY - halfHeight, centerX + halfWidth,
899 centerY + halfHeight, threshold);
900 }
901
902 /**
903 * Indicates if provided point coordinates are located at left side of
904 * rectangle defined by provided center and size values.
905 *
906 * @param x x coordinate of point to be checked.
907 * @param y y coordinate of point to be checked.
908 * @param center center of rectangle.
909 * @param width width of rectangle.
910 * @param height height of rectangle.
911 * @return true if point is at left side, false otherwise.
912 */
913 public static boolean isAtLeftSide(
914 final double x, final double y, final Point2D center, final double width, final double height) {
915 return isAtLeftSide(x, y, center, width, height, 0.0);
916 }
917
918 /**
919 * Indicates if provided point is located at left side of rectangle defined
920 * by provided center and size values up to a certain threshold.
921 * A positive threshold moves left border to the right, a negative threshold
922 * moves left border to the left.
923 *
924 * @param point point to be checked.
925 * @param center center of rectangle.
926 * @param width width of rectangle.
927 * @param height height of rectangle.
928 * @param threshold threshold to use as a margin to determine whether point
929 * lies at left side or not.
930 * @return true if point is at left side, false otherwise.
931 */
932 public static boolean isAtLeftSide(
933 final Point2D point, final Point2D center, final double width, final double height,
934 final double threshold) {
935 return isAtLeftSide(point.getInhomX(), point.getInhomY(), center, width, height, threshold);
936 }
937
938 /**
939 * Indicates if provided point is located at left side of rectangle defined
940 * by provided center and size values.
941 *
942 * @param point point to be checked.
943 * @param center center of rectangle.
944 * @param width width of rectangle.
945 * @param height height of rectangle.
946 * @return true if point is at left side, false otherwise.
947 */
948 public static boolean isAtLeftSide(
949 final Point2D point, final Point2D center, final double width, final double height) {
950 return isAtLeftSide(point, center, width, height, 0.0);
951 }
952
953 /**
954 * Indicates if provided point coordinates are located at left side of this
955 * rectangle up to a certain threshold.
956 * A positive threshold moves left border to the right, a negative threshold
957 * moves left border to the left.
958 *
959 * @param x x coordinate of point to be checked.
960 * @param y y coordinate of point to be checked.
961 * @param threshold threshold to use as a margin to determine whether point
962 * lies at left side or not.
963 * @return true if point is at left side, false otherwise.
964 */
965 public boolean isAtLeftSide(final double x, final double y, final double threshold) {
966 return isAtLeftSide(x, y, topLeft, bottomRight, threshold);
967 }
968
969 /**
970 * Indicates if provided point coordinates are located at left side of this
971 * rectangle.
972 *
973 * @param x x coordinate of point to be checked.
974 * @param y y coordinate of point to be checked.
975 * @return true if point is at left side, false otherwise.
976 */
977 public boolean isAtLeftSide(final double x, final double y) {
978 return isAtLeftSide(x, y, 0.0);
979 }
980
981 /**
982 * Indicates if provided point is located at left side of this rectangle up
983 * to a certain threshold.
984 * A positive threshold moves left border to the right, a negative threshold
985 * moves left border to the left.
986 *
987 * @param point point to be checked.
988 * @param threshold threshold to use as a margin to determine whether point
989 * lies at left side or not.
990 * @return true if point is at left side, false otherwise.
991 */
992 public boolean isAtLeftSide(final Point2D point, final double threshold) {
993 return isAtLeftSide(point.getInhomX(), point.getInhomY(), threshold);
994 }
995
996 /**
997 * Indicates if provided point is located at left side of this rectangle.
998 *
999 * @param point point to be checked.
1000 * @return true if point is at left side, false otherwise.
1001 */
1002 public boolean isAtLeftSide(final Point2D point) {
1003 return isAtLeftSide(point, 0.0);
1004 }
1005
1006 /**
1007 * Indicates if provided point coordinates are located at top-left corner of
1008 * rectangle defined by provided top-left and bottom-right corners up to a
1009 * certain threshold.
1010 * A positive threshold moves top-left corner towards the rectangle
1011 * interior, a negative threshold moves top-left corner towards rectangle
1012 * exterior.
1013 *
1014 * @param x x coordinate of point to be checked.
1015 * @param y y coordinate of point to be checked.
1016 * @param left left coordinate of rectangle.
1017 * @param top top coordinate of rectangle.
1018 * @param right right coordinate of rectangle.
1019 * @param bottom bottom coordinate of rectangle.
1020 * @param threshold threshold to use as a margin to determine whether point
1021 * lies at top-left corner or not.
1022 * @return true if point is at top-left corner, false otherwise.
1023 */
1024 public static boolean isAtTopLeftCorner(
1025 final double x, final double y, final double left, final double top, final double right,
1026 final double bottom, final double threshold) {
1027 // fix values in case that corners are reversed
1028 final var top2 = Math.max(top, bottom);
1029 final var left2 = Math.min(left, right);
1030
1031 return x < (left2 + threshold) && y > (top2 - threshold);
1032 }
1033
1034 /**
1035 * Indicates if point at provided coordinates is located at top-left corner
1036 * of rectangle defined by provided top-left and bottom-right corners.
1037 *
1038 * @param x x coordinate of point to be checked.
1039 * @param y y coordinate of point to be checked.
1040 * @param left left coordinate of rectangle.
1041 * @param top top coordinate of rectangle.
1042 * @param right right coordinate of rectangle.
1043 * @param bottom bottom coordinate of rectangle.
1044 * @return true if point is at top-left corner, false otherwise.
1045 */
1046 public static boolean isAtTopLeftCorner(
1047 final double x, final double y, final double left, final double top, final double right,
1048 final double bottom) {
1049 return isAtTopLeftCorner(x, y, left, top, right, bottom, 0.0);
1050 }
1051
1052 /**
1053 * Indicates if provided point is located at top-left corner of rectangle
1054 * defined by provided top-left and bottom-right corners up to a certain
1055 * threshold.
1056 * A positive threshold moves top-left corner towards the rectangle
1057 * interior, a negative threshold moves top-left corner towards rectangle
1058 * exterior.
1059 *
1060 * @param point point to be checked.
1061 * @param left left coordinate of rectangle.
1062 * @param top top coordinate of rectangle.
1063 * @param right right coordinate of rectangle.
1064 * @param bottom bottom coordinate of rectangle.
1065 * @param threshold threshold to use as a margin to determine whether point
1066 * lies at top-left or not.
1067 * @return true if point is at top-left corner, false otherwise.
1068 */
1069 public static boolean isAtTopLeftCorner(
1070 final Point2D point, final double left, final double top, final double right, final double bottom,
1071 final double threshold) {
1072 return isAtTopLeftCorner(point.getInhomX(), point.getInhomY(), left, top, right, bottom, threshold);
1073 }
1074
1075 /**
1076 * Indicates if provided point is located at top-left corner of rectangle
1077 * defined by provided top-left and bottom-right corners.
1078 *
1079 * @param point point to be checked.
1080 * @param left left coordinate of rectangle.
1081 * @param top top coordinate of rectangle.
1082 * @param right right coordinate of rectangle.
1083 * @param bottom bottom coordinate of rectangle.
1084 * @return true if point is at top-left corner, false otherwise.
1085 */
1086 public static boolean isAtTopLeftCorner(
1087 final Point2D point, final double left, final double top, final double right, final double bottom) {
1088 return isAtTopLeftCorner(point, left, top, right, bottom, 0.0);
1089 }
1090
1091 /**
1092 * Indicates if provided point coordinates are located at top-left corner of
1093 * rectangle defined by provided top-left and bottom-right corners up to a
1094 * certain threshold.
1095 * A positive threshold moves top-left corner towards the rectangle
1096 * interior, a negative threshold moves top-left corner towards rectangle
1097 * exterior.
1098 *
1099 * @param x x coordinate of point to be checked.
1100 * @param y y coordinate of point to be checked.
1101 * @param topLeft top-left corner of rectangle.
1102 * @param bottomRight bottom-right corner of rectangle.
1103 * @param threshold threshold to use as a margin to determine whether point
1104 * lies at top-left corner or not.
1105 * @return true if point is at top-left corner, false otherwise.
1106 */
1107 public static boolean isAtTopLeftCorner(
1108 final double x, final double y, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
1109 return isAtTopLeftCorner(x, y, topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(),
1110 bottomRight.getInhomY(), threshold);
1111 }
1112
1113 /**
1114 * Indicates if provided point coordinates are located at top-left corner of
1115 * rectangle defined by provided top-left and bottom-right corners.
1116 *
1117 * @param x x coordinate of point to be checked.
1118 * @param y y coordinate of point to be checked.
1119 * @param topLeft top-left corner of rectangle.
1120 * @param bottomRight bottom-right corner of rectangle.
1121 * @return true if point is at top-left corner, false otherwise.
1122 */
1123 public static boolean isAtTopLeftCorner(
1124 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
1125 return isAtTopLeftCorner(x, y, topLeft, bottomRight, 0.0);
1126 }
1127
1128 /**
1129 * Indicates if provided point is located at top-left corner of rectangle
1130 * defined by provided top-left and bottom-right corners up to a certain
1131 * threshold.
1132 * A positive threshold moves top-left corner towards the rectangle
1133 * interior, a negative threshold moves top-left corner towards rectangle
1134 * exterior.
1135 *
1136 * @param point point to be checked.
1137 * @param topLeft top-left corner of rectangle.
1138 * @param bottomRight bottom-right corner of rectangle.
1139 * @param threshold threshold to use as a margin to determine whether point
1140 * lies at top-left corner or not.
1141 * @return true if point is at top-left corner, false otherwise.
1142 */
1143 public static boolean isAtTopLeftCorner(
1144 final Point2D point, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
1145 return isAtTopLeftCorner(point.getInhomX(), point.getInhomY(), topLeft, bottomRight, threshold);
1146 }
1147
1148 /**
1149 * Indicates if provided point is located at top-left corner of rectangle
1150 * defined by provided top-left and bottom-right corners.
1151 *
1152 * @param point point to be checked.
1153 * @param topLeft top-left corner of rectangle.
1154 * @param bottomRight bottom-right corner of rectangle.
1155 * @return true if point is at top-left corner, false otherwise.
1156 */
1157 public static boolean isAtTopLeftCorner(final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
1158 return isAtTopLeftCorner(point, topLeft, bottomRight, 0.0);
1159 }
1160
1161 /**
1162 * Indicates if provided point coordinates are located at top-left corner of
1163 * rectangle defined by provided center and size values up to a certain
1164 * threshold.
1165 * A positive threshold moves top-left corner towards the rectangle
1166 * interior, a negative threshold moves top-left corner towards rectangle
1167 * exterior.
1168 *
1169 * @param x x coordinate of point to be checked.
1170 * @param y y coordinate of point to be checked.
1171 * @param center center of rectangle.
1172 * @param width width of rectangle.
1173 * @param height height of rectangle.
1174 * @param threshold threshold to use as a margin to determine whether point
1175 * lies at top-left corner or not.
1176 * @return true if point is at top-left corner, false otherwise.
1177 */
1178 public static boolean isAtTopLeftCorner(
1179 final double x, final double y, final Point2D center, final double width, final double height,
1180 final double threshold) {
1181 final var halfWidth = width / 2.0;
1182 final var halfHeight = height / 2.0;
1183 final var centerX = center.getInhomX();
1184 final var centerY = center.getInhomY();
1185 return isAtTopLeftCorner(x, y, centerX - halfWidth, centerY - halfHeight, centerX + halfWidth,
1186 centerY + halfHeight, threshold);
1187 }
1188
1189 /**
1190 * Indicates if provided point coordinates are located at top-left corner of
1191 * rectangle defined by provided center and size values.
1192 *
1193 * @param x x coordinate of point to be checked.
1194 * @param y y coordinate of point to be checked.
1195 * @param center center of rectangle.
1196 * @param width width of rectangle.
1197 * @param height height of rectangle.
1198 * @return true if point is at top-left corner, false otherwise.
1199 */
1200 public static boolean isAtTopLeftCorner(
1201 final double x, final double y, final Point2D center, final double width, final double height) {
1202 return isAtTopLeftCorner(x, y, center, width, height, 0.0);
1203 }
1204
1205 /**
1206 * Indicates if provided point is located at top-left corner of rectangle
1207 * defined by provided center and size values up to a certain threshold.
1208 * A positive threshold moves top-left corner towards the rectangle
1209 * interior, a negative threshold moves top-left corner towards rectangle
1210 * exterior.
1211 *
1212 * @param point point to be checked.
1213 * @param center center of rectangle.
1214 * @param width width of rectangle.
1215 * @param height height of rectangle.
1216 * @param threshold threshold to use as a margin to determine whether point
1217 * lies at top-left corner or not.
1218 * @return true if point is at top-left corner, false otherwise.
1219 */
1220 public static boolean isAtTopLeftCorner(
1221 final Point2D point, final Point2D center, final double width, final double height,
1222 final double threshold) {
1223 return isAtTopLeftCorner(point.getInhomX(), point.getInhomY(), center, width, height, threshold);
1224 }
1225
1226 /**
1227 * Indicates if provided point is located at top-left corner of rectangle
1228 * defined by provided center and size values.
1229 *
1230 * @param point point to be checked.
1231 * @param center center of rectangle.
1232 * @param width width of rectangle.
1233 * @param height height of rectangle.
1234 * @return true if point is at top-left corner, false otherwise.
1235 */
1236 public static boolean isAtTopLeftCorner(
1237 final Point2D point, final Point2D center, final double width, final double height) {
1238 return isAtTopLeftCorner(point, center, width, height, 0.0);
1239 }
1240
1241 /**
1242 * Indicates if provided point coordinates are located at top-left corner of
1243 * this rectangle up to a certain threshold.
1244 * A positive threshold moves top-left corner towards the rectangle
1245 * interior, a negative threshold moves top-left corner towards rectangle
1246 * exterior.
1247 *
1248 * @param x x coordinate of point to be checked.
1249 * @param y y coordinate of point to be checked.
1250 * @param threshold threshold to use as a margin to determine whether point
1251 * lies at top-left corner or not.
1252 * @return true if point is at top-left corner, false otherwise.
1253 */
1254 public boolean isAtTopLeftCorner(final double x, final double y, final double threshold) {
1255 return isAtTopLeftCorner(x, y, topLeft, bottomRight, threshold);
1256 }
1257
1258 /**
1259 * Indicates if provided point coordinates are located at top-left corner of
1260 * this rectangle.
1261 *
1262 * @param x x coordinate of point to be checked.
1263 * @param y y coordinate of point to be checked.
1264 * @return true if point is at top-left corner, false otherwise.
1265 */
1266 public boolean isAtTopLeftCorner(final double x, final double y) {
1267 return isAtTopLeftCorner(x, y, 0.0);
1268 }
1269
1270 /**
1271 * Indicates if provided point is located at top-left corner of this
1272 * rectangle up to a certain threshold.
1273 * A positive threshold moves top-left corner towards the rectangle
1274 * interior, a negative threshold moves top-left corner towards rectangle
1275 * exterior.
1276 *
1277 * @param point point to be checked.
1278 * @param threshold threshold to use as a margin to determine whether point
1279 * lies at top-left corner or not.
1280 * @return true if point is at top-left corner, false otherwise.
1281 */
1282 public boolean isAtTopLeftCorner(final Point2D point, final double threshold) {
1283 return isAtTopLeftCorner(point.getInhomX(), point.getInhomY(), threshold);
1284 }
1285
1286 /**
1287 * Indicates if provided point is located at top-left corner of this
1288 * rectangle.
1289 *
1290 * @param point point to be checked.
1291 * @return true if point is at top-left corner, false otherwise.
1292 */
1293 public boolean isAtTopLeftCorner(final Point2D point) {
1294 return isAtTopLeftCorner(point, 0.0);
1295 }
1296
1297 /**
1298 * Indicates if provided point coordinates are located at top side of
1299 * rectangle defined by provided top-left and bottom-right corners up to a
1300 * certain threshold.
1301 * A positive threshold moves top border downwards, a negative threshold
1302 * moves top border upwards.
1303 *
1304 * @param x x coordinate of point to be checked.
1305 * @param y y coordinate of point to be checked.
1306 * @param left left coordinate of rectangle.
1307 * @param top top coordinate of rectangle.
1308 * @param right right coordinate of rectangle.
1309 * @param bottom bottom coordinate of rectangle.
1310 * @param threshold threshold to use as a margin to determine whether point
1311 * lies at top side or not.
1312 * @return true if point is at top side, false otherwise.
1313 */
1314 public static boolean isAtTopSide(
1315 final double x, final double y, final double left, final double top, final double right,
1316 final double bottom, final double threshold) {
1317 final var top2 = Math.max(top, bottom);
1318 final var left2 = Math.min(left, right);
1319 final var right2 = Math.max(left, right);
1320
1321 return y > (top2 - threshold) && x >= (left2 + threshold) && x <= (right2 - threshold);
1322 }
1323
1324 /**
1325 * Indicates if point at provided coordinates is located at top side of
1326 * rectangle defined by provided top-left and bottom-right corners.
1327 *
1328 * @param x x coordinate of point to be checked.
1329 * @param y y coordinate of point to be checked.
1330 * @param left left coordinate of rectangle.
1331 * @param top top coordinate of rectangle.
1332 * @param right right coordinate of rectangle.
1333 * @param bottom bottom coordinate of rectangle.
1334 * @return true if point is at top side, false otherwise.
1335 */
1336 public static boolean isAtTopSide(
1337 final double x, final double y, final double left, final double top, final double right,
1338 final double bottom) {
1339 return isAtTopSide(x, y, left, top, right, bottom, 0.0);
1340 }
1341
1342 /**
1343 * Indicates if provided point is located at top side of rectangle defined
1344 * by provided top-left and bottom-right corners up to a certain threshold.
1345 * A positive threshold moves top border downwards, a negative threshold
1346 * moves top border upwards.
1347 *
1348 * @param point point to be checked.
1349 * @param left left coordinate of rectangle.
1350 * @param top top coordinate of rectangle.
1351 * @param right right coordinate of rectangle.
1352 * @param bottom bottom coordinate of rectangle.
1353 * @param threshold threshold to use as a margin to determine whether point
1354 * lies at top side or not.
1355 * @return true if point is at top side, false otherwise.
1356 */
1357 public static boolean isAtTopSide(
1358 final Point2D point, final double left, final double top, final double right, final double bottom,
1359 final double threshold) {
1360 return isAtTopSide(point.getInhomX(), point.getInhomY(), left, top, right, bottom, threshold);
1361 }
1362
1363 /**
1364 * Indicates if provided point is located at top side of rectangle defined
1365 * by provided top-left and bottom-right corners.
1366 *
1367 * @param point point to be checked.
1368 * @param left left coordinate of rectangle.
1369 * @param top top coordinate of rectangle.
1370 * @param right right coordinate of rectangle.
1371 * @param bottom bottom coordinate of rectangle.
1372 * @return true if point is at top side, false otherwise.
1373 */
1374 public static boolean isAtTopSide(
1375 final Point2D point, final double left, final double top, final double right, final double bottom) {
1376 return isAtTopSide(point, left, top, right, bottom, 0.0);
1377 }
1378
1379 /**
1380 * Indicates if provided point coordinates are located at top side of
1381 * rectangle defined by provided top-left and bottom-right corners up to a
1382 * certain threshold.
1383 * A positive threshold moves top border downwards, a negative threshold
1384 * moves top border upwards.
1385 *
1386 * @param x x coordinate of point to be checked.
1387 * @param y y coordinate of point to be checked.
1388 * @param topLeft top-left corner of rectangle.
1389 * @param bottomRight bottom-right corner of rectangle.
1390 * @param threshold threshold to use as a margin to determine whether point
1391 * lies at top side or not.
1392 * @return true if point is at top side, false otherwise.
1393 */
1394 public static boolean isAtTopSide(
1395 final double x, final double y, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
1396 return isAtTopSide(x, y, topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(),
1397 bottomRight.getInhomY(), threshold);
1398 }
1399
1400 /**
1401 * Indicates if provided point coordinates are located at top side of
1402 * rectangle defined by provided top-left and bottom-right corners.
1403 *
1404 * @param x x coordinate of point to be checked.
1405 * @param y y coordinate of point to be checked.
1406 * @param topLeft top-left corner of rectangle.
1407 * @param bottomRight bottom-right corner of rectangle.
1408 * @return true if point is at top side, false otherwise.
1409 */
1410 public static boolean isAtTopSide(
1411 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
1412 return isAtTopSide(x, y, topLeft, bottomRight, 0.0);
1413 }
1414
1415 /**
1416 * Indicates if provided point is located at top side of rectangle defined
1417 * by provided top-left and bottom-right corners.
1418 * A positive threshold moves top border downwards, a negative threshold
1419 * moves top border upwards.
1420 *
1421 * @param point point to be checked.
1422 * @param topLeft top-left corner of rectangle.
1423 * @param bottomRight bottom-right corner of rectangle.
1424 * @param threshold threshold to use as a margin to determine whether point
1425 * lies at top side or not.
1426 * @return true if point is at top side, false otherwise.
1427 */
1428 public static boolean isAtTopSide(
1429 final Point2D point, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
1430 return isAtTopSide(point.getInhomX(), point.getInhomY(), topLeft, bottomRight, threshold);
1431 }
1432
1433 /**
1434 * Indicates if provided point is located at top side of rectangle defined
1435 * by provided top-left and bottom-right corners.
1436 *
1437 * @param point point to be checked.
1438 * @param topLeft top-left corner of rectangle.
1439 * @param bottomRight bottom-right corner of rectangle.
1440 * @return true if point is at top side, false otherwise.
1441 */
1442 public static boolean isAtTopSide(final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
1443 return isAtTopSide(point, topLeft, bottomRight, 0.0);
1444 }
1445
1446 /**
1447 * Indicates if provided point coordinates are located at top side of
1448 * rectangle defined by provided center and size values up to a certain
1449 * threshold.
1450 * A positive threshold moves top border downwards, a negative threshold
1451 * moves top border upwards.
1452 *
1453 * @param x x coordinate of point to be checked.
1454 * @param y y coordinate of point to be checked.
1455 * @param center center of rectangle.
1456 * @param width width of rectangle.
1457 * @param height height of rectangle.
1458 * @param threshold threshold to use as a margin to determine whether point
1459 * lies at top side or not.
1460 * @return true if point is at top side, false otherwise.
1461 */
1462 public static boolean isAtTopSide(
1463 final double x, final double y, final Point2D center, final double width, final double height,
1464 final double threshold) {
1465 final var halfWidth = width / 2.0;
1466 final var halfHeight = height / 2.0;
1467 final var centerX = center.getInhomX();
1468 final var centerY = center.getInhomY();
1469 return isAtTopSide(x, y, centerX - halfWidth, centerY - halfHeight, centerX + halfWidth,
1470 centerY + halfHeight, threshold);
1471 }
1472
1473 /**
1474 * Indicates if provided point coordinates are located at top side of
1475 * rectangle defined by provided center and size values.
1476 *
1477 * @param x x coordinate of point to be checked.
1478 * @param y y coordinate of point to be checked.
1479 * @param center center of rectangle.
1480 * @param width width of rectangle.
1481 * @param height height of rectangle.
1482 * @return true if point is at top side, false otherwise.
1483 */
1484 public static boolean isAtTopSide(
1485 final double x, final double y, final Point2D center, final double width, final double height) {
1486 return isAtTopSide(x, y, center, width, height, 0.0);
1487 }
1488
1489 /**
1490 * Indicates if provided point is located at top side of rectangle defined
1491 * by provided center and size values up to a certain threshold.
1492 * A positive threshold moves top border downwards, a negative threshold
1493 * moves top border upwards.
1494 *
1495 * @param point point to be checked.
1496 * @param center center of rectangle.
1497 * @param width width of rectangle.
1498 * @param height height of rectangle.
1499 * @param threshold threshold to use as a margin to determine whether point
1500 * lies at top side or not.
1501 * @return true if point is at top side, false otherwise.
1502 */
1503 public static boolean isAtTopSide(
1504 final Point2D point, final Point2D center, final double width, final double height,
1505 final double threshold) {
1506 return isAtTopSide(point.getInhomX(), point.getInhomY(), center, width, height, threshold);
1507 }
1508
1509 /**
1510 * Indicates if provided point is located at top side of rectangle defined
1511 * by provided center and size values.
1512 *
1513 * @param point point to be checked.
1514 * @param center center of rectangle.
1515 * @param width width of rectangle.
1516 * @param height height of rectangle.
1517 * @return true if point is at top side, false otherwise.
1518 */
1519 public static boolean isAtTopSide(
1520 final Point2D point, final Point2D center, final double width, final double height) {
1521 return isAtTopSide(point, center, width, height, 0.0);
1522 }
1523
1524 /**
1525 * Indicates if provided point coordinates are located at top side of this
1526 * rectangle up to a certain threshold.
1527 * A positive threshold moves top border downwards, a negative threshold
1528 * moves top border upwards.
1529 *
1530 * @param x x coordinate of point to be checked.
1531 * @param y y coordinate of point to be checked.
1532 * @param threshold threshold to use as a margin to determine whether point
1533 * lies at top side or not.
1534 * @return true if point is at top side, false otherwise.
1535 */
1536 public boolean isAtTopSide(final double x, final double y, final double threshold) {
1537 return isAtTopSide(x, y, topLeft, bottomRight, threshold);
1538 }
1539
1540 /**
1541 * Indicates if provided point coordinates are located at top side of this
1542 * rectangle.
1543 *
1544 * @param x x coordinate of point to be checked.
1545 * @param y y coordinate of point to be checked.
1546 * @return true if point is at top side, false otherwise.
1547 */
1548 public boolean isAtTopSide(final double x, final double y) {
1549 return isAtTopSide(x, y, 0.0);
1550 }
1551
1552 /**
1553 * Indicates if provided point is located at top side of this rectangle up
1554 * to a certain threshold.
1555 * A positive threshold moves top border downwards, a negative threshold
1556 * moves top border upwards.
1557 *
1558 * @param point point to be checked.
1559 * @param threshold threshold to use as a margin to determine whether point
1560 * lies at top side or not.
1561 * @return true if point is at top side, false otherwise.
1562 */
1563 public boolean isAtTopSide(final Point2D point, final double threshold) {
1564 return isAtTopSide(point.getInhomX(), point.getInhomY(), threshold);
1565 }
1566
1567 /**
1568 * Indicates if provided point is located at top side of this rectangle.
1569 *
1570 * @param point point to be checked.
1571 * @return true if point is at top side, false otherwise.
1572 */
1573 public boolean isAtTopSide(final Point2D point) {
1574 return isAtTopSide(point, 0.0);
1575 }
1576
1577 /**
1578 * Indicates if provided point coordinates are located at top-right corner
1579 * of rectangle defined by provided top-left and bottom-right corners up to
1580 * a certain threshold.
1581 * A positive threshold moves top-right corner towards rectangle interior,
1582 * a negative threshold moves top-right corner towards rectangle exterior.
1583 *
1584 * @param x x coordinate of point to be checked.
1585 * @param y y coordinate of point to be checked.
1586 * @param left left coordinate of rectangle.
1587 * @param top top coordinate of rectangle.
1588 * @param right right coordinate of rectangle.
1589 * @param bottom bottom coordinate of rectangle.
1590 * @param threshold threshold to use as a margin to determine whether point
1591 * lies at top-right corner or not.
1592 * @return true if point is at top-right corner, false otherwise.
1593 */
1594 public static boolean isAtTopRightCorner(
1595 final double x, final double y, final double left, final double top, final double right,
1596 final double bottom, final double threshold) {
1597 // fix values in case that corners are reversed
1598 final var top2 = Math.max(top, bottom);
1599 final var right2 = Math.max(left, right);
1600
1601 return x > (right2 - threshold) && y > (top2 - threshold);
1602 }
1603
1604 /**
1605 * Indicates if point at provided coordinates is located at top-right corner
1606 * of rectangle defined by provided top-left and bottom-right corners.
1607 *
1608 * @param x x coordinate of point to be checked.
1609 * @param y y coordinate of point to be checked.
1610 * @param left left coordinate of rectangle.
1611 * @param top top coordinate of rectangle.
1612 * @param right right coordinate of rectangle.
1613 * @param bottom bottom coordinate of rectangle.
1614 * @return true if point is at top-right corner, false otherwise.
1615 */
1616 public static boolean isAtTopRightCorner(
1617 final double x, final double y, final double left, final double top, final double right,
1618 final double bottom) {
1619 return isAtTopRightCorner(x, y, left, top, right, bottom, 0.0);
1620 }
1621
1622 /**
1623 * Indicates if provided point is located at top-right corner of rectangle
1624 * defined by provided top-left and bottom-right corners up to a certain
1625 * threshold.
1626 * A positive threshold moves top-right corner towards rectangle interior,
1627 * a negative threshold moves top-right corner towards rectangle exterior.
1628 *
1629 * @param point point to be checked.
1630 * @param left left coordinate of rectangle.
1631 * @param top top coordinate of rectangle.
1632 * @param right right coordinate of rectangle.
1633 * @param bottom bottom coordinate of rectangle.
1634 * @param threshold threshold to use as a margin to determine whether point
1635 * lies at top-right corner or not.
1636 * @return true if point is at top-right corner, false otherwise.
1637 */
1638 public static boolean isAtTopRightCorner(
1639 final Point2D point, final double left, final double top, final double right, final double bottom,
1640 final double threshold) {
1641 return isAtTopRightCorner(point.getInhomX(), point.getInhomY(), left, top, right, bottom, threshold);
1642 }
1643
1644 /**
1645 * Indicates if provided point is located at top-right corner of rectangle
1646 * defined by provided top-left and bottom-right corners.
1647 *
1648 * @param point point to be checked.
1649 * @param left left coordinate of rectangle.
1650 * @param top top coordinate of rectangle.
1651 * @param right right coordinate of rectangle.
1652 * @param bottom bottom coordinate of rectangle.
1653 * @return true if point is at top-right corner, false otherwise.
1654 */
1655 public static boolean isAtTopRightCorner(
1656 final Point2D point, final double left, final double top, final double right, final double bottom) {
1657 return isAtTopRightCorner(point, left, top, right, bottom, 0.0);
1658 }
1659
1660 /**
1661 * Indicates if provided point coordinates are located at top-right corner
1662 * of rectangle defined by provided top-left and bottom-right corners up to
1663 * a certain threshold.
1664 * A positive threshold moves top-right corner towards rectangle interior,
1665 * a negative threshold moves top-right corner towards rectangle exterior.
1666 *
1667 * @param x x coordinate of point to be checked.
1668 * @param y y coordinate of point to be checked.
1669 * @param topLeft top-left corner of rectangle.
1670 * @param bottomRight bottom-right corner of rectangle.
1671 * @param threshold threshold to use as margin to determine whether point
1672 * lies at top-right corner or not.
1673 * @return true if point is at top-right corner, false otherwise.
1674 */
1675 public static boolean isAtTopRightCorner(
1676 final double x, final double y, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
1677 return isAtTopRightCorner(x, y, topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(),
1678 bottomRight.getInhomY(), threshold);
1679 }
1680
1681 /**
1682 * Indicates if provided point coordinates are located at top-right corner
1683 * of rectangle defined by provided top-left and bottom-right corners.
1684 *
1685 * @param x x coordinate of point to be checked.
1686 * @param y y coordinate of point to be checked.
1687 * @param topLeft top-left corner of rectangle.
1688 * @param bottomRight bottom-right corner of rectangle.
1689 * @return true if point is at top-right corner, false otherwise.
1690 */
1691 public static boolean isAtTopRightCorner(
1692 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
1693 return isAtTopRightCorner(x, y, topLeft, bottomRight, 0.0);
1694 }
1695
1696 /**
1697 * Indicates if provided point is located at top-right corner of rectangle
1698 * defined by provided top-left and bottom-right corners up to a certain
1699 * threshold.
1700 * A positive threshold moves top-right corner towards rectangle interior,
1701 * a negative threshold moves top-right corner towards rectangle exterior.
1702 *
1703 * @param point point to be checked.
1704 * @param topLeft top-left corner of rectangle.
1705 * @param bottomRight bottom-right corner of rectangle.
1706 * @param threshold threshold to use as a margin to determine whether point
1707 * lies at top-right corner side or not.
1708 * @return true if point is at top-right corner, false otherwise.
1709 */
1710 public static boolean isAtTopRightCorner(
1711 final Point2D point, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
1712 return isAtTopRightCorner(point.getInhomX(), point.getInhomY(), topLeft, bottomRight, threshold);
1713 }
1714
1715 /**
1716 * Indicates if provided point is located at top-right corner of rectangle
1717 * defined by provided top-left and bottom-right corners.
1718 *
1719 * @param point point to be checked.
1720 * @param topLeft top-left corner of rectangle.
1721 * @param bottomRight bottom-right corner of rectangle.
1722 * @return true if point is at top-left corner, false otherwise.
1723 */
1724 public static boolean isAtTopRightCorner(final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
1725 return isAtTopRightCorner(point, topLeft, bottomRight, 0.0);
1726 }
1727
1728 /**
1729 * Indicates if provided point coordinates are located at top-right corner
1730 * of rectangle defined by provided center and size values up to a certain
1731 * threshold.
1732 * A positive threshold moves top-right corner towards rectangle interior,
1733 * a negative threshold moves top-right corner towards rectangle exterior.
1734 *
1735 * @param x x coordinate of point to be checked.
1736 * @param y y coordinate of point to be checked.
1737 * @param center center of rectangle.
1738 * @param width width of rectangle.
1739 * @param height height of rectangle.
1740 * @param threshold threshold to use as a margin to determine whether point
1741 * lies at top-left corner or not.
1742 * @return true if point is at top-right corner, false otherwise.
1743 */
1744 public static boolean isAtTopRightCorner(
1745 final double x, final double y, final Point2D center, final double width, final double height,
1746 final double threshold) {
1747 final var halfWidth = width / 2.0;
1748 final var halfHeight = height / 2.0;
1749 final var centerX = center.getInhomX();
1750 final var centerY = center.getInhomY();
1751 return isAtTopRightCorner(x, y, centerX - halfWidth, centerY - halfHeight, centerX + halfWidth,
1752 centerY + halfHeight, threshold);
1753 }
1754
1755 /**
1756 * Indicates if provided point coordinates are located at top-right corner
1757 * of rectangle defined by provided center and size values.
1758 *
1759 * @param x x coordinate of point to be checked.
1760 * @param y y coordinate of point to be checked.
1761 * @param center center of rectangle.
1762 * @param width width of rectangle.
1763 * @param height height of rectangle.
1764 * @return true if point is at top-right corner, false otherwise.
1765 */
1766 public static boolean isAtTopRightCorner(
1767 final double x, final double y, final Point2D center, final double width, final double height) {
1768 return isAtTopRightCorner(x, y, center, width, height, 0.0);
1769 }
1770
1771 /**
1772 * Indicates if provided point is located at top-right corner of rectangle
1773 * defined by provided center and size values up to a certain threshold.
1774 * A positive threshold moves top-right corner towards rectangle interior,
1775 * a negative threshold moves top-right corner towards rectangle exterior.
1776 *
1777 * @param point point to be checked.
1778 * @param center center of rectangle.
1779 * @param width width of rectangle.
1780 * @param height height of rectangle.
1781 * @param threshold threshold to use as a margin to determine whether point
1782 * lies at top-right corner or not.
1783 * @return true if point is at top-right corner, false otherwise.
1784 */
1785 public static boolean isAtTopRightCorner(
1786 final Point2D point, final Point2D center, final double width, final double height,
1787 final double threshold) {
1788 return isAtTopRightCorner(point.getInhomX(), point.getInhomY(), center, width, height, threshold);
1789 }
1790
1791 /**
1792 * Indicates if provided point is located at top-right corner of rectangle
1793 * defined by provided center and size values.
1794 *
1795 * @param point point to be checked.
1796 * @param center center of rectangle.
1797 * @param width width of rectangle.
1798 * @param height height of rectangle.
1799 * @return true if point is at top-right corner, false otherwise.
1800 */
1801 public static boolean isAtTopRightCorner(
1802 final Point2D point, final Point2D center, final double width, final double height) {
1803 return isAtTopRightCorner(point, center, width, height, 0.0);
1804 }
1805
1806 /**
1807 * Indicates if provided point coordinates are located at top-right corner
1808 * of this rectangle up to a certain threshold.
1809 * A positive threshold moves top-right corner towards rectangle interior,
1810 * a negative threshold moves top-right corner towards rectangle exterior.
1811 *
1812 * @param x x coordinate of point to be checked.
1813 * @param y y coordinate of point to be checked.
1814 * @param threshold threshold to use as a margin to determine whether point
1815 * lies at top-right corner or not.
1816 * @return true if point is at top-right corner, false otherwise.
1817 */
1818 public boolean isAtTopRightCorner(final double x, final double y, final double threshold) {
1819 return isAtTopRightCorner(x, y, topLeft, bottomRight, threshold);
1820 }
1821
1822 /**
1823 * Indicates if provided point coordinates are located at top-right corner
1824 * of this rectangle.
1825 *
1826 * @param x x coordinate of point to be checked.
1827 * @param y y coordinate of point to be checked.
1828 * @return true if point is at top-right corner, false otherwise.
1829 */
1830 public boolean isAtTopRightCorner(final double x, final double y) {
1831 return isAtTopRightCorner(x, y, 0.0);
1832 }
1833
1834 /**
1835 * Indicates if provided point is located at top-right corner of this
1836 * rectangle up to a certain threshold.
1837 * A positive threshold moves top-right corner towards rectangle interior,
1838 * a negative threshold moves top-right corner towards rectangle exterior.
1839 *
1840 * @param point point to be checked.
1841 * @param threshold threshold to use as a margin to determine whether point
1842 * lies at top-right corner or not.
1843 * @return true if point is at top-right corner, false otherwise.
1844 */
1845 public boolean isAtTopRightCorner(final Point2D point, final double threshold) {
1846 return isAtTopRightCorner(point.getInhomX(), point.getInhomY(), threshold);
1847 }
1848
1849 /**
1850 * Indicates if provided point is located at top-right corner of this
1851 * rectangle.
1852 *
1853 * @param point point to be checked.
1854 * @return true if point is at top-right corner, false otherwise.
1855 */
1856 public boolean isAtTopRightCorner(final Point2D point) {
1857 return isAtTopRightCorner(point, 0.0);
1858 }
1859
1860 /**
1861 * Indicates if provided point coordinates are located at right side of
1862 * rectangle defined by provided top-left and bottom-right corners up to a
1863 * certain threshold.
1864 * A positive threshold moves right border to the left, a negative threshold
1865 * moves right border to the right.
1866 *
1867 * @param x x coordinate of point to be checked.
1868 * @param y y coordinate of point to be checked.
1869 * @param left left coordinate of rectangle.
1870 * @param top top coordinate of rectangle.
1871 * @param right right coordinate of rectangle.
1872 * @param bottom bottom coordinate of rectangle.
1873 * @param threshold threshold to use as a margin to determine whether point
1874 * lies at right side or not.
1875 * @return true if point is at right side, false otherwise.
1876 */
1877 public static boolean isAtRightSide(
1878 final double x, final double y, final double left, final double top, final double right,
1879 final double bottom, final double threshold) {
1880 // fix values in case that corners are reversed
1881 final var right2 = Math.max(left, right);
1882 final var top2 = Math.max(top, bottom);
1883 final var bottom2 = Math.min(top, bottom);
1884
1885 return x > (right2 - threshold) && y >= (bottom2 + threshold) && y <= (top2 - threshold);
1886 }
1887
1888 /**
1889 * Indicates if point at provided coordinates is located at right side of
1890 * rectangle defined by provided top-left and bottom-right corners.
1891 *
1892 * @param x x coordinate of point to be checked.
1893 * @param y y coordinate of point to be checked.
1894 * @param left left coordinate of rectangle.
1895 * @param top top coordinate of rectangle.
1896 * @param right right coordinate of rectangle.
1897 * @param bottom bottom coordinate of rectangle.
1898 * @return true if point is at right side, false otherwise.
1899 */
1900 public static boolean isAtRightSide(
1901 final double x, final double y, final double left, final double top, final double right,
1902 final double bottom) {
1903 return isAtRightSide(x, y, left, top, right, bottom, 0.0);
1904 }
1905
1906 /**
1907 * Indicates if provided point is located at right side of rectangle defined
1908 * by provided top-left and bottom-right corners up to a certain threshold.
1909 * A positive threshold moves right border to the left, a negative threshold
1910 * moves right border to the right.
1911 *
1912 * @param point point to be checked.
1913 * @param left left coordinate of rectangle.
1914 * @param top top coordinate of rectangle.
1915 * @param right right coordinate of rectangle.
1916 * @param bottom bottom coordinate of rectangle.
1917 * @param threshold threshold to use as a margin to determine whether point
1918 * lies at right side or not.
1919 * @return true if point is at right side, false otherwise.
1920 */
1921 public static boolean isAtRightSide(
1922 final Point2D point, final double left, final double top, final double right, final double bottom,
1923 final double threshold) {
1924 return isAtRightSide(point.getInhomX(), point.getInhomY(), left, top, right, bottom, threshold);
1925 }
1926
1927 /**
1928 * Indicates if provided point is located at right side of rectangle defined
1929 * by provided top-left and bottom-right corners.
1930 *
1931 * @param point point to be checked.
1932 * @param left left coordinate of rectangle.
1933 * @param top top coordinate of rectangle.
1934 * @param right right coordinate of rectangle.
1935 * @param bottom bottom coordinate of rectangle.
1936 * @return true if point is at right side, false otherwise.
1937 */
1938 public static boolean isAtRightSide(
1939 final Point2D point, final double left, final double top, final double right, final double bottom) {
1940 return isAtRightSide(point, left, top, right, bottom, 0.0);
1941 }
1942
1943 /**
1944 * Indicates if provided point coordinates are located at right side of
1945 * rectangle defined by provided top-left and bottom-right corners up to a
1946 * certain threshold.
1947 * A positive threshold moves right border to the left, a negative threshold
1948 * moves right border to the right.
1949 *
1950 * @param x x coordinate of point to be checked.
1951 * @param y y coordinate of point to be checked.
1952 * @param topLeft top-left corner of rectangle.
1953 * @param bottomRight bottom-right corner of rectangle.
1954 * @param threshold threshold to use as a margin to determine whether point
1955 * lies at right side or not.
1956 * @return true if point is at right side, false otherwise.
1957 */
1958 public static boolean isAtRightSide(
1959 final double x, final double y, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
1960 return isAtRightSide(x, y, topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(),
1961 bottomRight.getInhomY(), threshold);
1962 }
1963
1964 /**
1965 * Indicates if provided point coordinates are located at right side of
1966 * rectangle defined by provided top-left and bottom-right corners.
1967 *
1968 * @param x x coordinate of point to be checked.
1969 * @param y y coordinate of point to be checked.
1970 * @param topLeft top-left corner of rectangle.
1971 * @param bottomRight bottom-right corner of rectangle.
1972 * @return true if point is at right side, false otherwise.
1973 */
1974 public static boolean isAtRightSide(
1975 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
1976 return isAtRightSide(x, y, topLeft, bottomRight, 0.0);
1977 }
1978
1979 /**
1980 * Indicates if provided point is located at right side of rectangle defined
1981 * by provided top-left and bottom-right corners.
1982 * A positive threshold moves right border to the left, a negative threshold
1983 * moves right border to the right.
1984 *
1985 * @param point point to be checked.
1986 * @param topLeft top-left corner of rectangle.
1987 * @param bottomRight bottom-right corner of rectangle.
1988 * @param threshold threshold to use as a margin to determine whether point
1989 * lies at right side or not.
1990 * @return true if point lies at right side, false otherwise.
1991 */
1992 public static boolean isAtRightSide(
1993 final Point2D point, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
1994 return isAtRightSide(point.getInhomX(), point.getInhomY(), topLeft, bottomRight, threshold);
1995 }
1996
1997 /**
1998 * Indicates if provided point is located at right side of rectangle defined
1999 * by provided top-left and bottom-right corners.
2000 *
2001 * @param point point to be checked.
2002 * @param topLeft top-left corner of rectangle.
2003 * @param bottomRight bottom-right corner of rectangle.
2004 * @return true if point lies at right side, false otherwise.
2005 */
2006 public static boolean isAtRightSide(
2007 final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
2008 return isAtRightSide(point, topLeft, bottomRight, 0.0);
2009 }
2010
2011 /**
2012 * Indicates if provided point coordinates are located at right side of
2013 * rectangle defined by provided center and size values.
2014 * A positive threshold moves right border to the left, a negative threshold
2015 * moves right border to the right.
2016 *
2017 * @param x x coordinate of point to be checked.
2018 * @param y y coordinate of point to be checked.
2019 * @param center center of rectangle.
2020 * @param width width of rectangle.
2021 * @param height height of rectangle.
2022 * @param threshold threshold to use as a margin to determine whether point
2023 * lies at right side or not.
2024 * @return true if point is at right side, false otherwise.
2025 */
2026 public static boolean isAtRightSide(
2027 final double x, final double y, final Point2D center, final double width, final double height,
2028 final double threshold) {
2029 final var halfWidth = width / 2.0;
2030 final var halfHeight = height / 2.0;
2031 final var centerX = center.getInhomX();
2032 final var centerY = center.getInhomY();
2033 return isAtRightSide(x, y, centerX - halfWidth, centerY - halfHeight, centerX + halfWidth,
2034 centerY + halfHeight, threshold);
2035 }
2036
2037 /**
2038 * Indicates if provided point coordinates are located at right side of
2039 * rectangle defined by provided center and size values.
2040 *
2041 * @param x x coordinate of point to be checked.
2042 * @param y y coordinate of point to be checked.
2043 * @param center center of rectangle.
2044 * @param width width of rectangle.
2045 * @param height height of rectangle.
2046 * @return true if point is at right side, false otherwise.
2047 */
2048 public static boolean isAtRightSide(
2049 final double x, final double y, final Point2D center, final double width, final double height) {
2050 return isAtRightSide(x, y, center, width, height, 0.0);
2051 }
2052
2053 /**
2054 * Indicates if provided point is located at right side of rectangle defined
2055 * by provided center and size values up to a certain threshold.
2056 * A positive threshold moves right border to the left, a negative threshold
2057 * moves right border to the right.
2058 *
2059 * @param point point to be checked.
2060 * @param center center of rectangle.
2061 * @param width width of rectangle.
2062 * @param height height of rectangle.
2063 * @param threshold threshold to use as a margin to determine whether point
2064 * lies at left side or not.
2065 * @return true if point is at left side, false otherwise.
2066 */
2067 public static boolean isAtRightSide(
2068 final Point2D point, final Point2D center, final double width, final double height,
2069 final double threshold) {
2070 return isAtRightSide(point.getInhomX(), point.getInhomY(), center, width, height, threshold);
2071 }
2072
2073 /**
2074 * Indicates if provided point is located at right side of rectangle defined
2075 * by provided center and size values.
2076 *
2077 * @param point point to be checked.
2078 * @param center center of rectangle.
2079 * @param width width of rectangle.
2080 * @param height height of rectangle.
2081 * @return true if point is at right side, false otherwise.
2082 */
2083 public static boolean isAtRightSide(
2084 final Point2D point, final Point2D center, final double width, final double height) {
2085 return isAtRightSide(point, center, width, height, 0.0);
2086 }
2087
2088 /**
2089 * Indicates if provided point coordinates are located at right side of this
2090 * rectangle up to a certain threshold.
2091 * A positive threshold moves right border to the left, a negative threshold
2092 * moves right border to the right.
2093 *
2094 * @param x x coordinate of point to be checked.
2095 * @param y y coordinate of point to be checked.
2096 * @param threshold threshold to use as a margin to determine whether point
2097 * lies at right side or not.
2098 * @return true if point is at right side, false otherwise.
2099 */
2100 public boolean isAtRightSide(final double x, final double y, final double threshold) {
2101 return isAtRightSide(x, y, topLeft, bottomRight, threshold);
2102 }
2103
2104 /**
2105 * Indicates if provided point coordinates are located at right side of this
2106 * rectangle.
2107 *
2108 * @param x x coordinate of point to be checked.
2109 * @param y y coordinate of point to be checked.
2110 * @return true if point is at right side, false otherwise.
2111 */
2112 public boolean isAtRightSide(final double x, final double y) {
2113 return isAtRightSide(x, y, 0.0);
2114 }
2115
2116 /**
2117 * Indicates if provided point is located at right side of this rectangle up
2118 * to a certain threshold.
2119 * A positive threshold moves right border to the left, a negative threshold
2120 * moves right border to the right.
2121 *
2122 * @param point point to be checked.
2123 * @param threshold threshold to use as a margin to determine whether point
2124 * lies at right side or not.
2125 * @return true if point is at right side, false otherwise.
2126 */
2127 public boolean isAtRightSide(final Point2D point, final double threshold) {
2128 return isAtRightSide(point.getInhomX(), point.getInhomY(), threshold);
2129 }
2130
2131 /**
2132 * Indicates if provided point is located at right side of this rectangle.
2133 *
2134 * @param point point to be checked.
2135 * @return true if point is at right side, false otherwise.
2136 */
2137 public boolean isAtRightSide(final Point2D point) {
2138 return isAtRightSide(point, 0.0);
2139 }
2140
2141 /**
2142 * Indicates if provided point coordinates are located at bottom-right
2143 * corner of rectangle defined by provided top-left and bottom-right corners
2144 * up to a certain threshold.
2145 * A positive threshold moves bottom-right corner towards the rectangle
2146 * interior, a negative threshold moves bottom-right corner towards
2147 * rectangle exterior.
2148 *
2149 * @param x x coordinate of point to be checked.
2150 * @param y y coordinate of point to be checked.
2151 * @param left left coordinate of rectangle.
2152 * @param top top coordinate of rectangle.
2153 * @param right right coordinate of rectangle.
2154 * @param bottom bottom coordinate of rectangle.
2155 * @param threshold threshold to use as a margin to determine whether point
2156 * lies at bottom-right corner, false otherwise
2157 * @return true if point is at bottom-right corner, false otherwise.
2158 */
2159 public static boolean isAtBottomRightCorner(
2160 final double x, final double y, final double left, final double top, final double right,
2161 final double bottom, final double threshold) {
2162 // fix values in case that corners are reversed
2163 final var bottom2 = Math.min(top, bottom);
2164 final var right2 = Math.max(left, right);
2165
2166 return x > (right2 - threshold) && y < (bottom2 + threshold);
2167 }
2168
2169 /**
2170 * Indicates if point at provided coordinates is located at bottom-right
2171 * corner of rectangle defined by provided top-left and bottom-right
2172 * corners.
2173 *
2174 * @param x x coordinate of point to be checked.
2175 * @param y y coordinate of point to be checked.
2176 * @param left left coordinate of rectangle.
2177 * @param top top coordinate of rectangle.
2178 * @param right right coordinate of rectangle.
2179 * @param bottom bottom coordinate of rectangle.
2180 * @return true if point is at bottom-right corner, false otherwise.
2181 */
2182 public static boolean isAtBottomRightCorner(
2183 final double x, final double y, final double left, final double top, final double right,
2184 final double bottom) {
2185 return isAtBottomRightCorner(x, y, left, top, right, bottom, 0.0);
2186 }
2187
2188 /**
2189 * Indicates if provided point is located at bottom-right corner of
2190 * rectangle defined by provided top-left and bottom-right corners up to a
2191 * certain threshold.
2192 * A positive threshold moves bottom-right corner towards the rectangle
2193 * interior, a negative threshold moves bottom-right corner towards
2194 * rectangle exterior.
2195 *
2196 * @param point point to be checked.
2197 * @param left left coordinate of rectangle.
2198 * @param top top coordinate of rectangle.
2199 * @param right right coordinate of rectangle.
2200 * @param bottom bottom coordinate of rectangle.
2201 * @param threshold threshold to use as a margin to determine whether point
2202 * lies at bottom-right or not.
2203 * @return true if point is at top-left corner, false otherwise.
2204 */
2205 public static boolean isAtBottomRightCorner(
2206 final Point2D point, final double left, final double top, final double right, final double bottom,
2207 final double threshold) {
2208 return isAtBottomRightCorner(point.getInhomX(), point.getInhomY(), left, top, right, bottom, threshold);
2209 }
2210
2211 /**
2212 * Indicates if provided point is located at bottom-right corner of
2213 * rectangle defined by provided top-left and bottom-right corners.
2214 *
2215 * @param point point to be checked.
2216 * @param left left coordinate of rectangle.
2217 * @param top top coordinate of rectangle.
2218 * @param right right coordinate of rectangle.
2219 * @param bottom bottom coordinate of rectangle.
2220 * @return true if point is at top-left corner, false otherwise.
2221 */
2222 public static boolean isAtBottomRightCorner(
2223 final Point2D point, final double left, final double top, final double right, final double bottom) {
2224 return isAtBottomRightCorner(point, left, top, right, bottom, 0.0);
2225 }
2226
2227 /**
2228 * Indicates if provided point coordinates are located at bottom-right
2229 * corner of rectangle defined by provided top-left and bottom-right corners
2230 * up to a certain threshold.
2231 * A positive threshold moves bottom-right corner towards the rectangle
2232 * interior, a negative threshold moves bottom-right corner towards
2233 * rectangle exterior.
2234 *
2235 * @param x x coordinate of point to be checked.
2236 * @param y y coordinate of point to be checked.
2237 * @param topLeft top-left corner of rectangle.
2238 * @param bottomRight bottom-right corner of rectangle.
2239 * @param threshold threshold to use as a margin to determine whether point
2240 * lies at bottom-right corner or not.
2241 * @return true if point is at top-left corner, false otherwise.
2242 */
2243 public static boolean isAtBottomRightCorner(
2244 final double x, final double y, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
2245 return isAtBottomRightCorner(x, y, topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(),
2246 bottomRight.getInhomY(), threshold);
2247 }
2248
2249 /**
2250 * Indicates if provided point coordinates are located at bottom-right
2251 * corner of rectangle defined by provided top-left and bottom-right
2252 * corners.
2253 *
2254 * @param x x coordinate of point to be checked.
2255 * @param y y coordinate of point to be checked.
2256 * @param topLeft top-left corner of rectangle.
2257 * @param bottomRight bottom-right corner of rectangle.
2258 * @return true if point is at bottom-right corner, false otherwise.
2259 */
2260 public static boolean isAtBottomRightCorner(
2261 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
2262 return isAtBottomRightCorner(x, y, topLeft, bottomRight, 0.0);
2263 }
2264
2265 /**
2266 * Indicates if provided point is located at bottom-right corner of
2267 * rectangle defined by provided top-left and bottom-right corners up to a
2268 * certain threshold.
2269 * A positive threshold moves bottom-right corner towards the rectangle
2270 * interior, a negative threshold moves bottom-right corner towards
2271 * rectangle exterior.
2272 *
2273 * @param point point to be checked.
2274 * @param topLeft top-left corner of rectangle.
2275 * @param bottomRight bottom-right corner of rectangle.
2276 * @param threshold threshold to use as a margin to determine whether point
2277 * lies at bottom-right corner or not
2278 * @return true if point is at bottom-right corner, false otherwise.
2279 */
2280 public static boolean isAtBottomRightCorner(
2281 final Point2D point, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
2282 return isAtBottomRightCorner(point.getInhomX(), point.getInhomY(), topLeft, bottomRight, threshold);
2283 }
2284
2285 /**
2286 * Indicates if provided point is located at bottom-right corner of
2287 * rectangle defined by provided top-left and bottom-right corners.
2288 *
2289 * @param point point to be checked.
2290 * @param topLeft top-left corner of rectangle.
2291 * @param bottomRight bottom-right corner of rectangle.
2292 * @return true if point is at bottom-right corner, false otherwise.
2293 */
2294 public static boolean isAtBottomRightCorner(
2295 final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
2296 return isAtBottomRightCorner(point, topLeft, bottomRight, 0.0);
2297 }
2298
2299 /**
2300 * Indicates if provided point is located bottom-right corner of rectangle
2301 * defined by provided center and size values up to a certain threshold.
2302 * A positive threshold moves bottom-right corner towards the rectangle
2303 * interior, a negative threshold moves bottom-right corner towards
2304 * rectangle exterior.
2305 *
2306 * @param x x coordinate of point to be checked.
2307 * @param y y coordinate of point to be checked.
2308 * @param center center of rectangle.
2309 * @param width width of rectangle.
2310 * @param height height of rectangle.
2311 * @param threshold threshold to use as a margin to determine whether point
2312 * lies at bottom-right corner or not.
2313 * @return true if point is at bottom-right corner, false otherwise.
2314 */
2315 public static boolean isAtBottomRightCorner(
2316 final double x, final double y, final Point2D center, final double width, final double height,
2317 final double threshold) {
2318 final var halfWidth = width / 2.0;
2319 final var halfHeight = height / 2.0;
2320 final var centerX = center.getInhomX();
2321 final var centerY = center.getInhomY();
2322 return isAtBottomRightCorner(x, y, centerX - halfWidth,
2323 centerY - halfHeight, centerX + halfWidth, centerY + halfHeight, threshold);
2324 }
2325
2326 /**
2327 * Indicates if provided point coordinates are located at bottom-right
2328 * corner of rectangle defined by provided center and size values.
2329 *
2330 * @param x x coordinate of point to be checked.
2331 * @param y y coordinate of point to be checked.
2332 * @param center center of rectangle.
2333 * @param width width of rectangle.
2334 * @param height height of rectangle.
2335 * @return true if point is at bottom-right corner, false otherwise.
2336 */
2337 public static boolean isAtBottomRightCorner(
2338 final double x, final double y, final Point2D center, final double width, final double height) {
2339 return isAtBottomRightCorner(x, y, center, width, height, 0.0);
2340 }
2341
2342 /**
2343 * Indicates if provided point is located at bottom-right corner of
2344 * rectangle defined by provided center and size values up to a certain
2345 * threshold.
2346 * A positive threshold moves bottom-right corner towards the rectangle
2347 * interior, a negative threshold moves bottom-right corner towards
2348 * rectangle exterior.
2349 *
2350 * @param point point to be checked.
2351 * @param center center of rectangle.
2352 * @param width width of rectangle.
2353 * @param height height of rectangle.
2354 * @param threshold threshold to use as a margin to determine whether point
2355 * lies at bottom-right corner or not.
2356 * @return true if point is at bottom-right corner, false otherwise.
2357 */
2358 public static boolean isAtBottomRightCorner(
2359 final Point2D point, final Point2D center, final double width, final double height,
2360 final double threshold) {
2361 return isAtBottomRightCorner(point.getInhomX(), point.getInhomY(), center, width, height, threshold);
2362 }
2363
2364 /**
2365 * indicates if provided point is located at bottom-right corner of
2366 * rectangle defined by provided center and size values.
2367 *
2368 * @param point point to be checked.
2369 * @param center center of rectangle.
2370 * @param width width of rectangle.
2371 * @param height height of rectangle.
2372 * @return true if point is at bottom-right corner, false otherwise.
2373 */
2374 public static boolean isAtBottomRightCorner(
2375 final Point2D point, final Point2D center, final double width, final double height) {
2376 return isAtBottomRightCorner(point, center, width, height, 0.0);
2377 }
2378
2379 /**
2380 * Indicates if provided point coordinates are located at bottom-right
2381 * corner of this rectangle up to a certain threshold.
2382 * A positive threshold moves bottom-right corner towards the rectangle
2383 * interior, a negative threshold moves bottom-right corner towards
2384 * rectangle exterior.
2385 *
2386 * @param x x coordinate of point to be checked.
2387 * @param y y coordinate of point to be checked.
2388 * @param threshold threshold to use as a margin to determine whether point
2389 * lies at bottom-right corner or not.
2390 * @return true if point is at bottom-right corner, false otherwise.
2391 */
2392 public boolean isAtBottomRightCorner(final double x, final double y, final double threshold) {
2393 return isAtBottomRightCorner(x, y, topLeft, bottomRight, threshold);
2394 }
2395
2396 /**
2397 * Indicates if provided point is located at bottom-right corner of this
2398 * rectangle.
2399 *
2400 * @param x x coordinate of point to be checked.
2401 * @param y y coordinate of point to be checked.
2402 * @return true if point is at bottom-right corner, false otherwise.
2403 */
2404 public boolean isAtBottomRightCorner(final double x, final double y) {
2405 return isAtBottomRightCorner(x, y, 0.0);
2406 }
2407
2408 /**
2409 * Indicates if provided point is located at bottom-right corner of this
2410 * rectangle.
2411 * A positive threshold moves bottom-right corner towards the rectangle
2412 * interior, a negative threshold moves bottom-right corner towards
2413 * rectangle exterior.
2414 *
2415 * @param point point to be checked.
2416 * @param threshold threshold to use as a margin to determine whether point
2417 * lies at bottom-right corner or not.
2418 * @return true if point is at bottom-right corner, false otherwise.
2419 */
2420 public boolean isAtBottomRightCorner(final Point2D point, final double threshold) {
2421 return isAtBottomRightCorner(point.getInhomX(), point.getInhomY(), threshold);
2422 }
2423
2424 /**
2425 * Indicates if provided point is located at bottom-right corner of this
2426 * rectangle.
2427 *
2428 * @param point point to be checked.
2429 * @return true if point is at bottom-right corner, false otherwise.
2430 */
2431 public boolean isAtBottomRightCorner(final Point2D point) {
2432 return isAtBottomRightCorner(point, 0.0);
2433 }
2434
2435 /**
2436 * Indicates if provided point coordinates are located at bottom side of
2437 * rectangle defined by provided top-left and bottom-right corners up to a
2438 * certain threshold.
2439 * A positive threshold moves bottom border upwards, a negative threshold
2440 * moves bottom border downwards
2441 *
2442 * @param x x coordinate of point to be checked.
2443 * @param y y coordinate of point to be checked.
2444 * @param left left coordinate of rectangle.
2445 * @param top top coordinate of rectangle.
2446 * @param right right coordinate of rectangle.
2447 * @param bottom bottom coordinate of rectangle.
2448 * @param threshold threshold to use as a margin to determine whether point
2449 * lies at bottom side or not.
2450 * @return true if point is at bottom side, false otherwise.
2451 */
2452 public static boolean isAtBottomSide(
2453 final double x, final double y, final double left, final double top, final double right,
2454 final double bottom, final double threshold) {
2455 final var bottom2 = Math.min(top, bottom);
2456 final var left2 = Math.min(left, right);
2457 final var right2 = Math.max(left, right);
2458
2459 return y < (bottom2 + threshold) && x >= (left2 + threshold) &&
2460 x <= (right2 - threshold);
2461 }
2462
2463 /**
2464 * Indicates if point at provided coordinates is located at bottom side of
2465 * rectangle defined by provided top-left and bottom-right corners.
2466 *
2467 * @param x x coordinate of point to be checked.
2468 * @param y y coordinate of point to be checked.
2469 * @param left left coordinate of rectangle.
2470 * @param top top coordinate of rectangle.
2471 * @param right right coordinate of rectangle.
2472 * @param bottom bottom coordinate of rectangle.
2473 * @return true if point is at bottom side, false otherwise.
2474 */
2475 public static boolean isAtBottomSide(
2476 final double x, final double y, final double left, final double top, final double right,
2477 final double bottom) {
2478 return isAtBottomSide(x, y, left, top, right, bottom, 0.0);
2479 }
2480
2481 /**
2482 * Indicates if provided point is located at bottom side of rectangle
2483 * defined by provided top-left and bottom-right corners up to a certain
2484 * threshold.
2485 * A positive threshold moves bottom border upwards, a negative threshold
2486 * moves bottom border downwards
2487 *
2488 * @param point point to be checked.
2489 * @param left left coordinate of rectangle.
2490 * @param top top coordinate of rectangle.
2491 * @param right right coordinate of rectangle.
2492 * @param bottom bottom coordinate of rectangle.
2493 * @param threshold threshold to use as a margin to determine whether point
2494 * lies at bottom side or not.
2495 * @return true if point is at bottom side, false otherwise.
2496 */
2497 public static boolean isAtBottomSide(
2498 final Point2D point, final double left, final double top, final double right, final double bottom,
2499 final double threshold) {
2500 return isAtBottomSide(point.getInhomX(), point.getInhomY(), left, top, right, bottom, threshold);
2501 }
2502
2503 /**
2504 * Indicates if provided point is located at bottom side of rectangle
2505 * defined by provided top-left and bottom-right corners.
2506 *
2507 * @param point point to be checked.
2508 * @param left left coordinate of rectangle.
2509 * @param top top coordinate of rectangle.
2510 * @param right right coordinate of rectangle.
2511 * @param bottom bottom coordinate of rectangle.
2512 * @return true if point is at bottom side, false otherwise.
2513 */
2514 public static boolean isAtBottomSide(
2515 final Point2D point, final double left, final double top, final double right, final double bottom) {
2516 return isAtBottomSide(point, left, top, right, bottom, 0.0);
2517 }
2518
2519 /**
2520 * Indicates if provided point coordinates are located at bottom side of
2521 * rectangle defined by provided top-left and bottom-right corners up to a
2522 * certain threshold.
2523 * A positive threshold moves bottom border upwards, a negative threshold
2524 * moves bottom border downwards
2525 *
2526 * @param x x coordinate of point to be checked.
2527 * @param y y coordinate of point to be checked.
2528 * @param topLeft top-left corner of rectangle.
2529 * @param bottomRight bottom-right corner of rectangle.
2530 * @param threshold threshold to use as a margin to determine whether point
2531 * lies at bottom side or not.
2532 * @return true if point is at bottom side, false otherwise.
2533 */
2534 public static boolean isAtBottomSide(
2535 final double x, final double y, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
2536 return isAtBottomSide(x, y, topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(),
2537 bottomRight.getInhomY(), threshold);
2538 }
2539
2540 /**
2541 * Indicates if provided point coordinates are located at bottom side of
2542 * rectangle defined by provided top-left and bottom-right corners.
2543 *
2544 * @param x x coordinate of point to be checked.
2545 * @param y y coordinate of point to be checked.
2546 * @param topLeft top-left corner of rectangle.
2547 * @param bottomRight bottom-right corner of rectangle.
2548 * @return true if point is at bottom side, false otherwise.
2549 */
2550 public static boolean isAtBottomSide(
2551 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
2552 return isAtBottomSide(x, y, topLeft, bottomRight, 0.0);
2553 }
2554
2555 /**
2556 * Indicates if provided point is located at bottom side of rectangle
2557 * defined by provided top-left and bottom-right corners.
2558 * A positive threshold moves bottom border upwards, a negative threshold
2559 * moves bottom border downwards
2560 *
2561 * @param point point to be checked.
2562 * @param topLeft top-left corner of rectangle.
2563 * @param bottomRight bottom-right corner of rectangle.
2564 * @param threshold threshold to use as a margin to determine whether point
2565 * lies at bottom side or not.
2566 * @return true if point is at bottom side, false otherwise.
2567 */
2568 public static boolean isAtBottomSide(
2569 final Point2D point, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
2570 return isAtBottomSide(point.getInhomX(), point.getInhomY(), topLeft, bottomRight, threshold);
2571 }
2572
2573 /**
2574 * Indicates if provided point is located at bottom side of rectangle
2575 * defined by provided top-left and bottom-right corners.
2576 *
2577 * @param point point to be checked.
2578 * @param topLeft top-left corner of rectangle.
2579 * @param bottomRight bottom-right corner of rectangle.
2580 * @return true if point is at bottom side, false otherwise.
2581 */
2582 public static boolean isAtBottomSide(final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
2583 return isAtBottomSide(point, topLeft, bottomRight, 0.0);
2584 }
2585
2586 /**
2587 * Indicates if provided point coordinates are located at bottom side of
2588 * rectangle defined by provided center and size values up to a certain
2589 * threshold.
2590 * A positive threshold moves bottom border upwards, a negative threshold
2591 * moves bottom border downwards
2592 *
2593 * @param x x coordinate of point to be checked.
2594 * @param y y coordinate of point to be checked.
2595 * @param center center of rectangle.
2596 * @param width width of rectangle.
2597 * @param height height of rectangle.
2598 * @param threshold threshold to use as a margin to determine whether point
2599 * lies at bottom side or not.
2600 * @return true if point is at bottom side, false otherwise.
2601 */
2602 public static boolean isAtBottomSide(
2603 final double x, final double y, final Point2D center, final double width, final double height,
2604 final double threshold) {
2605 final var halfWidth = width / 2.0;
2606 final var halfHeight = height / 2.0;
2607 final var centerX = center.getInhomX();
2608 final var centerY = center.getInhomY();
2609 return isAtBottomSide(x, y, centerX - halfWidth, centerY - halfHeight, centerX + halfWidth,
2610 centerY + halfHeight, threshold);
2611 }
2612
2613 /**
2614 * Indicates if provided point coordinates are located at bottom side of
2615 * rectangle defined by provided center and size values.
2616 *
2617 * @param x x coordinate of point to be checked.
2618 * @param y y coordinate of point to be checked.
2619 * @param center center of rectangle.
2620 * @param width width of rectangle.
2621 * @param height height of rectangle.
2622 * @return true if point is at top side, false otherwise.
2623 */
2624 public static boolean isAtBottomSide(
2625 final double x, final double y, final Point2D center, final double width, final double height) {
2626 return isAtBottomSide(x, y, center, width, height, 0.0);
2627 }
2628
2629 /**
2630 * Indicates if provided point is located at bottom side of rectangle
2631 * defined by provided center and size values up to a certain threshold.
2632 * A positive threshold moves bottom border upwards, a negative threshold
2633 * moves bottom border downwards
2634 *
2635 * @param point point to be checked.
2636 * @param center center of rectangle.
2637 * @param width width of rectangle.
2638 * @param height height of rectangle.
2639 * @param threshold threshold to use as a margin to determine whether point
2640 * lies at bottom side or not.
2641 * @return true if point is at bottom side, false otherwise.
2642 */
2643 public static boolean isAtBottomSide(
2644 final Point2D point, final Point2D center, final double width, final double height,
2645 final double threshold) {
2646 return isAtBottomSide(point.getInhomX(), point.getInhomY(), center, width, height, threshold);
2647 }
2648
2649 /**
2650 * Indicates if provided point is located at bottom side of rectangle
2651 * defined by provided center and size values.
2652 *
2653 * @param point point to be checked.
2654 * @param center center of rectangle.
2655 * @param width width of rectangle.
2656 * @param height height of rectangle.
2657 * @return true if point is at bottom side, false otherwise.
2658 */
2659 public static boolean isAtBottomSide(
2660 final Point2D point, final Point2D center, final double width, final double height) {
2661 return isAtBottomSide(point, center, width, height, 0.0);
2662 }
2663
2664 /**
2665 * Indicates if provided point coordinates are located at bottom side of
2666 * this rectangle up to a certain threshold.
2667 * A positive threshold moves bottom border upwards, a negative threshold
2668 * moves bottom border downwards
2669 *
2670 * @param x x coordinate of point to be checked.
2671 * @param y y coordinate of point to be checked.
2672 * @param threshold threshold to use as a margin to determine whether point
2673 * lies at bottom side or not.
2674 * @return true if point is at bottom side, false otherwise.
2675 */
2676 public boolean isAtBottomSide(final double x, final double y, final double threshold) {
2677 return isAtBottomSide(x, y, topLeft, bottomRight, threshold);
2678 }
2679
2680 /**
2681 * Indicates if provided point coordinates are located at bottom side of
2682 * this rectangle.
2683 *
2684 * @param x x coordinate of point to be checked.
2685 * @param y y coordinate of point to be checked.
2686 * @return true if point is at bottom side, false otherwise.
2687 */
2688 public boolean isAtBottomSide(final double x, final double y) {
2689 return isAtBottomSide(x, y, 0.0);
2690 }
2691
2692 /**
2693 * Indicates if provided point is located at bottom side of this rectangle.
2694 * A positive threshold moves bottom border upwards, a negative threshold
2695 * moves bottom border downwards
2696 *
2697 * @param point point to be checked.
2698 * @param threshold threshold to use as a margin to determine whether point
2699 * lies at bottom side or not.
2700 * @return true if point is at bottom side, false otherwise.
2701 */
2702 public boolean isAtBottomSide(final Point2D point, final double threshold) {
2703 return isAtBottomSide(point.getInhomX(), point.getInhomY(), threshold);
2704 }
2705
2706 /**
2707 * Indicates if provided point is located at bottom side of this rectangle.
2708 *
2709 * @param point point to be checked.
2710 * @return true if point is at bottom side, false otherwise.
2711 */
2712 public boolean isAtBottomSide(final Point2D point) {
2713 return isAtBottomSide(point, 0.0);
2714 }
2715
2716 /**
2717 * Indicates if provided point coordinates are located at bottom-left corner
2718 * of rectangle defined by provided top-left and bottom-right corners up to
2719 * a certain threshold.
2720 * A positive threshold moves bottom-right corner towards rectangle
2721 * interior, a negative threshold moves top-right corner towards rectangle
2722 * exterior.
2723 *
2724 * @param x x coordinate of point to be checked.
2725 * @param y y coordinate of point to be checked.
2726 * @param left left coordinate of rectangle.
2727 * @param top top coordinate of rectangle.
2728 * @param right right coordinate of rectangle.
2729 * @param bottom bottom coordinate of rectangle.
2730 * @param threshold threshold to use as a margin to determine whether point
2731 * lies at bottom-left corner or not.
2732 * @return true if point is at bottom-left corner, false otherwise.
2733 */
2734 public static boolean isAtBottomLeftCorner(
2735 final double x, final double y, final double left, final double top, final double right,
2736 final double bottom, final double threshold) {
2737 // fix values in case that corners are reversed
2738 final var bottom2 = Math.min(top, bottom);
2739 final var left2 = Math.min(left, right);
2740
2741 return x < (left2 + threshold) && y < (bottom2 + threshold);
2742 }
2743
2744 /**
2745 * Indicates if point at provided coordinates is located at bottom-left
2746 * corner of rectangle defined by provided top-left and bottom-right
2747 * corners.
2748 *
2749 * @param x x coordinate of point to be checked.
2750 * @param y y coordinate of point to be checked.
2751 * @param left left coordinate of rectangle.
2752 * @param top top coordinate of rectangle.
2753 * @param right right coordinate of rectangle.
2754 * @param bottom bottom coordinate of rectangle.
2755 * @return true if point is at bottom-left corner, false otherwise.
2756 */
2757 public static boolean isAtBottomLeftCorner(
2758 final double x, final double y, final double left, final double top, final double right,
2759 final double bottom) {
2760 return isAtBottomLeftCorner(x, y, left, top, right, bottom, 0.0);
2761 }
2762
2763 /**
2764 * Indicates if provided point is located at bottom-left corner of rectangle
2765 * defined by provided top-left and bottom-right corners up to a certain
2766 * threshold.
2767 * A positive threshold moves bottom-right corner towards rectangle
2768 * interior, a negative threshold moves top-right corner towards rectangle
2769 * exterior.
2770 *
2771 * @param point point to be checked.
2772 * @param left left coordinate of rectangle.
2773 * @param top top coordinate of rectangle.
2774 * @param right right coordinate of rectangle.
2775 * @param bottom bottom coordinate of rectangle.
2776 * @param threshold threshold to use as a margin to determine whether point
2777 * lies at bottom-left corner or not.
2778 * @return true if point is at bottom-left corner, false otherwise.
2779 */
2780 public static boolean isAtBottomLeftCorner(
2781 final Point2D point, final double left, final double top, final double right, final double bottom,
2782 final double threshold) {
2783 return isAtBottomLeftCorner(point.getInhomX(), point.getInhomY(), left, top, right, bottom, threshold);
2784 }
2785
2786 /**
2787 * Indicates if provided point is located at bottom-left corner of rectangle
2788 * defined by provided top-left and bottom-right corner.
2789 *
2790 * @param point point to be checked.
2791 * @param left left coordinate of rectangle.
2792 * @param top top coordinate of rectangle.
2793 * @param right right coordinate of rectangle.
2794 * @param bottom bottom coordinate of rectangle.
2795 * @return true if point is at bottom-left corner, false otherwise.
2796 */
2797 public static boolean isAtBottomLeftCorner(
2798 final Point2D point, final double left, final double top, final double right, final double bottom) {
2799 return isAtBottomLeftCorner(point, left, top, right, bottom, 0.0);
2800 }
2801
2802 /**
2803 * Indicates if provided point coordinates are located at bottom-left corner
2804 * of rectangle defined by provided top-left and bottom-right corners up to
2805 * a certain threshold.
2806 * A positive threshold moves bottom-right corner towards rectangle
2807 * interior, a negative threshold moves top-right corner towards rectangle
2808 * exterior.
2809 *
2810 * @param x x coordinate of point to be checked.
2811 * @param y y coordinate of point to be checked.
2812 * @param topLeft top-left corner of rectangle.
2813 * @param bottomRight bottom-right corner of rectangle.
2814 * @param threshold threshold to use as margin to determine whether point
2815 * lies at bottom-left corner or not.
2816 * @return true if point is at bottom-left corner, false otherwise.
2817 */
2818 public static boolean isAtBottomLeftCorner(
2819 final double x, final double y, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
2820 return isAtBottomLeftCorner(x, y, topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(),
2821 bottomRight.getInhomY(), threshold);
2822 }
2823
2824 /**
2825 * Indicates if provided point coordinates are located at bottom-left corner
2826 * of rectangle defined by provided top-left and bottom-right corners.
2827 *
2828 * @param x x coordinate of point to be checked.
2829 * @param y y coordinate of point to be checked.
2830 * @param topLeft top-left corner of rectangle.
2831 * @param bottomRight bottom-right corner of rectangle.
2832 * @return true if point is at bottom-left corner, false otherwise.
2833 */
2834 public static boolean isAtBottomLeftCorner(
2835 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
2836 return isAtBottomLeftCorner(x, y, topLeft, bottomRight, 0.0);
2837 }
2838
2839 /**
2840 * Indicates if provided point is located at bottom-left corner of rectangle
2841 * defined by provided top-left and bottom-right corners up to a certain
2842 * threshold.
2843 * A positive threshold moves bottom-right corner towards rectangle
2844 * interior, a negative threshold moves top-right corner towards rectangle
2845 * exterior.
2846 *
2847 * @param point point to be checked.
2848 * @param topLeft top-left corner of rectangle.
2849 * @param bottomRight bottom-right corner of rectangle.
2850 * @param threshold threshold to use as a margin to
2851 * @return true if point is at bottom-left corner, false otherwise.
2852 */
2853 public static boolean isAtBottomLeftCorner(
2854 final Point2D point, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
2855 return isAtBottomLeftCorner(point.getInhomX(), point.getInhomY(), topLeft, bottomRight, threshold);
2856 }
2857
2858 /**
2859 * Indicates if provided point is located at bottom-left corner of rectangle
2860 * defined by provided top-left and bottom-right corners.
2861 *
2862 * @param point point to be checked.
2863 * @param topLeft top-left corner of rectangle.
2864 * @param bottomRight bottom-right corner of rectangle.
2865 * @return true if point is at bottom-left corner, false otherwise.
2866 */
2867 public static boolean isAtBottomLeftCorner(final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
2868 return isAtBottomLeftCorner(point, topLeft, bottomRight, 0.0);
2869 }
2870
2871 /**
2872 * Indicates if provided point coordinates are located at bottom-left corner
2873 * of rectangle defined by provided center and size values up to a certain
2874 * threshold.
2875 * A positive threshold moves bottom-right corner towards rectangle
2876 * interior, a negative threshold moves top-right corner towards rectangle
2877 * exterior.
2878 *
2879 * @param x x coordinate of point to be checked.
2880 * @param y y coordinate of point to be checked.
2881 * @param center center of rectangle.
2882 * @param width width of rectangle.
2883 * @param height height of rectangle.
2884 * @param threshold threshold to use as a margin to determine whether point
2885 * lies at bottom-left corner or not.
2886 * @return true if point is at bottom-left corner, false otherwise.
2887 */
2888 public static boolean isAtBottomLeftCorner(
2889 final double x, final double y, final Point2D center, final double width, final double height,
2890 final double threshold) {
2891 final var halfWidth = width / 2.0;
2892 final var halfHeight = height / 2.0;
2893 final var centerX = center.getInhomX();
2894 final var centerY = center.getInhomY();
2895 return isAtBottomLeftCorner(x, y, centerX - halfWidth, centerY - halfHeight, centerX + halfWidth,
2896 centerY + halfHeight, threshold);
2897 }
2898
2899 /**
2900 * Indicates if provided point coordinates are located at bottom-left corner
2901 * of rectangle defined by provided center and size values up to a certain
2902 * threshold.
2903 *
2904 * @param x x coordinate of point to be checked.
2905 * @param y y coordinate of point to be checked.
2906 * @param center center of rectangle.
2907 * @param width width of rectangle.
2908 * @param height height of rectangle.
2909 * @return true if point is at bottom-left corner, false otherwise.
2910 */
2911 public static boolean isAtBottomLeftCorner(
2912 final double x, final double y, final Point2D center, final double width, final double height) {
2913 return isAtBottomLeftCorner(x, y, center, width, height, 0.0);
2914 }
2915
2916 /**
2917 * Indicates if provided point is located at bottom-left corner of rectangle
2918 * defined by provided center and size values up to a certain threshold.
2919 * A positive threshold moves bottom-right corner towards rectangle
2920 * interior, a negative threshold moves top-right corner towards rectangle
2921 * exterior.
2922 *
2923 * @param point point to be checked.
2924 * @param center center of rectangle.
2925 * @param width width of rectangle.
2926 * @param height height of rectangle.
2927 * @param threshold threshold to use as a margin to determine whether point
2928 * lies at top-right corner or not.
2929 * @return true if point is at bottom-left corner, false otherwise.
2930 */
2931 public static boolean isAtBottomLeftCorner(
2932 final Point2D point, final Point2D center, final double width, final double height,
2933 final double threshold) {
2934 return isAtBottomLeftCorner(point.getInhomX(), point.getInhomY(), center, width, height, threshold);
2935 }
2936
2937 /**
2938 * Indicates if provided point is located at bottom-left corner of rectangle
2939 * defined by provided center and size values.
2940 *
2941 * @param point point to be checked.
2942 * @param center center of rectangle.
2943 * @param width width of rectangle.
2944 * @param height height of rectangle.
2945 * @return true if point is at bottom-left corner, false otherwise.
2946 */
2947 public static boolean isAtBottomLeftCorner(
2948 final Point2D point, final Point2D center, final double width, final double height) {
2949 return isAtBottomLeftCorner(point, center, width, height, 0.0);
2950 }
2951
2952 /**
2953 * Indicates if provided point coordinates are located at bottom-left corner
2954 * of this rectangle up to a certain threshold.
2955 * A positive threshold moves bottom-right corner towards rectangle
2956 * interior, a negative threshold moves top-right corner towards rectangle
2957 * exterior.
2958 *
2959 * @param x x coordinate of point to be checked.
2960 * @param y y coordinate of point to be checked.
2961 * @param threshold threshold to use as a margin to determine whether point
2962 * lies at bottom-left corner or not.
2963 * @return true if point is at bottom-left corner, false otherwise.
2964 */
2965 public boolean isAtBottomLeftCorner(final double x, final double y, final double threshold) {
2966 return isAtBottomLeftCorner(x, y, topLeft, bottomRight, threshold);
2967 }
2968
2969 /**
2970 * Indicates if provided point coordinates are located at bottom-left corner
2971 * of this rectangle.
2972 *
2973 * @param x x coordinate of point to be checked.
2974 * @param y y coordinate of point to be checked.
2975 * @return true if point is at bottom-left corner, false otherwise.
2976 */
2977 public boolean isAtBottomLeftCorner(final double x, final double y) {
2978 return isAtBottomLeftCorner(x, y, 0.0);
2979 }
2980
2981 /**
2982 * Indicates if provided point is located at bottom-left corner of this
2983 * rectangle up to a certain threshold.
2984 * A positive threshold moves bottom-right corner towards rectangle
2985 * interior, a negative threshold moves top-right corner towards rectangle
2986 * exterior.
2987 *
2988 * @param point point to be checked.
2989 * @param threshold threshold to use as a margin to determine whether point
2990 * lies at bottom-left corner or not.
2991 * @return true if point is at bottom-left corner, false otherwise.
2992 */
2993 public boolean isAtBottomLeftCorner(final Point2D point, final double threshold) {
2994 return isAtBottomLeftCorner(point.getInhomX(), point.getInhomY(), threshold);
2995 }
2996
2997 /**
2998 * Indicates if provided point is located at bottom-left corner of this
2999 * rectangle.
3000 *
3001 * @param point point to be checked.
3002 * @return true if point is at bottom-left corner, false otherwise.
3003 */
3004 public boolean isAtBottomLeftCorner(final Point2D point) {
3005 return isAtBottomLeftCorner(point, 0.0);
3006 }
3007
3008 /**
3009 * Gets signed distance to the closest point in the left border of the
3010 * rectangle.
3011 * A negative distance indicates that point is placed inside the rectangle,
3012 * a positive distance indicates that point is placed outside the rectangle.
3013 *
3014 * @param x x coordinate of point to obtain signed distance for.
3015 * @param y y coordinate of point to obtain signed distance for.
3016 * @param left left coordinate of rectangle.
3017 * @param top top coordinate of rectangle.
3018 * @param right right coordinate of rectangle.
3019 * @param bottom bottom coordinate of rectangle.
3020 * @return signed distance to the closest point in the rectangle left border.
3021 */
3022 public static double getSignedDistanceToLeftSide(
3023 final double x, final double y, final double left, final double top, final double right,
3024 final double bottom) {
3025 // fix values in case that corners are reversed
3026 final var left2 = Math.min(left, right);
3027 final var right2 = Math.max(left, right);
3028 final var bottom2 = Math.min(top, bottom);
3029 final var top2 = Math.max(top, bottom);
3030
3031 if (isAtLeftSide(x, y, left2, top2, right2, bottom2) || isInside(x, y, left2, top2, right2, bottom2)) {
3032 // at left, inside
3033 return left2 - x;
3034 } else if (isAtRightSide(x, y, left2, top2, right2, bottom2)) {
3035 // at right
3036 return x - left2;
3037 } else if (isAtTopLeftCorner(x, y, left2, top2, right2, bottom2)
3038 || isAtTopSide(x, y, left2, top2, right2, bottom2)
3039 || isAtTopRightCorner(x, y, left2, top2, right2, bottom2)) {
3040 // at top or top corners
3041 final var diffX = x - left2;
3042 final var diffY = y - top2;
3043 return Math.sqrt(diffX * diffX + diffY * diffY);
3044 } else {
3045 // at bottom or bottom corners
3046 final var diffX = x - left2;
3047 final var diffY = y - bottom2;
3048 return Math.sqrt(diffX * diffX + diffY * diffY);
3049 }
3050 }
3051
3052 /**
3053 * Gets signed distance to the closest point in the left border of the
3054 * rectangle.
3055 * A negative distance indicates that point is placed inside the rectangle,
3056 * a positive distance indicates that point is placed outside the rectangle.
3057 *
3058 * @param point point to obtain signed distance for.
3059 * @param left left coordinate of rectangle.
3060 * @param top top coordinate of rectangle.
3061 * @param right right coordinate of rectangle.
3062 * @param bottom bottom coordinate of rectangle.
3063 * @return signed distance to the closest point in the rectangle left border.
3064 */
3065 public static double getSignedDistanceToLeftSide(
3066 final Point2D point, final double left, final double top, final double right, final double bottom) {
3067 return getSignedDistanceToLeftSide(point.getInhomX(), point.getInhomY(), left, top, right, bottom);
3068 }
3069
3070 /**
3071 * Gets signed distance to the closest point in the left border of the
3072 * rectangle.
3073 * A negative distance indicates that point is placed inside the rectangle,
3074 * a positive distance indicates that point is placed outside the rectangle.
3075 *
3076 * @param x x coordinate of point to obtain signed distance for.
3077 * @param y y coordinate of point to obtain signed distance for.
3078 * @param topLeft top-left corner of rectangle.
3079 * @param bottomRight bottom-right corner of rectangle.
3080 * @return signed distance to the closest point in the rectangle left border.
3081 */
3082 public static double getSignedDistanceToLeftSide(
3083 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
3084 return getSignedDistanceToLeftSide(x, y, topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(),
3085 bottomRight.getInhomY());
3086 }
3087
3088 /**
3089 * Gets signed distance to the closest point in the left border of the
3090 * rectangle.
3091 * A negative distance indicates that point is placed inside the rectangle,
3092 * a positive distance indicates that point is placed outside the rectangle.
3093 *
3094 * @param point point to obtain signed distance for.
3095 * @param topLeft top-left corner of rectangle.
3096 * @param bottomRight bottom-right corner of rectangle.
3097 * @return signed distance to the closest point in the rectangle left border.
3098 */
3099 public static double getSignedDistanceToLeftSide(
3100 final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
3101 return getSignedDistanceToLeftSide(point.getInhomX(), point.getInhomY(), topLeft, bottomRight);
3102 }
3103
3104 /**
3105 * Gets signed distance to the closest point in the left border of the
3106 * rectangle.
3107 * A negative distance indicates that point is placed inside the rectangle,
3108 * a positive distance indicates that point is placed outside the rectangle.
3109 *
3110 * @param x x coordinate of point to obtain signed distance for.
3111 * @param y y coordinate of point to obtain signed distance for.
3112 * @param center center of rectangle.
3113 * @param width width of rectangle.
3114 * @param height height of rectangle.
3115 * @return signed distance to the closest point in the rectangle left border.
3116 */
3117 public static double getSignedDistanceToLeftSide(
3118 final double x, final double y, final Point2D center, final double width, final double height) {
3119 final var halfWidth = width / 2.0;
3120 final var halfHeight = height / 2.0;
3121 final var centerX = center.getInhomX();
3122 final var centerY = center.getInhomY();
3123 return getSignedDistanceToLeftSide(x, y, centerX - halfWidth, centerY - halfHeight,
3124 centerX + halfWidth, centerY + halfHeight);
3125 }
3126
3127 /**
3128 * Gets signed distance to the closest point in the left border of the
3129 * rectangle.
3130 * A negative distance indicates that point is placed inside the rectangle,
3131 * a positive distance indicates that point is placed outside the rectangle.
3132 *
3133 * @param point point to obtain signed distance for.
3134 * @param center center of rectangle.
3135 * @param width width of rectangle.
3136 * @param height height of rectangle.
3137 * @return signed distance to the closest point in the rectangle left border.
3138 */
3139 public static double getSignedDistanceToLeftSide(
3140 final Point2D point, final Point2D center, final double width, final double height) {
3141 return getSignedDistanceToLeftSide(point.getInhomX(), point.getInhomY(), center, width, height);
3142 }
3143
3144 /**
3145 * Gets signed distance to the closest point in the left border of this
3146 * rectangle.
3147 * A negative distance indicates that point is placed inside the rectangle,
3148 * a positive distance indicates that point is placed outside the rectangle.
3149 *
3150 * @param x x coordinate of point to obtain signed distance for.
3151 * @param y y coordinate of point to obtain signed distance for.
3152 * @return signed distance to the closest point in the rectangle left border.
3153 */
3154 public double getSignedDistanceToLeftSide(final double x, final double y) {
3155 return getSignedDistanceToLeftSide(x, y, topLeft, bottomRight);
3156 }
3157
3158 /**
3159 * Gets signed distance to the closest point in the left border of this
3160 * rectangle.
3161 * A negative distance indicates that point is placed inside the rectangle,
3162 * a positive distance indicates that point is placed outside the rectangle.
3163 *
3164 * @param point point to obtain signed distance for.
3165 * @return signed distance to the closest point in the rectangle left border.
3166 */
3167 public double getSignedDistanceToLeftSide(final Point2D point) {
3168 return getSignedDistanceToLeftSide(point.getInhomX(), point.getInhomY());
3169 }
3170
3171 /**
3172 * Gets signed distance to the closest point in the top border of the rectangle.
3173 * A negative distance indicates that point is placed inside the rectangle,
3174 * a positive distance indicates that point is placed outside the rectangle.
3175 *
3176 * @param x x coordinate of point to obtain signed distance for.
3177 * @param y y coordinate of point to obtain signed distance for.
3178 * @param left left coordinate of rectangle.
3179 * @param top top coordinate of rectangle.
3180 * @param right right coordinate of rectangle.
3181 * @param bottom bottom coordinate of rectangle.
3182 * @return signed distance to the closest point in the rectangle top border.
3183 */
3184 public static double getSignedDistanceToTopSide(
3185 final double x, final double y, final double left, final double top, final double right,
3186 final double bottom) {
3187 // fix values in case that corners are reversed
3188 final var left2 = Math.min(left, right);
3189 final var right2 = Math.max(left, right);
3190 final var bottom2 = Math.min(top, bottom);
3191 final var top2 = Math.max(top, bottom);
3192
3193 if (isAtTopSide(x, y, left2, top2, right2, bottom2) || isInside(x, y, left2, top2, right2, bottom2)) {
3194 // at top, inside or bottom
3195 return y - top2;
3196 } else if (isAtBottomSide(x, y, left2, top2, right2, bottom2)) {
3197 return top2 - y;
3198 } else if (isAtTopLeftCorner(x, y, left2, top2, right2, bottom2)
3199 || isAtLeftSide(x, y, left2, top2, right2, bottom2)
3200 || isAtBottomLeftCorner(x, y, left2, top2, right2, bottom2)) {
3201 // at left or left corners
3202 final var diffX = x - left2;
3203 final var diffY = y - top2;
3204 return Math.sqrt(diffX * diffX + diffY * diffY);
3205 } else {
3206 // at right or right corners
3207 final var diffX = x - right2;
3208 final var diffY = y - top2;
3209 return Math.sqrt(diffX * diffX + diffY * diffY);
3210 }
3211 }
3212
3213 /**
3214 * Gets signed distance to the closest point in the top border of the
3215 * rectangle.
3216 * A negative distance indicates that point is placed inside the rectangle,
3217 * a positive distance indicates that point is placed outside the rectangle.
3218 *
3219 * @param point point to obtain signed distance for.
3220 * @param left left coordinate of rectangle.
3221 * @param top top coordinate of rectangle.
3222 * @param right right coordinate of rectangle.
3223 * @param bottom bottom coordinate of rectangle.
3224 * @return signed distance to the closest point in the rectangle top border.
3225 */
3226 public static double getSignedDistanceToTopSide(
3227 final Point2D point, final double left, final double top, final double right, final double bottom) {
3228 return getSignedDistanceToTopSide(point.getInhomX(), point.getInhomY(), left, top, right, bottom);
3229 }
3230
3231 /**
3232 * Gets signed distance to the closest point in the top border of the
3233 * rectangle.
3234 * A negative distance indicates that point is placed inside the rectangle,
3235 * a positive distance indicates that point is placed outside the rectangle.
3236 *
3237 * @param x x coordinate of point to obtain signed distance for.
3238 * @param y y coordinate of point to obtain signed distance for.
3239 * @param topLeft top-left corner of rectangle.
3240 * @param bottomRight bottom-right corner of rectangle.
3241 * @return signed distance to the closest point in the rectangle top border.
3242 */
3243 public static double getSignedDistanceToTopSide(
3244 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
3245 return getSignedDistanceToTopSide(x, y, topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(),
3246 bottomRight.getInhomY());
3247 }
3248
3249 /**
3250 * Gets signed distance to the closest point in the top border of the
3251 * rectangle.
3252 * A negative distance indicates that point is placed inside the rectangle,
3253 * a positive distance indicates that point is placed outside the rectangle.
3254 *
3255 * @param point point to obtain signed distance for.
3256 * @param topLeft top-left corner of rectangle.
3257 * @param bottomRight bottom-right corner of rectangle.
3258 * @return signed distance to the closest point in the rectangle top border.
3259 */
3260 public static double getSignedDistanceToTopSide(
3261 final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
3262 return getSignedDistanceToTopSide(point.getInhomX(), point.getInhomY(), topLeft, bottomRight);
3263 }
3264
3265 /**
3266 * Gets signed distance to the closest point in the top border of the
3267 * rectangle.
3268 * A negative distance indicates that point is placed inside the rectangle,
3269 * a positive distance indicates that point is placed outside the rectangle.
3270 *
3271 * @param x x coordinate of point to obtain signed distance for.
3272 * @param y y coordinate of point to obtain signed distance for.
3273 * @param center center of rectangle.
3274 * @param width width of rectangle.
3275 * @param height height of rectangle.
3276 * @return signed distance to the closest point in the rectangle top border.
3277 */
3278 public static double getSignedDistanceToTopSide(
3279 final double x, final double y, final Point2D center, final double width, final double height) {
3280 final var halfWidth = width / 2.0;
3281 final var halfHeight = height / 2.0;
3282 final var centerX = center.getInhomX();
3283 final var centerY = center.getInhomY();
3284 return getSignedDistanceToTopSide(x, y, centerX - halfWidth,
3285 centerY - halfHeight, centerX + halfWidth, centerY + halfHeight);
3286 }
3287
3288 /**
3289 * Gets signed distance to the closest point in the top border of the
3290 * rectangle.
3291 * A negative distance indicates that point is placed inside the rectangle,
3292 * a positive distance indicates that point is placed outside the rectangle.
3293 *
3294 * @param point point to obtain signed distance for.
3295 * @param center center of rectangle.
3296 * @param width width of rectangle.
3297 * @param height height of rectangle.
3298 * @return signed distance to the closest point in the rectangle top border.
3299 */
3300 public static double getSignedDistanceToTopSide(
3301 final Point2D point, final Point2D center, final double width, final double height) {
3302 return getSignedDistanceToTopSide(point.getInhomX(), point.getInhomY(), center, width, height);
3303 }
3304
3305 /**
3306 * Gets signed distance to the closest point in the top border of this
3307 * rectangle.
3308 * A negative distance indicates that point is placed inside the rectangle,
3309 * a positive distance indicates that point is placed outside the rectangle.
3310 *
3311 * @param x x coordinate of point to obtain signed distance for.
3312 * @param y y coordinate of point to obtain signed distance for.
3313 * @return signed distance to the closest point in the rectangle top border.
3314 */
3315 public double getSignedDistanceToTopSide(final double x, final double y) {
3316 return getSignedDistanceToTopSide(x, y, topLeft, bottomRight);
3317 }
3318
3319 /**
3320 * Gets signed distance to the closest point in the top border of this
3321 * rectangle.
3322 * A negative distance indicates that point is placed inside the rectangle,
3323 * a positive distance indicates that point is placed outside the rectangle.
3324 *
3325 * @param point point to obtain signed distance for.
3326 * @return signed distance to the closest point in the rectangle top border.
3327 */
3328 public double getSignedDistanceToTopSide(final Point2D point) {
3329 return getSignedDistanceToTopSide(point.getInhomX(), point.getInhomY());
3330 }
3331
3332 /**
3333 * Gets signed distance to the closest point in the right border of the
3334 * rectangle.
3335 * A negative distance indicates that point is placed inside the rectangle,
3336 * a positive distance indicates that point is placed outside the rectangle.
3337 *
3338 * @param x x coordinate of point to obtain signed distance for.
3339 * @param y y coordinate of point to obtain signed distance for.
3340 * @param left left coordinate of rectangle.
3341 * @param top top coordinate of rectangle.
3342 * @param right right coordinate of rectangle.
3343 * @param bottom bottom coordinate of rectangle.
3344 * @return signed distance to the closest point in the rectangle right border.
3345 */
3346 public static double getSignedDistanceToRightSide(
3347 final double x, final double y, final double left, final double top, final double right,
3348 final double bottom) {
3349 // fix values inc ase that corners are reversed
3350 final var left2 = Math.min(left, right);
3351 final var right2 = Math.max(left, right);
3352 final var bottom2 = Math.min(top, bottom);
3353 final var top2 = Math.max(top, bottom);
3354
3355 if (isAtRightSide(x, y, left2, top2, right2, bottom2) || isInside(x, y, left2, top2, right2, bottom2)) {
3356 // at right, inside
3357 return x - right2;
3358 } else if (isAtLeftSide(x, y, left2, top2, right2, bottom2)) {
3359 // at left
3360 return right2 - x;
3361 } else if (isAtTopLeftCorner(x, y, left2, top2, right2, bottom2)
3362 || isAtTopSide(x, y, left2, top2, right2, bottom2)
3363 || isAtTopRightCorner(x, y, left2, top2, right2, bottom2)) {
3364 // at top or top corners
3365 final var diffX = x - right2;
3366 final var diffY = y - top2;
3367 return Math.sqrt(diffX * diffX + diffY * diffY);
3368 } else {
3369 // at bottom or bottom corners
3370 final var diffX = x - right2;
3371 final var diffY = y - bottom2;
3372 return Math.sqrt(diffX * diffX + diffY * diffY);
3373 }
3374 }
3375
3376 /**
3377 * Gets signed distance to the closest point in the right border of the
3378 * rectangle.
3379 * A negative distance indicates that point is placed inside the rectangle,
3380 * a positive distance indicates that point is placed outside the rectangle.
3381 *
3382 * @param point point to obtain signed distance for.
3383 * @param left left coordinate of rectangle.
3384 * @param top top coordinate of rectangle.
3385 * @param right right coordinate of rectangle.
3386 * @param bottom bottom coordinate of rectangle.
3387 * @return signed distance to the closest point in the rectangle right border.
3388 */
3389 public static double getSignedDistanceToRightSide(
3390 final Point2D point, final double left, final double top, final double right, final double bottom) {
3391 return getSignedDistanceToRightSide(point.getInhomX(), point.getInhomY(), left, top, right, bottom);
3392 }
3393
3394 /**
3395 * Gets signed distance to the closest point in the right border of the
3396 * rectangle.
3397 * A negative distance indicates that point is placed inside the rectangle,
3398 * a positive distance indicates that point is placed outside the rectangle.
3399 *
3400 * @param x x coordinate of point to obtain signed distance for.
3401 * @param y y coordinate of point to obtain signed distance for.
3402 * @param topLeft top-left corner of rectangle.
3403 * @param bottomRight bottom-right corner of rectangle.
3404 * @return signed distance to the closest point in the rectangle right border.
3405 */
3406 public static double getSignedDistanceToRightSide(
3407 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
3408 return getSignedDistanceToRightSide(x, y, topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(),
3409 bottomRight.getInhomY());
3410 }
3411
3412 /**
3413 * Gets signed distance to the closest point in the right border of the
3414 * rectangle.
3415 * A negative distance indicates that point is placed inside the rectangle,
3416 * a positive distance indicates that point is placed outside the rectangle.
3417 *
3418 * @param point point to obtain signed distance for.
3419 * @param topLeft top-left corner of rectangle.
3420 * @param bottomRight bottom-right corner of rectangle.
3421 * @return signed distance to the closest point in the rectangle right border.
3422 */
3423 public static double getSignedDistanceToRightSide(
3424 final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
3425 return getSignedDistanceToRightSide(point.getInhomX(), point.getInhomY(), topLeft, bottomRight);
3426 }
3427
3428 /**
3429 * Gets signed distance to the closest point in the right border of the
3430 * rectangle.
3431 * A negative distance indicates that point is placed inside the rectangle,
3432 * a positive distance indicates that point is placed outside the rectangle.
3433 *
3434 * @param x x coordinate of point to obtain signed distance for.
3435 * @param y y coordinate of point to obtain signed distance for.
3436 * @param center center of rectangle.
3437 * @param width width of rectangle.
3438 * @param height height of rectangle.
3439 * @return signed distance to the closest point in the rectangle right border.
3440 */
3441 public static double getSignedDistanceToRightSide(
3442 final double x, final double y, final Point2D center, final double width, final double height) {
3443 final var halfWidth = width / 2.0;
3444 final var halfHeight = height / 2.0;
3445 final var centerX = center.getInhomX();
3446 final var centerY = center.getInhomY();
3447 return getSignedDistanceToRightSide(x, y, centerX - halfWidth, centerY - halfHeight,
3448 centerX + halfWidth, centerY + halfHeight);
3449 }
3450
3451 /**
3452 * Gets signed distance to the closest point in the right border of the
3453 * rectangle.
3454 * A negative distance indicates that point is placed inside the rectangle,
3455 * a positive distance indicates that point is placed outside the rectangle.
3456 *
3457 * @param point point to obtain signed distance for.
3458 * @param center center of rectangle.
3459 * @param width width of rectangle.
3460 * @param height height of rectangle.
3461 * @return signed distance to the closest point in the rectangle right border.
3462 */
3463 public static double getSignedDistanceToRightSide(
3464 final Point2D point, final Point2D center, final double width, final double height) {
3465 return getSignedDistanceToRightSide(point.getInhomX(), point.getInhomY(), center, width, height);
3466 }
3467
3468 /**
3469 * Gets signed distance to the closest point in the right border of this
3470 * rectangle.
3471 * A negative distance indicates that point is placed inside the rectangle,
3472 * a positive distance indicates that point is placed outside the rectangle.
3473 *
3474 * @param x x coordinate of point to obtain signed distance for.
3475 * @param y y coordinate of point to obtain signed distance for.
3476 * @return signed distance to the closest point in the rectangle right border.
3477 */
3478 public double getSignedDistanceToRightSide(final double x, final double y) {
3479 return getSignedDistanceToRightSide(x, y, topLeft, bottomRight);
3480 }
3481
3482 /**
3483 * Gets signed distance to the closest point in the right border of this
3484 * rectangle.
3485 * A negative distance indicates that point is placed inside the rectangle,
3486 * a positive distance indicates that point is placed outside the rectangle.
3487 *
3488 * @param point point to obtain signed distance for.
3489 * @return signed distance to the closest point in the rectangle right border.
3490 */
3491 public double getSignedDistanceToRightSide(final Point2D point) {
3492 return getSignedDistanceToRightSide(point.getInhomX(), point.getInhomY());
3493 }
3494
3495 /**
3496 * Gets signed distance to the closest point in the bottom border of the
3497 * rectangle.
3498 * A negative distance indicates that point is placed inside the rectangle,
3499 * a positive distance indicates that point is placed outside the rectangle.
3500 *
3501 * @param x x coordinate of point to obtain signed distance for.
3502 * @param y y coordinate of point to obtain signed distance for.
3503 * @param left left coordinate of rectangle.
3504 * @param top top coordinate of rectangle.
3505 * @param right right coordinate of rectangle.
3506 * @param bottom bottom coordinate of rectangle.
3507 * @return signed distance to the closest point in the rectangle bottom border.
3508 */
3509 public static double getSignedDistanceToBottomSide(
3510 final double x, final double y, final double left, final double top, final double right,
3511 final double bottom) {
3512 // fix values in case that corners are reversed
3513 final var left2 = Math.min(left, right);
3514 final var right2 = Math.max(left, right);
3515 final var bottom2 = Math.min(top, bottom);
3516 final var top2 = Math.max(top, bottom);
3517
3518 if (isAtBottomSide(x, y, left2, top2, right2, bottom2) || isInside(x, y, left2, top2, right2, bottom2)) {
3519 // at bottom, inside or top
3520 return bottom2 - y;
3521 } else if (isAtTopSide(x, y, left2, top2, right2, bottom2)) {
3522 // at top
3523 return y - bottom2;
3524 } else if (isAtBottomLeftCorner(x, y, left2, top2, right2, bottom2)
3525 || isAtLeftSide(x, y, left2, top2, right2, bottom2)
3526 || isAtTopLeftCorner(x, y, left2, top2, right2, bottom2)) {
3527 // at left or left corners
3528 final var diffX = x - left2;
3529 final var diffY = y - bottom2;
3530 return Math.sqrt(diffX * diffX + diffY * diffY);
3531 } else {
3532 // at right or right corners
3533 final var diffX = x - right2;
3534 final var diffY = y - bottom2;
3535 return Math.sqrt(diffX * diffX + diffY * diffY);
3536 }
3537 }
3538
3539 /**
3540 * Gets signed distance to the closest point in the bottom border of the
3541 * rectangle.
3542 * A negative distance indicates that point is placed inside the rectangle,
3543 * a positive distance indicates that point is placed outside the rectangle.
3544 *
3545 * @param point point to obtain signed distance for.
3546 * @param left left coordinate of rectangle.
3547 * @param top top coordinate of rectangle.
3548 * @param right right coordinate of rectangle.
3549 * @param bottom bottom coordinate of rectangle.
3550 * @return signed distance to the closest point in the rectangle bottom border.
3551 */
3552 public static double getSignedDistanceToBottomSide(
3553 final Point2D point, final double left, final double top, final double right, final double bottom) {
3554 return getSignedDistanceToBottomSide(point.getInhomX(), point.getInhomY(), left, top, right, bottom);
3555 }
3556
3557 /**
3558 * Gets signed distance to the closest point in the bottom border of the
3559 * rectangle.
3560 * A negative distance indicates that point is placed inside the rectangle,
3561 * a positive distance indicates that point is placed outside the rectangle.
3562 *
3563 * @param x x coordinate of point to obtain signed distance for.
3564 * @param y y coordinate of point to obtain signed distance for.
3565 * @param topLeft top-left corner of rectangle.
3566 * @param bottomRight bottom-right corner of rectangle.
3567 * @return signed distance to the closest point in the rectangle bottom border.
3568 */
3569 public static double getSignedDistanceToBottomSide(
3570 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
3571 return getSignedDistanceToBottomSide(x, y, topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(),
3572 bottomRight.getInhomY());
3573 }
3574
3575 /**
3576 * Gets signed distance to the closest point in the bottom border of the
3577 * rectangle.
3578 * A negative distance indicates that point is placed inside the rectangle,
3579 * a positive distance indicates that point is placed outside the rectangle.
3580 *
3581 * @param point point to obtain signed distance for.
3582 * @param topLeft top-left corner of rectangle.
3583 * @param bottomRight bottom-right corner of rectangle.
3584 * @return signed distance to the closest point in the rectangle bottom border.
3585 */
3586 public static double getSignedDistanceToBottomSide(
3587 final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
3588 return getSignedDistanceToBottomSide(point.getInhomX(), point.getInhomY(), topLeft, bottomRight);
3589 }
3590
3591 /**
3592 * Gets signed distance to the closest point in the bottom border of the
3593 * rectangle.
3594 * A negative distance indicates that point is placed inside the rectangle,
3595 * a positive distance indicates that point is placed outside the rectangle.
3596 *
3597 * @param x x coordinate of point to obtain signed distance for.
3598 * @param y y coordinate of point to obtain signed distance for.
3599 * @param center center of rectangle.
3600 * @param width width of rectangle.
3601 * @param height height of rectangle.
3602 * @return signed distance to the closest point in the rectangle bottom border.
3603 */
3604 public static double getSignedDistanceToBottomSide(
3605 final double x, final double y, final Point2D center, final double width, final double height) {
3606 final var halfWidth = width / 2.0;
3607 final var halfHeight = height / 2.0;
3608 final var centerX = center.getInhomX();
3609 final var centerY = center.getInhomY();
3610 return getSignedDistanceToBottomSide(x, y, centerX - halfWidth, centerY - halfHeight,
3611 centerX + halfWidth, centerY + halfHeight);
3612 }
3613
3614 /**
3615 * Gets signed distance to the closest point in the bottom border of the
3616 * rectangle.
3617 * A negative distance indicates that point is placed inside the rectangle,
3618 * a positive distance indicates that point is placed outside the rectangle.
3619 *
3620 * @param point point to obtain signed distance for.
3621 * @param center center of rectangle.
3622 * @param width width of rectangle.
3623 * @param height height of rectangle.
3624 * @return signed distance to the closest point in the rectangle bottom border.
3625 */
3626 public static double getSignedDistanceToBottomSide(
3627 final Point2D point, final Point2D center, final double width, final double height) {
3628 return getSignedDistanceToBottomSide(point.getInhomX(), point.getInhomY(), center, width, height);
3629 }
3630
3631 /**
3632 * Gets signed distance to the closest point in the bottom border of this
3633 * rectangle.
3634 * A negative distance indicates that point is placed inside the rectangle,
3635 * a positive distance indicates that point is placed outside the rectangle.
3636 *
3637 * @param x x coordinate of point to obtain signed distance for.
3638 * @param y y coordinate of point to obtain signed distance for.
3639 * @return signed distance to the closest point in the rectangle bottom border.
3640 */
3641 public double getSignedDistanceToBottomSide(final double x, final double y) {
3642 return getSignedDistanceToBottomSide(x, y, topLeft, bottomRight);
3643 }
3644
3645 /**
3646 * Gets signed distance to the closest point in the bottom border of this
3647 * rectangle.
3648 * A negative distance indicates that point is placed inside the rectangle,
3649 * a positive distance indicates that point is placed outside the rectangle.
3650 *
3651 * @param point point to obtain signed distance for.
3652 * @return signed distance to the closest point in the rectangle bottom border.
3653 */
3654 public double getSignedDistanceToBottomSide(final Point2D point) {
3655 return getSignedDistanceToBottomSide(point.getInhomX(), point.getInhomY());
3656 }
3657
3658 /**
3659 * Gets signed distance to the closest point in the rectangle locus.
3660 * A negative distance indicates that point is placed inside the rectangle,
3661 * a positive distance indicates that point is placed outside the rectangle.
3662 *
3663 * @param x x coordinate of point to obtain signed distance for.
3664 * @param y y coordinate of point to obtain signed distance for.
3665 * @param left left coordinate of rectangle.
3666 * @param top top coordinate of rectangle.
3667 * @param right right coordinate of rectangle.
3668 * @param bottom bottom coordinate of rectangle.
3669 * @return signed distance to the closest point in the rectangle locus.
3670 */
3671 public static double getSignedDistance(
3672 final double x, final double y, final double left, final double top, final double right,
3673 final double bottom) {
3674 // fix values in case that corners are reversed
3675 final var left2 = Math.min(left, right);
3676 final var right2 = Math.max(left, right);
3677 final var bottom2 = Math.min(top, bottom);
3678 final var top2 = Math.max(top, bottom);
3679
3680 if (isAtLeftSide(x, y, left2, top2, right2, bottom2)) {
3681 // left side
3682 return getSignedDistanceToLeftSide(x, y, left2, top2, right2, bottom2);
3683
3684 } else if (isAtTopSide(x, y, left2, top2, right2, bottom2)) {
3685 // top side
3686 return getSignedDistanceToTopSide(x, y, left2, top2, right2, bottom2);
3687
3688 } else if (isAtRightSide(x, y, left2, top2, right2, bottom2)) {
3689 // right side
3690 return getSignedDistanceToRightSide(x, y, left2, top2, right2, bottom2);
3691
3692 } else if (isAtBottomSide(x, y, left2, top2, right2, bottom2)) {
3693 // bottom side
3694 return getSignedDistanceToBottomSide(x, y, left2, top2, right2, bottom2);
3695 } else if (isAtTopLeftCorner(x, y, left2, top2, right2, bottom2)) {
3696 // top-left corner
3697 return getSignedDistanceToLeftSide(x, y, left2, top2, right2, bottom2);
3698
3699 } else if (isAtTopRightCorner(x, y, left2, top2, right2, bottom2)) {
3700 // top-right corner
3701 return getSignedDistanceToTopSide(x, y, left2, top2, right2, bottom2);
3702
3703 } else if (isAtBottomRightCorner(x, y, left2, top2, right2, bottom2)) {
3704 // bottom-right corner
3705 return getSignedDistanceToRightSide(x, y, left2, top2, right2, bottom2);
3706
3707 } else if (isAtBottomLeftCorner(x, y, left2, top2, right2, bottom2)) {
3708 // bottom-left corner
3709 return getSignedDistanceToBottomSide(x, y, left2, top2, right2, bottom2);
3710 } else {
3711 // inside. When inside, distance is negative
3712 // return closest distance to one of the sides (the largest value)
3713 final var leftDist = getSignedDistanceToLeftSide(x, y, left2, top2, right2, bottom2);
3714 final var topDist = getSignedDistanceToTopSide(x, y, left2, top2, right2, bottom2);
3715 final var rightDist = getSignedDistanceToRightSide(x, y, left2, top2, right2, bottom2);
3716 final var bottomDist = getSignedDistanceToBottomSide(x, y, left2, top2, right2, bottom2);
3717
3718 var largest = -Double.MAX_VALUE;
3719 if (leftDist > largest) {
3720 largest = leftDist;
3721 }
3722 if (topDist > largest) {
3723 largest = topDist;
3724 }
3725 if (rightDist > largest) {
3726 largest = rightDist;
3727 }
3728 if (bottomDist > largest) {
3729 largest = bottomDist;
3730 }
3731
3732 return largest;
3733 }
3734 }
3735
3736 /**
3737 * Gets signed distance to the closest point in the rectangle locus.
3738 * A negative distance indicates that point is placed inside the rectangle,
3739 * a positive distance indicates that point is placed outside the rectangle.
3740 *
3741 * @param point point to obtain signed distance for.
3742 * @param left left coordinate of rectangle.
3743 * @param top top coordinate of rectangle.
3744 * @param right right coordinate of rectangle.
3745 * @param bottom bottom coordinate of rectangle.
3746 * @return signed distance to the closest point in the rectangle locus.
3747 */
3748 public static double getSignedDistance(
3749 final Point2D point, final double left, final double top, final double right, final double bottom) {
3750 return getSignedDistance(point.getInhomX(), point.getInhomY(), left, top, right, bottom);
3751 }
3752
3753 /**
3754 * Gets signed distance to the closest point in the rectangle locus.
3755 * A negative distance indicates that point is placed inside the rectangle,
3756 * a positive distance indicates that point is placed outside the rectangle.
3757 *
3758 * @param x x coordinate of point to obtain signed distance for.
3759 * @param y y coordinate of point to obtain signed distance for.
3760 * @param topLeft top-left corner of rectangle.
3761 * @param bottomRight bottom-right corner of rectangle.
3762 * @return signed distance to the closest point in the rectangle locus.
3763 */
3764 public static double getSignedDistance(
3765 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
3766 return getSignedDistance(x, y, topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(),
3767 bottomRight.getInhomY());
3768 }
3769
3770 /**
3771 * Gets signed distance to the closest point in the rectangle locus.
3772 * A negative distance indicates that point is placed inside the rectangle,
3773 * a positive distance indicates that point is placed outside the rectangle.
3774 *
3775 * @param point point to obtain signed distance for.
3776 * @param topLeft top-left corner of rectangle.
3777 * @param bottomRight bottom-right corner of rectangle.
3778 * @return signed distance to the closest point in the rectangle locus.
3779 */
3780 public static double getSignedDistance(
3781 final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
3782 return getSignedDistance(point.getInhomX(), point.getInhomY(), topLeft, bottomRight);
3783 }
3784
3785 /**
3786 * Gets signed distance to the closest point in the rectangle locus.
3787 * A negative distance indicates that point is placed inside the rectangle,
3788 * a positive distance indicates that point is placed outside the rectangle.
3789 *
3790 * @param x x coordinate of point to obtain signed distance for.
3791 * @param y y coordinate of point to obtain signed distance for.
3792 * @param center center of rectangle.
3793 * @param width width of rectangle.
3794 * @param height height of rectangle.
3795 * @return signed distance to the closest point in the rectangle locus.
3796 */
3797 public static double getSignedDistance(
3798 final double x, final double y, final Point2D center, final double width, final double height) {
3799 final var halfWidth = width / 2.0;
3800 final var halfHeight = height / 2.0;
3801 final var centerX = center.getInhomX();
3802 final var centerY = center.getInhomY();
3803 return getSignedDistance(x, y, centerX - halfWidth, centerY - halfHeight, centerX + halfWidth,
3804 centerY + halfHeight);
3805 }
3806
3807 /**
3808 * Gets signed distance to the closest point in the rectangle locus.
3809 * A negative distance indicates that point is placed inside the rectangle,
3810 * a positive distance indicates that point is placed outside the rectangle.
3811 *
3812 * @param point point to obtain signed distance for.
3813 * @param center center of rectangle.
3814 * @param width width of rectangle.
3815 * @param height height of rectangle.
3816 * @return signed distance to the closest point in the rectangle locus.
3817 */
3818 public static double getSignedDistance(
3819 final Point2D point, final Point2D center, final double width, final double height) {
3820 return getSignedDistance(point.getInhomX(), point.getInhomY(), center, width, height);
3821 }
3822
3823 /**
3824 * Gets signed distance to the closest point in the rectangle locus.
3825 * A negative distance indicates that point is placed inside the rectangle,
3826 * a positive distance indicates that point is placed outside the rectangle.
3827 *
3828 * @param x x coordinate of point to obtain signed distance for.
3829 * @param y y coordinate of point to obtain signed distance for.
3830 * @return signed distance to the closest point in the rectangle locus.
3831 */
3832 public double getSignedDistance(final double x, final double y) {
3833 return getSignedDistance(x, y, topLeft, bottomRight);
3834 }
3835
3836 /**
3837 * Gets signed distance to the closest point in the rectangle locus.
3838 * A negative distance indicates that point is placed inside the rectangle,
3839 * a positive distance indicates that point is placed outside the rectangle.
3840 *
3841 * @param point point to obtain signed distance for.
3842 * @return signed distance to the closest point in the rectangle locus.
3843 */
3844 public double getSignedDistance(final Point2D point) {
3845 return getSignedDistance(point.getInhomX(), point.getInhomY());
3846 }
3847
3848 /**
3849 * Gets distance to the closest point in the left border of the rectangle.
3850 *
3851 * @param x x coordinate of point to obtain distance for.
3852 * @param y y coordinate of point to obtain distance for.
3853 * @param left left coordinate of rectangle.
3854 * @param top top coordinate of rectangle.
3855 * @param right right coordinate of rectangle.
3856 * @param bottom bottom coordinate of rectangle.
3857 * @return distance to the closest point in the rectangle left border.
3858 */
3859 public static double getDistanceToLeftSide(
3860 final double x, final double y, final double left, final double top, final double right,
3861 final double bottom) {
3862 return Math.abs(getSignedDistanceToLeftSide(x, y, left, top, right, bottom));
3863 }
3864
3865 /**
3866 * Gets distance to the closest point in the left border of the rectangle.
3867 *
3868 * @param point point to obtain distance for.
3869 * @param left left coordinate of rectangle.
3870 * @param top top coordinate of rectangle.
3871 * @param right right coordinate of rectangle.
3872 * @param bottom bottom coordinate of rectangle.
3873 * @return distance to the closest point in the rectangle left border.
3874 */
3875 public static double getDistanceToLeftSide(
3876 final Point2D point, final double left, final double top, final double right, final double bottom) {
3877 return Math.abs(getSignedDistanceToLeftSide(point, left, top, right, bottom));
3878 }
3879
3880 /**
3881 * Gets distance to the closest point in the left border of the rectangle.
3882 *
3883 * @param x x coordinate of point to obtain distance for.
3884 * @param y y coordinate of point to obtain distance for.
3885 * @param topLeft top-left corner of rectangle.
3886 * @param bottomRight bottom-right corner of rectangle.
3887 * @return distance to the closest point in the rectangle left border.
3888 */
3889 public static double getDistanceToLeftSide(
3890 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
3891 return Math.abs(getSignedDistanceToLeftSide(x, y, topLeft, bottomRight));
3892 }
3893
3894 /**
3895 * Gets distance to the closest point in the left border of the rectangle.
3896 *
3897 * @param point point to obtain distance for.
3898 * @param topLeft top-left corner of rectangle.
3899 * @param bottomRight bottom-right corner of rectangle.
3900 * @return distance to the closest point in the rectangle left border.
3901 */
3902 public static double getDistanceToLeftSide(
3903 final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
3904 return Math.abs(getSignedDistanceToLeftSide(point, topLeft, bottomRight));
3905 }
3906
3907 /**
3908 * Gets distance to the closest point in the left border of the rectangle.
3909 *
3910 * @param x x coordinate of point to obtain distance for.
3911 * @param y y coordinate of point to obtain distance for.
3912 * @param center center of rectangle.
3913 * @param width width of rectangle.
3914 * @param height height of rectangle.
3915 * @return distance to the closest point in the rectangle left border.
3916 */
3917 public static double getDistanceToLeftSide(
3918 final double x, final double y, final Point2D center, final double width, final double height) {
3919 return Math.abs(getSignedDistanceToLeftSide(x, y, center, width, height));
3920 }
3921
3922 /**
3923 * Gets distance to the closest point in the left border of the rectangle.
3924 *
3925 * @param point point to obtain distance for.
3926 * @param center center of rectangle.
3927 * @param width width of rectangle.
3928 * @param height height of rectangle.
3929 * @return distance to the closest point in the rectangle left border.
3930 */
3931 public static double getDistanceToLeftSide(
3932 final Point2D point, final Point2D center, final double width, final double height) {
3933 return Math.abs(getSignedDistanceToLeftSide(point, center, width, height));
3934 }
3935
3936 /**
3937 * Gets distance to the closest point in the left border of this rectangle.
3938 *
3939 * @param x x coordinate of point to obtain distance for.
3940 * @param y y coordinate of point to obtain distance for.
3941 * @return distance to the closest point in the rectangle left border.
3942 */
3943 public double getDistanceToLeftSide(final double x, final double y) {
3944 return Math.abs(getSignedDistanceToLeftSide(x, y));
3945 }
3946
3947 /**
3948 * Gets distance to the closest point in the left border of this rectangle.
3949 *
3950 * @param point point to obtain distance for.
3951 * @return distance to the closest point in the rectangle left border.
3952 */
3953 public double getDistanceToLeftSide(final Point2D point) {
3954 return Math.abs(getSignedDistanceToLeftSide(point));
3955 }
3956
3957 /**
3958 * Gets distance to the closest point in the top border of the rectangle.
3959 *
3960 * @param x x coordinate of point to obtain distance for.
3961 * @param y y coordinate of point to obtain distance for.
3962 * @param left left coordinate of rectangle.
3963 * @param top top coordinate of rectangle.
3964 * @param right right coordinate of rectangle.
3965 * @param bottom bottom coordinate of rectangle.
3966 * @return distance to the closest point in the rectangle top border.
3967 */
3968 public static double getDistanceToTopSide(
3969 final double x, final double y, final double left, final double top, final double right,
3970 final double bottom) {
3971 return Math.abs(getSignedDistanceToTopSide(x, y, left, top, right, bottom));
3972 }
3973
3974 /**
3975 * Gets distance to the closest point in the top border of the rectangle.
3976 *
3977 * @param point point to obtain distance for.
3978 * @param left left coordinate of rectangle.
3979 * @param top top coordinate of rectangle.
3980 * @param right right coordinate of rectangle.
3981 * @param bottom bottom coordinate of rectangle.
3982 * @return distance to the closest point in the rectangle top border.
3983 */
3984 public static double getDistanceToTopSide(
3985 final Point2D point, final double left, final double top, final double right, final double bottom) {
3986 return Math.abs(getSignedDistanceToTopSide(point, left, top, right, bottom));
3987 }
3988
3989 /**
3990 * Gets distance to the closest point in the top border of the rectangle.
3991 *
3992 * @param x x coordinate of point to obtain distance for.
3993 * @param y y coordinate of point to obtain distance for.
3994 * @param topLeft top-left corner of rectangle.
3995 * @param bottomRight bottom-right corner of rectangle.
3996 * @return distance to the closest point in the rectangle top border.
3997 */
3998 public static double getDistanceToTopSide(
3999 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
4000 return Math.abs(getSignedDistanceToTopSide(x, y, topLeft, bottomRight));
4001 }
4002
4003 /**
4004 * Gets distance to the closest point in the top border of the rectangle.
4005 *
4006 * @param point point to obtain distance for.
4007 * @param topLeft top-left corner of rectangle.
4008 * @param bottomRight bottom-right corner of rectangle.
4009 * @return distance to the closest point in the rectangle top border.
4010 */
4011 public static double getDistanceToTopSide(final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
4012 return Math.abs(getSignedDistanceToTopSide(point, topLeft, bottomRight));
4013 }
4014
4015 /**
4016 * Gets distance to the closest point in the top border of the rectangle.
4017 *
4018 * @param x x coordinate of point to obtain distance for.
4019 * @param y y coordinate of point to obtain distance for.
4020 * @param center center of rectangle.
4021 * @param width width of rectangle.
4022 * @param height height of rectangle.
4023 * @return distance to the closest point in the rectangle top border.
4024 */
4025 public static double getDistanceToTopSide(
4026 final double x, final double y, final Point2D center, final double width, final double height) {
4027 return Math.abs(getSignedDistanceToTopSide(x, y, center, width, height));
4028 }
4029
4030 /**
4031 * Gets distance to the closest point in the top border of the rectangle.
4032 *
4033 * @param point point to obtain distance for.
4034 * @param center center of rectangle.
4035 * @param width width of rectangle.
4036 * @param height height of rectangle.
4037 * @return distance to the closest point in the rectangle top border.
4038 */
4039 public static double getDistanceToTopSide(
4040 final Point2D point, final Point2D center, final double width, final double height) {
4041 return Math.abs(getSignedDistanceToTopSide(point, center, width, height));
4042 }
4043
4044 /**
4045 * Gets distance to the closest point in the top border of this rectangle.
4046 *
4047 * @param x x coordinate of point to obtain distance for.
4048 * @param y y coordinate of point to obtain distance for.
4049 * @return distance to the closest point in the rectangle top border.
4050 */
4051 public double getDistanceToTopSide(final double x, final double y) {
4052 return Math.abs(getSignedDistanceToTopSide(x, y));
4053 }
4054
4055 /**
4056 * Gets distance to the closest point in the top border of this rectangle.
4057 *
4058 * @param point point to obtain distance for.
4059 * @return distance to the closest point in the rectangle top border.
4060 */
4061 public double getDistanceToTopSide(final Point2D point) {
4062 return Math.abs(getSignedDistanceToTopSide(point));
4063 }
4064
4065 /**
4066 * Gets distance to the closest point in the right border of the rectangle.
4067 *
4068 * @param x x coordinate of point to obtain distance for.
4069 * @param y y coordinate of point to obtain distance for.
4070 * @param left left coordinate of rectangle.
4071 * @param top top coordinate of rectangle.
4072 * @param right right coordinate of rectangle.
4073 * @param bottom bottom coordinate of rectangle.
4074 * @return distance to the closest point in the rectangle right border.
4075 */
4076 public static double getDistanceToRightSide(
4077 final double x, final double y, final double left, final double top, final double right,
4078 final double bottom) {
4079 return Math.abs(getSignedDistanceToRightSide(x, y, left, top, right, bottom));
4080 }
4081
4082 /**
4083 * Gets distance to the closest point in the right border of the rectangle.
4084 *
4085 * @param point point to obtain distance for.
4086 * @param left left coordinate of rectangle.
4087 * @param top top coordinate of rectangle.
4088 * @param right right coordinate of rectangle.
4089 * @param bottom bottom coordinate of rectangle.
4090 * @return distance to the closest point in the rectangle right border.
4091 */
4092 public static double getDistanceToRightSide(
4093 final Point2D point, final double left, final double top, final double right, final double bottom) {
4094 return Math.abs(getSignedDistanceToRightSide(point, left, top, right, bottom));
4095 }
4096
4097 /**
4098 * Gets distance to the closest point in the right border of the rectangle.
4099 *
4100 * @param x x coordinate of point to obtain distance for.
4101 * @param y y coordinate of point to obtain distance for.
4102 * @param topLeft top-left corner of rectangle.
4103 * @param bottomRight bottom-right corner of rectangle.
4104 * @return distance to the closest point in the rectangle right border
4105 */
4106 public static double getDistanceToRightSide(
4107 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
4108 return Math.abs(getSignedDistanceToRightSide(x, y, topLeft, bottomRight));
4109 }
4110
4111 /**
4112 * Gets distance to the closest point in the right border of the rectangle.
4113 *
4114 * @param point point to obtain distance for.
4115 * @param topLeft top-left corner of rectangle.
4116 * @param bottomRight bottom-right corner of rectangle.
4117 * @return distance to the closest point in the rectangle right border.
4118 */
4119 public static double getDistanceToRightSide(final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
4120 return Math.abs(getSignedDistanceToRightSide(point, topLeft, bottomRight));
4121 }
4122
4123 /**
4124 * Gets distance to the closest point in the right border of the rectangle.
4125 *
4126 * @param x x coordinate of point to obtain distance for.
4127 * @param y y coordinate of point to obtain distance for.
4128 * @param center center of rectangle.
4129 * @param width width of rectangle.
4130 * @param height height of rectangle.
4131 * @return distance to the closest point in the rectangle right border.
4132 */
4133 public static double getDistanceToRightSide(
4134 final double x, final double y, final Point2D center, final double width, final double height) {
4135 return Math.abs(getSignedDistanceToRightSide(x, y, center, width, height));
4136 }
4137
4138 /**
4139 * Gets distance to the closest point in the right border of the rectangle.
4140 *
4141 * @param point point to obtain distance for.
4142 * @param center center of rectangle.
4143 * @param width width of rectangle.
4144 * @param height height of rectangle.
4145 * @return distance to the closest point in the rectangle right border.
4146 */
4147 public static double getDistanceToRightSide(
4148 final Point2D point, final Point2D center, final double width, final double height) {
4149 return Math.abs(getSignedDistanceToRightSide(point, center, width, height));
4150 }
4151
4152 /**
4153 * Gets distance to the closest point in the right border of this rectangle.
4154 *
4155 * @param x x coordinate of point to obtain distance for.
4156 * @param y y coordinate of point to obtain distance for.
4157 * @return distance to the closest point in the rectangle right border.
4158 */
4159 public double getDistanceToRightSide(final double x, final double y) {
4160 return Math.abs(getSignedDistanceToRightSide(x, y));
4161 }
4162
4163 /**
4164 * Gets distance to the closest point in the right border of this rectangle.
4165 *
4166 * @param point point to obtain distance for.
4167 * @return distance to the closest point in the rectangle right border.
4168 */
4169 public double getDistanceToRightSide(final Point2D point) {
4170 return Math.abs(getSignedDistanceToRightSide(point));
4171 }
4172
4173 /**
4174 * Gets distance to the closest point in the bottom border of the rectangle.
4175 *
4176 * @param x x coordinate of point to obtain distance for.
4177 * @param y y coordinate of point to obtain distance for.
4178 * @param left left coordinate of rectangle.
4179 * @param top top coordinate of rectangle.
4180 * @param right right coordinate of rectangle.
4181 * @param bottom bottom coordinate of rectangle.
4182 * @return distance to the closest point in the rectangle bottom border.
4183 */
4184 public static double getDistanceToBottomSide(
4185 final double x, final double y, final double left, final double top, final double right,
4186 final double bottom) {
4187 return Math.abs(getSignedDistanceToBottomSide(x, y, left, top, right, bottom));
4188 }
4189
4190 /**
4191 * Gets distance to the closest point in the bottom border of the rectangle.
4192 *
4193 * @param point point to obtain distance for.
4194 * @param left left coordinate of rectangle.
4195 * @param top top coordinate of rectangle.
4196 * @param right right coordinate of rectangle.
4197 * @param bottom bottom coordinate of rectangle.
4198 * @return distance to the closest point in the rectangle bottom border.
4199 */
4200 public static double getDistanceToBottomSide(
4201 final Point2D point, final double left, final double top, final double right, final double bottom) {
4202 return Math.abs(getSignedDistanceToBottomSide(point, left, top, right, bottom));
4203 }
4204
4205 /**
4206 * Gets distance to the closest point in the bottom border of the rectangle.
4207 *
4208 * @param x x coordinate of point to obtain distance for.
4209 * @param y y coordinate of point to obtain distance for.
4210 * @param topLeft top-left corner of rectangle.
4211 * @param bottomRight bottom-right corner of rectangle.
4212 * @return distance to the closest point in the rectangle bottom border.
4213 */
4214 public static double getDistanceToBottomSide(
4215 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
4216 return Math.abs(getSignedDistanceToBottomSide(x, y, topLeft, bottomRight));
4217 }
4218
4219 /**
4220 * Gets distance to the closest point in the bottom border of the rectangle.
4221 *
4222 * @param point point to obtain distance for.
4223 * @param topLeft top-left corner of rectangle.
4224 * @param bottomRight bottom-right corner of rectangle.
4225 * @return distance to the closest point in the rectangle bottom border.
4226 */
4227 public static double getDistanceToBottomSide(
4228 final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
4229 return Math.abs(getSignedDistanceToBottomSide(point, topLeft, bottomRight));
4230 }
4231
4232 /**
4233 * Gets distance to the closest point in the bottom border of the rectangle.
4234 *
4235 * @param x x coordinate of point to obtain distance for.
4236 * @param y y coordinate of point to obtain distance for.
4237 * @param center center of rectangle.
4238 * @param width width of rectangle.
4239 * @param height height of rectangle.
4240 * @return distance to the closest point in the rectangle bottom border.
4241 */
4242 public static double getDistanceToBottomSide(
4243 final double x, final double y, final Point2D center, final double width, final double height) {
4244 return Math.abs(getSignedDistanceToBottomSide(x, y, center, width, height));
4245 }
4246
4247 /**
4248 * Gets distance to the closest point in the bottom border of the rectangle.
4249 *
4250 * @param point point to obtain distance for.
4251 * @param center center of rectangle.
4252 * @param width width of rectangle.
4253 * @param height height of rectangle.
4254 * @return distance to the closest point in the rectangle bottom border.
4255 */
4256 public static double getDistanceToBottomSide(
4257 final Point2D point, final Point2D center, final double width, final double height) {
4258 return Math.abs(getSignedDistanceToBottomSide(point, center, width, height));
4259 }
4260
4261 /**
4262 * Gets distance to the closest point in the bottom border of this rectangle.
4263 *
4264 * @param x x coordinate of point to obtain distance for.
4265 * @param y y coordinate of point to obtain distance for.
4266 * @return distance to the closest point in the rectangle bottom border.
4267 */
4268 public double getDistanceToBottomSide(final double x, final double y) {
4269 return Math.abs(getSignedDistanceToBottomSide(x, y));
4270 }
4271
4272 /**
4273 * Gets distance to the closest point in the bottom border of this rectangle.
4274 *
4275 * @param point point to obtain distance for.
4276 * @return distance to the closest point in the rectangle bottom.
4277 */
4278 public double getDistanceToBottomSide(final Point2D point) {
4279 return Math.abs(getSignedDistanceToBottomSide(point));
4280 }
4281
4282 /**
4283 * Gets distance to the closest point in the rectangle locus.
4284 *
4285 * @param x x coordinate of point to obtain distance for.
4286 * @param y y coordinate of point to obtain distance for.
4287 * @param left left coordinate of rectangle.
4288 * @param top top coordinate of rectangle.
4289 * @param right right coordinate of rectangle.
4290 * @param bottom bottom coordinate of rectangle.
4291 * @return distance to the closest point in the rectangle locus.
4292 */
4293 public static double getDistance(
4294 final double x, final double y, final double left, final double top, final double right,
4295 final double bottom) {
4296 return Math.abs(getSignedDistance(x, y, left, top, right, bottom));
4297 }
4298
4299 /**
4300 * Gets distance to the closest point in the rectangle locus.
4301 *
4302 * @param point point to obtain distance for.
4303 * @param left left coordinate of rectangle.
4304 * @param top top coordinate of rectangle.
4305 * @param right right coordinate of rectangle.
4306 * @param bottom bottom coordinate of rectangle.
4307 * @return distance to the closest point in the rectangle locus.
4308 */
4309 public static double getDistance(
4310 final Point2D point, final double left, final double top, final double right, final double bottom) {
4311 return Math.abs(getSignedDistance(point, left, top, right, bottom));
4312 }
4313
4314 /**
4315 * Gets distance to the closest point in the rectangle locus.
4316 *
4317 * @param x x coordinate of point to obtain distance for.
4318 * @param y y coordinate of point to obtain distance for.
4319 * @param topLeft top-left corner of rectangle.
4320 * @param bottomRight bottom-right corner of rectangle.
4321 * @return distance to the closest point in the rectangle locus.
4322 */
4323 public static double getDistance(final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
4324 return Math.abs(getSignedDistance(x, y, topLeft, bottomRight));
4325 }
4326
4327 /**
4328 * Gets distance to the closest point in the rectangle locus.
4329 *
4330 * @param point point to obtain distance for.
4331 * @param topLeft top-left corner of rectangle.
4332 * @param bottomRight bottom-right corner of rectangle.
4333 * @return distance to the closest point in the rectangle locus.
4334 */
4335 public static double getDistance(final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
4336 return Math.abs(getSignedDistance(point, topLeft, bottomRight));
4337 }
4338
4339 /**
4340 * Gets distance to the closest point in the rectangle locus.
4341 *
4342 * @param x x coordinate of point to obtain distance for.
4343 * @param y y coordinate of point to obtain distance for.
4344 * @param center center of rectangle.
4345 * @param width width of rectangle.
4346 * @param height height of rectangle.
4347 * @return distance to the closest point in the rectangle locus.
4348 */
4349 public static double getDistance(
4350 final double x, final double y, final Point2D center, final double width, final double height) {
4351 return Math.abs(getSignedDistance(x, y, center, width, height));
4352 }
4353
4354 /**
4355 * Gets distance to the closest point in the rectangle locus.
4356 *
4357 * @param point point to obtain distance for.
4358 * @param center center of rectangle.
4359 * @param width width of rectangle.
4360 * @param height height of rectangle.
4361 * @return distance to the closest point in the rectangle locus.
4362 */
4363 public static double getDistance(
4364 final Point2D point, final Point2D center, final double width, final double height) {
4365 return Math.abs(getSignedDistance(point, center, width, height));
4366 }
4367
4368 /**
4369 * Gets distance to the closest point in the rectangle locus.
4370 *
4371 * @param x x coordinate of point to obtain distance for.
4372 * @param y y coordinate of point to obtain distance for.
4373 * @return distance to the closest point in the rectangle locus.
4374 */
4375 public double getDistance(final double x, final double y) {
4376 return Math.abs(getSignedDistance(x, y));
4377 }
4378
4379 /**
4380 * Gets distance to the closest point in the rectangle locus.
4381 *
4382 * @param point point to obtain distance for.
4383 * @return distance to the closest point in the rectangle locus.
4384 */
4385 public double getDistance(final Point2D point) {
4386 return Math.abs(getSignedDistance(point));
4387 }
4388
4389 /**
4390 * Gets closest point in the rectangle locus defined by provided top-left
4391 * and bottom-right corners to provided point coordinates.
4392 *
4393 * @param x x point coordinate to find the closest point to.
4394 * @param y y point coordinate to find the closest point to.
4395 * @param left left coordinate of rectangle.
4396 * @param top top coordinate of rectangle.
4397 * @param right right coordinate of rectangle.
4398 * @param bottom bottom coordinate of rectangle.
4399 * @param result instance where coordinates of resulting closest point will
4400 * be stored.
4401 */
4402 public static void closestPoint(
4403 final double x, final double y, final double left, final double top, final double right,
4404 final double bottom, final Point2D result) {
4405 // fix values in case that corners are reversed
4406 final var left2 = Math.min(left, right);
4407 final var right2 = Math.max(left, right);
4408 final var bottom2 = Math.min(top, bottom);
4409 final var top2 = Math.max(top, bottom);
4410
4411 if (isAtLeftSide(x, y, left2, top2, right2, bottom2)) {
4412 // left side
4413 result.setInhomogeneousCoordinates(left2, y);
4414
4415 } else if (isAtTopSide(x, y, left2, top2, right2, bottom2)) {
4416 // top side
4417 result.setInhomogeneousCoordinates(x, top2);
4418
4419 } else if (isAtRightSide(x, y, left2, top2, right2, bottom2)) {
4420 // right side
4421 result.setInhomogeneousCoordinates(right2, y);
4422
4423 } else if (isAtBottomSide(x, y, left2, top2, right2, bottom2)) {
4424 // bottom side
4425 result.setInhomogeneousCoordinates(x, bottom2);
4426
4427 } else if (isAtTopLeftCorner(x, y, left2, top2, right2, bottom2)) {
4428 // top-left corner. Return top-left corner
4429 result.setInhomogeneousCoordinates(left2, top2);
4430
4431 } else if (isAtTopRightCorner(x, y, left2, top2, right2, bottom2)) {
4432 // top-right corner. Return top-right corner
4433 result.setInhomogeneousCoordinates(right2, top2);
4434
4435 } else if (isAtBottomRightCorner(x, y, left2, top2, right2, bottom2)) {
4436 // bottom-right corner. Return bottom-right corner
4437 result.setInhomogeneousCoordinates(right2, bottom2);
4438
4439 } else if (isAtBottomLeftCorner(x, y, left, top2, right2, bottom2)) {
4440 // bottom-left corner. Return bottom-left corner
4441 result.setInhomogeneousCoordinates(left2, bottom2);
4442
4443 } else {
4444 // inside.
4445 // Pick the side with the shortest distance to a border
4446 final var leftDist = getDistanceToLeftSide(x, y, left2, top2, right2, bottom2);
4447 final var topDist = getDistanceToTopSide(x, y, left2, top2, right2, bottom2);
4448 final var rightDist = getDistanceToRightSide(x, y, left2, top2, right2, bottom2);
4449 final var bottomDist = getDistanceToBottomSide(x, y, left2, top2, right2, bottom2);
4450
4451 if (leftDist < topDist && leftDist < rightDist && leftDist < bottomDist) {
4452 // pick left side
4453 result.setInhomogeneousCoordinates(left2, y);
4454
4455 } else if (topDist < leftDist && topDist < rightDist && topDist < bottomDist) {
4456 // pick top side
4457 result.setInhomogeneousCoordinates(x, top2);
4458
4459 } else if (rightDist < leftDist && rightDist < topDist && rightDist < bottomDist) {
4460 // pick right side
4461 result.setInhomogeneousCoordinates(right2, y);
4462
4463 } else {
4464 // pick bottom side
4465 result.setInhomogeneousCoordinates(x, bottom2);
4466 }
4467 }
4468 }
4469
4470 /**
4471 * Gets closest point in the rectangle locus defined by provided top-left
4472 * and bottom-right corners to provided point coordinates.
4473 *
4474 * @param point point to find the closest point to.
4475 * @param left left coordinate of rectangle.
4476 * @param top top coordinate of rectangle.
4477 * @param right right coordinate of rectangle.
4478 * @param bottom bottom coordinate of rectangle.
4479 * @param result instance where coordinates of resulting closest point will
4480 * be stored.
4481 */
4482 public static void closestPoint(
4483 final Point2D point, final double left, final double top, final double right, final double bottom,
4484 final Point2D result) {
4485 closestPoint(point.getInhomX(), point.getInhomY(), left, top, right, bottom, result);
4486 }
4487
4488 /**
4489 * Gets closest point in the rectangle locus defined by provided top-left
4490 * and bottom-right corners to provided point coordinates.
4491 *
4492 * @param x x point coordinate to find the closest point to.
4493 * @param y y point coordinate to find the closest point to.
4494 * @param topLeft top-left corner of rectangle.
4495 * @param bottomRight bottom-right corner of rectangle.
4496 * @param result instance where coordinates of resulting closest point will
4497 * be stored.
4498 */
4499 public static void closestPoint(
4500 final double x, final double y, final Point2D topLeft, final Point2D bottomRight, final Point2D result) {
4501 closestPoint(x, y, topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(), bottomRight.getInhomY(),
4502 result);
4503 }
4504
4505 /**
4506 * Gets closest point in the rectangle locus defined by provided top-left
4507 * and bottom-right corners to provided point.
4508 *
4509 * @param point point to find the closest point to.
4510 * @param topLeft top-left corner of rectangle.
4511 * @param bottomRight bottom-right corner of rectangle.
4512 * @param result instance where coordinates of resulting closest point will
4513 * be stored.
4514 */
4515 public static void closestPoint(
4516 final Point2D point, final Point2D topLeft, final Point2D bottomRight, final Point2D result) {
4517 closestPoint(point.getInhomX(), point.getInhomY(), topLeft, bottomRight, result);
4518 }
4519
4520 /**
4521 * Gets closest point in the rectangle locus defined by provided center and
4522 * rectangle size.
4523 *
4524 * @param x x point coordinate to find the closest point to.
4525 * @param y y point coordinate to find the closest point to.
4526 * @param center center of rectangle.
4527 * @param width width of rectangle.
4528 * @param height height of rectangle.
4529 * @param result instance where coordinates of resulting closest point will
4530 * be stored.
4531 */
4532 public static void closestPoint(
4533 final double x, final double y, final Point2D center, final double width, final double height,
4534 final Point2D result) {
4535 final var halfWidth = width / 2.0;
4536 final var halfHeight = height / 2.0;
4537 final var centerX = center.getInhomX();
4538 final var centerY = center.getInhomY();
4539 closestPoint(x, y, centerX - halfWidth, centerY - halfHeight, centerX + halfWidth,
4540 centerY + halfHeight, result);
4541 }
4542
4543 /**
4544 * Gets closest point in the rectangle locus defined by provided center
4545 * rectangle size.
4546 *
4547 * @param point point to find the closest point to.
4548 * @param center center of rectangle.
4549 * @param width width of rectangle.
4550 * @param height height of rectangle.
4551 * @param result instance where coordinates of resulting closest point will
4552 * be stored.
4553 */
4554 public static void closestPoint(
4555 final Point2D point, final Point2D center, final double width, final double height, final Point2D result) {
4556 closestPoint(point.getInhomX(), point.getInhomY(), center, width, height, result);
4557 }
4558
4559 /**
4560 * Gets closest point in this rectangle locus.
4561 *
4562 * @param x x point coordinate to find the closest point to.
4563 * @param y y point coordinate to find the closest point to.
4564 * @param result instance where coordinates of resulting closest point will
4565 * be stored.
4566 */
4567 public void closestPoint(final double x, final double y, final Point2D result) {
4568 closestPoint(x, y, topLeft, bottomRight, result);
4569 }
4570
4571 /**
4572 * Gets closest point in this rectangle locus.
4573 *
4574 * @param point point to find the closest point to.
4575 * @param result instance where coordinates of resulting closest point will
4576 * be stored.
4577 */
4578 public void closestPoint(final Point2D point, final Point2D result) {
4579 closestPoint(point, topLeft, bottomRight, result);
4580 }
4581
4582 /**
4583 * Gets closest point in the rectangle locus defined by provided top-left
4584 * and bottom-right corners to provided point coordinates.
4585 *
4586 * @param x x point coordinate to find the closest point to.
4587 * @param y y point coordinate to find the closest point to.
4588 * @param left left coordinate of rectangle.
4589 * @param top top coordinate of rectangle.
4590 * @param right right coordinate of rectangle.
4591 * @param bottom bottom coordinate of rectangle.
4592 * @return closest point in the rectangle locus.
4593 */
4594 public static Point2D getClosestPoint(
4595 final double x, final double y, final double left, final double top, final double right,
4596 final double bottom) {
4597 final var result = Point2D.create();
4598 closestPoint(x, y, left, top, right, bottom, result);
4599 return result;
4600 }
4601
4602 /**
4603 * Gets closest point in the rectangle locus defined by provided top-left
4604 * and bottom-right corners to provided point.
4605 *
4606 * @param point point to find the closest point to.
4607 * @param left left coordinate of rectangle.
4608 * @param top top coordinate of rectangle.
4609 * @param right right coordinate of rectangle.
4610 * @param bottom bottom coordinate of rectangle.
4611 * @return closest point in the rectangle locus.
4612 */
4613 public static Point2D getClosestPoint(
4614 final Point2D point, final double left, final double top, final double right, final double bottom) {
4615 final var result = Point2D.create();
4616 closestPoint(point, left, top, right, bottom, result);
4617 return result;
4618 }
4619
4620 /**
4621 * Gets closest point in the rectangle locus defined by provided top-left
4622 * and bottom-right corners to provided point coordinates.
4623 *
4624 * @param x x point coordinate to find the closest point to.
4625 * @param y y point coordinate to find the closest point to.
4626 * @param topLeft top-left corner of rectangle.
4627 * @param bottomRight bottom-right corner of rectangle.
4628 * @return closest point in the rectangle locus.
4629 */
4630 public static Point2D getClosestPoint(
4631 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
4632 final var result = Point2D.create();
4633 closestPoint(x, y, topLeft, bottomRight, result);
4634 return result;
4635 }
4636
4637 /**
4638 * Gets closest point in the rectangle locus defined by provided top-left
4639 * and bottom-right corners to provided point.
4640 *
4641 * @param point point to find the closest point to.
4642 * @param topLeft top-left corner of rectangle.
4643 * @param bottomRight bottom-right corner of rectangle.
4644 * @return closest point in the rectangle locus.
4645 */
4646 public static Point2D getClosestPoint(
4647 final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
4648 final var result = Point2D.create();
4649 closestPoint(point, topLeft, bottomRight, result);
4650 return result;
4651 }
4652
4653 /**
4654 * Gets closest point in the rectangle locus defined by provided center
4655 * and rectangle size to provided point.
4656 *
4657 * @param x x point coordinate to find the closest point to.
4658 * @param y y point coordinate to find the closest point to.
4659 * @param center center of rectangle.
4660 * @param width width of rectangle.
4661 * @param height height of rectangle.
4662 * @return closest point in the rectangle locus.
4663 */
4664 public static Point2D getClosestPoint(
4665 final double x, final double y, final Point2D center, final double width, final double height) {
4666 final var result = Point2D.create();
4667 closestPoint(x, y, center, width, height, result);
4668 return result;
4669 }
4670
4671 /**
4672 * Gets closest point in the rectangle locus defined by provided center
4673 * and rectangle size to provided point.
4674 *
4675 * @param point point to find the closest point to.
4676 * @param center center of rectangle.
4677 * @param width width of rectangle.
4678 * @param height height of rectangle.
4679 * @return closest point in the rectangle locus.
4680 */
4681 public static Point2D getClosestPoint(
4682 final Point2D point, final Point2D center, final double width, final double height) {
4683 final var result = Point2D.create();
4684 closestPoint(point, center, width, height, result);
4685 return result;
4686 }
4687
4688 /**
4689 * Gets closest point in this rectangle locus to provided point coordinates.
4690 *
4691 * @param x x coordinate to find the closest point to.
4692 * @param y y coordinate to find the closest point to.
4693 * @return closest point in the rectangle locus.
4694 */
4695 public Point2D getClosestPoint(final double x, final double y) {
4696 final var result = Point2D.create();
4697 closestPoint(x, y, result);
4698 return result;
4699 }
4700
4701 /**
4702 * Gets closest point in this rectangle locus to provided point.
4703 *
4704 * @param point point to find the closest point to.
4705 * @return closest point in the rectangle locus.
4706 */
4707 public Point2D getClosestPoint(final Point2D point) {
4708 final var result = Point2D.create();
4709 closestPoint(point, result);
4710 return result;
4711 }
4712
4713 /**
4714 * Indicates whether provided point coordinates belong to the locus of the
4715 * left side of the rectangle defined by provided top-left and bottom-right
4716 * corners up to a certain threshold.
4717 *
4718 * @param x x coordinate of point to be checked.
4719 * @param y y coordinate of point to be checked.
4720 * @param left left coordinate of rectangle.
4721 * @param top top coordinate of rectangle.
4722 * @param right right coordinate of rectangle.
4723 * @param bottom bottom coordinate of rectangle.
4724 * @param threshold threshold to use as a margin to determine whether
4725 * point is locus to left side of rectangle.
4726 * @return true if point is locus to left side of rectangle, false
4727 * otherwise.
4728 * @throws IllegalArgumentException if provided threshold is negative.
4729 */
4730 public static boolean isLocusToLeftSide(
4731 final double x, final double y, final double left, final double top, final double right,
4732 final double bottom, final double threshold) {
4733 if (threshold < 0.0) {
4734 throw new IllegalArgumentException();
4735 }
4736
4737 return getDistanceToLeftSide(x, y, left, top, right, bottom) <= threshold;
4738 }
4739
4740 /**
4741 * Indicates whether provided point belongs to the locus of the left side
4742 * of the rectangle defined by provided top-left and bottom-right corners up
4743 * to a certain threshold.
4744 *
4745 * @param point point to be checked.
4746 * @param left left coordinate of rectangle.
4747 * @param top top coordinate of rectangle.
4748 * @param right right coordinate of rectangle.
4749 * @param bottom bottom coordinate of rectangle.
4750 * @param threshold threshold to use as a margin to determine whether
4751 * point is locus to left side of rectangle.
4752 * @return true if point is locus to left side of rectangle, false
4753 * otherwise.
4754 * @throws IllegalArgumentException if provided threshold is negative.
4755 */
4756 public static boolean isLocusToLeftSide(
4757 final Point2D point, final double left, final double top, final double right, final double bottom,
4758 final double threshold) {
4759 return isLocusToLeftSide(point.getInhomX(), point.getInhomY(), left, top, right, bottom, threshold);
4760 }
4761
4762 /**
4763 * Indicates whether provided point coordinates belong to the locus of the
4764 * left side of the rectangle defined by provided top-left and bottom-right
4765 * corners up to a certain threshold.
4766 *
4767 * @param x x coordinate of point to be checked.
4768 * @param y y coordinate of point to be checked.
4769 * @param topLeft top-left corner of rectangle.
4770 * @param bottomRight bottom-right corner of rectangle.
4771 * @param threshold threshold to use as a margin to determine whether point
4772 * is locus to left side of rectangle.
4773 * @return true if point is locus to left side of rectangle, false
4774 * otherwise.
4775 * @throws IllegalArgumentException if provided threshold is negative.
4776 */
4777 public static boolean isLocusToLeftSide(
4778 final double x, final double y, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
4779 return isLocusToLeftSide(x, y, topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(),
4780 bottomRight.getInhomY(), threshold);
4781 }
4782
4783 /**
4784 * Indicates whether provided point belongs to the locus of the left side of
4785 * the rectangle defined by provided top-left and bottom-right corners up to
4786 * a certain threshold.
4787 *
4788 * @param point point to be checked.
4789 * @param topLeft top-left corner of rectangle.
4790 * @param bottomRight bottom-right corner of rectangle.
4791 * @param threshold threshold to use as a margin to determine whether point
4792 * is locus to left side of rectangle.
4793 * @return true if point is locus to left side of rectangle, false
4794 * otherwise.
4795 * @throws IllegalArgumentException if provided threshold is negative.
4796 */
4797 public static boolean isLocusToLeftSide(
4798 final Point2D point, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
4799 return isLocusToLeftSide(point.getInhomX(), point.getInhomY(), topLeft, bottomRight, threshold);
4800 }
4801
4802 /**
4803 * Indicates whether provided point coordinates belong to the locus of the
4804 * left side of the rectangle defined by provided rectangle center and size
4805 * up to a certain threshold.
4806 *
4807 * @param x x coordinate of point to be checked.
4808 * @param y y coordinate of point to be checked.
4809 * @param center center of rectangle.
4810 * @param width width of rectangle.
4811 * @param height height of rectangle.
4812 * @param threshold threshold to use as a margin to determine whether point
4813 * is locus to left side of rectangle.
4814 * @return true if point is locus to left side of rectangle, false
4815 * otherwise.
4816 * @throws IllegalArgumentException if provided threshold is negative.
4817 */
4818 public static boolean isLocusToLeftSide(
4819 final double x, final double y, final Point2D center, final double width, final double height,
4820 final double threshold) {
4821 final var halfWidth = width / 2.0;
4822 final var halfHeight = height / 2.0;
4823 final var centerX = center.getInhomX();
4824 final var centerY = center.getInhomY();
4825 return isLocusToLeftSide(x, y, centerX - halfWidth, centerY - halfHeight, centerX + halfWidth,
4826 centerY + halfHeight, threshold);
4827 }
4828
4829 /**
4830 * Indicates whether provided point belongs to the locus of the left side
4831 * of the rectangle defined by provided rectangle center and size up to a
4832 * certain threshold.
4833 *
4834 * @param point point to be checked.
4835 * @param center center of rectangle.
4836 * @param width width of rectangle.
4837 * @param height height of rectangle.
4838 * @param threshold threshold to use as a margin to determine whether point
4839 * is locus to left side of rectangle.
4840 * @return true if point is locus to left side of rectangle, false
4841 * otherwise.
4842 * @throws IllegalArgumentException if provided threshold is negative.
4843 */
4844 public static boolean isLocusToLeftSide(
4845 final Point2D point, final Point2D center, final double width, final double height,
4846 final double threshold) {
4847 return isLocusToLeftSide(point.getInhomX(), point.getInhomY(), center, width, height, threshold);
4848 }
4849
4850 /**
4851 * Indicates whether provided point coordinates belong to the locus of the
4852 * left side of this rectangle.
4853 *
4854 * @param x x coordinate of point to be checked.
4855 * @param y y coordinate of point to be checked.
4856 * @param threshold threshold to use as a margin to determine whether point
4857 * is locus to left side of rectangle.
4858 * @return true if point is locus to left side of rectangle, false
4859 * otherwise.
4860 * @throws IllegalArgumentException if provided threshold is negative.
4861 */
4862 public boolean isLocusToLeftSide(final double x, final double y, final double threshold) {
4863 return isLocusToLeftSide(x, y, topLeft, bottomRight, threshold);
4864 }
4865
4866 /**
4867 * Indicates whether provided point belongs to the locus of the left side
4868 * of this rectangle.
4869 *
4870 * @param point point to be checked.
4871 * @param threshold threshold to use as a margin to determine whether point
4872 * is locus to left side of rectangle.
4873 * @return true if point is locus to left side of rectangle, false
4874 * otherwise.
4875 * @throws IllegalArgumentException if provided threshold is negative.
4876 */
4877 public boolean isLocusToLeftSide(final Point2D point, final double threshold) {
4878 return isLocusToLeftSide(point, topLeft, bottomRight, threshold);
4879 }
4880
4881 /**
4882 * Indicates whether provided point coordinates belong to the locus of the
4883 * left side of the rectangle defined by provided top-left and bottom-right
4884 * corners.
4885 *
4886 * @param x x coordinate of point to be checked.
4887 * @param y y coordinate of point to be checked.
4888 * @param left left coordinate of rectangle.
4889 * @param top top coordinate of rectangle.
4890 * @param right right coordinate of rectangle.
4891 * @param bottom bottom coordinate of rectangle.
4892 * @return true if point is locus to left side of rectangle, false
4893 * otherwise.
4894 */
4895 public static boolean isLocusToLeftSide(
4896 final double x, final double y, final double left, final double top, final double right,
4897 final double bottom) {
4898 return isLocusToLeftSide(x, y, left, top, right, bottom, DEFAULT_THRESHOLD);
4899 }
4900
4901 /**
4902 * Indicates whether provided point belongs to the locus of the left side
4903 * of the rectangle defined by provided top-left and bottom-right corners.
4904 *
4905 * @param point point to be checked.
4906 * @param left left coordinate of rectangle.
4907 * @param top top coordinate of rectangle.
4908 * @param right right coordinate of rectangle.
4909 * @param bottom bottom coordinate of rectangle.
4910 * @return true if point is locus to left side of rectangle, false
4911 * otherwise.
4912 */
4913 public static boolean isLocusToLeftSide(
4914 final Point2D point, final double left, final double top, final double right, final double bottom) {
4915 return isLocusToLeftSide(point, left, top, right, bottom, DEFAULT_THRESHOLD);
4916 }
4917
4918 /**
4919 * Indicates whether provided point coordinates belong to the locus of the
4920 * left side of the rectangle defined by provided top-left and bottom-right
4921 * corners up to a certain threshold.
4922 *
4923 * @param x x coordinate of point to be checked.
4924 * @param y y coordinate of point to be checked.
4925 * @param topLeft top-left corner of rectangle.
4926 * @param bottomRight bottom-right corner of rectangle.
4927 * @return true if point is locus to left side of rectangle, false
4928 * otherwise.
4929 */
4930 public static boolean isLocusToLeftSide(
4931 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
4932 return isLocusToLeftSide(x, y, topLeft, bottomRight, DEFAULT_THRESHOLD);
4933 }
4934
4935 /**
4936 * Indicates whether provided point belongs to the locus of the left side of
4937 * the rectangle defined by provided top-left and bottom-right corners.
4938 *
4939 * @param point point to be checked.
4940 * @param topLeft top-left corner of rectangle.
4941 * @param bottomRight bottom-right corner of rectangle.
4942 * @return true if point is locus to left side of rectangle, false
4943 * otherwise.
4944 */
4945 public static boolean isLocusToLeftSide(final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
4946 return isLocusToLeftSide(point, topLeft, bottomRight, DEFAULT_THRESHOLD);
4947 }
4948
4949 /**
4950 * Indicates whether provided point coordinates belong to the locus of the
4951 * left side of the rectangle defined by provided rectangle center and size.
4952 *
4953 * @param x x coordinate of point to be checked.
4954 * @param y y coordinate of point to be checked.
4955 * @param center center of rectangle.
4956 * @param width width of rectangle.
4957 * @param height height of rectangle.
4958 * @return true if point is locus to left side of rectangle, false
4959 * otherwise.
4960 */
4961 public static boolean isLocusToLeftSide(
4962 final double x, final double y, final Point2D center, final double width, final double height) {
4963 return isLocusToLeftSide(x, y, center, width, height, DEFAULT_THRESHOLD);
4964 }
4965
4966 /**
4967 * Indicates whether provided point belongs to the locus of the left side
4968 * of the rectangle defined by provided rectangle center and size.
4969 *
4970 * @param point point to be checked.
4971 * @param center center of rectangle.
4972 * @param width width of rectangle.
4973 * @param height height of rectangle.
4974 * @return true if point is locus to left side of rectangle, false
4975 * otherwise.
4976 */
4977 public static boolean isLocusToLeftSide(
4978 final Point2D point, final Point2D center, final double width, final double height) {
4979 return isLocusToLeftSide(point, center, width, height, DEFAULT_THRESHOLD);
4980 }
4981
4982 /**
4983 * Indicates whether provided point coordinates belong to the locus of the
4984 * left side of this rectangle.
4985 *
4986 * @param x x coordinate of point to be checked.
4987 * @param y y coordinate of point to be checked.
4988 * @return true if point is locus to left side of rectangle, false
4989 * otherwise.
4990 */
4991 public boolean isLocusToLeftSide(final double x, final double y) {
4992 return isLocusToLeftSide(x, y, DEFAULT_THRESHOLD);
4993 }
4994
4995 /**
4996 * Indicates whether provided point belongs to the locus of the left side of
4997 * this rectangle.
4998 *
4999 * @param point point to be checked.
5000 * @return true if point is locus to left side of rectangle, false
5001 * otherwise.
5002 */
5003 public boolean isLocusToLeftSide(final Point2D point) {
5004 return isLocusToLeftSide(point, DEFAULT_THRESHOLD);
5005 }
5006
5007 /**
5008 * Indicates whether provided point coordinates belong to the locus of the
5009 * top side of the rectangle defined by provided top-left and bottom-right
5010 * corners up to a certain threshold.
5011 *
5012 * @param x x coordinate of point to be checked.
5013 * @param y y coordinate of point to be checked.
5014 * @param left left coordinate of rectangle.
5015 * @param top top coordinate of rectangle.
5016 * @param right right coordinate of rectangle.
5017 * @param bottom bottom coordinate of rectangle.
5018 * @param threshold threshold to use as a margin to determine whether
5019 * point is locus to top side of rectangle.
5020 * @return true if point is locus to top side of rectangle, false
5021 * otherwise.
5022 * @throws IllegalArgumentException if provided threshold is negative.
5023 */
5024 public static boolean isLocusToTopSide(
5025 final double x, final double y, final double left, final double top, final double right,
5026 final double bottom, final double threshold) {
5027 if (threshold < 0.0) {
5028 throw new IllegalArgumentException();
5029 }
5030
5031 return getDistanceToTopSide(x, y, left, top, right, bottom) <= threshold;
5032 }
5033
5034 /**
5035 * Indicates whether provided point belongs to the locus of the top side
5036 * of the rectangle defined by provided top-left and bottom-right corners up
5037 * to a certain threshold.
5038 *
5039 * @param point point to be checked.
5040 * @param left left coordinate of rectangle.
5041 * @param top top coordinate of rectangle.
5042 * @param right right coordinate of rectangle.
5043 * @param bottom bottom coordinate of rectangle.
5044 * @param threshold threshold to use as a margin to determine whether
5045 * point is locus to top side of rectangle.
5046 * @return true if point is locus to top side of rectangle, false
5047 * otherwise.
5048 * @throws IllegalArgumentException if provided threshold is negative.
5049 */
5050 public static boolean isLocusToTopSide(
5051 final Point2D point, final double left, final double top, final double right, final double bottom,
5052 final double threshold) {
5053 return isLocusToTopSide(point.getInhomX(), point.getInhomY(), left, top, right, bottom, threshold);
5054 }
5055
5056 /**
5057 * Indicates whether provided point coordinates belong to the locus of the
5058 * top side of the rectangle defined by provided top-left and bottom-right
5059 * corners up to a certain threshold.
5060 *
5061 * @param x x coordinate of point to be checked.
5062 * @param y y coordinate of point to be checked.
5063 * @param topLeft top-left corner of rectangle.
5064 * @param bottomRight bottom-right corner of rectangle.
5065 * @param threshold threshold to use as a margin to determine whether point
5066 * is locus to top side of rectangle.
5067 * @return true if point is locus to top side of rectangle, false
5068 * otherwise.
5069 * @throws IllegalArgumentException if provided threshold is negative.
5070 */
5071 public static boolean isLocusToTopSide(
5072 final double x, final double y, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
5073 return isLocusToTopSide(x, y, topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(),
5074 bottomRight.getInhomY(), threshold);
5075 }
5076
5077 /**
5078 * Indicates whether provided point belongs to the locus of the top side of
5079 * the rectangle defined by provided top-left and bottom-right corners up to
5080 * a certain threshold.
5081 *
5082 * @param point point to be checked.
5083 * @param topLeft top-left corner of rectangle.
5084 * @param bottomRight bottom-right corner of rectangle.
5085 * @param threshold threshold to use as a margin to determine whether point
5086 * is locus to top side of rectangle.
5087 * @return true if point is locus to top side of rectangle, false
5088 * otherwise.
5089 * @throws IllegalArgumentException if provided threshold is negative.
5090 */
5091 public static boolean isLocusToTopSide(
5092 final Point2D point, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
5093 return isLocusToTopSide(point.getInhomX(), point.getInhomY(), topLeft, bottomRight, threshold);
5094 }
5095
5096 /**
5097 * Indicates whether provided point coordinates belong to the locus of the
5098 * top side of the rectangle defined by provided rectangle center and size
5099 * up to a certain threshold.
5100 *
5101 * @param x x coordinate of point to be checked.
5102 * @param y y coordinate of point to be checked.
5103 * @param center center of rectangle.
5104 * @param width width of rectangle.
5105 * @param height height of rectangle.
5106 * @param threshold threshold to use as a margin to determine whether point
5107 * is locus to top side of rectangle.
5108 * @return true if point is locus to top side of rectangle, false
5109 * otherwise.
5110 * @throws IllegalArgumentException if provided threshold is negative.
5111 */
5112 public static boolean isLocusToTopSide(
5113 final double x, final double y, final Point2D center, final double width, final double height,
5114 final double threshold) {
5115 final var halfWidth = width / 2.0;
5116 final var halfHeight = height / 2.0;
5117 final var centerX = center.getInhomX();
5118 final var centerY = center.getInhomY();
5119 return isLocusToTopSide(x, y, centerX - halfWidth, centerY - halfHeight, centerX + halfWidth,
5120 centerY + halfHeight, threshold);
5121 }
5122
5123 /**
5124 * Indicates whether provided point belongs to the locus of the top side
5125 * of the rectangle defined by provided rectangle center and size up to a
5126 * certain threshold.
5127 *
5128 * @param point point to be checked.
5129 * @param center center of rectangle.
5130 * @param width width of rectangle.
5131 * @param height height of rectangle.
5132 * @param threshold threshold to use as a margin to determine whether point
5133 * is locus to top side of rectangle.
5134 * @return true if point is locus to top side of rectangle, false
5135 * otherwise.
5136 * @throws IllegalArgumentException if provided threshold is negative.
5137 */
5138 public static boolean isLocusToTopSide(
5139 final Point2D point, final Point2D center, final double width, final double height,
5140 final double threshold) {
5141 return isLocusToTopSide(point.getInhomX(), point.getInhomY(), center, width, height, threshold);
5142 }
5143
5144 /**
5145 * Indicates whether provided point coordinates belong to the locus of the
5146 * top side of this rectangle.
5147 *
5148 * @param x x coordinate of point to be checked.
5149 * @param y y coordinate of point to be checked.
5150 * @param threshold threshold to use as a margin to determine whether point
5151 * is locus to top side of rectangle.
5152 * @return true if point is locus to top side of rectangle, false
5153 * otherwise.
5154 * @throws IllegalArgumentException if provided threshold is negative.
5155 */
5156 public boolean isLocusToTopSide(final double x, final double y, final double threshold) {
5157 return isLocusToTopSide(x, y, topLeft, bottomRight, threshold);
5158 }
5159
5160 /**
5161 * Indicates whether provided point belongs to the locus of the top side
5162 * of this rectangle.
5163 *
5164 * @param point point to be checked.
5165 * @param threshold threshold to use as a margin to determine whether point
5166 * is locus to top side of rectangle.
5167 * @return true if point is locus to top side of rectangle, false
5168 * otherwise.
5169 * @throws IllegalArgumentException if provided threshold is negative.
5170 */
5171 public boolean isLocusToTopSide(final Point2D point, final double threshold) {
5172 return isLocusToTopSide(point, topLeft, bottomRight, threshold);
5173 }
5174
5175 /**
5176 * Indicates whether provided point coordinates belong to the locus of the
5177 * top side of the rectangle defined by provided top-left and bottom-right
5178 * corners.
5179 *
5180 * @param x x coordinate of point to be checked.
5181 * @param y y coordinate of point to be checked.
5182 * @param left left coordinate of rectangle.
5183 * @param top top coordinate of rectangle.
5184 * @param right right coordinate of rectangle.
5185 * @param bottom bottom coordinate of rectangle.
5186 * @return true if point is locus to top side of rectangle, false
5187 * otherwise.
5188 */
5189 public static boolean isLocusToTopSide(
5190 final double x, final double y, final double left, final double top, final double right,
5191 final double bottom) {
5192 return isLocusToTopSide(x, y, left, top, right, bottom, DEFAULT_THRESHOLD);
5193 }
5194
5195 /**
5196 * Indicates whether provided point belongs to the locus of the top side
5197 * of the rectangle defined by provided top-left and bottom-right corners.
5198 *
5199 * @param point point to be checked.
5200 * @param left left coordinate of rectangle.
5201 * @param top top coordinate of rectangle.
5202 * @param right right coordinate of rectangle.
5203 * @param bottom bottom coordinate of rectangle.
5204 * @return true if point is locus to top side of rectangle, false
5205 * otherwise.
5206 */
5207 public static boolean isLocusToTopSide(
5208 final Point2D point, final double left, final double top, final double right, final double bottom) {
5209 return isLocusToTopSide(point, left, top, right, bottom, DEFAULT_THRESHOLD);
5210 }
5211
5212 /**
5213 * Indicates whether provided point coordinates belong to the locus of the
5214 * top side of the rectangle defined by provided top-left and bottom-right
5215 * corners up to a certain threshold.
5216 *
5217 * @param x x coordinate of point to be checked.
5218 * @param y y coordinate of point to be checked.
5219 * @param topLeft top-left corner of rectangle.
5220 * @param bottomRight bottom-right corner of rectangle.
5221 * @return true if point is locus to top side of rectangle, false
5222 * otherwise.
5223 */
5224 public static boolean isLocusToTopSide(
5225 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
5226 return isLocusToTopSide(x, y, topLeft, bottomRight, DEFAULT_THRESHOLD);
5227 }
5228
5229 /**
5230 * Indicates whether provided point belongs to the locus of the top side of
5231 * the rectangle defined by provided top-left and bottom-right corners.
5232 *
5233 * @param point point to be checked.
5234 * @param topLeft top-left corner of rectangle.
5235 * @param bottomRight bottom-right corner of rectangle.
5236 * @return true if point is locus to top side of rectangle, false
5237 * otherwise.
5238 */
5239 public static boolean isLocusToTopSide(
5240 final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
5241 return isLocusToTopSide(point, topLeft, bottomRight, DEFAULT_THRESHOLD);
5242 }
5243
5244 /**
5245 * Indicates whether provided point coordinates belong to the locus of the
5246 * top side of the rectangle defined by provided rectangle center and size.
5247 *
5248 * @param x x coordinate of point to be checked.
5249 * @param y y coordinate of point to be checked.
5250 * @param center center of rectangle.
5251 * @param width width of rectangle.
5252 * @param height height of rectangle.
5253 * @return true if point is locus to top side of rectangle, false
5254 * otherwise.
5255 */
5256 public static boolean isLocusToTopSide(
5257 final double x, final double y, final Point2D center, final double width, final double height) {
5258 return isLocusToTopSide(x, y, center, width, height, DEFAULT_THRESHOLD);
5259 }
5260
5261 /**
5262 * Indicates whether provided point belongs to the locus of the top side
5263 * of the rectangle defined by provided rectangle center and size.
5264 *
5265 * @param point point to be checked.
5266 * @param center center of rectangle.
5267 * @param width width of rectangle.
5268 * @param height height of rectangle.
5269 * @return true if point is locus to top side of rectangle, false
5270 * otherwise.
5271 */
5272 public static boolean isLocusToTopSide(
5273 final Point2D point, final Point2D center, final double width, final double height) {
5274 return isLocusToTopSide(point, center, width, height, DEFAULT_THRESHOLD);
5275 }
5276
5277 /**
5278 * Indicates whether provided point coordinates belong to the locus of the
5279 * top side of this rectangle.
5280 *
5281 * @param x x coordinate of point to be checked.
5282 * @param y y coordinate of point to be checked.
5283 * @return true if point is locus to top side of rectangle, false
5284 * otherwise.
5285 */
5286 public boolean isLocusToTopSide(final double x, final double y) {
5287 return isLocusToTopSide(x, y, DEFAULT_THRESHOLD);
5288 }
5289
5290 /**
5291 * Indicates whether provided point belongs to the locus of the top side of
5292 * this rectangle.
5293 *
5294 * @param point point to be checked.
5295 * @return true if point is locus to top side of rectangle, false
5296 * otherwise.
5297 */
5298 public boolean isLocusToTopSide(final Point2D point) {
5299 return isLocusToTopSide(point, DEFAULT_THRESHOLD);
5300 }
5301
5302 /**
5303 * Indicates whether provided point coordinates belong to the locus of the
5304 * right side of the rectangle defined by provided top-left and bottom-right
5305 * corners up to a certain threshold.
5306 *
5307 * @param x x coordinate of point to be checked.
5308 * @param y y coordinate of point to be checked.
5309 * @param left left coordinate of rectangle.
5310 * @param top top coordinate of rectangle.
5311 * @param right right coordinate of rectangle.
5312 * @param bottom bottom coordinate of rectangle.
5313 * @param threshold threshold to use as a margin to determine whether
5314 * point is locus to right side of rectangle.
5315 * @return true if point is locus to right side of rectangle, false
5316 * otherwise.
5317 * @throws IllegalArgumentException if provided threshold is negative.
5318 */
5319 public static boolean isLocusToRightSide(
5320 final double x, final double y, final double left, final double top, final double right,
5321 final double bottom, final double threshold) {
5322 if (threshold < 0.0) {
5323 throw new IllegalArgumentException();
5324 }
5325
5326 return getDistanceToRightSide(x, y, left, top, right, bottom) <= threshold;
5327 }
5328
5329 /**
5330 * Indicates whether provided point belongs to the locus of the right side
5331 * of the rectangle defined by provided top-left and bottom-right corners up
5332 * to a certain threshold.
5333 *
5334 * @param point point to be checked.
5335 * @param left left coordinate of rectangle.
5336 * @param top top coordinate of rectangle.
5337 * @param right right coordinate of rectangle.
5338 * @param bottom bottom coordinate of rectangle.
5339 * @param threshold threshold to use as a margin to determine whether
5340 * point is locus to right side of rectangle.
5341 * @return true if point is locus to right side of rectangle, false
5342 * otherwise.
5343 * @throws IllegalArgumentException if provided threshold is negative.
5344 */
5345 public static boolean isLocusToRightSide(
5346 final Point2D point, final double left, final double top, final double right, final double bottom,
5347 final double threshold) {
5348 return isLocusToRightSide(point.getInhomX(), point.getInhomY(), left, top, right, bottom, threshold);
5349 }
5350
5351 /**
5352 * Indicates whether provided point coordinates belong to the locus of the
5353 * right side of the rectangle defined by provided top-left and bottom-right
5354 * corners up to a certain threshold.
5355 *
5356 * @param x x coordinate of point to be checked.
5357 * @param y y coordinate of point to be checked.
5358 * @param topLeft top-left corner of rectangle.
5359 * @param bottomRight bottom-right corner of rectangle.
5360 * @param threshold threshold to use as a margin to determine whether point
5361 * is locus to right side of rectangle.
5362 * @return true if point is locus to right side of rectangle, false
5363 * otherwise.
5364 * @throws IllegalArgumentException if provided threshold is negative.
5365 */
5366 public static boolean isLocusToRightSide(
5367 final double x, final double y, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
5368 return isLocusToRightSide(x, y, topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(),
5369 bottomRight.getInhomY(), threshold);
5370 }
5371
5372 /**
5373 * Indicates whether provided point belongs to the locus of the right side
5374 * of the rectangle defined by provided top-left and bottom-right corners up
5375 * to a certain threshold.
5376 *
5377 * @param point point to be checked.
5378 * @param topLeft top-left corner of rectangle.
5379 * @param bottomRight bottom-right corner of rectangle.
5380 * @param threshold threshold to use as a margin to determine whether point
5381 * is locus to right side of rectangle.
5382 * @return true if point is locus to right side of rectangle, false
5383 * otherwise.
5384 * @throws IllegalArgumentException if provided threshold is negative.
5385 */
5386 public static boolean isLocusToRightSide(
5387 final Point2D point, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
5388 return isLocusToRightSide(point.getInhomX(), point.getInhomY(), topLeft, bottomRight, threshold);
5389 }
5390
5391 /**
5392 * Indicates whether provided point coordinates belong to the locus of the
5393 * right side of the rectangle defined by provided rectangle center and size
5394 * up to a certain threshold.
5395 *
5396 * @param x x coordinate of point to be checked.
5397 * @param y y coordinate of point to be checked.
5398 * @param center center of rectangle.
5399 * @param width width of rectangle.
5400 * @param height height of rectangle.
5401 * @param threshold threshold to use as a margin to determine whether point
5402 * is locus to right side of rectangle.
5403 * @return true if point is locus to right side of rectangle, false
5404 * otherwise.
5405 * @throws IllegalArgumentException if provided threshold is negative.
5406 */
5407 public static boolean isLocusToRightSide(
5408 final double x, final double y, final Point2D center, final double width, final double height,
5409 final double threshold) {
5410 final var halfWidth = width / 2.0;
5411 final var halfHeight = height / 2.0;
5412 final var centerX = center.getInhomX();
5413 final var centerY = center.getInhomY();
5414 return isLocusToRightSide(x, y, centerX - halfWidth, centerY - halfHeight, centerX + halfWidth,
5415 centerY + halfHeight, threshold);
5416 }
5417
5418 /**
5419 * Indicates whether provided point belongs to the locus of the right side
5420 * of the rectangle defined by provided rectangle center and size up to a
5421 * certain threshold.
5422 *
5423 * @param point point to be checked.
5424 * @param center center of rectangle.
5425 * @param width width of rectangle.
5426 * @param height height of rectangle.
5427 * @param threshold threshold to use as a margin to determine whether point
5428 * is locus to right side of rectangle.
5429 * @return true if point is locus to right side of rectangle, false
5430 * otherwise.
5431 * @throws IllegalArgumentException if provided threshold is negative.
5432 */
5433 public static boolean isLocusToRightSide(
5434 final Point2D point, final Point2D center, final double width, final double height,
5435 final double threshold) {
5436 return isLocusToRightSide(point.getInhomX(), point.getInhomY(), center, width, height, threshold);
5437 }
5438
5439 /**
5440 * Indicates whether provided point coordinates belong to the locus of the
5441 * right side of this rectangle.
5442 *
5443 * @param x x coordinate of point to be checked.
5444 * @param y y coordinate of point to be checked.
5445 * @param threshold threshold to use as a margin to determine whether point
5446 * is locus to right side of rectangle.
5447 * @return true if point is locus to right side of rectangle, false
5448 * otherwise.
5449 * @throws IllegalArgumentException if provided threshold is negative.
5450 */
5451 public boolean isLocusToRightSide(final double x, final double y, final double threshold) {
5452 return isLocusToRightSide(x, y, topLeft, bottomRight, threshold);
5453 }
5454
5455 /**
5456 * Indicates whether provided point belongs to the locus of the right side
5457 * of this rectangle.
5458 *
5459 * @param point point to be checked.
5460 * @param threshold threshold to use as a margin to determine whether point
5461 * is locus to right side of rectangle.
5462 * @return true if point is locus to right side of rectangle, false
5463 * otherwise.
5464 * @throws IllegalArgumentException if provided threshold is negative.
5465 */
5466 public boolean isLocusToRightSide(final Point2D point, final double threshold) {
5467 return isLocusToRightSide(point, topLeft, bottomRight, threshold);
5468 }
5469
5470 /**
5471 * Indicates whether provided point coordinates belong to the locus of the
5472 * right side of the rectangle defined by provided top-left and bottom-right
5473 * corners.
5474 *
5475 * @param x x coordinate of point to be checked.
5476 * @param y y coordinate of point to be checked.
5477 * @param left left coordinate of rectangle.
5478 * @param top top coordinate of rectangle.
5479 * @param right right coordinate of rectangle.
5480 * @param bottom bottom coordinate of rectangle.
5481 * @return true if point is locus to right side of rectangle, false
5482 * otherwise.
5483 */
5484 public static boolean isLocusToRightSide(
5485 final double x, final double y, final double left, final double top, final double right,
5486 final double bottom) {
5487 return isLocusToRightSide(x, y, left, top, right, bottom, DEFAULT_THRESHOLD);
5488 }
5489
5490 /**
5491 * Indicates whether provided point belongs to the locus of the right side
5492 * of the rectangle defined by provided top-left and bottom-right corners.
5493 *
5494 * @param point point to be checked.
5495 * @param left left coordinate of rectangle.
5496 * @param top top coordinate of rectangle.
5497 * @param right right coordinate of rectangle.
5498 * @param bottom bottom coordinate of rectangle.
5499 * @return true if point is locus to right side of rectangle, false
5500 * otherwise.
5501 */
5502 public static boolean isLocusToRightSide(
5503 final Point2D point, final double left, final double top, final double right, final double bottom) {
5504 return isLocusToRightSide(point, left, top, right, bottom, DEFAULT_THRESHOLD);
5505 }
5506
5507 /**
5508 * Indicates whether provided point coordinates belong to the locus of the
5509 * right side of the rectangle defined by provided top-left and bottom-right
5510 * corners up to a certain threshold.
5511 *
5512 * @param x x coordinate of point to be checked.
5513 * @param y y coordinate of point to be checked.
5514 * @param topLeft top-left corner of rectangle.
5515 * @param bottomRight bottom-right corner of rectangle.
5516 * @return true if point is locus to right side of rectangle, false
5517 * otherwise.
5518 */
5519 public static boolean isLocusToRightSide(
5520 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
5521 return isLocusToRightSide(x, y, topLeft, bottomRight, DEFAULT_THRESHOLD);
5522 }
5523
5524 /**
5525 * Indicates whether provided point belongs to the locus of the right side
5526 * of the rectangle defined by provided top-left and bottom-right corners.
5527 *
5528 * @param point point to be checked.
5529 * @param topLeft top-left corner of rectangle.
5530 * @param bottomRight bottom-right corner of rectangle.
5531 * @return true if point is locus to right side of rectangle, false
5532 * otherwise.
5533 */
5534 public static boolean isLocusToRightSide(
5535 final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
5536 return isLocusToRightSide(point, topLeft, bottomRight, DEFAULT_THRESHOLD);
5537 }
5538
5539 /**
5540 * Indicates whether provided point coordinates belong to the locus of the
5541 * right side of the rectangle defined by provided rectangle center and
5542 * size.
5543 *
5544 * @param x x coordinate of point to be checked.
5545 * @param y y coordinate of point to be checked.
5546 * @param center center of rectangle.
5547 * @param width width of rectangle.
5548 * @param height height of rectangle.
5549 * @return true if point is locus to right side of rectangle, false
5550 * otherwise.
5551 */
5552 public static boolean isLocusToRightSide(
5553 final double x, final double y, final Point2D center, final double width, final double height) {
5554 return isLocusToRightSide(x, y, center, width, height, DEFAULT_THRESHOLD);
5555 }
5556
5557 /**
5558 * Indicates whether provided point belongs to the locus of the right side
5559 * of the rectangle defined by provided rectangle center and size.
5560 *
5561 * @param point point to be checked.
5562 * @param center center of rectangle.
5563 * @param width width of rectangle.
5564 * @param height height of rectangle.
5565 * @return true if point is locus to right side of rectangle, false
5566 * otherwise.
5567 */
5568 public static boolean isLocusToRightSide(
5569 final Point2D point, final Point2D center, final double width, final double height) {
5570 return isLocusToRightSide(point, center, width, height, DEFAULT_THRESHOLD);
5571 }
5572
5573 /**
5574 * Indicates whether provided point coordinates belong to the locus of the
5575 * right side of this rectangle.
5576 *
5577 * @param x x coordinate of point to be checked.
5578 * @param y y coordinate of point to be checked.
5579 * @return true if point is locus to right side of rectangle, false
5580 * otherwise.
5581 */
5582 public boolean isLocusToRightSide(final double x, final double y) {
5583 return isLocusToRightSide(x, y, DEFAULT_THRESHOLD);
5584 }
5585
5586 /**
5587 * Indicates whether provided point belongs to the locus of the right side
5588 * of this rectangle.
5589 *
5590 * @param point point to be checked.
5591 * @return true if point is locus to right side of rectangle, false
5592 * otherwise.
5593 */
5594 public boolean isLocusToRightSide(final Point2D point) {
5595 return isLocusToRightSide(point, DEFAULT_THRESHOLD);
5596 }
5597
5598 /**
5599 * Indicates whether provided point coordinates belong to the locus of the
5600 * bottom side of the rectangle defined by provided top-left and
5601 * bottom-right corners up to a certain threshold.
5602 *
5603 * @param x x coordinate of point to be checked.
5604 * @param y y coordinate of point to be checked.
5605 * @param left left coordinate of rectangle.
5606 * @param top top coordinate of rectangle.
5607 * @param right right coordinate of rectangle.
5608 * @param bottom bottom coordinate of rectangle.
5609 * @param threshold threshold to use as a margin to determine whether
5610 * point is locus to right side of rectangle.
5611 * @return true if point is locus to bottom side of rectangle, false
5612 * otherwise.
5613 * @throws IllegalArgumentException if provided threshold is negative.
5614 */
5615 public static boolean isLocusToBottomSide(
5616 final double x, final double y, final double left, final double top, final double right,
5617 final double bottom, final double threshold) {
5618 if (threshold < 0.0) {
5619 throw new IllegalArgumentException("threshold must be positive");
5620 }
5621
5622 return getDistanceToBottomSide(x, y, left, top, right, bottom) <= threshold;
5623 }
5624
5625 /**
5626 * Indicates whether provided point belongs to the locus of the bottom side
5627 * of the rectangle defined by provided top-left and bottom-right corners up
5628 * to a certain threshold.
5629 *
5630 * @param point point to be checked.
5631 * @param left left coordinate of rectangle.
5632 * @param top top coordinate of rectangle.
5633 * @param right right coordinate of rectangle.
5634 * @param bottom bottom coordinate of rectangle.
5635 * @param threshold threshold to use as a margin to determine whether
5636 * point is locus to bottom side of rectangle.
5637 * @return true if point is locus to bottom side of rectangle, false
5638 * otherwise.
5639 * @throws IllegalArgumentException if provided threshold is negative.
5640 */
5641 public static boolean isLocusToBottomSide(
5642 final Point2D point, final double left, final double top, final double right, final double bottom,
5643 final double threshold) {
5644 return isLocusToBottomSide(point.getInhomX(), point.getInhomY(), left, top, right, bottom, threshold);
5645 }
5646
5647 /**
5648 * Indicates whether provided point coordinates belong to the locus of the
5649 * bottom side of the rectangle defined by provided top-left and
5650 * bottom-right
5651 * corners up to a certain threshold.
5652 *
5653 * @param x x coordinate of point to be checked.
5654 * @param y y coordinate of point to be checked.
5655 * @param topLeft top-left corner of rectangle.
5656 * @param bottomRight bottom-right corner of rectangle.
5657 * @param threshold threshold to use as a margin to determine whether point
5658 * is locus to bottom side of rectangle.
5659 * @return true if point is locus to bottom side of rectangle, false
5660 * otherwise.
5661 * @throws IllegalArgumentException if provided threshold is negative.
5662 */
5663 public static boolean isLocusToBottomSide(
5664 final double x, final double y, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
5665 return isLocusToBottomSide(x, y, topLeft.getInhomX(), topLeft.getInhomY(), bottomRight.getInhomX(),
5666 bottomRight.getInhomY(), threshold);
5667 }
5668
5669 /**
5670 * Indicates whether provided point belongs to the locus of the bottom side
5671 * of the rectangle defined by provided top-left and bottom-right corners up
5672 * to a certain threshold.
5673 *
5674 * @param point point to be checked.
5675 * @param topLeft top-left corner of rectangle.
5676 * @param bottomRight bottom-right corner of rectangle.
5677 * @param threshold threshold to use as a margin to determine whether point
5678 * is locus to bottom side of rectangle.
5679 * @return true if point is locus to bottom side of rectangle, false
5680 * otherwise.
5681 * @throws IllegalArgumentException if provided threshold is negative.
5682 */
5683 public static boolean isLocusToBottomSide(
5684 final Point2D point, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
5685 return isLocusToBottomSide(point.getInhomX(), point.getInhomY(), topLeft, bottomRight, threshold);
5686 }
5687
5688 /**
5689 * Indicates whether provided point coordinates belong to the locus of the
5690 * bottom side of the rectangle defined by provided rectangle center and size
5691 * up to a certain threshold.
5692 *
5693 * @param x x coordinate of point to be checked.
5694 * @param y y coordinate of point to be checked.
5695 * @param center center of rectangle.
5696 * @param width width of rectangle.
5697 * @param height height of rectangle.
5698 * @param threshold threshold to use as a margin to determine whether point
5699 * is locus to bottom side of rectangle.
5700 * @return true if point is locus to bottom side of rectangle, false
5701 * otherwise.
5702 * @throws IllegalArgumentException if provided threshold is negative.
5703 */
5704 public static boolean isLocusToBottomSide(
5705 final double x, final double y, final Point2D center, final double width, final double height,
5706 final double threshold) {
5707 final var halfWidth = width / 2.0;
5708 final var halfHeight = height / 2.0;
5709 final var centerX = center.getInhomX();
5710 final var centerY = center.getInhomY();
5711 return isLocusToBottomSide(x, y, centerX - halfWidth, centerY - halfHeight, centerX + halfWidth,
5712 centerY + halfHeight, threshold);
5713 }
5714
5715 /**
5716 * Indicates whether provided point belongs to the locus of the bottom side
5717 * of the rectangle defined by provided rectangle center and size up to a
5718 * certain threshold.
5719 *
5720 * @param point point to be checked.
5721 * @param center center of rectangle.
5722 * @param width width of rectangle.
5723 * @param height height of rectangle.
5724 * @param threshold threshold to use as a margin to determine whether point
5725 * is locus to bottom side of rectangle.
5726 * @return true if point is locus to bottom side of rectangle, false
5727 * otherwise.
5728 * @throws IllegalArgumentException if provided threshold is negative.
5729 */
5730 public static boolean isLocusToBottomSide(
5731 final Point2D point, final Point2D center, final double width, final double height,
5732 final double threshold) {
5733 return isLocusToBottomSide(point.getInhomX(), point.getInhomY(), center, width, height, threshold);
5734 }
5735
5736 /**
5737 * Indicates whether provided point coordinates belong to the locus of the
5738 * bottom side of this rectangle.
5739 *
5740 * @param x x coordinate of point to be checked.
5741 * @param y y coordinate of point to be checked.
5742 * @param threshold threshold to use as a margin to determine whether point
5743 * is locus to bottom side of rectangle.
5744 * @return true if point is locus to bottom side of rectangle, false
5745 * otherwise.
5746 * @throws IllegalArgumentException if provided threshold is negative.
5747 */
5748 public boolean isLocusToBottomSide(final double x, final double y, final double threshold) {
5749 return isLocusToBottomSide(x, y, topLeft, bottomRight, threshold);
5750 }
5751
5752 /**
5753 * Indicates whether provided point belongs to the locus of the bottom side
5754 * of this rectangle.
5755 *
5756 * @param point point to be checked.
5757 * @param threshold threshold to use as a margin to determine whether point
5758 * is locus to bottom side of rectangle.
5759 * @return true if point is locus to bottom side of rectangle, false
5760 * otherwise.
5761 * @throws IllegalArgumentException if provided threshold is negative.
5762 */
5763 public boolean isLocusToBottomSide(final Point2D point, final double threshold) {
5764 return isLocusToBottomSide(point, topLeft, bottomRight, threshold);
5765 }
5766
5767 /**
5768 * Indicates whether provided point coordinates belong to the locus of the
5769 * bottom side of the rectangle defined by provided top-left and
5770 * bottom-right corners.
5771 *
5772 * @param x x coordinate of point to be checked.
5773 * @param y y coordinate of point to be checked.
5774 * @param left left coordinate of rectangle.
5775 * @param top top coordinate of rectangle.
5776 * @param right right coordinate of rectangle.
5777 * @param bottom bottom coordinate of rectangle.
5778 * @return true if point is locus to bottom side of rectangle, false
5779 * otherwise.
5780 */
5781 public static boolean isLocusToBottomSide(
5782 final double x, final double y, final double left, final double top, final double right,
5783 final double bottom) {
5784 return isLocusToBottomSide(x, y, left, top, right, bottom, DEFAULT_THRESHOLD);
5785 }
5786
5787 /**
5788 * Indicates whether provided point belongs to the locus of the bottom side
5789 * of the rectangle defined by provided top-left and bottom-right corners.
5790 *
5791 * @param point point to be checked.
5792 * @param left left coordinate of rectangle.
5793 * @param top top coordinate of rectangle.
5794 * @param right right coordinate of rectangle.
5795 * @param bottom bottom coordinate of rectangle.
5796 * @return true if point is locus to bottom side of rectangle, false
5797 * otherwise.
5798 */
5799 public static boolean isLocusToBottomSide(
5800 final Point2D point, final double left, final double top, final double right, final double bottom) {
5801 return isLocusToBottomSide(point, left, top, right, bottom, DEFAULT_THRESHOLD);
5802 }
5803
5804 /**
5805 * Indicates whether provided point coordinates belong to the locus of the
5806 * bottom side of the rectangle defined by provided top-left and
5807 * bottom-right corners up to a certain threshold.
5808 *
5809 * @param x x coordinate of point to be checked.
5810 * @param y y coordinate of point to be checked.
5811 * @param topLeft top-left corner of rectangle.
5812 * @param bottomRight bottom-right corner of rectangle.
5813 * @return true if point is locus to bottom side of rectangle, false
5814 * otherwise.
5815 */
5816 public static boolean isLocusToBottomSide(
5817 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
5818 return isLocusToBottomSide(x, y, topLeft, bottomRight, DEFAULT_THRESHOLD);
5819 }
5820
5821 /**
5822 * Indicates whether provided point belongs to the locus of the bottom side
5823 * of the rectangle defined by provided top-left and bottom-right corners.
5824 *
5825 * @param point point to be checked.
5826 * @param topLeft top-left corner of rectangle.
5827 * @param bottomRight bottom-right corner of rectangle.
5828 * @return true if point is locus to bottom side of rectangle, false
5829 * otherwise.
5830 */
5831 public static boolean isLocusToBottomSide(
5832 final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
5833 return isLocusToBottomSide(point, topLeft, bottomRight, DEFAULT_THRESHOLD);
5834 }
5835
5836 /**
5837 * Indicates whether provided point coordinates belong to the locus of the
5838 * bottom side of the rectangle defined by provided rectangle center and
5839 * size.
5840 *
5841 * @param x x coordinate of point to be checked.
5842 * @param y y coordinate of point to be checked.
5843 * @param center center of rectangle.
5844 * @param width width of rectangle.
5845 * @param height height of rectangle.
5846 * @return true if point is locus to bottom side of rectangle, false
5847 * otherwise.
5848 */
5849 public static boolean isLocusToBottomSide(
5850 final double x, final double y, final Point2D center, final double width, final double height) {
5851 return isLocusToBottomSide(x, y, center, width, height, DEFAULT_THRESHOLD);
5852 }
5853
5854 /**
5855 * Indicates whether provided point belongs to the locus of the bottom side
5856 * of the rectangle defined by provided rectangle center and size.
5857 *
5858 * @param point point to be checked.
5859 * @param center center of rectangle.
5860 * @param width width of rectangle.
5861 * @param height height of rectangle.
5862 * @return true if point is locus to bottom side of rectangle, false
5863 * otherwise.
5864 */
5865 public static boolean isLocusToBottomSide(
5866 final Point2D point, final Point2D center, final double width, final double height) {
5867 return isLocusToBottomSide(point, center, width, height, DEFAULT_THRESHOLD);
5868 }
5869
5870 /**
5871 * Indicates whether provided point coordinates belong to the locus of the
5872 * bottom side of this rectangle.
5873 *
5874 * @param x x coordinate of point to be checked.
5875 * @param y y coordinate of point to be checked.
5876 * @return true if point is locus to bottom side of rectangle, false
5877 * otherwise.
5878 */
5879 public boolean isLocusToBottomSide(final double x, final double y) {
5880 return isLocusToBottomSide(x, y, DEFAULT_THRESHOLD);
5881 }
5882
5883 /**
5884 * Indicates whether provided point belongs to the locus of the bottom side
5885 * of this rectangle.
5886 *
5887 * @param point point to be checked.
5888 * @return true if point is locus to bottom side of rectangle, false
5889 * otherwise.
5890 */
5891 public boolean isLocusToBottomSide(final Point2D point) {
5892 return isLocusToBottomSide(point, DEFAULT_THRESHOLD);
5893 }
5894
5895 /**
5896 * Indicates whether provided point coordinates belong to the locus of the
5897 * rectangle defined by provided top-left and bottom-right corners up to a
5898 * certain threshold.
5899 *
5900 * @param x x coordinate of point to be checked.
5901 * @param y y coordinate of point to be checked.
5902 * @param left left coordinate of rectangle.
5903 * @param top top coordinate of rectangle.
5904 * @param right right coordinate of rectangle.
5905 * @param bottom bottom coordinate of rectangle.
5906 * @param threshold threshold to use as a margin to determine whether
5907 * point is locus of rectangle.
5908 * @return true if point is locus of rectangle, false otherwise.
5909 * @throws IllegalArgumentException if provided threshold is negative.
5910 */
5911 public static boolean isLocus(
5912 final double x, final double y, final double left, final double top, final double right,
5913 final double bottom, final double threshold) {
5914 if (threshold < 0.0) {
5915 throw new IllegalArgumentException("threshold must be positive");
5916 }
5917
5918 return isLocusToLeftSide(x, y, left, top, right, bottom, threshold)
5919 || isLocusToTopSide(x, y, left, top, right, bottom, threshold)
5920 || isLocusToRightSide(x, y, left, top, right, bottom, threshold)
5921 || isLocusToBottomSide(x, y, left, top, right, bottom, threshold);
5922 }
5923
5924 /**
5925 * Indicates whether provided point belongs to the locus of the rectangle
5926 * defined by provided top-left and bottom-right corners up to a certain
5927 * threshold.
5928 *
5929 * @param point point to be checked.
5930 * @param left left coordinate of rectangle.
5931 * @param top top coordinate of rectangle.
5932 * @param right right coordinate of rectangle.
5933 * @param bottom bottom coordinate of rectangle.
5934 * @param threshold threshold to use as a margin to determine whether
5935 * point is locus of rectangle.
5936 * @return true if point is locus of rectangle, false otherwise.
5937 * @throws IllegalArgumentException if provided threshold is negative.
5938 */
5939 public static boolean isLocus(
5940 final Point2D point, final double left, final double top, final double right, final double bottom,
5941 final double threshold) {
5942 return isLocusToLeftSide(point, left, top, right, bottom, threshold)
5943 || isLocusToTopSide(point, left, top, right, bottom, threshold)
5944 || isLocusToRightSide(point, left, top, right, bottom, threshold)
5945 || isLocusToBottomSide(point, left, top, right, bottom, threshold);
5946 }
5947
5948 /**
5949 * Indicates whether provided point coordinates belong to the locus of the
5950 * rectangle defined by provided top-left and bottom-right corners up to a
5951 * certain threshold.
5952 *
5953 * @param x x coordinate of point to be checked.
5954 * @param y y coordinate of point to be checked.
5955 * @param topLeft top-left corner of rectangle.
5956 * @param bottomRight bottom-right corner of rectangle.
5957 * @param threshold threshold to use as a margin to determine whether
5958 * point is locus of rectangle.
5959 * @return true if point is locus of rectangle, false otherwise.
5960 * @throws IllegalArgumentException if provided threshold is negative.
5961 */
5962 public static boolean isLocus(
5963 final double x, final double y, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
5964 return isLocusToLeftSide(x, y, topLeft, bottomRight, threshold)
5965 || isLocusToTopSide(x, y, topLeft, bottomRight, threshold)
5966 || isLocusToRightSide(x, y, topLeft, bottomRight, threshold)
5967 || isLocusToBottomSide(x, y, topLeft, bottomRight, threshold);
5968 }
5969
5970 /**
5971 * Indicates whether provided point belongs to the locus of the rectangle
5972 * defined by provided top-left and bottom-right corners up to a certain
5973 * threshold.
5974 *
5975 * @param point point to be checked.
5976 * @param topLeft top-left corner of rectangle.
5977 * @param bottomRight bottom-right corner of rectangle.
5978 * @param threshold threshold to use as a margin to determine whether
5979 * point is locus of rectangle.
5980 * @return true if point is locus of rectangle, false otherwise.
5981 * @throws IllegalArgumentException if provided threshold is negative.
5982 */
5983 public static boolean isLocus(
5984 final Point2D point, final Point2D topLeft, final Point2D bottomRight, final double threshold) {
5985 return isLocusToLeftSide(point, topLeft, bottomRight, threshold)
5986 || isLocusToTopSide(point, topLeft, bottomRight, threshold)
5987 || isLocusToRightSide(point, topLeft, bottomRight, threshold)
5988 || isLocusToBottomSide(point, topLeft, bottomRight, threshold);
5989 }
5990
5991 /**
5992 * Indicates whether provided point coordinates belong to the locus of the
5993 * rectangle defined by provided center and size up to a certain threshold.
5994 *
5995 * @param x x coordinate of point to be checked.
5996 * @param y y coordinate of point to be checked.
5997 * @param center center of rectangle.
5998 * @param width width of rectangle.
5999 * @param height height of rectangle.
6000 * @param threshold threshold to use as a margin to determine whether
6001 * point is locus of rectangle.
6002 * @return true if point is locus of rectangle, false otherwise.
6003 * @throws IllegalArgumentException if provided threshold is negative.
6004 */
6005 public static boolean isLocus(
6006 final double x, final double y, final Point2D center, final double width, final double height,
6007 final double threshold) {
6008 return isLocusToLeftSide(x, y, center, width, height, threshold)
6009 || isLocusToTopSide(x, y, center, width, height, threshold)
6010 || isLocusToRightSide(x, y, center, width, height, threshold)
6011 || isLocusToBottomSide(x, y, center, width, height, threshold);
6012 }
6013
6014 /**
6015 * Indicates whether provided point belongs to the locus of the rectangle
6016 * defined by provided center and size up to a certain threshold.
6017 *
6018 * @param point point to be checked.
6019 * @param center center of rectangle.
6020 * @param width width of rectangle.
6021 * @param height height of rectangle.
6022 * @param threshold threshold to use as a margin to determine whether point
6023 * is locus of rectangle.
6024 * @return true if point is locus of rectangle, false otherwise.
6025 * @throws IllegalArgumentException if provided threshold is negative.
6026 */
6027 public static boolean isLocus(
6028 final Point2D point, final Point2D center, final double width, final double height,
6029 final double threshold) {
6030 return isLocusToLeftSide(point, center, width, height, threshold)
6031 || isLocusToTopSide(point, center, width, height, threshold)
6032 || isLocusToRightSide(point, center, width, height, threshold)
6033 || isLocusToBottomSide(point, center, width, height, threshold);
6034 }
6035
6036 /**
6037 * Indicates whether provided point coordinates belong to the locus of this
6038 * rectangle up to a certain threshold.
6039 *
6040 * @param x x coordinate of point to be checked.
6041 * @param y y coordinate of point to be checked.
6042 * @param threshold threshold to use as a margin to determine whether
6043 * point is locus of rectangle.
6044 * @return true if point is locus of rectangle, false otherwise.
6045 * @throws IllegalArgumentException if provided threshold is negative.
6046 */
6047 public boolean isLocus(final double x, final double y, final double threshold) {
6048 return isLocus(x, y, topLeft, bottomRight, threshold);
6049 }
6050
6051 /**
6052 * Indicates whether provided point coordinates belong to the locus of this
6053 * rectangle up to a certain threshold.
6054 *
6055 * @param point point to be checked.
6056 * @param threshold threshold to use as a margin to determine whether
6057 * point is locus of rectangle.
6058 * @return true if point is locus of rectangle, false otherwise.
6059 * @throws IllegalArgumentException if provided threshold is negative.
6060 */
6061 public boolean isLocus(final Point2D point, final double threshold) {
6062 return isLocus(point, topLeft, bottomRight, threshold);
6063 }
6064
6065 /**
6066 * Indicates whether provided point coordinates belong to the locus of the
6067 * rectangle defined by provided top-left and bottom-right corners up to a
6068 * certain threshold.
6069 *
6070 * @param x x coordinate of point to be checked.
6071 * @param y y coordinate of point to be checked.
6072 * @param left left coordinate of rectangle.
6073 * @param top top coordinate of rectangle.
6074 * @param right right coordinate of rectangle.
6075 * @param bottom bottom coordinate of rectangle.
6076 * @return true if point is locus of rectangle, false otherwise.
6077 */
6078 public static boolean isLocus(
6079 final double x, final double y, final double left, final double top, final double right,
6080 final double bottom) {
6081 return isLocus(x, y, left, top, right, bottom, DEFAULT_THRESHOLD);
6082 }
6083
6084 /**
6085 * Indicates whether provided point belongs to the locus of the rectangle
6086 * defined by provided top-left and bottom-right corners.
6087 *
6088 * @param point point to be checked.
6089 * @param left left coordinate of rectangle.
6090 * @param top top coordinate of rectangle.
6091 * @param right right coordinate of rectangle.
6092 * @param bottom bottom coordinate of rectangle.
6093 * @return true if point is locus of rectangle, false otherwise.
6094 */
6095 public static boolean isLocus(
6096 final Point2D point, final double left, final double top, final double right, final double bottom) {
6097 return isLocus(point, left, top, right, bottom, DEFAULT_THRESHOLD);
6098 }
6099
6100 /**
6101 * Indicates whether provided point coordinates belong to the locus of the
6102 * rectangle defined by provided top-left and bottom-right corners.
6103 *
6104 * @param x x coordinate of point to be checked.
6105 * @param y y coordinate of point to be checked.
6106 * @param topLeft top-left corner of rectangle.
6107 * @param bottomRight bottom-right corner of rectangle.
6108 * @return true if point is locus of rectangle, false otherwise.
6109 */
6110 public static boolean isLocus(
6111 final double x, final double y, final Point2D topLeft, final Point2D bottomRight) {
6112 return isLocus(x, y, topLeft, bottomRight, DEFAULT_THRESHOLD);
6113 }
6114
6115 /**
6116 * Indicates whether provided point belongs to the locus of the rectangle
6117 * defined by provided top-left and bottom-right corners.
6118 *
6119 * @param point point to be checked.
6120 * @param topLeft top-left corner of rectangle.
6121 * @param bottomRight bottom-right corner of rectangle.
6122 * @return true if point is locus of rectangle, false otherwise.
6123 */
6124 public static boolean isLocus(final Point2D point, final Point2D topLeft, final Point2D bottomRight) {
6125 return isLocus(point, topLeft, bottomRight, DEFAULT_THRESHOLD);
6126 }
6127
6128 /**
6129 * Indicates whether provided point coordinates belong to the locus of the
6130 * rectangle defined by provided center and size.
6131 *
6132 * @param x x coordinate of point to be checked.
6133 * @param y y coordinate of point to be checked.
6134 * @param center center of rectangle.
6135 * @param width width of rectangle.
6136 * @param height height of rectangle.
6137 * @return true if point is locus of rectangle, false otherwise.
6138 */
6139 public static boolean isLocus(
6140 final double x, final double y, final Point2D center, final double width, final double height) {
6141 return isLocus(x, y, center, width, height, DEFAULT_THRESHOLD);
6142 }
6143
6144 /**
6145 * Indicates whether provided point belongs to the locus of the rectangle
6146 * defined by provided center and size.
6147 *
6148 * @param point point to be checked.
6149 * @param center center of rectangle.
6150 * @param width width of rectangle.
6151 * @param height height of rectangle.
6152 * @return true if point is locus of rectangle, false otherwise.
6153 */
6154 public static boolean isLocus(
6155 final Point2D point, final Point2D center, final double width, final double height) {
6156 return isLocus(point, center, width, height, DEFAULT_THRESHOLD);
6157 }
6158
6159 /**
6160 * Indicates whether provided point coordinates belong to the locus of this
6161 * rectangle up to a certain threshold.
6162 *
6163 * @param x x coordinate of point to be checked.
6164 * @param y y coordinate of point to be checked.
6165 * @return true if point is locus of rectangle, false otherwise.
6166 */
6167 public boolean isLocus(final double x, final double y) {
6168 return isLocus(x, y, DEFAULT_THRESHOLD);
6169 }
6170
6171 /**
6172 * Indicates whether provided point coordinates belong to the locus of this
6173 * rectangle.
6174 *
6175 * @param point point to be checked.
6176 * @return true if point is locus of rectangle, false otherwise.
6177 */
6178 public boolean isLocus(final Point2D point) {
6179 return isLocus(point, DEFAULT_THRESHOLD);
6180 }
6181 }