Changed license to Creative Commons Zero (CC0).
[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 *
6  */
7
8
9 package eu.svjatoslav.sixth.e3d.geometry;
10
11 public class Rectangle {
12
13     public Point2D p1, p2;
14
15     public Rectangle(final double size) {
16         p2 = new Point2D(size / 2, size / 2);
17         p1 = p2.clone().invert();
18     }
19
20     public Rectangle(final Point2D p1, final Point2D p2) {
21         this.p1 = p1;
22         this.p2 = p2;
23     }
24
25     public double getHeight() {
26         return Math.abs(p1.y - p2.y);
27     }
28
29     public double getLowerX() {
30         if (p1.x < p2.x)
31             return p1.x;
32         return p2.x;
33     }
34
35     public double getLowerY() {
36         if (p1.y < p2.y)
37             return p1.y;
38         return p2.y;
39     }
40
41     public double getWidth() {
42         return Math.abs(p1.x - p2.x);
43     }
44
45 }