private static bool Contains(Node?node, double x, double y, PlanePartitioning partitioning) { while (true) { if (node is null) { return(false); } switch (ChooseHalfPlane(node, x, y, partitioning)) { case < 0: node = node.Right; partitioning = partitioning.Flip(); continue; case > 0: node = node.Left; partitioning = partitioning.Flip(); continue; case 0: return(true); } } }
private static Node Add(Node?node, double x, double y, PlanePartitioning partitioning) { if (node is null) { return(new Node(x, y)); } switch (ChooseHalfPlane(node, x, y, partitioning)) { case < 0: node.Right = Add(node.Right, x, y, partitioning.Flip()); break; case > 0: node.Left = Add(node.Left, x, y, partitioning.Flip()); break; case 0: Console.WriteLine($"WARN: Trying to insert ({x}, {y}) point which is on one line with another: " + $"({node.X}, {node.Y}). Insertion is aborted."); break; } node.SubtreeSize = 1 + Size(node.Left) + Size(node.Right); return(node); }