Skip to content

Boundingbox getcorners expand#2861

Open
xinzhoudev wants to merge 4 commits into
jMonkeyEngine:masterfrom
xinzhoudev:xinzhoudev-boundingbox-getcorners-expand
Open

Boundingbox getcorners expand#2861
xinzhoudev wants to merge 4 commits into
jMonkeyEngine:masterfrom
xinzhoudev:xinzhoudev-boundingbox-getcorners-expand

Conversation

@xinzhoudev

Copy link
Copy Markdown

This PR adds four new convenience methods to BoundingBox in jme3-core:

Methods and Descriptions:
getCorners(Vector3f[] store): Returns all 8 AABB corner vertices; reuses caller-supplied array to avoid allocation in tight loops
getCorners(): Zero-arg convenience overload; allocates a fresh 8-element array
expand(float amount): Uniformly grows/shrinks all three extents; clamps to zero; returns this for chaining
expand(Vector3f amounts): Per-axis variant of expand

Motivation

Getting all 8 corners of a BoundingBox currently requires manual getMin/getMax arithmetic every time. This pattern appears repeatedly in debug rendering, shadow-map frustum fitting, and physics hull construction. Comparable frameworks all expose an equivalent method:

  • libGDX: BoundingBox.getCorners(Array<Vector3>)
  • XNA / MonoGame: BoundingBox.GetCorners() → Vector3[]
  • DirectX: BoundingBox::GetCorners(XMFLOAT3 *Corners)

The expand methods 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 methods
  • jme3-examples/.../bounding/TestBoundingBoxEnhancements.java — 12 new JUnit 4 test cases

Testing

TestBoundingBoxEnhancements covers:

  • Corner count and content (unit box, offset center, point box)
  • Documented corner ordering (indices 0–7)
  • store array reuse vs. null allocation
  • Uniform expand: grow, shrink, clamp-to-zero, center unchanged
  • Per-axis expand: independent axes, mixed grow/shrink, clamp-to-zero
  • Chaining: expand() returns this
  • Interaction: getCorners() reflects updated extents after expand()

Notes

  • No breaking changes — purely additive API surface.
  • No new dependencies introduced.
  • Follows the existing store-parameter convention used by getMin(Vector3f),
    getMax(Vector3f), and getExtent(Vector3f).
  • expand() is intentionally scoped to BoundingBox only (not the abstract
    BoundingVolume) as the operation is AABB-specific.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 806 to +814
@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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
@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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
  1. Issues found in test code should be reported with a reduced priority, at most medium.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant