Ejemplo n.º 1
0
        public int CompareTo(Rectangle3D other)
        {
            if (other == null)
            {
                return(1);
            }
            var result = Bottom.CompareTo(other.Bottom);

            if (result == 0)
            {
                result = Left.CompareTo(other.Left);
            }
            if (result == 0)
            {
                result = Near.CompareTo(other.Near);
            }
            if (result == 0)
            {
                result = Top.CompareTo(other.Top);
            }
            if (result == 0)
            {
                result = Right.CompareTo(other.Right);
            }
            if (result == 0)
            {
                result = Far.CompareTo(other.Far);
            }
            return(result);
        }
Ejemplo n.º 2
0
        private Node <T> FindParent(T value)
        {
            Node <T> current = Top;
            Node <T> parent  = null;

            if (Top.CompareTo(value) == 0)
            {
                current = Top.Right;
                parent  = Top;
            }

            while (current != null)
            {
                int result = current.CompareTo(value);

                if (result > 0)
                {
                    parent  = current;
                    current = current.Left;
                }
                else if (result < 0)
                {
                    parent  = current;
                    current = current.Right;
                }
                else
                {
                    return(parent);
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
        public int CompareTo(CellRect other)
        {
            if (other == null)
            {
                return(-1);
            }
            int result = Left.CompareTo(other.Left);

            if (result == 0)
            {
                result = Top.CompareTo(other.Top);
            }
            return(result);
        }
Ejemplo n.º 4
0
        public int CompareTo(ISpatiallyComparable rhs)
        {
            if (rhs is Bundle)
            {
                return(Top.CompareTo(((Bundle)rhs).Top));
            }

            int comp = Top.CompareTo(rhs);

            if (comp <= 0)
            {
                return(comp);
            }

            comp = Bottom.CompareTo(rhs);
            return(comp < 0 ? 0 : comp);
        }
Ejemplo n.º 5
0
 public int CompareTo(Lithology other)
 {
     return(Top.CompareTo(other.Top));
 }
Ejemplo n.º 6
0
 public int CompareTo(Paragraph other)
 {
     return(Top.CompareTo(other.Top));
 }
Ejemplo n.º 7
0
 public bool FitsExactlyVertically(T top, T bottom)
 {
     return(Top.CompareTo(top) == 0 && Bottom.CompareTo(bottom) == 0);
 }
Ejemplo n.º 8
0
 public bool IsWithinVertically(T top, T bottom)
 {
     return(Top.CompareTo(top) <= 0 && Bottom.CompareTo(bottom) >= 0);
 }
Ejemplo n.º 9
0
        public bool Remove(T value)
        {
            if (Top == null)
            {
                return(false);
            }
            else if (Top.CompareTo(value) == 0)
            {
                if (Top.Left == null && Top.Right == null)
                {
                    Top = null;
                }
                else if (Top.Left != null && Top.Right == null)
                {
                    Top = Top.Left;
                }
                else if (Top.Left == null && Top.Right != null)
                {
                    Top = Top.Right;
                }
                else
                {
                    Node <T> minLeft = Top.Right;

                    while (minLeft.Left != null)
                    {
                        minLeft = minLeft.Left;
                    }

                    Node <T> newNode = new Node <T>(minLeft.Data, Top.Left, Top.Right);
                    Top = newNode;
                    if (Top.Right == minLeft)
                    {
                        Top.Right = Top.Right.Right;
                    }
                    else if (minLeft.Right == null)
                    {
                        FindParent(minLeft.Data).Left = null;
                    }
                    else
                    {
                        FindParent(minLeft.Data).Left = FindParent(minLeft.Data).Left.Right;
                    }
                }
                Count--;
                return(true);
            }
            else
            {
                if (FindParent(value) == null)
                {
                    return(false);
                }
                else
                {
                    Node <T> parent     = FindParent(value);
                    Node <T> deleteNode = null;

                    int leftOrRight = parent.CompareTo(value);
                    if (leftOrRight > 0)
                    {
                        deleteNode = parent.Left;
                    }
                    else
                    {
                        deleteNode = parent.Right;
                    }

                    if (deleteNode.Right == null && deleteNode.Left == null)
                    {
                        if (leftOrRight > 0)
                        {
                            parent.Left = null;
                        }
                        else
                        {
                            parent.Right = null;
                        }
                    }
                    else if (deleteNode.Right == null && deleteNode.Left != null)
                    {
                        if (leftOrRight > 0)
                        {
                            parent.Left = parent.Left.Left;
                        }
                        else
                        {
                            parent.Right = parent.Right.Left;
                        }
                    }
                    else if (deleteNode.Right != null && deleteNode.Left == null)
                    {
                        if (leftOrRight > 0)
                        {
                            parent.Left = parent.Left.Right;
                        }
                        else
                        {
                            parent.Right = parent.Right.Right;
                        }
                    }
                    else
                    {
                        Node <T> minLeft = deleteNode.Right;

                        while (minLeft.Left != null)
                        {
                            minLeft = minLeft.Left;
                        }

                        if (deleteNode.Right == minLeft)
                        {
                            deleteNode.Right = deleteNode.Right.Right;
                        }
                        else if (minLeft.Right == null)
                        {
                            Node <T> parentMinLeft = FindParent(minLeft.Data);
                            parentMinLeft.Left = null;
                        }
                        else
                        {
                            Node <T> parentMinLeft = FindParent(minLeft.Data);
                            parentMinLeft.Left = parentMinLeft.Left.Right;
                        }

                        Node <T> newNode = new Node <T>(minLeft.Data, deleteNode.Left, deleteNode.Right);

                        if (leftOrRight > 0)
                        {
                            parent.Left = newNode;
                        }
                        else
                        {
                            parent.Right = newNode;
                        }
                    }
                    Count--;
                    return(true);
                }
            }
        }