示例#1
0
 private static int ChooseHalfPlane(Node node, double x, double y, PlanePartitioning partitioning)
 {
     var(nodeX, nodeY) = node;
     return(partitioning == PlanePartitioning.Horizontal
         ? nodeY.CompareTo(y)
         : nodeX.CompareTo(x));
 }
示例#2
0
        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);
                }
            }
        }
示例#3
0
        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);
        }