/** * Get the distance between a point and this cuboid. * * @param pos * @return */ public double distance(Vector pos) { Vector max = origin.add(new Vector(width, height, length)); int closestX = Math.max(origin.getBlockX(), Math.min(max.getBlockX(), pos.getBlockX())); int closestY = Math.max(origin.getBlockY(), Math.min(max.getBlockY(), pos.getBlockY())); int closestZ = Math.max(origin.getBlockZ(), Math.min(max.getBlockZ(), pos.getBlockZ())); return pos.distance(new Vector(closestX, closestY, closestZ)); }