Skip to content

Commit

Permalink
BoundingVolume: add equals() and hashCode() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jun 8, 2024
1 parent 37375bb commit 6567eb2
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion jme3-core/src/main/java/com/jme3/bounding/BoundingVolume.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2021 jMonkeyEngine
* Copyright (c) 2009-2024 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -180,6 +180,49 @@ public final BoundingVolume transform(Transform trans) {
*/
public abstract BoundingVolume clone(BoundingVolume store);

/**
* Tests for exact equality with the argument, distinguishing -0 from 0. If
* {@code other} is null, false is returned. Either way, the current
* instance is unaffected.
*
* @param other the object to compare (may be null, unaffected)
* @return true if {@code this} and {@code other} have identical values,
* otherwise false
*/
@Override
public boolean equals(Object other) {
if (!(other instanceof BoundingVolume)) {
return false;
}

if (this == other) {
return true;
}

BoundingVolume otherBoundingVolume = (BoundingVolume) other;
if (!center.equals(otherBoundingVolume.getCenter())) {
return false;
}
// The checkPlane field is ignored.

return true;
}

/**
* Returns a hash code. If two bounding volumes have identical values, they
* will have the same hash code. The current instance is unaffected.
*
* @return a 32-bit value for use in hashing
*/
@Override
public int hashCode() {
int hash = 3;
hash = 59 * hash + center.hashCode();
// The checkPlane field is ignored.

return hash;
}

public final Vector3f getCenter() {
return center;
}
Expand Down

0 comments on commit 6567eb2

Please sign in to comment.