X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Fgeometry%2FRectangle.java;h=966d366965834328ac87fe58bc1bb8124d9089d4;hb=7e383c71392e298dde478015129bc739f3eb4e4a;hp=9329180e6ed4dccf1798725832f1e0342845004f;hpb=59baa428fb2d9e7f0fe5423f4cea47f2d6245914;p=sixth-3d.git diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Rectangle.java b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Rectangle.java index 9329180..966d366 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Rectangle.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Rectangle.java @@ -1,47 +1,63 @@ /* - * Sixth 3D engine. Copyright ©2012-2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 3 of the GNU Lesser General Public License - * or later as published by the Free Software Foundation. - * + * Sixth 3D engine. Author: Svjatoslav Agejenko. + * This project is released under Creative Commons Zero (CC0) license. */ - - package eu.svjatoslav.sixth.e3d.geometry; +import static java.lang.Math.abs; +import static java.lang.Math.min; + +/** + * Rectangle class. + */ public class Rectangle { + /** + * Rectangle points. + */ public Point2D p1, p2; + /** + * Creates new rectangle with given size. + * The rectangle will be centered at the origin. + * The rectangle will be square. + * + * @param size The size of the rectangle. + */ public Rectangle(final double size) { p2 = new Point2D(size / 2, size / 2); p1 = p2.clone().invert(); } + /** + * @param p1 The first point of the rectangle. + * @param p2 The second point of the rectangle. + */ public Rectangle(final Point2D p1, final Point2D p2) { this.p1 = p1; this.p2 = p2; } public double getHeight() { - return Math.abs(p1.y - p2.y); + return abs(p1.y - p2.y); } + /** + * @return The leftmost x coordinate of the rectangle. + */ public double getLowerX() { - if (p1.x < p2.x) - return p1.x; - return p2.x; + return min(p1.x, p2.x); } public double getLowerY() { - if (p1.y < p2.y) - return p1.y; - return p2.y; + return min(p1.y, p2.y); } + /** + * @return rectangle width. + */ public double getWidth() { - return Math.abs(p1.x - p2.x); + return abs(p1.x - p2.x); } }