private static int GetMaxValueLeft(RangeTreeNode node) { if (node.RightChild == null) { return(node.Value); } return(GetMaxValueLeft(node.RightChild)); }
public RangeTreeNode(Point point, int value, List <int> second, RangeTreeNode left = null, RangeTreeNode right = null, RangeTreeNode parent = null) { Node = point; Value = value; Parent = parent; LeftChild = left; RightChild = right; SecondDimension = second; }
public RangeTree(List <Point> points) { sortedX = points.OrderBy(x => x.X).ToList(); var basicNodes = new List <RangeTreeNode>(); foreach (var point in sortedX) { basicNodes.Add(new RangeTreeNode(point, point.X, new List <int> { point.Y })); } Root = CreateUpwardNode(basicNodes); }
private void GetPoints(RangeTreeNode node, List <Point> result, int minX, int maxX, int minY, int maxY) { if (node.LeftChild == null && node.RightChild == null) { if (node.Value >= minX && node.Value <= maxX && SatisfySecondDimention(node.SecondDimension, minY, maxY)) { result.Add(node.Node); } } if (node.Value < minX) { if (node.RightChild != null) { GetPoints(node.RightChild, result, minX, maxX, minY, maxY); } return; } if (node.Value > maxX) { if (node.LeftChild != null) { GetPoints(node.LeftChild, result, minX, maxX, minY, maxY); } return; } if (!SatisfySecondDimention(node.SecondDimension, minY, maxY)) { return; } if (node.LeftChild != null) { GetPoints(node.LeftChild, result, minX, maxX, minY, maxY); } if (node.RightChild != null) { GetPoints(node.RightChild, result, minX, maxX, minY, maxY); } }