summaryrefslogtreecommitdiffstats
path: root/src/javax/vecmath
diff options
context:
space:
mode:
Diffstat (limited to 'src/javax/vecmath')
-rw-r--r--src/javax/vecmath/AxisAngle4d.java8
-rw-r--r--src/javax/vecmath/AxisAngle4f.java8
-rw-r--r--src/javax/vecmath/GMatrix.java2
-rw-r--r--src/javax/vecmath/GVector.java2
-rw-r--r--src/javax/vecmath/Matrix3d.java18
-rw-r--r--src/javax/vecmath/Matrix3f.java18
-rw-r--r--src/javax/vecmath/Matrix4d.java32
-rw-r--r--src/javax/vecmath/Matrix4f.java32
-rw-r--r--src/javax/vecmath/Tuple2d.java4
-rw-r--r--src/javax/vecmath/Tuple2f.java4
-rw-r--r--src/javax/vecmath/Tuple3d.java6
-rw-r--r--src/javax/vecmath/Tuple3f.java6
-rw-r--r--src/javax/vecmath/Tuple4d.java8
-rw-r--r--src/javax/vecmath/Tuple4f.java8
-rw-r--r--src/javax/vecmath/VecMathUtil.java84
15 files changed, 162 insertions, 78 deletions
diff --git a/src/javax/vecmath/AxisAngle4d.java b/src/javax/vecmath/AxisAngle4d.java
index d856081..ca16742 100644
--- a/src/javax/vecmath/AxisAngle4d.java
+++ b/src/javax/vecmath/AxisAngle4d.java
@@ -508,10 +508,10 @@ public class AxisAngle4d implements java.io.Serializable, Cloneable {
*/
public int hashCode() {
long bits = 1L;
- bits = 31L * bits + Double.doubleToLongBits(x);
- bits = 31L * bits + Double.doubleToLongBits(y);
- bits = 31L * bits + Double.doubleToLongBits(z);
- bits = 31L * bits + Double.doubleToLongBits(angle);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(x);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(y);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(z);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(angle);
return (int) (bits ^ (bits >> 32));
}
diff --git a/src/javax/vecmath/AxisAngle4f.java b/src/javax/vecmath/AxisAngle4f.java
index 7de19f9..6367313 100644
--- a/src/javax/vecmath/AxisAngle4f.java
+++ b/src/javax/vecmath/AxisAngle4f.java
@@ -504,10 +504,10 @@ public class AxisAngle4f implements java.io.Serializable, Cloneable {
*/
public int hashCode() {
long bits = 1L;
- bits = 31L * bits + (long)Float.floatToIntBits(x);
- bits = 31L * bits + (long)Float.floatToIntBits(y);
- bits = 31L * bits + (long)Float.floatToIntBits(z);
- bits = 31L * bits + (long)Float.floatToIntBits(angle);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(x);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(y);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(z);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(angle);
return (int) (bits ^ (bits >> 32));
}
diff --git a/src/javax/vecmath/GMatrix.java b/src/javax/vecmath/GMatrix.java
index 5ccdbb4..f6c76b1 100644
--- a/src/javax/vecmath/GMatrix.java
+++ b/src/javax/vecmath/GMatrix.java
@@ -1378,7 +1378,7 @@ public class GMatrix implements java.io.Serializable, Cloneable {
for (int i = 0; i < nRow; i++) {
for (int j = 0; j < nCol; j++) {
- bits = 31L * bits + Double.doubleToLongBits(values[i][j]);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(values[i][j]);
}
}
diff --git a/src/javax/vecmath/GVector.java b/src/javax/vecmath/GVector.java
index 89a9b37..da1bf6e 100644
--- a/src/javax/vecmath/GVector.java
+++ b/src/javax/vecmath/GVector.java
@@ -648,7 +648,7 @@ public class GVector implements java.io.Serializable, Cloneable {
long bits = 1L;
for (int i = 0; i < length; i++) {
- bits = 31L * bits + Double.doubleToLongBits(values[i]);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(values[i]);
}
return (int) (bits ^ (bits >> 32));
diff --git a/src/javax/vecmath/Matrix3d.java b/src/javax/vecmath/Matrix3d.java
index eb696b8..ac3a382 100644
--- a/src/javax/vecmath/Matrix3d.java
+++ b/src/javax/vecmath/Matrix3d.java
@@ -1970,15 +1970,15 @@ public class Matrix3d implements java.io.Serializable, Cloneable {
*/
public int hashCode() {
long bits = 1L;
- bits = 31L * bits + Double.doubleToLongBits(m00);
- bits = 31L * bits + Double.doubleToLongBits(m01);
- bits = 31L * bits + Double.doubleToLongBits(m02);
- bits = 31L * bits + Double.doubleToLongBits(m10);
- bits = 31L * bits + Double.doubleToLongBits(m11);
- bits = 31L * bits + Double.doubleToLongBits(m12);
- bits = 31L * bits + Double.doubleToLongBits(m20);
- bits = 31L * bits + Double.doubleToLongBits(m21);
- bits = 31L * bits + Double.doubleToLongBits(m22);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m00);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m01);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m02);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m10);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m11);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m12);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m20);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m21);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m22);
return (int) (bits ^ (bits >> 32));
}
diff --git a/src/javax/vecmath/Matrix3f.java b/src/javax/vecmath/Matrix3f.java
index 155d5e1..43f5301 100644
--- a/src/javax/vecmath/Matrix3f.java
+++ b/src/javax/vecmath/Matrix3f.java
@@ -1953,15 +1953,15 @@ public class Matrix3f implements java.io.Serializable, Cloneable {
*/
public int hashCode() {
long bits = 1L;
- bits = 31L * bits + (long)Float.floatToIntBits(m00);
- bits = 31L * bits + (long)Float.floatToIntBits(m01);
- bits = 31L * bits + (long)Float.floatToIntBits(m02);
- bits = 31L * bits + (long)Float.floatToIntBits(m10);
- bits = 31L * bits + (long)Float.floatToIntBits(m11);
- bits = 31L * bits + (long)Float.floatToIntBits(m12);
- bits = 31L * bits + (long)Float.floatToIntBits(m20);
- bits = 31L * bits + (long)Float.floatToIntBits(m21);
- bits = 31L * bits + (long)Float.floatToIntBits(m22);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m00);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m01);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m02);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m10);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m11);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m12);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m20);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m21);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m22);
return (int) (bits ^ (bits >> 32));
}
diff --git a/src/javax/vecmath/Matrix4d.java b/src/javax/vecmath/Matrix4d.java
index 0aa353b..dd338a7 100644
--- a/src/javax/vecmath/Matrix4d.java
+++ b/src/javax/vecmath/Matrix4d.java
@@ -3060,22 +3060,22 @@ public class Matrix4d implements java.io.Serializable, Cloneable {
*/
public int hashCode() {
long bits = 1L;
- bits = 31L * bits + Double.doubleToLongBits(m00);
- bits = 31L * bits + Double.doubleToLongBits(m01);
- bits = 31L * bits + Double.doubleToLongBits(m02);
- bits = 31L * bits + Double.doubleToLongBits(m03);
- bits = 31L * bits + Double.doubleToLongBits(m10);
- bits = 31L * bits + Double.doubleToLongBits(m11);
- bits = 31L * bits + Double.doubleToLongBits(m12);
- bits = 31L * bits + Double.doubleToLongBits(m13);
- bits = 31L * bits + Double.doubleToLongBits(m20);
- bits = 31L * bits + Double.doubleToLongBits(m21);
- bits = 31L * bits + Double.doubleToLongBits(m22);
- bits = 31L * bits + Double.doubleToLongBits(m23);
- bits = 31L * bits + Double.doubleToLongBits(m30);
- bits = 31L * bits + Double.doubleToLongBits(m31);
- bits = 31L * bits + Double.doubleToLongBits(m32);
- bits = 31L * bits + Double.doubleToLongBits(m33);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m00);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m01);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m02);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m03);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m10);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m11);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m12);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m13);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m20);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m21);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m22);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m23);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m30);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m31);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m32);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(m33);
return (int) (bits ^ (bits >> 32));
}
diff --git a/src/javax/vecmath/Matrix4f.java b/src/javax/vecmath/Matrix4f.java
index 395d209..32d83e1 100644
--- a/src/javax/vecmath/Matrix4f.java
+++ b/src/javax/vecmath/Matrix4f.java
@@ -2820,22 +2820,22 @@ public class Matrix4f implements java.io.Serializable, Cloneable {
*/
public int hashCode() {
long bits = 1L;
- bits = 31L * bits + (long)Float.floatToIntBits(m00);
- bits = 31L * bits + (long)Float.floatToIntBits(m01);
- bits = 31L * bits + (long)Float.floatToIntBits(m02);
- bits = 31L * bits + (long)Float.floatToIntBits(m03);
- bits = 31L * bits + (long)Float.floatToIntBits(m10);
- bits = 31L * bits + (long)Float.floatToIntBits(m11);
- bits = 31L * bits + (long)Float.floatToIntBits(m12);
- bits = 31L * bits + (long)Float.floatToIntBits(m13);
- bits = 31L * bits + (long)Float.floatToIntBits(m20);
- bits = 31L * bits + (long)Float.floatToIntBits(m21);
- bits = 31L * bits + (long)Float.floatToIntBits(m22);
- bits = 31L * bits + (long)Float.floatToIntBits(m23);
- bits = 31L * bits + (long)Float.floatToIntBits(m30);
- bits = 31L * bits + (long)Float.floatToIntBits(m31);
- bits = 31L * bits + (long)Float.floatToIntBits(m32);
- bits = 31L * bits + (long)Float.floatToIntBits(m33);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m00);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m01);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m02);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m03);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m10);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m11);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m12);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m13);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m20);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m21);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m22);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m23);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m30);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m31);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m32);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(m33);
return (int) (bits ^ (bits >> 32));
}
diff --git a/src/javax/vecmath/Tuple2d.java b/src/javax/vecmath/Tuple2d.java
index 21f7da7..a60ff49 100644
--- a/src/javax/vecmath/Tuple2d.java
+++ b/src/javax/vecmath/Tuple2d.java
@@ -276,8 +276,8 @@ public abstract class Tuple2d implements java.io.Serializable, Cloneable {
*/
public int hashCode() {
long bits = 1L;
- bits = 31L * bits + Double.doubleToLongBits(x);
- bits = 31L * bits + Double.doubleToLongBits(y);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(x);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(y);
return (int) (bits ^ (bits >> 32));
}
diff --git a/src/javax/vecmath/Tuple2f.java b/src/javax/vecmath/Tuple2f.java
index b482d80..ee4b801 100644
--- a/src/javax/vecmath/Tuple2f.java
+++ b/src/javax/vecmath/Tuple2f.java
@@ -278,8 +278,8 @@ public abstract class Tuple2f implements java.io.Serializable, Cloneable {
*/
public int hashCode() {
long bits = 1L;
- bits = 31L * bits + (long)Float.floatToIntBits(x);
- bits = 31L * bits + (long)Float.floatToIntBits(y);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(x);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(y);
return (int) (bits ^ (bits >> 32));
}
diff --git a/src/javax/vecmath/Tuple3d.java b/src/javax/vecmath/Tuple3d.java
index 23d31dc..8379a8a 100644
--- a/src/javax/vecmath/Tuple3d.java
+++ b/src/javax/vecmath/Tuple3d.java
@@ -324,9 +324,9 @@ public abstract class Tuple3d implements java.io.Serializable, Cloneable {
*/
public int hashCode() {
long bits = 1L;
- bits = 31L * bits + Double.doubleToLongBits(x);
- bits = 31L * bits + Double.doubleToLongBits(y);
- bits = 31L * bits + Double.doubleToLongBits(z);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(x);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(y);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(z);
return (int) (bits ^ (bits >> 32));
}
diff --git a/src/javax/vecmath/Tuple3f.java b/src/javax/vecmath/Tuple3f.java
index 4e96f4b..d32a109 100644
--- a/src/javax/vecmath/Tuple3f.java
+++ b/src/javax/vecmath/Tuple3f.java
@@ -386,9 +386,9 @@ public abstract class Tuple3f implements java.io.Serializable, Cloneable {
*/
public int hashCode() {
long bits = 1L;
- bits = 31L * bits + (long)Float.floatToIntBits(x);
- bits = 31L * bits + (long)Float.floatToIntBits(y);
- bits = 31L * bits + (long)Float.floatToIntBits(z);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(x);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(y);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(z);
return (int) (bits ^ (bits >> 32));
}
diff --git a/src/javax/vecmath/Tuple4d.java b/src/javax/vecmath/Tuple4d.java
index 063e130..2898dad 100644
--- a/src/javax/vecmath/Tuple4d.java
+++ b/src/javax/vecmath/Tuple4d.java
@@ -432,10 +432,10 @@ public abstract class Tuple4d implements java.io.Serializable, Cloneable {
*/
public int hashCode() {
long bits = 1L;
- bits = 31L * bits + Double.doubleToLongBits(x);
- bits = 31L * bits + Double.doubleToLongBits(y);
- bits = 31L * bits + Double.doubleToLongBits(z);
- bits = 31L * bits + Double.doubleToLongBits(w);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(x);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(y);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(z);
+ bits = 31L * bits + VecMathUtil.doubleToLongBits(w);
return (int) (bits ^ (bits >> 32));
}
diff --git a/src/javax/vecmath/Tuple4f.java b/src/javax/vecmath/Tuple4f.java
index fea4e31..5b213ea 100644
--- a/src/javax/vecmath/Tuple4f.java
+++ b/src/javax/vecmath/Tuple4f.java
@@ -418,10 +418,10 @@ public abstract class Tuple4f implements java.io.Serializable, Cloneable {
*/
public int hashCode() {
long bits = 1L;
- bits = 31L * bits + (long)Float.floatToIntBits(x);
- bits = 31L * bits + (long)Float.floatToIntBits(y);
- bits = 31L * bits + (long)Float.floatToIntBits(z);
- bits = 31L * bits + (long)Float.floatToIntBits(w);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(x);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(y);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(z);
+ bits = 31L * bits + (long)VecMathUtil.floatToIntBits(w);
return (int) (bits ^ (bits >> 32));
}
diff --git a/src/javax/vecmath/VecMathUtil.java b/src/javax/vecmath/VecMathUtil.java
new file mode 100644
index 0000000..cc34d90
--- /dev/null
+++ b/src/javax/vecmath/VecMathUtil.java
@@ -0,0 +1,84 @@
+/*
+ * $RCSfile$
+ *
+ * Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
+ * $Revision$
+ * $Date$
+ * $State$
+ */
+
+package javax.vecmath;
+
+/**
+ * Utility vecmath class used when computing the hash code for vecmath
+ * objects containing float or double values. This fixes Issue 36.
+ */
+class VecMathUtil {
+ /**
+ * Returns the representation of the specified floating-point
+ * value according to the IEEE 754 floating-point "single format"
+ * bit layout, after first mapping -0.0 to 0.0. This method is
+ * identical to Float.floatToIntBits(float) except that an integer
+ * value of 0 is returned for a floating-point value of
+ * -0.0f. This is done for the purpose of computing a hash code
+ * that satisfies the contract of hashCode() and equals(). The
+ * equals() method in each vecmath class does a pair-wise "=="
+ * test on each floating-point field in the class (e.g., x, y, and
+ * z for a Tuple3f). Since 0.0f&nbsp;==&nbsp;-0.0f returns true,
+ * we must also return the same hash code for two objects, one of
+ * which has a field with a value of -0.0f and the other of which
+ * has a cooresponding field with a value of 0.0f.
+ *
+ * @param f an input floating-point number
+ * @return the integer bits representing that floating-point
+ * number, after first mapping -0.0f to 0.0f
+ */
+ static int floatToIntBits(float f) {
+ // Check for +0 or -0
+ if (f == 0.0f) {
+ return 0;
+ }
+ else {
+ return Float.floatToIntBits(f);
+ }
+ }
+
+ /**
+ * Returns the representation of the specified floating-point
+ * value according to the IEEE 754 floating-point "double format"
+ * bit layout, after first mapping -0.0 to 0.0. This method is
+ * identical to Double.doubleToLongBits(double) except that an
+ * integer value of 0L is returned for a floating-point value of
+ * -0.0. This is done for the purpose of computing a hash code
+ * that satisfies the contract of hashCode() and equals(). The
+ * equals() method in each vecmath class does a pair-wise "=="
+ * test on each floating-point field in the class (e.g., x, y, and
+ * z for a Tuple3d). Since 0.0&nbsp;==&nbsp;-0.0 returns true, we
+ * must also return the same hash code for two objects, one of
+ * which has a field with a value of -0.0 and the other of which
+ * has a cooresponding field with a value of 0.0.
+ *
+ * @param d an input double precision floating-point number
+ * @return the integer bits representing that floating-point
+ * number, after first mapping -0.0f to 0.0f
+ */
+ static long doubleToLongBits(double d) {
+ // Check for +0 or -0
+ if (d == 0.0) {
+ return 0L;
+ }
+ else {
+ return Double.doubleToLongBits(d);
+ }
+ }
+
+
+ /**
+ * Do not construct an instance of this class.
+ */
+ private VecMathUtil() {
+ }
+}