private List <T> FindNeighbours(T point, double radius, BalancedKdTreeNode <T> node, Func <T, T, double> distanceFunc = null) { var result = new List <T>(); //if (distanceFunc(point, node.Point) <= radius) //{ // result.Add(node.Point); //} if (node.LeftChild != null && !node.LeftChild.IsNilNode()) { var relation = SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(PointFunc(point), radius, node.LeftChild.MinimumBoundingBox); if (relation == IRI.Msh.Common.Model.SpatialRelation.Contained) { result.AddRange(GetAllValues(node.LeftChild)); } else if (relation == IRI.Msh.Common.Model.SpatialRelation.Intersects) { result.AddRange(FindNeighbours(point, radius, node.LeftChild, distanceFunc)); } } if (node.RightChild != null && !node.RightChild.IsNilNode()) { var relation = SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(PointFunc(point), radius, node.RightChild.MinimumBoundingBox); if (relation == IRI.Msh.Common.Model.SpatialRelation.Contained) { result.AddRange(GetAllValues(node.RightChild)); } else if (relation == IRI.Msh.Common.Model.SpatialRelation.Intersects) { result.AddRange(FindNeighbours(point, radius, node.RightChild, distanceFunc)); } } return(result); }
public void TestCircleRectangleIntersects() { // ------- // | | // | | // | | // ------- BoundingBox rectangle = new BoundingBox(0, 0, 10, 20); var radius = 5; Point insideRectangle = new Point(5, 9); Assert.AreEqual(true, SpatialUtility.CircleRectangleIntersects(insideRectangle, radius, rectangle)); Point topOfRectangle = new Point(5, 25.1); Assert.AreEqual(false, SpatialUtility.CircleRectangleIntersects(topOfRectangle, radius, rectangle)); Point bottomOfRectangle = new Point(5, -6); Assert.AreEqual(false, SpatialUtility.CircleRectangleIntersects(bottomOfRectangle, radius, rectangle)); Point topRightCorner = new Point(13, 24); Assert.AreEqual(true, SpatialUtility.CircleRectangleIntersects(topRightCorner, radius, rectangle)); Point topRightCorner2 = new Point(13.1, 24); Assert.AreEqual(false, SpatialUtility.CircleRectangleIntersects(topRightCorner2, radius, rectangle)); Point centerRectangle = new Point(5, 10); Assert.AreEqual(false, SpatialUtility.IsAxisAlignedRectangleInsideCircle(centerRectangle, radius, rectangle)); Point insideRectangle2 = new Point(5.1, 10); Assert.AreEqual(false, SpatialUtility.IsAxisAlignedRectangleInsideCircle(insideRectangle2, radius, rectangle)); Point insideRectangle3 = new Point(5.1, 10); Assert.AreEqual(false, SpatialUtility.IsAxisAlignedRectangleInsideCircle(insideRectangle3, 11.19, rectangle)); Point insideRectangle4 = new Point(5, 10); Assert.AreEqual(true, SpatialUtility.IsAxisAlignedRectangleInsideCircle(insideRectangle4, 11.19, rectangle)); Assert.AreEqual(Intersects, SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(insideRectangle, radius, rectangle)); Assert.AreEqual(Disjoint, SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(topOfRectangle, radius, rectangle)); Assert.AreEqual(Disjoint, SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(bottomOfRectangle, radius, rectangle)); Assert.AreEqual(Intersects, SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(topRightCorner, radius, rectangle)); Assert.AreEqual(Disjoint, SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(topRightCorner2, radius, rectangle)); Assert.AreEqual(Intersects, SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(centerRectangle, radius, rectangle)); Assert.AreEqual(Intersects, SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(insideRectangle2, radius, rectangle)); Assert.AreEqual(Intersects, SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(insideRectangle3, 11.19, rectangle)); Assert.AreEqual(Contained, SpatialUtility.CalculateAxisAlignedRectangleRelationToCircle(insideRectangle4, 11.19, rectangle)); }