A 2D Rectangle
| 8 | * A 2D Rectangle |
| 9 | */ |
| 10 | public class Rect implements Mutable<Rect>, Serializable { |
| 11 | private static final long serialVersionUID = 1L; |
| 12 | |
| 13 | |
| 14 | public float x; |
| 15 | public float y; |
| 16 | public float w; |
| 17 | public float h; |
| 18 | |
| 19 | public Rect(double x, double y, double w, double h) { |
| 20 | this.x = (float)x; |
| 21 | this.y = (float)y; |
| 22 | this.h = (float)h; |
| 23 | this.w = (float)w; |
| 24 | } |
| 25 | |
| 26 | public Rect(float x, float y, float w, float h) { |
| 27 | this.x = (float)x; |
| 28 | this.y = (float)y; |
| 29 | this.h = (float)h; |
| 30 | this.w = (float)w; |
| 31 | } |
| 32 | |
| 33 | public static Rect union(Rect r, Rect rect) { |
| 34 | if (r == null) |
| 35 | return rect; |
| 36 | if (rect == null) |
| 37 | return r; |
| 38 | return r.union(rect); |
| 39 | } |
| 40 | |
| 41 | public static Rect union(Rect r, Vec2 rect) { |
| 42 | if (r == null) |
| 43 | return r; |
| 44 | if (rect == null) |
| 45 | return r; |
| 46 | return r.union(rect); |
| 47 | } |
| 48 | |
| 49 | public Rect union(Rect r) { |
| 50 | if (r==null) return this; |
| 51 | float minx = Math.min(r.x, x); |
| 52 | float miny = Math.min(r.y, y); |
| 53 | |
| 54 | float maxx = Math.max(r.x + r.w, x + w); |
| 55 | float maxy = Math.max(r.y + r.h, y + h); |
| 56 | |
| 57 | return new Rect(minx, miny, maxx - minx, maxy - miny); |
| 58 | } |
| 59 | |
| 60 | public Rect union(Vec2 r) { |
| 61 | if (r==null) return this; |
| 62 | float minx = (float) Math.min(r.x, x); |
| 63 | float miny = (float) Math.min(r.y, y); |
| 64 | |
| 65 | float maxx = (float) Math.max(r.x, x + w); |
| 66 | float maxy = (float) Math.max(r.y, y + h); |
| 67 |
no outgoing calls
no test coverage detected