package com.coillighting.udder.geometry;

/** A 3D bounding box.
 *
 *  See notes about ditching JavaFX (and possibly switching
 *  to Toxic) in Point3D.java.
 */
public class BoundingCube {

    protected double minX = 0.0;
    protected double minY = 0.0;
    protected double minZ = 0.0;

    protected double maxX = 0.0;
    protected double maxY = 0.0;
    protected double maxZ = 0.0;

    protected double width = 0.0;
    protected double height = 0.0;
    protected double depth = 0.0;

    /** Create a 3D bounding box with the given location and dimensions. */
    public BoundingCube(double minX, double minY, double minZ,
                        double width, double height, double depth)
    {
        this.minX = minX;
        this.minY = minY;
        this.minZ = minZ;

        this.width = width;
        this.height = height;
        this.depth = depth;

        this.maxX = width + minX;
        this.maxY = height + minY;
        this.maxZ = depth + minZ;
    }

    /** Create a 2D bounding box as a BoundingCube in the XY plane. */
    public BoundingCube(double minX, double minY,
                        double width, double height)
    {
        this(minX, minY, 0.0, width, height, 0.0);
    }

    public boolean isEmpty() {
        return width < 0.0 || height < 0.0 || depth < 0.0;
    }

    public boolean contains(double x, double y, double z) {
        if(this.isEmpty()) {
            return false;
        } else {
            return x >= minX && x <= maxX
                && y >= minY && y <= maxY
                && z >= minZ && z <= maxZ;
        }
    }

    public boolean contains(Point3D pt) {
        if(pt != null) {
            return this.contains(pt.getX(), pt.getY(), pt.getZ());
        } else {
            return false;
        }
    }

    public String toString() {
        return "x:[" + minX + ", " + maxX + "] y:[" + minY + ", " + maxY + "] z:[" + minZ + ", " + maxZ + "] w:" + width + " h:" + height + " d:" + depth + "w/h:" + (width/height);
    }

    public double getMinX() {
        return minX;
    }

    public void setMinX(double minX) {
        this.minX = minX;
    }

    public double getMinY() {
        return minY;
    }

    public void setMinY(double minY) {
        this.minY = minY;
    }

    public double getMinZ() {
        return minZ;
    }

    public void setMinZ(double minZ) {
        this.minZ = minZ;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public double getDepth() {
        return depth;
    }

    public void setDepth(double depth) {
        this.depth = depth;
    }

    public double getMaxX() {
        return minX + width;
    }

    public double getMaxY() {
        return minY + height;
    }
}

@@ -1218,32 +1218,38 @@
   %7D%0A%0A    public 
+final 
 boolean isEmpty(
@@ -1321,32 +1321,38 @@
   %7D%0A%0A    public 
+final 
 boolean contains
@@ -1611,16 +1611,22 @@
  public 
+final 
 boolean 
@@ -2022,32 +2022,38 @@
   %7D%0A%0A    public 
+final 
 double getMinX()
@@ -2086,32 +2086,38 @@
   %7D%0A%0A    public 
+final 
 void setMinX(dou
@@ -2164,32 +2164,38 @@
   %7D%0A%0A    public 
+final 
 double getMinY()
@@ -2228,32 +2228,38 @@
   %7D%0A%0A    public 
+final 
 void setMinY(dou
@@ -2306,32 +2306,38 @@
   %7D%0A%0A    public 
+final 
 double getMinZ()
@@ -2370,32 +2370,38 @@
   %7D%0A%0A    public 
+final 
 void setMinZ(dou
@@ -2448,32 +2448,38 @@
   %7D%0A%0A    public 
+final 
 double getWidth(
@@ -2514,32 +2514,38 @@
   %7D%0A%0A    public 
+final 
 void setWidth(do
@@ -2596,32 +2596,38 @@
   %7D%0A%0A    public 
+final 
 double getHeight
@@ -2664,32 +2664,38 @@
   %7D%0A%0A    public 
+final 
 void setHeight(d
@@ -2750,32 +2750,38 @@
   %7D%0A%0A    public 
+final 
 double getDepth(
@@ -2824,16 +2824,22 @@
  public 
+final 
 void set
@@ -2898,32 +2898,38 @@
   %7D%0A%0A    public 
+final 
 double getMaxX()
@@ -2978,16 +2978,22 @@
  public 
+final 
 double g
@@ -3038,11 +3038,83 @@
 t;%0A    %7D
+%0A%0A    public final double getMaxZ() %7B%0A        return minZ + depth;%0A    %7D
 %0A%7D%0A

add missing 3D functions to BoundingCube