Updated copyright
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / geometry / Rectangle.java
1 /*
2  * Sixth 3D engine. Copyright ©2012-2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of version 3 of the GNU Lesser General Public License
6  * or later as published by the Free Software Foundation.
7  *
8  */
9
10
11 package eu.svjatoslav.sixth.e3d.geometry;
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 Math.abs(p1.y - p2.y);
29     }
30
31     public double getLowerX() {
32         if (p1.x < p2.x)
33             return p1.x;
34         return p2.x;
35     }
36
37     public double getLowerY() {
38         if (p1.y < p2.y)
39             return p1.y;
40         return p2.y;
41     }
42
43     public double getWidth() {
44         return Math.abs(p1.x - p2.x);
45     }
46
47 }