diff --git a/CSMath/BoundingBox.cs b/CSMath/BoundingBox.cs
index f7439cc..4e291d2 100644
--- a/CSMath/BoundingBox.cs
+++ b/CSMath/BoundingBox.cs
@@ -1,22 +1,22 @@
namespace CSMath
{
///
- /// Bounding box representation aligned to XYZ axis
+ /// Bounding box representation aligned to XYZ axis.
///
public struct BoundingBox
{
///
- /// Get the min corner of the bounding box
+ /// Get the min corner of the bounding box.
///
public XYZ Min { get; set; }
///
- /// Get the max corner of the bounding box
+ /// Get the max corner of the bounding box.
///
public XYZ Max { get; set; }
///
- /// Center of the box
+ /// Center of the box.
///
public XYZ Center
{
@@ -27,7 +27,7 @@ public XYZ Center
}
///
- /// Bounding box constructor with 2 points
+ /// Bounding box constructor with 2 points.
///
///
///
@@ -38,7 +38,7 @@ public BoundingBox(XYZ min, XYZ max)
}
///
- /// Bounding box contructor
+ /// Bounding box contructor.
///
///
///
@@ -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));
}
+
+ ///
+ /// Merge 2 boxes into the common one.
+ ///
+ ///
+ /// The merged box.
+ 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);
+ }
}
}