本文整理汇总了C#中QuadTree.Intersect方法的典型用法代码示例。如果您正苦于以下问题:C# QuadTree.Intersect方法的具体用法?C# QuadTree.Intersect怎么用?C# QuadTree.Intersect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QuadTree
的用法示例。
在下文中一共展示了QuadTree.Intersect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IntersectingRectangle
/// <summary>
/// Returns all points inside the requested region.
/// If include adjacent is set to true we include points with an edge that crosses the border of the requested rectangle
/// </summary>
/// <param name="gridRect"></param>
/// <returns></returns>
private List<MappingGridVector2> IntersectingRectangle(GridRectangle gridRect,
QuadTree<List<MappingGridTriangle>> PointTree)
{
List<GridVector2> Points;
List<List<MappingGridTriangle>> ListofListTriangles;
List<MappingGridVector2> MappingPointList= null;
if (gridRect.Contains(PointTree.Border))
{
MappingPointList = new List<MappingGridVector2>(_mapPoints);
return MappingPointList;
}
PointTree.Intersect(gridRect, out Points, out ListofListTriangles);
bool[] Added = new bool[_mapPoints.Length];
MappingPointList = new List<MappingGridVector2>(Points.Count * 2);
List<List<MappingGridTriangle>> MappingTriangleList = new List<List<MappingGridTriangle>>(Points.Count * 2);
//Add all the unique points bordering the requested rectangle
for (int iPoint = 0; iPoint < Points.Count; iPoint++)
{
List<MappingGridTriangle> FoundTriangleList = ListofListTriangles[iPoint];
for (int iTri = 0; iTri < FoundTriangleList.Count; iTri++)
{
MappingGridTriangle Triangle = FoundTriangleList[iTri];
if (!Added[Triangle.N1])
{
Added[Triangle.N1] = true;
MappingPointList.Add(this._mapPoints[Triangle.N1]);
MappingTriangleList.Add(this._TriangleList[Triangle.N1]);
}
if (!Added[Triangle.N2])
{
Added[Triangle.N2] = true;
MappingPointList.Add(this._mapPoints[Triangle.N2]);
MappingTriangleList.Add(this._TriangleList[Triangle.N1]);
}
if (!Added[Triangle.N3])
{
Added[Triangle.N3] = true;
MappingPointList.Add(this._mapPoints[Triangle.N3]);
MappingTriangleList.Add(this._TriangleList[Triangle.N1]);
}
}
}
return MappingPointList;
}
示例2: 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));
}