aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/math/geom/AABBox.java
diff options
context:
space:
mode:
authorSven Göthel <[email protected]>2024-01-15 23:31:20 +0100
committerSven Göthel <[email protected]>2024-01-15 23:31:20 +0100
commit106142dfa4cdbf0579f8d07f23ca3c4897a5cc95 (patch)
treee0601317e29e673c39687ef4d6798cde53b93469 /src/jogl/classes/com/jogamp/math/geom/AABBox.java
parentd778889f36bd6bee999ceb502c5f0ce265b014bf (diff)
AABBox: Add intersects(AABBox), contains(AABBox), scale(float, float, float) and scale2(float, float, float)
Diffstat (limited to 'src/jogl/classes/com/jogamp/math/geom/AABBox.java')
-rw-r--r--src/jogl/classes/com/jogamp/math/geom/AABBox.java59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/jogl/classes/com/jogamp/math/geom/AABBox.java b/src/jogl/classes/com/jogamp/math/geom/AABBox.java
index 6dd95e2ed..49578337c 100644
--- a/src/jogl/classes/com/jogamp/math/geom/AABBox.java
+++ b/src/jogl/classes/com/jogamp/math/geom/AABBox.java
@@ -422,6 +422,26 @@ public class AABBox {
z<bl.z() || z>tr.z() );
}
+ /** Returns whether this AABBox intersects (partially contains) given AABBox. */
+ public final boolean intersects(final AABBox o) {
+ return !( tr.x() < o.bl.x() ||
+ tr.y() < o.bl.y() ||
+ tr.z() < o.bl.z() ||
+ bl.x() > o.tr.x() ||
+ bl.y() > o.tr.y() ||
+ bl.z() > o.tr.z());
+ }
+
+ /** Returns whether this AABBox fully contains given AABBox. */
+ public final boolean contains(final AABBox o) {
+ return tr.x() >= o.tr.x() &&
+ tr.y() >= o.tr.y() &&
+ tr.z() >= o.tr.z() &&
+ bl.x() <= o.bl.x() &&
+ bl.y() <= o.bl.y() &&
+ bl.z() <= o.bl.z();
+ }
+
/**
* Check if there is a common region between this AABBox and the passed
* 2D region irrespective of z range
@@ -729,6 +749,27 @@ public class AABBox {
return this;
}
+ /**
+ * Scale this AABBox by constants around fixed center
+ * <p>
+ * high and low is recomputed by scaling its distance to fixed center.
+ * </p>
+ * @param sX horizontal scale factor
+ * @param sY vertical scale factor
+ * @param sZ Z-axis scale factor
+ * @return this AABBox for chaining
+ * @see #scale2(float, float[])
+ */
+ public final AABBox scale(final float sX, final float sY, final float sZ) {
+ final Vec3f tmp = new Vec3f();
+ tmp.set(tr).sub(center).scale(sX, sY, sZ);
+ tr.set(center).add(tmp);
+
+ tmp.set(bl).sub(center).scale(sX, sY, sZ);
+ bl.set(center).add(tmp);
+
+ return this;
+ }
/**
* Scale this AABBox by a constant, recomputing center
@@ -747,6 +788,24 @@ public class AABBox {
}
/**
+ * Scale this AABBox by constants, recomputing center
+ * <p>
+ * high and low is scaled and center recomputed.
+ * </p>
+ * @param sX horizontal scale factor
+ * @param sY vertical scale factor
+ * @param sZ Z-axis scale factor
+ * @return this AABBox for chaining
+ * @see #scale(float, float[])
+ */
+ public final AABBox scale2(final float sX, final float sY, final float sZ) {
+ tr.scale(sX, sY, sZ);
+ bl.scale(sX, sY, sZ);
+ computeCenter();
+ return this;
+ }
+
+ /**
* Translate this AABBox by a float[3] vector
* @param dx the translation x-component
* @param dy the translation y-component