package net.glowstone.generator.structures.util;

import org.bukkit.util.Vector;

public class StructureBoundingBox {

    private Vector min;
    private Vector max;

    public StructureBoundingBox(Vector min, Vector max) {
        this.min = min;
        this.max = max;
    }

    public Vector getMin() {
        return min;
    }

    public Vector getMax() {
        return max;
    }

    public boolean isVectorInside(Vector vec) {
        return vec.getBlockX() >= min.getBlockX() && vec.getBlockX() <= max.getBlockX() &&
            vec.getBlockY() >= min.getBlockY() && vec.getBlockY() <= max.getBlockY() &&
            vec.getBlockZ() >= min.getBlockZ() && vec.getBlockZ() <= max.getBlockZ();
    }

    public boolean intersectsWith(StructureBoundingBox boundingBox) {
        return boundingBox.getMin().getBlockX() <= max.getBlockX()
            && boundingBox.getMax().getBlockX() >= min.getBlockX() &&
            boundingBox.getMin().getBlockY() <= max.getBlockY()
            && boundingBox.getMax().getBlockY() >= min.getBlockY() &&
            boundingBox.getMin().getBlockZ() <= max.getBlockZ()
            && boundingBox.getMax().getBlockZ() >= min.getBlockZ();
    }

    public boolean intersectsWith(int minX, int minZ, int maxX, int maxZ) {
        return minX <= max.getBlockX() && maxX >= min.getBlockX() &&
            minZ <= max.getBlockZ() && maxZ >= min.getBlockZ();
    }

    public void expandTo(StructureBoundingBox boundingBox) {
        min = new Vector(Math.min(min.getBlockX(), boundingBox.getMin().getBlockX()),
            Math.min(min.getBlockY(), boundingBox.getMin().getBlockY()),
            Math.min(min.getBlockZ(), boundingBox.getMin().getBlockZ()));
        max = new Vector(Math.max(max.getBlockX(), boundingBox.getMax().getBlockX()),
            Math.max(max.getBlockY(), boundingBox.getMax().getBlockY()),
            Math.max(max.getBlockZ(), boundingBox.getMax().getBlockZ()));
    }

    public void offset(Vector offset) {
        min = min.add(offset);
        max = max.add(offset);
    }
}

@@ -378,32 +378,250 @@
 urn max;%0A    %7D%0A%0A
+    /**%0A     * Checks whether the given point is inside a block that intersects this box.%0A     *%0A     * @param vec the point to check%0A     * @return true if this box intersects the block containing %7B@code vec%7D%0A     */%0A
     public boole
@@ -731,35 +731,32 @@
  max.getBlockX()
- &&
 %0A            vec
@@ -743,32 +743,39 @@
 kX()%0A           
+     &&
  vec.getBlockY()
@@ -823,36 +823,36 @@
  max.getBlockY()
- &&%0A
+%0A   
             vec.
@@ -846,16 +846,20 @@
         
+  &&
  vec.get
@@ -924,32 +924,240 @@
 lockZ();%0A    %7D%0A%0A
+    /**%0A     * Whether this box intersects the given box.%0A     *%0A     * @param boundingBox the box to check intersection with%0A     * @return true if the given box intersects this box; false otherwise%0A     */%0A
     public boole
@@ -1281,32 +1281,36 @@
 X()%0A            
+    
 && boundingBox.g
@@ -1339,36 +1339,38 @@
  min.getBlockX()
- &&%0A
+%0A     
             boun
@@ -1356,32 +1356,34 @@
                 
+&&
  boundingBox.get
@@ -1423,32 +1423,36 @@
 Y()%0A            
+    
 && boundingBox.g
@@ -1489,20 +1489,18 @@
 BlockY()
- &&
 %0A
+ 
         
@@ -1502,16 +1502,22 @@
         
+    &&
  boundin
@@ -1561,16 +1561,20 @@
 lockZ()%0A
+    
         
@@ -1632,32 +1632,375 @@
 lockZ();%0A    %7D%0A%0A
+    /**%0A     * Whether this box intersects the given vertically-infinite box.%0A     *%0A     * @param minX the minimum X coordinate%0A     * @param minZ the minimum Z coordinate%0A     * @param maxX the maximum X coordinate%0A     * @param maxZ the maximum Z coordinate%0A     * @return true if the given box intersects this box; false otherwise%0A     */%0A
     public boole
@@ -2124,19 +2124,16 @@
 BlockX()
- &&
 %0A       
@@ -2132,24 +2132,31 @@
 %0A           
+     &&
  minZ %3C= max
@@ -2195,32 +2195,224 @@
 lockZ();%0A    %7D%0A%0A
+    /**%0A     * Changes this bounding box to the bounding box of the union of itself and another bounding%0A     * box.%0A     *%0A     * @param boundingBox the other bounding box to contain%0A     */%0A
     public void 
@@ -2546,32 +2546,36 @@
 )),%0A            
+    
 Math.min(min.get
@@ -2611,32 +2611,36 @@
 ).getBlockY()),%0A
+    
             Math
@@ -2787,32 +2787,36 @@
 )),%0A            
+    
 Math.max(max.get
@@ -2852,32 +2852,36 @@
 ).getBlockY()),%0A
+    
             Math

Fix CheckStyle issues in generator/structures/util/StructureBoundingBox.java (#798)