diff options
author | Harvey Harrison <[email protected]> | 2012-01-14 19:03:02 -0800 |
---|---|---|
committer | Harvey Harrison <[email protected]> | 2012-01-14 19:47:14 -0800 |
commit | 145862f0370059961084b2f73638822de98e7aad (patch) | |
tree | 3d75c08ccfb086c70bba6ed29044b120e78b1a0b | |
parent | ab4f30f03edf3da4215e7d0a22c8d5d0ddc34309 (diff) |
j3dcore: small optimizations in BoundingBox constructors
Avoid the calls to updateBoundsStates when we know exactly what bounds we set in
the default cases. Also add a check to the (Bounds) constructor for an empty Bounds
argument and directly set the empty state.
Signed-off-by: Harvey Harrison <[email protected]>
-rw-r--r-- | src/classes/share/javax/media/j3d/BoundingBox.java | 61 |
1 files changed, 30 insertions, 31 deletions
diff --git a/src/classes/share/javax/media/j3d/BoundingBox.java b/src/classes/share/javax/media/j3d/BoundingBox.java index c8ce0a9..f102f46 100644 --- a/src/classes/share/javax/media/j3d/BoundingBox.java +++ b/src/classes/share/javax/media/j3d/BoundingBox.java @@ -82,41 +82,41 @@ final Point3d upper; } - /** - * Constructs and initializes a BoundingBox given min,max in x,y,z. - * @param lower the "small" corner - * @param upper the "large" corner - */ - public BoundingBox(Point3d lower, Point3d upper) { +/** + * Constructs and initializes a BoundingBox given min,max in x,y,z. + * @param lower the "small" corner + * @param upper the "large" corner + */ +public BoundingBox(Point3d lower, Point3d upper) { boundId = BOUNDING_BOX; this.lower = new Point3d(lower); this.upper = new Point3d(upper); updateBoundsStates(); - } +} - /** - * Constructs and initializes a 2X bounding box about the - * origin. The lower corner is initialized to (-1.0d, -1.0d, -1.0d) - * and the opper corner is initialized to (1.0d, 1.0d, 1.0d). - */ - public BoundingBox() { +/** + * Constructs and initializes a 2X bounding box about the origin. The lower + * corner is initialized to (-1.0d, -1.0d, -1.0d) and the upper corner is + * initialized to (1.0d, 1.0d, 1.0d). + */ +public BoundingBox() { boundId = BOUNDING_BOX; lower = new Point3d(-1.0d, -1.0d, -1.0d); upper = new Point3d( 1.0d, 1.0d, 1.0d); - updateBoundsStates(); - } + boundsIsEmpty = false; + boundsIsInfinite = false; +} - /** - * Constructs a BoundingBox from a bounding object. - * @param boundsObject a bounds object - */ - public BoundingBox(Bounds boundsObject) { - int i; +/** + * Constructs a BoundingBox from a bounding object. + * @param boundsObject a bounds object + */ +public BoundingBox(Bounds boundsObject) { boundId = BOUNDING_BOX; lower = new Point3d(); upper = new Point3d(); - if (boundsObject == null) { + if (boundsObject == null || boundsObject.boundsIsEmpty) { setEmptyBounds(); return; } @@ -152,7 +152,7 @@ final Point3d upper; lower.set(polytope.verts[0]); upper.set(polytope.verts[0]); - for(i=1;i<polytope.nVerts;i++) { + for(int i=1;i<polytope.nVerts;i++) { if( polytope.verts[i].x < lower.x ) lower.x = polytope.verts[i].x; if( polytope.verts[i].y < lower.y ) @@ -175,22 +175,21 @@ final Point3d upper; updateBoundsStates(); } - /** - * Constructs a BoundingBox from an array of bounding objects. - * @param bounds an array of bounding objects - */ - public BoundingBox(Bounds[] bounds) { - int i=0; - +/** + * Constructs a BoundingBox from an array of bounding objects. + * @param bounds an array of bounding objects + */ +public BoundingBox(Bounds[] bounds) { + boundId = BOUNDING_BOX; upper = new Point3d(); lower = new Point3d(); - boundId = BOUNDING_BOX; if (bounds == null || bounds.length <= 0) { setEmptyBounds(); return; } + int i = 0; // find first non empty bounds object while ((i < bounds.length) && ((bounds[i] == null) || bounds[i].boundsIsEmpty)) { i++; |