Boundingbox getcorners expand#2861
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors BoundingBox by cleaning up imports, updating Javadocs, optimizing existing methods (such as computeFromTris and containAABB), and introducing new utility methods like getCorners and expand. It also adds corresponding unit tests and a new test suite for Vector3Serializer. Feedback on these changes highlights a bug in the simplified equals implementation of BoundingBox where using == instead of Float.compare for float comparisons breaks the equals and hashCode contract. Additionally, a package declaration mismatch was identified in the newly added Vector3SerializerTest file.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| @Override | ||
| public float getVolume() { | ||
| return (8 * xExtent * yExtent * zExtent); | ||
| public boolean equals(Object obj) { | ||
| if (!(obj instanceof BoundingBox)) return false; | ||
| BoundingBox other = (BoundingBox) obj; | ||
| return center.equals(other.center) | ||
| && xExtent == other.xExtent | ||
| && yExtent == other.yExtent | ||
| && zExtent == other.zExtent; | ||
| } |
There was a problem hiding this comment.
The simplified equals implementation uses == for float comparisons (xExtent == other.xExtent), which behaves differently than Float.compare for -0.0f and 0.0f. This breaks the existing test testEquals in TestBoundingBox.java which expects 0.0f and -0.0f extents to be considered unequal. Additionally, since hashCode uses Float.floatToIntBits (which distinguishes -0.0f and 0.0f), this creates a violation of the equals and hashCode contract where two objects can be equal but have different hash codes.
Please restore the use of Float.compare to ensure correctness and preserve backward compatibility.
| @Override | |
| public float getVolume() { | |
| return (8 * xExtent * yExtent * zExtent); | |
| public boolean equals(Object obj) { | |
| if (!(obj instanceof BoundingBox)) return false; | |
| BoundingBox other = (BoundingBox) obj; | |
| return center.equals(other.center) | |
| && xExtent == other.xExtent | |
| && yExtent == other.yExtent | |
| && zExtent == other.zExtent; | |
| } | |
| @Override | |
| public boolean equals(Object obj) { | |
| if (this == obj) return true; | |
| if (!(obj instanceof BoundingBox)) return false; | |
| BoundingBox other = (BoundingBox) obj; | |
| return center.equals(other.center) | |
| && Float.compare(xExtent, other.xExtent) == 0 | |
| && Float.compare(yExtent, other.yExtent) == 0 | |
| && Float.compare(zExtent, other.zExtent) == 0; | |
| } |
| * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
| package com.jme3.network.serializing.serializers; |
There was a problem hiding this comment.
The package declaration com.jme3.network.serializing.serializers does not match the file's directory path com/jme3/network/message/. In Java, the package structure must align with the directory structure. Please move this test file to jme3-networking/src/test/java/com/jme3/network/serializing/serializers/Vector3SerializerTest.java to resolve this mismatch.
References
- Issues found in test code should be reported with a reduced priority, at most medium.
This PR adds four new convenience methods to
BoundingBoxinjme3-core:Methods and Descriptions:
getCorners(Vector3f[] store): Returns all 8 AABB corner vertices; reuses caller-supplied array to avoid allocation in tight loopsgetCorners(): Zero-arg convenience overload; allocates a fresh 8-element arrayexpand(float amount): Uniformly grows/shrinks all three extents; clamps to zero; returnsthisfor chainingexpand(Vector3f amounts): Per-axis variant ofexpandMotivation
Getting all 8 corners of a
BoundingBoxcurrently requires manualgetMin/getMaxarithmetic every time. This pattern appears repeatedly in debug rendering, shadow-map frustum fitting, and physics hull construction. Comparable frameworks all expose an equivalent method:BoundingBox.getCorners(Array<Vector3>)BoundingBox.GetCorners() → Vector3[]BoundingBox::GetCorners(XMFLOAT3 *Corners)The
expandmethods address an equally common pattern: trigger volumes and hitbox tolerances routinely need a slightly padded copy of a mesh's world bound, which today requires manually recomputing center and extents.Changes
jme3-core/.../bounding/BoundingBox.java— four new public methodsjme3-examples/.../bounding/TestBoundingBoxEnhancements.java— 12 new JUnit 4 test casesTesting
TestBoundingBoxEnhancementscovers:storearray reuse vs.nullallocationexpand()returnsthisgetCorners()reflects updated extents afterexpand()Notes
getMin(Vector3f),getMax(Vector3f), andgetExtent(Vector3f).expand()is intentionally scoped toBoundingBoxonly (not the abstractBoundingVolume) as the operation is AABB-specific.