/// <summary> /// Get the sub-node where a coordinate is /// </summary> /// <param name="coord"></param> /// <returns></returns> public Node GetSubNode(QuadTreeCoord coord) { if (IsLeafNode) { throw new InvalidOperationException("leaf node"); } if (coord.Y < PivotCoord.Y) { if (coord.X < PivotCoord.X) { return(mSubNodes[0]); } else { return(mSubNodes[1]); } } else { if (coord.X < PivotCoord.X) { return(mSubNodes[2]); } else { return(mSubNodes[3]); } } }
public Node(QuadTree tree, QuadTreeCoord coord, QuadTreeCoord size) { Tree = tree; PivotCoord = coord; NodeSize = size; if (NodeLevel < Tree.MaxDepthAllowed) { QuadTreeCoord size2 = size / 2.0; mSubNodes = new Node[] { new Node(tree, coord - new QuadTreeCoord(-size2.X, -size2.Y), size2), // LL new Node(tree, coord - new QuadTreeCoord(+size2.X, -size2.Y), size2), // LR new Node(tree, coord - new QuadTreeCoord(-size2.X, +size2.Y), size2), // UL new Node(tree, coord - new QuadTreeCoord(+size2.X, +size2.Y), size2), // UR }; } }
public void FindNodes(QuadTreeCoord coord) { }
/// <summary> /// Get the sub-node where a coordinate is /// </summary> /// <param name="coord"></param> /// <returns></returns> public Node GetSubNode(QuadTreeCoord coord) { if (IsLeafNode) throw new InvalidOperationException("leaf node"); if (coord.Y < PivotCoord.Y) { if (coord.X < PivotCoord.X) return (mSubNodes[0]); else return (mSubNodes[1]); } else { if (coord.X < PivotCoord.X) return (mSubNodes[2]); else return (mSubNodes[3]); } }