3132333435363738394041
* Gets the center of the specified rectangle. * @param rect * @return */ public static Point2D center(Rectangle2D rect) { Point2D c = new Point2D( (float) (rect.getMinX() + rect.getWidth() / 2), (float) (rect.getMinY() + rect.getHeight() / 2)); return c; }
4546474849505152
* @param rect1 * @param rect2 * @return */ public static Rectangle2D center(Rectangle2D rect1, Rectangle2D rect2) { Point2D c2 = GeoFx.center(rect2); return GeoFx.center(rect1, c2); }
91011121314151617
public class GeoFxTest { @Test public void centerRectangle2D() { Rectangle2D r1 = new Rectangle2D(0, 0, 5, 10); Rectangle2D r2 = GeoFx.center(r1, new Point2D(10, 10)); Assert.assertEquals(new Rectangle2D(7.5, 5, 5, 10), r2); }
18192021222324
@Test public void centerPoint2D() { Rectangle2D r1 = new Rectangle2D(0, 0, 5, 10); Assert.assertEquals(new Point2D(2.5f, 5f), GeoFx.center(r1)); }