本文整理汇总了C#中QuadTree.FindNearest方法的典型用法代码示例。如果您正苦于以下问题:C# QuadTree.FindNearest方法的具体用法?C# QuadTree.FindNearest怎么用?C# QuadTree.FindNearest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QuadTree
的用法示例。
在下文中一共展示了QuadTree.FindNearest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QuadTreeTestOne
public void QuadTreeTestOne()
{
GridVector2[] points = new GridVector2[] { new GridVector2(0,0),
new GridVector2(1,1),
new GridVector2(-10,-10),
new GridVector2(-7.5, 2.5),
new GridVector2(8.5, -1.5),
new GridVector2(3.5, -6.5),
new GridVector2(1.5, -8.5),
new GridVector2(10, 10)};
int[] values = new int[] {0,1,2,3,4,5,6,7};
GridRectangle border = GridVector2.Border(points);
QuadTree<int> tree = new QuadTree<int>(points, values, border);
//Start with a basic test ensuring we can find all the existing points
for(int i = 0; i < points.Length; i++)
{
double distance;
int RetValue;
RetValue = tree.FindNearest(points[i], out distance);
Debug.Assert(RetValue == i);
Debug.Assert(distance == 0);
}
//Check to see if we can find nearby points
GridVector2[] nearpoints = new GridVector2[] { new GridVector2(.25,.25),
new GridVector2(.5,.51),
new GridVector2(-7.5,-7.5),
new GridVector2(-7.5, -1.5),
new GridVector2(8.5, -5.5),
new GridVector2(4.5, -7.75),
new GridVector2(1, -8.75),
new GridVector2(11, 11)}; //Out of original boundaries
for (int i = 0; i < nearpoints.Length; i++)
{
double distance;
int RetValue;
RetValue = tree.FindNearest(nearpoints[i], out distance);
Debug.Assert(RetValue == i);
Debug.Assert(distance == GridVector2.Distance(points[i], nearpoints[i]));
}
//Check to see if we can return all points in a rectangle
GridRectangle gridRect = new GridRectangle(0,15, 0,15);
List<GridVector2> intersectPoints;
List<int> intersectValues;
tree.Intersect(gridRect, out intersectPoints, out intersectValues);
Debug.Assert(intersectValues.Contains(0));
Debug.Assert(intersectValues.Contains(1));
Debug.Assert(intersectValues.Contains(7));
Debug.Assert(false == intersectValues.Contains(2));
Debug.Assert(false == intersectValues.Contains(3));
Debug.Assert(false == intersectValues.Contains(4));
Debug.Assert(false == intersectValues.Contains(5));
Debug.Assert(false == intersectValues.Contains(6));
}
示例2: QuadTreeTestTwo
public void QuadTreeTestTwo()
{
int numPoints = 1000;
double BoundarySize = 1000;
int seed = 0;
Random RandGen = new Random(seed);
QuadTree<int> Tree = new QuadTree<int>(new GridRectangle(-BoundarySize, BoundarySize, -BoundarySize, BoundarySize));
GridVector2[] points = new GridVector2[numPoints];
//Create the QuadTree
for (int i = 0; i < numPoints; i++)
{
points[i] = new GridVector2(RandGen.NextDouble() * BoundarySize, RandGen.NextDouble() * BoundarySize);
Tree.Add(points[i], i);
}
double distance;
//Check to see we can find every item in the quad tree
for (int i = 0; i < numPoints; i++)
{
int iFound = Tree.FindNearest(points[i], out distance);
Debug.Assert(iFound == i, "Could not find previously inserted point");
}
//Remove half the points
for (int i = 0; i < numPoints / 2; i++)
{
Tree.Remove(i);
//Make sure if we look for the removed point we get an index higher than the ones we've already removed
int iFound = Tree.FindNearest(points[i], out distance);
Debug.Assert(iFound > i, "Found previously deleted point");
}
//Look for the remaining points
for (int i = numPoints / 2; i < numPoints; i++)
{
//Make sure if we look for the removed point we get an index higher than the ones we've already removed
int iFound = Tree.FindNearest(points[i], out distance);
Debug.Assert(iFound == i, "Could not find previously inserted point after deletes");
}
//Re-insert the removed points
for (int i = 0; i < numPoints / 2; i++)
{
Tree.Add(points[i], i);
//Make sure if we look for the removed point we get an index higher than the ones we've already removed
int iFound = Tree.FindNearest(points[i], out distance);
Debug.Assert(iFound == i, "Could not find newly inserted point after deletes");
}
//Look for the remaining points
for (int i = numPoints / 2; i < numPoints; i++)
{
//Make sure if we look for the removed point we get an index higher than the ones we've already removed
int iFound = Tree.FindNearest(points[i], out distance);
Debug.Assert(iFound == i, "Could not find previously inserted point after delete and insert");
}
//Delete all the points
for (int i = 0; i < numPoints; i++)
{
Tree.Remove(i);
//Make sure if we look for the removed point we get an index higher than the ones we've already removed
if (i < numPoints - 1)
{
int iFound = Tree.FindNearest(points[i], out distance);
Debug.Assert(iFound > i, "Found previously deleted point");
}
}
//Insert some points into the empty tree to make sure we still can
for (int i = 0; i < numPoints; i++)
{
points[i] = new GridVector2(RandGen.NextDouble() * BoundarySize, RandGen.NextDouble() * BoundarySize);
Tree.Add(points[i], i);
}
//Check to see we can find every item in the quad tree
for (int i = 0; i < numPoints; i++)
{
int iFound = Tree.FindNearest(points[i], out distance);
Debug.Assert(iFound == i, "Could not find previously inserted point");
}
//The end
}