aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarvey Harrison <[email protected]>2012-01-16 10:44:43 -0800
committerHarvey Harrison <[email protected]>2012-01-16 10:46:48 -0800
commit340456818fc9514428639bb154254af57e23cda4 (patch)
tree4114b979216eea2b3210dd66672ca7a3ce1c175e
parent0dfc49a2042105d515d4177f31a3ef225c409ceb (diff)
j3dcore: small optimization in BoundingSphere/BoundingBox::transform(Bounds, Transform3d)
When the type of Bounds being passed matches the current Object, this method can simply set the state and then transform the current object, avoid the need for a temporary object in BoundingBox's case. BoundingSphere was already open-coding this pattern, make it explicit. Signed-off-by: Harvey Harrison <[email protected]>
-rw-r--r--src/classes/share/javax/media/j3d/BoundingBox.java11
-rw-r--r--src/classes/share/javax/media/j3d/BoundingSphere.java12
2 files changed, 4 insertions, 19 deletions
diff --git a/src/classes/share/javax/media/j3d/BoundingBox.java b/src/classes/share/javax/media/j3d/BoundingBox.java
index 9ccb4d8..817b831 100644
--- a/src/classes/share/javax/media/j3d/BoundingBox.java
+++ b/src/classes/share/javax/media/j3d/BoundingBox.java
@@ -61,7 +61,6 @@ final Point3d upper;
// reusable temp objects
private BoundingSphere tmpSphere = null;
- private BoundingBox tmpBox = null;
private BoundingPolytope tmpPolytope = null;
private Point3d tmpP3d = null;
@@ -657,13 +656,8 @@ public void setUpper(Point3d p1) {
}
if(boundsObject.boundId == BOUNDING_BOX){
- if (tmpBox == null) {
- tmpBox = new BoundingBox( (BoundingBox)boundsObject);
- } else {
- tmpBox.set((BoundingBox)boundsObject);
- }
- tmpBox.transform(matrix);
- this.set(tmpBox);
+ this.set(boundsObject);
+ this.transform(matrix);
}
else if(boundsObject.boundId == BOUNDING_SPHERE) {
if (tmpSphere == null) {
@@ -692,7 +686,6 @@ public void setUpper(Point3d p1) {
// Release the temporary fields:
if (releaseBoundingBoxMemory) {
tmpSphere = null;
- tmpBox = null;
tmpPolytope = null;
}
}
diff --git a/src/classes/share/javax/media/j3d/BoundingSphere.java b/src/classes/share/javax/media/j3d/BoundingSphere.java
index 2bf17a6..9e163f2 100644
--- a/src/classes/share/javax/media/j3d/BoundingSphere.java
+++ b/src/classes/share/javax/media/j3d/BoundingSphere.java
@@ -757,8 +757,6 @@ public void setCenter(Point3d center) {
* @param matrix a transformation matrix
*/
public void transform( Bounds boundsObject, Transform3D matrix) {
- double scale;
-
if (boundsObject == null || boundsObject.boundsIsEmpty) {
setEmptyBounds();
return;
@@ -778,14 +776,8 @@ public void setCenter(Point3d center) {
tmpBox.transform(matrix);
this.set(tmpBox);
}else if( boundsObject.boundId == BOUNDING_SPHERE ) {
- matrix.transform(((BoundingSphere)boundsObject).center, this.center);
- // A very simple radius scale.
- scale = matrix.getDistanceScale();
- this.radius = ((BoundingSphere)boundsObject).radius * scale;
- if (Double.isNaN(radius)) {
- setEmptyBounds();
- return;
- }
+ this.set(boundsObject);
+ this.transform(matrix);
} else if(boundsObject.boundId == BOUNDING_POLYTOPE) {
if (tmpPolytope == null) {
tmpPolytope = new BoundingPolytope((BoundingPolytope)boundsObject);