diff options
author | Sven Gothel <[email protected]> | 2014-03-05 03:23:44 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-03-05 03:23:44 +0100 |
commit | 79156e080ef919857f1624543e37b62794fb5a64 (patch) | |
tree | 8c7b3eeea7bb85b5af05356c7adce1f69606be3a /src/jogl/classes/com/jogamp/opengl/math/geom | |
parent | fe3daea00da48c90a4e0c90cf37514a3ab7093d6 (diff) |
Bug 801: VectorUtil: Pass result vector, allowing caller to manage memory (performance, reduce temp objects)
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/math/geom')
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java b/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java index 5fbc28c60..81928888c 100644 --- a/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java +++ b/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java @@ -37,9 +37,9 @@ import com.jogamp.opengl.math.VectorUtil; * */ public class AABBox implements Cloneable { - private float[] low = new float[3]; - private float[] high = new float[3]; - private float[] center = new float[3]; + private final float[] low = new float[3]; + private final float[] high = new float[3]; + private final float[] center = new float[3]; /** Create a Axis Aligned bounding box (AABBox) * where the low and and high MAX float Values. @@ -275,26 +275,25 @@ public class AABBox implements Cloneable { return center; } - /** Scale the AABBox by a constant + /** + * Scale the AABBox by a constant * @param size a constant float value + * @param tmpV3 caller provided temporary 3-component vector */ - public final void scale(float size) { - float[] diffH = new float[3]; - diffH[0] = high[0] - center[0]; - diffH[1] = high[1] - center[1]; - diffH[2] = high[2] - center[2]; - - diffH = VectorUtil.scale(diffH, size); + public final void scale(float size, float[] tmpV3) { + tmpV3[0] = high[0] - center[0]; + tmpV3[1] = high[1] - center[1]; + tmpV3[2] = high[2] - center[2]; - float[] diffL = new float[3]; - diffL[0] = low[0] - center[0]; - diffL[1] = low[1] - center[1]; - diffL[2] = low[2] - center[2]; + VectorUtil.scale(tmpV3, tmpV3, size); // in-place scale + VectorUtil.vectorAdd(high, center, tmpV3); - diffL = VectorUtil.scale(diffL, size); + tmpV3[0] = low[0] - center[0]; + tmpV3[1] = low[1] - center[1]; + tmpV3[2] = low[2] - center[2]; - high = VectorUtil.vectorAdd(center, diffH); - low = VectorUtil.vectorAdd(center, diffL); + VectorUtil.scale(tmpV3, tmpV3, size); // in-place scale + VectorUtil.vectorAdd(low, center, tmpV3); } public final float getMinX() { |