private static void AddToBranch(
            PointRegionQuadTreeNodeBranch branch,
            double x, double y,
            XYPointWValue <TL> value,
            PointRegionQuadTree <object> tree)
        {
            switch (branch.Bb.GetQuadrant(x, y))
            {
            case QuadrantEnum.NW:
                branch.Nw = SetOnNode(x, y, value, branch.Nw, tree);
                break;

            case QuadrantEnum.NE:
                branch.Ne = SetOnNode(x, y, value, branch.Ne, tree);
                break;

            case QuadrantEnum.SW:
                branch.Sw = SetOnNode(x, y, value, branch.Sw, tree);
                break;

            default:
                branch.Se = SetOnNode(x, y, value, branch.Se, tree);
                break;
            }
        }
        private static void SubdividePoint(
            XYPointWValue <TL> point,
            PointRegionQuadTreeNodeBranch branch,
            PointRegionQuadTree <object> tree)
        {
            var x = point.X;
            var y = point.Y;

            switch (branch.Bb.GetQuadrant(x, y))
            {
            case QuadrantEnum.NW:
                branch.Nw = SetOnNode(x, y, point, branch.Nw, tree);
                break;

            case QuadrantEnum.NE:
                branch.Ne = SetOnNode(x, y, point, branch.Ne, tree);
                break;

            case QuadrantEnum.SW:
                branch.Sw = SetOnNode(x, y, point, branch.Sw, tree);
                break;

            default:
                branch.Se = SetOnNode(x, y, point, branch.Se, tree);
                break;
            }
        }
        private static int SetOnLeaf(
            PointRegionQuadTreeNodeLeaf <object> leaf,
            double x, double y,
            XYPointWValue <TL> pointXY)
        {
            if (pointXY.X != x && pointXY.Y != y)
            {
                throw new IllegalStateException();
            }

            return(SetOnLeaf(leaf, x, y, pointXY.Value));
        }
        private static PointRegionQuadTreeNode SetOnNode(
            double x, double y,
            XYPointWValue <TL> value,
            PointRegionQuadTreeNode node,
            PointRegionQuadTree <object> tree)
        {
            if (node is PointRegionQuadTreeNodeLeaf <object> leaf)
            {
                var count = SetOnLeaf(leaf, x, y, value);
                leaf.IncCount(count);

                if (leaf.Count <= tree.LeafCapacity || node.Level >= tree.MaxTreeHeight)
                {
                    return(leaf);
                }

                node = Subdivide(leaf, tree);
            }

            var branch = (PointRegionQuadTreeNodeBranch)node;

            AddToBranch(branch, x, y, value, tree);
            return(node);
        }