/*
- * Sixth 3D engine. Author: Svjatoslav Agejenko.
+ * Sixth 3D engine. Author: Svjatoslav Agejenko.
* This project is released under Creative Commons Zero (CC0) license.
*/
package eu.svjatoslav.sixth.e3d.geometry;
+import static java.lang.Math.abs;
+
/**
* Same as: 3D rectangle, rectangular box, rectangular parallelopiped, cuboid,
* rhumboid, hexahedron, rectangular prism.
*/
public class Box implements Cloneable {
+ /**
+ * The first point of the box.
+ */
public final Point3D p1;
+ /**
+ * The second point of the box.
+ */
public final Point3D p2;
+ /**
+ * Creates a new box with two points at the origin.
+ */
public Box() {
p1 = new Point3D();
p2 = new Point3D();
}
+ /**
+ * Creates a new box with two points at the specified coordinates.
+ */
public Box(final Point3D p1, final Point3D p2) {
this.p1 = p1;
this.p2 = p2;
}
- public Box addBorder(final double border) {
+
+ /**
+ * Enlarges the box by the specified border in all directions.
+ *
+ * @param border The border to enlarge the box by.
+ * If the border is negative, the box will be shrunk.
+ * @return The current box.
+ */
+ public Box enlarge(final double border) {
if (p1.x < p2.x) {
p1.translateX(-border);
return new Box(p1.clone(), p2.clone());
}
+ /**
+ * @return The depth of the box. The depth is the distance between the two points on the z-axis.
+ */
public double getDepth() {
- return Math.abs(p1.z - p2.z);
+ return abs(p1.z - p2.z);
}
+ /**
+ * @return The height of the box. The height is the distance between the two points on the y-axis.
+ */
public double getHeight() {
- return Math.abs(p1.y - p2.y);
+ return abs(p1.y - p2.y);
}
+ /**
+ * @return The width of the box. The width is the distance between the two points on the x-axis.
+ */
public double getWidth() {
- return Math.abs(p1.x - p2.x);
+ return abs(p1.x - p2.x);
}
- public void setSizeCentered(final Point3D size) {
+
+ /**
+ * Sets the size of the box. The box will be centered at the origin.
+ * Previous size and position of the box will be lost.
+ *
+ * @param size {@link Point3D} specifies box size in x, y and z axis.
+ */
+ public void setBoxSize(final Point3D size) {
p2.clone(size).scaleDown(2);
p1.clone(p2).invert();
}