public void ReturnTrue_If_TwoBoundingBoxes_Intersect(List <Point> ptsBBox1, List <Point> ptsBBox2, bool result) { BoundingBox bBox1 = new BoundingBox(ptsBBox1); BoundingBox bBox2 = new BoundingBox(ptsBBox2); bool intersectionResult = BoundingBox.AreOverlapping(bBox1, bBox2, 0.0); intersectionResult.Should().Be(result); }
public void It_Returns_True_If_TwoBoundingBoxes_Intersect(Point3[] ptsBBox1, Point3[] ptsBBox2, bool result) { // Arrange var bBox1 = new BoundingBox(ptsBBox1); var bBox2 = new BoundingBox(ptsBBox2); // Act var intersectionResult = BoundingBox.AreOverlapping(bBox1, bBox2, 0.0); // Assert intersectionResult.Should().Be(result); }
/// <summary> /// The core algorithm for bounding box tree intersection.<br/> /// Supporting both lazy and pre-computed bounding box trees via the <see cref="IBoundingBoxTree{CurveParameter}"/> interface. /// </summary> /// <param name="aTrees">The first Bounding box tree object.</param> /// <param name="bTrees">The second Bounding box tree object.</param> /// <param name="tolerance">Tolerance as per default set as 1e-9.</param> /// <returns>A collection of tuples extracted from the Yield method of the BoundingBoxTree.</returns> private static List <Tuple <T1, T2> > GetRoot <T1, T2>(List <IBoundingBoxTree <T1> > aTrees, List <IBoundingBoxTree <T2> > bTrees, double tolerance) { List <Tuple <T1, T2> > result = new List <Tuple <T1, T2> >(); while (aTrees.Count > 0) { IBoundingBoxTree <T1> a = aTrees[aTrees.Count - 1]; aTrees.RemoveAt(aTrees.Count - 1); IBoundingBoxTree <T2> b = bTrees[bTrees.Count - 1]; bTrees.RemoveAt(bTrees.Count - 1); if (a.IsEmpty() || b.IsEmpty()) { continue; } if (BoundingBox.AreOverlapping(a.BoundingBox(), b.BoundingBox(), tolerance) == false) { continue; } bool aIndivisible = a.IsIndivisible(tolerance); bool bIndivisible = b.IsIndivisible(tolerance); Tuple <IBoundingBoxTree <T1>, IBoundingBoxTree <T1> > aSplit = a.Split(); Tuple <IBoundingBoxTree <T2>, IBoundingBoxTree <T2> > bSplit = b.Split(); if (aIndivisible && bIndivisible) { result.Add(new Tuple <T1, T2>(a.Yield(), b.Yield())); continue; } if (aIndivisible) { aTrees.Add(a); bTrees.Add(bSplit.Item2); aTrees.Add(a); bTrees.Add(bSplit.Item1); continue; } if (bIndivisible) { aTrees.Add(aSplit.Item2); bTrees.Add(b); aTrees.Add(aSplit.Item1); bTrees.Add(b); continue; } aTrees.Add(aSplit.Item2); bTrees.Add(bSplit.Item2); aTrees.Add(aSplit.Item2); bTrees.Add(bSplit.Item1); aTrees.Add(aSplit.Item1); bTrees.Add(bSplit.Item2); aTrees.Add(aSplit.Item1); bTrees.Add(bSplit.Item1); } return(result); }