/** * 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)); }
/** * Construct the object. This is to create a new copy at a certain location. * * @param origin * @param size */ public CuboidCopy(Vector origin, Vector size) { this.origin = origin; width = size.getBlockX(); height = size.getBlockY(); length = size.getBlockZ(); blocks = new byte[width * height * length]; data = new byte[width * height * length]; }
/** * Save the copy to file. * * @param dest * @throws IOException */ public void save(File dest) throws IOException { FileOutputStream out = new FileOutputStream(dest); DataOutputStream writer = new DataOutputStream(out); writer.writeByte(1); writer.writeInt(origin.getBlockX()); writer.writeInt(origin.getBlockY()); writer.writeInt(origin.getBlockZ()); writer.writeInt(width); writer.writeInt(height); writer.writeInt(length); writer.write(blocks, 0, blocks.length); writer.write(data, 0, data.length); writer.close(); out.close(); }