diff options
| author | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
| commit | c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch) | |
| tree | df9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/scape/BoundBoxTemp.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/scape/BoundBoxTemp.java')
| -rw-r--r-- | NET/worlds/scape/BoundBoxTemp.java | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/NET/worlds/scape/BoundBoxTemp.java b/NET/worlds/scape/BoundBoxTemp.java new file mode 100644 index 0000000..31ddc3e --- /dev/null +++ b/NET/worlds/scape/BoundBoxTemp.java @@ -0,0 +1,84 @@ +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 + "]"; + } +} |