Skip to content

Commit

Permalink
BoundingBox Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed May 27, 2024
1 parent e2145b3 commit 95e916a
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions CSMath/BoundingBox.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
namespace CSMath
{
/// <summary>
/// Bounding box representation aligned to XYZ axis
/// Bounding box representation aligned to XYZ axis.
/// </summary>
public struct BoundingBox
{
/// <summary>
/// Get the min corner of the bounding box
/// Get the min corner of the bounding box.
/// </summary>
public XYZ Min { get; set; }

/// <summary>
/// Get the max corner of the bounding box
/// Get the max corner of the bounding box.
/// </summary>
public XYZ Max { get; set; }

/// <summary>
/// Center of the box
/// Center of the box.
/// </summary>
public XYZ Center
{
Expand All @@ -27,7 +27,7 @@ public XYZ Center
}

/// <summary>
/// Bounding box constructor with 2 points
/// Bounding box constructor with 2 points.
/// </summary>
/// <param name="min"></param>
/// <param name="max"></param>
Expand All @@ -38,7 +38,7 @@ public BoundingBox(XYZ min, XYZ max)
}

/// <summary>
/// Bounding box contructor
/// Bounding box contructor.
/// </summary>
/// <param name="minX"></param>
/// <param name="minY"></param>
Expand All @@ -50,5 +50,24 @@ public BoundingBox(double minX, double minY, double minZ, double maxX, double ma
{
this = new BoundingBox(new XYZ(minX, minY, minZ), new XYZ(maxX, maxY, maxZ));
}

/// <summary>
/// Merge 2 boxes into the common one.
/// </summary>
/// <param name="box"></param>
/// <returns>The merged box.</returns>
public BoundingBox Merge(BoundingBox box)
{
var min = new XYZ(
System.Math.Min(this.Min.X, box.Min.X),
System.Math.Min(this.Min.Y, box.Min.Y),
System.Math.Min(this.Min.Z, box.Min.Z));
var max = new XYZ(
System.Math.Max(this.Max.X, box.Max.X),
System.Math.Max(this.Max.Y, box.Max.Y),
System.Math.Max(this.Max.Z, box.Max.Z));

return new BoundingBox(min, max);
}
}
}

0 comments on commit 95e916a

Please sign in to comment.