package NET.worlds.scape; public class BoundBoxTemp { private static Recycler recycler = new Recycler(); public Point3Temp lo; public Point3Temp hi; public static BoundBoxTemp make(Point3Temp a, Point3Temp b) { BoundBoxTemp t = (BoundBoxTemp)recycler.alloc(); if (t == null) { recycler.recycle(new BoundBoxTemp()); t = (BoundBoxTemp)recycler.alloc(); } t.lo = Point3Temp.make(a); t.hi = Point3Temp.make(b); if (a.x > b.x) { t.lo.x = b.x; t.hi.x = a.x; } if (a.y > b.y) { t.lo.y = b.y; t.hi.y = a.y; } if (a.z > b.z) { t.lo.z = b.z; t.hi.z = a.z; } return t; } public static BoundBoxTemp make(BoundBoxTemp b) { return make(b.lo, b.hi); } private BoundBoxTemp() { } public boolean contains(Point3Temp p) { return p.x >= this.lo.x && p.x <= this.hi.x && p.y >= this.lo.y && p.y <= this.hi.y && p.z >= this.lo.z && p.z <= this.hi.z; } public boolean isEmpty() { return this.lo.x == this.hi.x && this.lo.y == this.hi.y && this.lo.z == this.hi.z; } public boolean overlaps(BoundBoxTemp r) { return !(this.hi.x < r.lo.x) && !(r.hi.x < this.lo.x) && !(this.hi.y < r.lo.y) && !(r.hi.y < this.lo.y) && !(this.hi.z < r.lo.z) && !(r.hi.z < this.lo.z); } public void encompass(Point3Temp p) { if (p.x < this.lo.x) { this.lo.x = p.x; } if (p.y < this.lo.y) { this.lo.y = p.y; } if (p.z < this.lo.z) { this.lo.z = p.z; } if (p.x > this.hi.x) { this.hi.x = p.x; } if (p.y > this.hi.y) { this.hi.y = p.y; } if (p.z > this.hi.z) { this.hi.z = p.z; } } @Override public String toString() { return "BoundBoxTemp[lo=" + this.lo + ", hi=" + this.hi + "]"; } }