From 6567eb283ac3e8239d99e4b58b53752a8c2bece4 Mon Sep 17 00:00:00 2001 From: stephengold Date: Fri, 7 Jun 2024 17:40:47 -0700 Subject: [PATCH] BoundingVolume: add equals() and hashCode() methods --- .../com/jme3/bounding/BoundingVolume.java | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/bounding/BoundingVolume.java b/jme3-core/src/main/java/com/jme3/bounding/BoundingVolume.java index 88cd4148ef..2575222c3b 100644 --- a/jme3-core/src/main/java/com/jme3/bounding/BoundingVolume.java +++ b/jme3-core/src/main/java/com/jme3/bounding/BoundingVolume.java @@ -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 @@ -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; }