Grow a BoundingInfo thanks to an Encapsulate method

Hi all,
I’m porting a software from Unity to BabylonJS, and I’m currently working on some code that uses Unity’s Bounds class… Babylon’s BoundingInfo seems to be what I am looking for (also thanks to the inglobed boundingBox field), and the only thing I am lacking is something similar to Unity’s Encapsulate, which grows the current Bounds to include a given point/bound.

Have I missed the existance of a method that does exactly this for BoundingInfo by any chance? Or maybe I should use another class?

Of course the underlying implementation of what I am looking for is quite simple (see beneath snippet) and I could (and will) store this code in a custom extension class… But I think it’s a pity that it is not something that’s already available, so I wonder if it could be roadmapped if it is not already the case? (couldn’t find any similar request/discussion)

/// <summary>
///   <para>Grows the Bounds to include the point.</para>
/// </summary>
/// <param name="point"></param>
public void Encapsulate(Vector3 point) => this.SetMinMax(Vector3.Min(this.min, point), Vector3.Max(this.max, point));

/// <summary>
///   <para>Grow the bounds to encapsulate the bounds.</para>
/// </summary>
/// <param name="bounds"></param>
public void Encapsulate(Bounds bounds)
{
  this.Encapsulate(bounds.center - bounds.extents);
  this.Encapsulate(bounds.center + bounds.extents);
}

I like the idea

Do you want to do a PR to add it?

1 Like

Sure!
I’ve never contributed to BabylonJS (or any other public repo before), I will take some time to read your PR documentation and create one for this feature today or in the following days :slight_smile:

There is no rush. I genuinely believe OSS is meant to be shared at developer level

So whatever it takes, please do a PR :slight_smile:

Here is the PR in case some may want to follow up the implementation of this feature into BJS.

1 Like