X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=sixth-3d.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Fgeometry%2FBox.java;h=e4615310ccafde68a5c304ae8486b982994b659d;hp=6e3b1d79b39f8c103d5598b22f01af6fecef27f4;hb=3e2b906bd05617a4d9725de39ac14c9ea1f8736c;hpb=a38bc412f8c6ae6c8fdf9466ae9b2073c2a73614 diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Box.java b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Box.java index 6e3b1d7..e461531 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Box.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Box.java @@ -1,29 +1,51 @@ /* - * 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); @@ -57,19 +79,35 @@ public class Box implements Cloneable { 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(); }