public bool SearchForIntersect(ref VMObstacleSetNode node, BaseMeshTriangle rect) { if (node.Intersects(rect)) { return(true); } //search in child nodes. int dontSearch = 0; switch (node.Dimension) { case IntersectRectDimension.Top: dontSearch = (rect.y2 <= node.y1) ? 2 : 0; break; //if true, do not have to search right (where top greater) case IntersectRectDimension.Left: dontSearch = (rect.x2 <= node.x1) ? 2 : 0; break; //if true, do not have to search right (where left greater) case IntersectRectDimension.Bottom: dontSearch = (rect.y1 >= node.y2) ? 1 : 0; break; //if true, do not have to search left (where bottom less) case IntersectRectDimension.Right: dontSearch = (rect.x1 >= node.x2) ? 1 : 0; break; //if true, do not have to search left (where right less) } //may need to search both :'( won't happen often with our small rectangles over large space though. return((dontSearch != 1 && node.LeftChild != -1 && SearchForIntersect(ref Nodes[node.LeftChild], rect)) || (dontSearch != 2 && node.RightChild != -1 && SearchForIntersect(ref Nodes[node.RightChild], rect))); }
public bool SearchForIntersect(BaseMeshTriangle rect) { if (Root == -1) { return(false); } else { return(SearchForIntersect(ref Nodes[Root], rect)); } }
public List <BaseMeshTriangle> OnEdge(BaseMeshTriangle rect) { var result = new List <BaseMeshTriangle>(); if (Root == -1) { return(result); } else { OnEdge(ref Nodes[Root], rect, result); return(result); } }
public List <BaseMeshTriangle> AllIntersect(BaseMeshTriangle rect) { var result = new List <BaseMeshTriangle>(); if (Root == -1) { return(result); } else { AllIntersect(ref Nodes[Root], rect, result); return(result); } }
public void Add(BaseMeshTriangle rect) { if (PoolInd >= Nodes.Length && FreeList.Count == 0) { InitNodes(Nodes.Length * 2); } Count++; if (Root == -1) { Root = GetNode(IntersectRectDimension.Left, rect); } else { AddAsChild(ref Nodes[Root], rect); } }
private int GetNode(IntersectRectDimension dir, BaseMeshTriangle rect) { var ind = GetNode(); Nodes[ind] = new VMObstacleSetNode() { Dimension = dir, Rect = rect, LeftChild = -1, RightChild = -1, Index = ind, x1 = rect.x1, x2 = rect.x2, y1 = rect.y1, y2 = rect.y2 }; return(ind); }
private void AddAsChild(ref VMObstacleSetNode node, BaseMeshTriangle rect) { bool rightSide = false; switch (node.Dimension) { case IntersectRectDimension.Top: rightSide = rect.y1 > node.Rect.y1; break; case IntersectRectDimension.Left: rightSide = rect.x1 > node.Rect.x1; break; case IntersectRectDimension.Bottom: rightSide = rect.y2 > node.Rect.y2; break; case IntersectRectDimension.Right: rightSide = rect.x2 > node.Rect.x2; break; } if (rightSide) { if (node.RightChild != -1) { AddAsChild(ref Nodes[node.RightChild], rect); } else { node.RightChild = GetNode((IntersectRectDimension)(((int)node.Dimension + 1) % 4), rect); } } else { if (node.LeftChild != -1) { AddAsChild(ref Nodes[node.LeftChild], rect); } else { node.LeftChild = GetNode((IntersectRectDimension)(((int)node.Dimension + 1) % 4), rect); } } }
public void OnEdge(ref VMObstacleSetNode node, BaseMeshTriangle rect, List <BaseMeshTriangle> result) { if (node.OnEdge(rect)) { result.Add(node.Rect); } //search in child nodes. //binary search to find equal opposing edges. int dontSearch = 0; switch (node.Dimension) { case IntersectRectDimension.Top: dontSearch = (rect.y2 < node.y1) ? 2 : 0; break; //if true, do not have to search right (where top greater) case IntersectRectDimension.Left: dontSearch = (rect.x2 < node.x1) ? 2 : 0; break; //if true, do not have to search right (where left greater) case IntersectRectDimension.Bottom: dontSearch = (rect.y1 > node.y2) ? 1 : 0; break; //if true, do not have to search left (where bottom less) case IntersectRectDimension.Right: dontSearch = (rect.x1 > node.x2) ? 1 : 0; break; //if true, do not have to search left (where right less) } //may need to search both :'( won't happen often with our small rectangles over large space though. //if (node.LeftChild != -1) OnEdge(ref Nodes[node.LeftChild], rect, result); //if (node.RightChild != -1) OnEdge(ref Nodes[node.RightChild], rect, result); if (dontSearch != 1 && node.LeftChild != -1) { OnEdge(ref Nodes[node.LeftChild], rect, result); } if (dontSearch != 2 && node.RightChild != -1) { OnEdge(ref Nodes[node.RightChild], rect, result); } }
public bool OnEdge(BaseMeshTriangle other) { return((x2 == other.x1) || (x1 == other.x2) || (y1 == other.y2) || (y2 == other.y1)); }
public bool Intersects(BaseMeshTriangle other) { return(!((other.x1 >= x2 || other.x2 <= x1) || (other.y1 >= y2 || other.y2 <= y1))); }