Skip to content

Bug: BoundingBox.merge() modifies object in place #2544

@capdevon

Description

@capdevon
  1. The BoundingBox.merge() method internally invokes the BoundingBox.mergeLocal() method, which alters the internal state of the BoundingBox object on which it is invoked. In contrast, the BoundingSphere.merge() method correctly creates a new object without altering the internal state of the BoundingSphere object on which it is invoked.

Does anyone else think this behavior is definitely wrong, or is there a hidden reason behind this choice?

https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-core/src/main/java/com/jme3/bounding/BoundingBox.java#L417

https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-core/src/main/java/com/jme3/bounding/BoundingSphere.java#L470


  1. Even in the whichSide() method, the < and > comparisons could be standardized:
// from BoundingBox

    @Override
    public Plane.Side whichSide(Plane plane) {
        float radius = FastMath.abs(xExtent * plane.getNormal().getX())
                + FastMath.abs(yExtent * plane.getNormal().getY())
                + FastMath.abs(zExtent * plane.getNormal().getZ());

        float distance = plane.pseudoDistance(center);

        //changed to < and > to prevent floating point precision problems
        if (distance < -radius) {
            return Plane.Side.Negative;
        } else if (distance > radius) {
            return Plane.Side.Positive;
        } else {
            return Plane.Side.None;
        }
    }
// from BoundingSphere

    @Override
    public Plane.Side whichSide(Plane plane) {
        float distance = plane.pseudoDistance(center);

        if (distance <= -radius) {
            return Plane.Side.Negative;
        } else if (distance >= radius) {
            return Plane.Side.Positive;
        } else {
            return Plane.Side.None;
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectSomething that is supposed to work, but doesn't. Less severe than a "bug"question

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions