Updated readability of the code.
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / geometry / Rectangle.java
1 /*
2  * Sixth 3D engine. Author: Svjatoslav Agejenko.
3  * This project is released under Creative Commons Zero (CC0) license.
4  */
5 package eu.svjatoslav.sixth.e3d.geometry;
6
7 import static java.lang.Math.abs;
8 import static java.lang.Math.min;
9
10 /**
11  * Rectangle class.
12  */
13 public class Rectangle {
14
15     public Point2D p1, p2;
16
17     public Rectangle(final double size) {
18         p2 = new Point2D(size / 2, size / 2);
19         p1 = p2.clone().invert();
20     }
21
22     public Rectangle(final Point2D p1, final Point2D p2) {
23         this.p1 = p1;
24         this.p2 = p2;
25     }
26
27     public double getHeight() {
28         return abs(p1.y - p2.y);
29     }
30
31     public double getLowerX() {
32         return min(p1.x, p2.x);
33     }
34
35     public double getLowerY() {
36         return min(p1.y, p2.y);
37     }
38
39     public double getWidth() {
40         return abs(p1.x - p2.x);
41     }
42
43 }