Skip to content

Conversation

@stephengold
Copy link
Member

This PR addresses the enhancements request in issue #2249.

Since the PR overrides equals(), it must also override hashCode() because the contract of hashCode() specifies that objects that are equal must return the same code.

The new methods intentionally ignore the checkPlane field, which holds auxiliary data used by the Camera class.

@stephengold stephengold linked an issue May 4, 2024 that may be closed by this pull request
@stephengold
Copy link
Member Author

@pspeed42: If you've got a moment, I'd like your opinion on whether equals() and hashCode() should ignore the checkPlane field or not.

@pspeed42
Copy link
Contributor

pspeed42 commented Jun 7, 2024

It probably should ignore... but probably also that's up to the class that contains the field. It would maybe be more forward-thinking of these subclasses called super.equals() and super.hashCode() as part of their processing rather than hoping to grab the right fields from the super class (which in my opinion should have been private fields in the first place... but that's a different religious hill to die on another day).
Also, was there a reason that Objects.hash() wasn't used vs hand-coding?

@stephengold
Copy link
Member Author

Thanks for your insights, Paul.

@stephengold stephengold marked this pull request as draft June 7, 2024 16:49
@stephengold stephengold marked this pull request as ready for review June 8, 2024 01:21
@stephengold
Copy link
Member Author

ready for review

@stephengold stephengold merged commit 79fd4fd into master Jun 9, 2024
@stephengold stephengold deleted the sgold/issue/2249 branch June 9, 2024 20:47
scenemax3d pushed a commit that referenced this pull request Jun 11, 2024
…2252)

* implement equals() and hashCode() for BoundingBox

* implement equals() and hashCode() for BoundingSphere

* implement isSimilar() for BoundingBox

* implement isSimilar() for BoundingSphere

* BoundingSphere:  add comments to emphasize the treatment of checkPlane

* TestBoundingSphere:  test equals() and isSimilar()

* jme3-core tests:  add the TestBoundingBox class

* BoundingVolume:  add equals() and hashCode() methods

* utilize super.equals() and super.hashCode()

* refactor to utilize Objects.hash()
@stephengold stephengold added this to the v3.7.0 milestone Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

comparison methods for BoundingBox and BoundingSphere

3 participants