2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.sixth.e3d.geometry;
7 import static java.lang.Math.abs;
8 import static java.lang.Math.min;
13 public class Rectangle {
18 public Point2D p1, p2;
21 * Creates new rectangle with given size.
22 * The rectangle will be centered at the origin.
23 * The rectangle will be square.
25 * @param size The size of the rectangle.
27 public Rectangle(final double size) {
28 p2 = new Point2D(size / 2, size / 2);
29 p1 = p2.clone().invert();
33 * @param p1 The first point of the rectangle.
34 * @param p2 The second point of the rectangle.
36 public Rectangle(final Point2D p1, final Point2D p2) {
41 public double getHeight() {
42 return abs(p1.y - p2.y);
46 * @return The leftmost x coordinate of the rectangle.
48 public double getLowerX() {
49 return min(p1.x, p2.x);
52 public double getLowerY() {
53 return min(p1.y, p2.y);
57 * @return rectangle width.
59 public double getWidth() {
60 return abs(p1.x - p2.x);