public void FindNeighborsThatSatisfyAGivenPredicate() { RBush <Box> bush = new RBush <Box>(); bush.BulkLoad(richData); IEnumerable <Box> result = bush.KnnToLineSegmentSearch(6386.5, 3349.5, 6393, 3353.5, 1, b => b.Version > 2); if (result.Count() == 1) { Box item = result.First(); if (item.Envelope.MinX == 6393.8 && item.Envelope.MinY == 3354.0 && item.Envelope.MaxX == 6395.3 && item.Envelope.MaxY == 3356.0 && item.Version == 3) { //Test passes. Found the correct item } else { Assert.True(false, "Could not find the correct item"); } } else { Assert.True(false, "Could not find the correct item"); } }
public void FindsNNeighbors1() { RBush <Box> bush = new RBush <Box>(); bush.BulkLoad(boxes); IEnumerable <Box> result = bush.KnnToLineSegmentSearch(6362, 3343.5, 6360.75, 3344, 10); Box[] mustBeReturned = Box.CreateBoxes(new double[, ] { { 6359.0, 3343.0, 6362.5, 3345.0 }, { 6357.0, 3342.0, 6363.5, 3343.0 }, { 6360.5, 3340.0, 6361.5, 3342.0 }, { 6364.0, 3342.0, 6365.0, 3344.5 }, { 6362.0, 3340.5, 6363.0, 3341.5 }, { 6358.5, 3337.5, 6360.5, 3341.5 }, { 6361.0, 3339.0, 6363.0, 3340.0 }, { 6364.5, 3340.5, 6368.0, 3341.0 }, { 6363.5, 3337.5, 6365.0, 3340.0 }, { 6367.0, 3342.0, 6368.0, 3344.0 }, }); Assert.True(mustBeReturned.Length == result.Count()); Assert.True(result.ElementAt(0).CompareTo(mustBeReturned[0]) == 0); Assert.True(result.ElementAt(1).CompareTo(mustBeReturned[1]) == 0); Assert.True(result.ElementAt(2).CompareTo(mustBeReturned[2]) == 0); Assert.True(result.ElementAt(3).CompareTo(mustBeReturned[3]) == 0 || result.ElementAt(3).CompareTo(mustBeReturned[4]) == 0); Assert.True(result.ElementAt(4).CompareTo(mustBeReturned[3]) == 0 || result.ElementAt(4).CompareTo(mustBeReturned[4]) == 0); Assert.True(result.ElementAt(5).CompareTo(mustBeReturned[5]) == 0); Assert.True(result.ElementAt(6).CompareTo(mustBeReturned[6]) == 0); Assert.True(result.ElementAt(7).CompareTo(mustBeReturned[7]) == 0); Assert.True(result.ElementAt(8).CompareTo(mustBeReturned[8]) == 0); Assert.True(result.ElementAt(9).CompareTo(mustBeReturned[9]) == 0); }
public void FindNNeighborsForMaxDistance() { RBush <Box> bush = new RBush <Box>(); bush.BulkLoad(boxes); IEnumerable <Box> result = bush.KnnToLineSegmentSearch(6373, 3324, 6396.5, 3336, 3, maxDist: 8); Box[] mustBeReturned = Box.CreateBoxes(new double[, ] { { 6374.5, 3327.0, 6380.5, 3329.5 }, { 6385.0, 3332.5, 6388.0, 3335.0 }, { 6377.5, 3330.5, 6380.0, 3332.5 } }); Assert.True(mustBeReturned.Length == result.Count()); Assert.True(result.ElementAt(0).CompareTo(mustBeReturned[0]) == 0); Assert.True(result.ElementAt(1).CompareTo(mustBeReturned[1]) == 0); Assert.True(result.ElementAt(2).CompareTo(mustBeReturned[2]) == 0); }
public void FindAllNeighborsForMaxDistance1() { RBush <Box> bush = new RBush <Box>(); bush.BulkLoad(boxes); IEnumerable <Box> result = bush.KnnToLineSegmentSearch(6377.5, 3351.5, 6379, 3350.5, 0, maxDist: 4); Box[] mustBeReturned = Box.CreateBoxes(new double[, ] { { 6378.5, 3348.5, 6379.5, 3351.0 }, { 6375.5, 3348.5, 6378.0, 3350.0 }, { 6379.5, 3343.5, 6382.0, 3349.0 }, { 6378.0, 3345.5, 6379.5, 3348.0 }, { 6372.5, 3347.5, 6377.0, 3348.0 }, { 6375.0, 3344.0, 6377.5, 3347.0 }, }); Assert.True(mustBeReturned.Length == result.Count()); Assert.True(result.ElementAt(0).CompareTo(mustBeReturned[0]) == 0); Assert.True(result.ElementAt(1).CompareTo(mustBeReturned[1]) == 0); Assert.True(result.ElementAt(2).CompareTo(mustBeReturned[2]) == 0); Assert.True(result.ElementAt(3).CompareTo(mustBeReturned[3]) == 0); Assert.True(result.ElementAt(4).CompareTo(mustBeReturned[4]) == 0); Assert.True(result.ElementAt(5).CompareTo(mustBeReturned[5]) == 0); }
public void FindsNNeighbors2() { RBush <Box> bush = new RBush <Box>(); bush.BulkLoad(boxes); IEnumerable <Box> result = bush.KnnToLineSegmentSearch(6361.5, 3352.5, 6367, 3354, 6); Box[] mustBeReturned = Box.CreateBoxes(new double[, ] { { 6361.0, 3352.5, 6361.0, 3352.5 }, { 6362.5, 3353.5, 6362.5, 3353.5 }, { 6364.0, 3354.0, 6364.0, 3354.0 }, { 6363.5, 3352.0, 6363.5, 3352.0 }, { 6363.0, 3351.0, 6363.0, 3351.0 }, { 6365.0, 3351.5, 6365.0, 3351.5 }, }); Assert.True(mustBeReturned.Length == result.Count()); Assert.True(result.ElementAt(0).CompareTo(mustBeReturned[0]) == 0); Assert.True(result.ElementAt(1).CompareTo(mustBeReturned[1]) == 0); Assert.True(result.ElementAt(2).CompareTo(mustBeReturned[2]) == 0); Assert.True(result.ElementAt(3).CompareTo(mustBeReturned[3]) == 0); Assert.True(result.ElementAt(4).CompareTo(mustBeReturned[4]) == 0); Assert.True(result.ElementAt(5).CompareTo(mustBeReturned[5]) == 0); }
public void FindAllNeighborsForMaxDistance2() { RBush <Box> bush = new RBush <Box>(); bush.BulkLoad(boxes); IEnumerable <Box> result = bush.KnnToLineSegmentSearch(6373, 3324, 6396.5, 3336, 0, maxDist: 8); Box[] mustBeReturned = Box.CreateBoxes(new double[, ] { { 6374.5, 3327.0, 6380.5, 3329.5 }, { 6385.0, 3332.5, 6388.0, 3335.0 }, { 6377.5, 3330.5, 6380.0, 3332.5 }, { 6388.5, 3338.5, 6390.5, 3342.5 }, { 6362.5, 3329.5, 6369.0, 3332.5 }, { 6379.5, 3336.0, 6381.5, 3339.0 }, { 6371.5, 3332.0, 6373.5, 3333.0 }, { 6374.5, 3333.5, 6375.0, 3335.5 }, }); Assert.True(mustBeReturned.Length == result.Count()); Assert.True(result.ElementAt(0).CompareTo(mustBeReturned[0]) == 0); Assert.True(result.ElementAt(1).CompareTo(mustBeReturned[1]) == 0); Assert.True(result.ElementAt(2).CompareTo(mustBeReturned[2]) == 0); Assert.True(result.ElementAt(3).CompareTo(mustBeReturned[3]) == 0); Assert.True(result.ElementAt(4).CompareTo(mustBeReturned[4]) == 0); Assert.True(result.ElementAt(5).CompareTo(mustBeReturned[5]) == 0); Assert.True(result.ElementAt(6).CompareTo(mustBeReturned[6]) == 0); }