aherbert commented on code in PR #227:
URL: https://github.com/apache/commons-geometry/pull/227#discussion_r1471723996
##########
commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java:
##########
@@ -399,16 +399,24 @@ public boolean eq(final Vector3D vec, final
Precision.DoubleEquivalence precisio
/**
* Get a hashCode for the vector.
- * <p>All NaN values have the same hash code.</p>
Review Comment:
Please revert formatting. It ad noise the the changes.
##########
commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/Vector3D.java:
##########
@@ -399,16 +399,24 @@ public boolean eq(final Vector3D vec, final
Precision.DoubleEquivalence precisio
/**
* Get a hashCode for the vector.
- * <p>All NaN values have the same hash code.</p>
- *
+ * <p>
+ * All NaN values have the same hash code.
* @return a hash code value for this object
*/
@Override
public int hashCode() {
if (isNaN()) {
return 642;
}
- return 643 * (164 * Double.hashCode(x) + 3 * Double.hashCode(y) +
Double.hashCode(z));
+ int result = 17;
+ long temp;
+ temp = Double.doubleToLongBits(x);
Review Comment:
I thought this was fixed with a different linear combination of
`Double.hashCode`. This seems to have reverted to using `doubleToLongBits`.
##########
commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Vector2D.java:
##########
@@ -340,15 +340,14 @@ public boolean eq(final Vector2D vec, final
Precision.DoubleEquivalence precisio
* Get a hashCode for the 2D coordinates.
* <p>
* All NaN values have the same hash code.</p>
- *
Review Comment:
Revert formatting
##########
commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/GreatCircleTest.java:
##########
@@ -664,7 +664,7 @@ void testHashCode() {
Assertions.assertEquals(hash, a.hashCode());
Assertions.assertNotEquals(hash, b.hashCode());
- Assertions.assertNotEquals(hash, c.hashCode());
+ Assertions.assertEquals(hash, c.hashCode());
Review Comment:
If the two circles are the same then this should be tested using
`Assertions.assertEquals`. If they are the same then the hash code **_must_**
be the same. If the objects are not equal then the hash code may or may not
collide; it doesn't matter.
Any test that uses not equals on hash codes for objects that are not equal
can potentially fail due to random hash collision.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]