diff options
Diffstat (limited to 'src')
5 files changed, 63 insertions, 27 deletions
diff --git a/src/classes/share/javax/media/j3d/BoundingBox.java b/src/classes/share/javax/media/j3d/BoundingBox.java index 8d0cc1c..4595ced 100644 --- a/src/classes/share/javax/media/j3d/BoundingBox.java +++ b/src/classes/share/javax/media/j3d/BoundingBox.java @@ -31,8 +31,6 @@ import javax.vecmath.Point4d; import javax.vecmath.Vector3d; import javax.vecmath.Vector4d; -import com.sun.j3d.internal.HashCodeUtil; - /** * This class defines an axis aligned bounding box which is used for * bounding regions. @@ -399,13 +397,13 @@ public void setUpper(Point3d p1) { */ public int hashCode() { long bits = 1L; - bits = 31L * bits + HashCodeUtil.doubleToLongBits(lower.x); - bits = 31L * bits + HashCodeUtil.doubleToLongBits(lower.y); - bits = 31L * bits + HashCodeUtil.doubleToLongBits(lower.z); - bits = 31L * bits + HashCodeUtil.doubleToLongBits(upper.x); - bits = 31L * bits + HashCodeUtil.doubleToLongBits(upper.y); - bits = 31L * bits + HashCodeUtil.doubleToLongBits(upper.z); - return (int) (bits ^ (bits >> 32)); + bits = J3dHash.mixDoubleBits(bits, lower.x); + bits = J3dHash.mixDoubleBits(bits, lower.y); + bits = J3dHash.mixDoubleBits(bits, lower.z); + bits = J3dHash.mixDoubleBits(bits, upper.x); + bits = J3dHash.mixDoubleBits(bits, upper.y); + bits = J3dHash.mixDoubleBits(bits, upper.z); + return J3dHash.finish(bits); } diff --git a/src/classes/share/javax/media/j3d/BoundingPolytope.java b/src/classes/share/javax/media/j3d/BoundingPolytope.java index ab74ae6..4dc6844 100644 --- a/src/classes/share/javax/media/j3d/BoundingPolytope.java +++ b/src/classes/share/javax/media/j3d/BoundingPolytope.java @@ -31,8 +31,6 @@ import javax.vecmath.Point4d; import javax.vecmath.Vector3d; import javax.vecmath.Vector4d; -import com.sun.j3d.internal.HashCodeUtil; - /** * A BoundingPolytope defines a polyhedral bounding region using the * intersection of four or more half spaces. The region defined by a @@ -531,13 +529,13 @@ public class BoundingPolytope extends Bounds { long bits = 1L; for (int i = 0; i < planes.length; i++) { - bits = 31L * bits + HashCodeUtil.doubleToLongBits(planes[i].x); - bits = 31L * bits + HashCodeUtil.doubleToLongBits(planes[i].y); - bits = 31L * bits + HashCodeUtil.doubleToLongBits(planes[i].z); - bits = 31L * bits + HashCodeUtil.doubleToLongBits(planes[i].w); + bits = J3dHash.mixDoubleBits(bits, planes[i].x); + bits = J3dHash.mixDoubleBits(bits, planes[i].y); + bits = J3dHash.mixDoubleBits(bits, planes[i].z); + bits = J3dHash.mixDoubleBits(bits, planes[i].w); } - return (int) (bits ^ (bits >> 32)); + return J3dHash.finish(bits); } diff --git a/src/classes/share/javax/media/j3d/BoundingSphere.java b/src/classes/share/javax/media/j3d/BoundingSphere.java index 94a1b59..ff9bf66 100644 --- a/src/classes/share/javax/media/j3d/BoundingSphere.java +++ b/src/classes/share/javax/media/j3d/BoundingSphere.java @@ -31,8 +31,6 @@ import javax.vecmath.Point4d; import javax.vecmath.Vector3d; import javax.vecmath.Vector4d; -import com.sun.j3d.internal.HashCodeUtil; - /** * This class defines a spherical bounding region which is defined by a * center point and a radius. @@ -410,11 +408,11 @@ public void setCenter(Point3d center) { */ public int hashCode() { long bits = 1L; - bits = 31L * bits + HashCodeUtil.doubleToLongBits(radius); - bits = 31L * bits + HashCodeUtil.doubleToLongBits(center.x); - bits = 31L * bits + HashCodeUtil.doubleToLongBits(center.y); - bits = 31L * bits + HashCodeUtil.doubleToLongBits(center.z); - return (int) (bits ^ (bits >> 32)); + bits = J3dHash.mixDoubleBits(bits, radius); + bits = J3dHash.mixDoubleBits(bits, center.x); + bits = J3dHash.mixDoubleBits(bits, center.y); + bits = J3dHash.mixDoubleBits(bits, center.z); + return J3dHash.finish(bits); } diff --git a/src/classes/share/javax/media/j3d/J3dHash.java b/src/classes/share/javax/media/j3d/J3dHash.java new file mode 100644 index 0000000..5db0437 --- /dev/null +++ b/src/classes/share/javax/media/j3d/J3dHash.java @@ -0,0 +1,44 @@ +/* + * Copyright 2013 Harvey Harrison <[email protected]> + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + */ +package javax.media.j3d; + +/** + * A Utility class wrapping the approach used to hash double values in Java3D + */ +class J3dHash { + +// prevent an instance from actually being created +private J3dHash() {} + +/** + * Mix the given double into the provided long hash. + */ +static final long mixDoubleBits(long hash, double d) { + hash *= 31L; + // Treat 0.0d and -0.0d the same (all zero bits) + if (d == 0.0d) + return hash; + + return hash + Double.doubleToLongBits(d); +} + +/** + * Return an integer hash from a long by mixing it with itself. + */ +static final int finish(long hash) { + return (int)(hash ^ (hash >> 32)); +} +} diff --git a/src/classes/share/javax/media/j3d/Transform3D.java b/src/classes/share/javax/media/j3d/Transform3D.java index 38414d9..99296f3 100644 --- a/src/classes/share/javax/media/j3d/Transform3D.java +++ b/src/classes/share/javax/media/j3d/Transform3D.java @@ -44,8 +44,6 @@ import javax.vecmath.Vector3f; import javax.vecmath.Vector4d; import javax.vecmath.Vector4f; -import com.sun.j3d.internal.HashCodeUtil; - /** * A generalized transform object represented internally as a 4x4 * double-precision floating point matrix. The mathematical @@ -4089,9 +4087,9 @@ public class Transform3D { long bits = 1L; for (int i = 0; i < 16; i++) { - bits = 31L * bits + HashCodeUtil.doubleToLongBits(mat[i]); + bits = J3dHash.mixDoubleBits(bits, mat[i]); } - return (int) (bits ^ (bits >> 32)); + return J3dHash.finish(bits); } |