BoundingSphere . merge() fix


[  I originally posted this in the jME3 area, when it probably should have been here.  ]

I'm new here, so please bear with me if the format of my fix proposal is incorrect or incomplete.

I found a defect in the merge() method of BoundingSphere and have identified a fix.

Here's a code snippet:

private BoundingVolume merge(float temp_radius, Vector3f temp_center, BoundingSphere rVal) {
        Vector3f rCenter = rVal.getCenter();
        if ( rCenter == null ) {
            rVal.setCenter( rCenter = new Vector3f() );
    -   if (length > radiusEpsilon) {
    +  if ((length + temp_radius) > radius) {
            float coeff = (length + radiusDiff) / (2.0f * length);
        } else {

        rVal.setRadius(0.5f * (length + radius + temp_radius));
        return rVal;

The if test [at line 607 in] in BoundingSphere.merge() was causing the Bounding Sphere center to not move if the distance between the two sphere's being merged was less than radiusEpsilon.
The corrected test now looks for the case where the sum of the center-center distance and the second sphere radius is greater than the radius of 'this'.

I have tested the fix in my app and verified that the merge method now operates correctly.

I suspect that I don't have commit access here, so perhaps another member can do the commit if you are satisfied with the fix.

All the best.


Could you make a small testcase which shows/verifies the problem ?


Sure, a can make a testcase.

I haven't made one before though.  Can you reply with a URL to an example of a testcase that I can use as a template ?



just a simple SimpleGame, so others can verify easily that it works and doesn't break the current behavior  :slight_smile:

Like this one: