2 * Sixth 3D engine. Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public License
6 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.sixth.e3d.geometry;
13 * Same as: 3D rectangle, rectangular box, rectangular parallelopiped, cuboid,
14 * rhumboid, hexahedron, rectangular prism.
16 public class Box implements Cloneable {
18 public final Point3D p1;
19 public final Point3D p2;
26 public Box(final Point3D p1, final Point3D p2) {
31 public Box addBorder(final double border) {
34 p1.translateX(-border);
35 p2.translateX(border);
37 p1.translateX(border);
38 p2.translateX(-border);
42 p1.translateY(-border);
43 p2.translateY(border);
45 p1.translateY(border);
46 p2.translateY(-border);
50 p1.translateZ(-border);
51 p2.translateZ(border);
53 p1.translateZ(border);
54 p2.translateZ(-border);
62 return new Box(p1.clone(), p2.clone());
65 public double getDepth() {
66 return Math.abs(p1.z - p2.z);
69 public double getHeight() {
70 return Math.abs(p1.y - p2.y);
73 public double getWidth() {
74 return Math.abs(p1.x - p2.x);
77 public void setSizeCentered(final Point3D size) {
78 p2.clone(size).scaleDown(2);
79 p1.clone(p2).invert();