Example #1
0
        public FltInterval Union(FltInterval interval)
        {
            if (interval.IsEmpty())
            {
                return(this);
            }

            if (IsEmpty())
            {
                return(interval);
            }

            if (interval.Contains(this))
            {
                return(interval);
            }

            if (Contains(interval))
            {
                return(this);
            }

            double min = Math.Min(m_Min, interval.m_Min);
            double max = Math.Max(m_Max, interval.m_Max);

            return(new FltInterval(min, max));
        }
Example #2
0
        public FltInterval Difference(FltInterval interval)
        {
            if (interval.IsEmpty())
            {
                return(this);
            }

            if (IsEmpty())
            {
                return(this);
            }

            // 4 : cannot divide into two intervals...
            if ((interval.m_Min > m_Min) && (interval.m_Max < m_Max))
            {
                return(this);
            }

            // 1, 6 : completely before or after
            if ((interval.m_Max < m_Min) || (interval.m_Min > m_Max))
            {
                return(this);
            }

            // 3 : completely remove interval => empty
            if (interval.Contains(this))
            {
                return(m_Empty);
            }

            // 2 : left overlap
            if (IntersectsWith(interval) &&
                (interval.m_Max < m_Max))
            {
                double min = Epsilon.Next(interval.m_Max);
                double max = m_Max;

                return(new FltInterval(min, max));
            }

            // 5 : right overlap
            if (IntersectsWith(interval) &&
                (interval.m_Min > m_Min))
            {
                double min = m_Min;
                double max = Epsilon.Prev(interval.m_Min);

                return(new FltInterval(min, max));
            }

            return(m_Empty);
        }