Ejemplo n.º 1
0
        public FltDomain Sqrt()
        {
            if (IsEmpty())
            {
                return(m_Empty);
            }

            if (m_Interval.Max < 0)
            {
                return(m_Empty);
            }

            if (m_Interval.IsZero() || m_Interval.IsOne())
            {
                return(this);
            }

            FltDomain result = new FltDomain();

            result.m_Interval = m_Interval.Sqrt();

            if (IsSimple())
            {
                return(result);
            }

            result.m_IntervalList = new List <FltInterval>(m_IntervalList.Count);
            foreach (FltInterval interval in m_IntervalList)
            {
                if (interval.Max >= 0)
                {
                    result.m_IntervalList.Add(interval.Sqrt());
                }
            }

            result.CheckSimple();

            return(result);
        }
Ejemplo n.º 2
0
        public FltDomain Difference(FltInterval interval)
        {
            if (interval.IsEmpty())
            {
                return(this);
            }

            // 1, 6
            if (!IntersectsWith(interval))
            {
                return(this);
            }

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

            // Result domain
            FltDomain result = new FltDomain();

            result.m_Interval = m_Interval.Difference(interval);

            if (IsSimple())
            {
                // 4 : divide into two intervals...
                if (I4_Divide(interval, m_Interval))
                {
                    result.m_IntervalList = new List <FltInterval>(2);
                    result.m_IntervalList.Add(new FltInterval(m_Interval.Min, Epsilon.Prev(interval.Min)));
                    result.m_IntervalList.Add(new FltInterval(Epsilon.Next(interval.Max), m_Interval.Max));
                }
            }
            else
            {
                result.m_IntervalList = new List <FltInterval>(m_IntervalList.Count + 1);

                int idx = 0;

                // 6
                for ( ; idx < m_IntervalList.Count && m_IntervalList[idx].Max < interval.Min; ++idx)
                {
                    result.m_IntervalList.Add(m_IntervalList[idx]);
                }

                // 2
                if (idx < m_IntervalList.Count &&
                    I2_IntersectMin(interval, m_IntervalList[idx]))
                {
                    result.m_IntervalList.Add(m_IntervalList[idx].Difference(interval));
                    ++idx;
                }

                // 4 : divide into two intervals...
                if (idx < m_IntervalList.Count &&
                    I4_Divide(interval, m_IntervalList[idx]))
                {
                    result.m_IntervalList.Add(new FltInterval(m_Interval.Min, Epsilon.Prev(interval.Min)));
                    result.m_IntervalList.Add(new FltInterval(Epsilon.Next(interval.Max), m_Interval.Max));
                }
                // 3
                else
                {
                    for ( ; idx < m_IntervalList.Count && interval.Contains(m_IntervalList[idx]); ++idx)
                    {
                    }
                }

                // 5
                if (idx < m_IntervalList.Count &&
                    I5_IntersectMax(interval, m_IntervalList[idx]))
                {
                    result.m_IntervalList.Add(m_IntervalList[idx].Difference(interval));
                    ++idx;
                }

                // 1
                for ( ; idx < m_IntervalList.Count; ++idx)
                {
                    result.m_IntervalList.Add(m_IntervalList[idx]);
                }

                result.CheckSimple();
            }

            return(result);
        }
Ejemplo n.º 3
0
        public FltDomain Union(FltDomain domain)
        {
            if (ReferenceEquals(domain, this))
            {
                return(this);
            }

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

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

            if (domain.IsSimple())
            {
                return(Union(domain.m_Interval));
            }

            if (IsSimple())
            {
                if (m_Interval.Contains(domain.m_Interval))
                {
                    return(this);
                }

                return(domain.Union(m_Interval));
            }
            else
            {
                FltDomain result = new FltDomain();
                result.m_Interval     = m_Interval.Union(domain.m_Interval);
                result.m_IntervalList = new List <FltInterval>(m_IntervalList.Count + domain.m_IntervalList.Count);

                // 1 : completely before
                if (domain.m_Interval.Max < m_Interval.Min)
                {
                    result.m_IntervalList.AddRange(domain.m_IntervalList);
                    result.m_IntervalList.AddRange(m_IntervalList);
                }

                // 6 : completely after
                else if (domain.m_Interval.Min > m_Interval.Max)
                {
                    result.m_IntervalList.AddRange(m_IntervalList);
                    result.m_IntervalList.AddRange(domain.m_IntervalList);
                }
                else
                {
                    int  idx    = 0;
                    int  domIdx = 0;
                    bool equal  = true;

                    while (idx < m_IntervalList.Count ||
                           domIdx < domain.m_IntervalList.Count)
                    {
                        // 6 :
                        if (idx == m_IntervalList.Count)
                        {
                            equal = false;

                            for ( ; domIdx < domain.m_IntervalList.Count; ++domIdx)
                            {
                                result.m_IntervalList.Add(domain.m_IntervalList[domIdx]);
                            }
                        }

                        // 1 : remaining intervals after
                        else if (domIdx == domain.m_IntervalList.Count)
                        {
                            for ( ; idx < m_IntervalList.Count; ++idx)
                            {
                                result.m_IntervalList.Add(m_IntervalList[idx]);
                            }
                        }
                        else
                        {
                            FltInterval intv    = m_IntervalList[idx];
                            FltInterval domIntv = domain.m_IntervalList[domIdx];

                            // 1 : completely before
                            if (domIntv.Max < intv.Min)
                            {
                                equal = false;

                                result.m_IntervalList.Add(domIntv);
                                ++domIdx;
                            }
                            // 6 : completely after
                            else if (domIntv.Min > intv.Max)
                            {
                                result.m_IntervalList.Add(intv);
                                ++idx;
                            }
                            // 3
                            else if (domIntv.Contains(intv))
                            {
                                equal = false;

                                ++idx;
                            }
                            // 3
                            else if (intv.Contains(domIntv))
                            {
                                ++domIdx;
                            }
                            // 2, 5
                            else
                            {
                                equal = false;

                                FltInterval intvTmp = intv.Union(domIntv);

                                ++idx;

                                // contains...
                                for ( ; idx < m_IntervalList.Count &&
                                      intvTmp.Contains(m_IntervalList[idx]);
                                      ++idx)
                                {
                                }
                                ;

                                // intersect...
                                while (idx < m_IntervalList.Count &&
                                       m_IntervalList[idx].IntersectsWith(intvTmp))
                                {
                                    intvTmp = intvTmp.Union(m_IntervalList[idx]);
                                    ++idx;
                                }

                                result.m_IntervalList.Add(intvTmp);

                                ++domIdx;
                            }
                        }
                    }

                    if (equal)
                    {
                        return(this);
                    }


                    result.CheckSimple();
                }

                return(result);
            }
        }
Ejemplo n.º 4
0
        public FltDomain Union(FltInterval interval)
        {
            if (interval.IsEmpty())
            {
                return(this);
            }

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

            // ~4
            if (Contains(interval))
            {
                return(this);
            }

            // 3
            if (interval.Contains(m_Interval))
            {
                return(new FltDomain(interval));
            }

            if (IsSimple())
            {
                // 1
                if (interval.Max < m_Interval.Min)
                {
                    return(new FltDomain(interval, m_Interval));
                }

                // 6
                if (interval.Min > m_Interval.Max)
                {
                    return(new FltDomain(m_Interval, interval));
                }

                // 2, 5
                return(new FltDomain(m_Interval.Union(interval)));
            }
            else
            {
                FltDomain result = new FltDomain();
                result.m_Interval     = m_Interval.Union(interval);
                result.m_IntervalList = new List <FltInterval>(m_IntervalList.Count + 1);

                // 1
                if (interval.Max < m_Interval.Min)
                {
                    result.m_IntervalList.Add(interval);
                    result.m_IntervalList.AddRange(m_IntervalList);
                }

                // 6
                else if (interval.Min > m_Interval.Max)
                {
                    result.m_IntervalList.AddRange(m_IntervalList);
                    result.m_IntervalList.Add(interval);
                }
                else
                {
                    // 6
                    int idx = 0;
                    for ( ; idx < m_IntervalList.Count && (m_IntervalList[idx].Max < interval.Min); ++idx)
                    {
                        result.m_IntervalList.Add(m_IntervalList[idx]);
                    }

                    if (idx < m_IntervalList.Count)
                    {
                        FltInterval intv = interval;

                        // intersect
                        if (idx < m_IntervalList.Count &&
                            m_IntervalList[idx].IntersectsWith(intv))
                        {
                            intv = intv.Union(m_IntervalList[idx]);
                            ++idx;
                        }

                        // 3
                        for ( ; idx < m_IntervalList.Count && intv.Contains(m_IntervalList[idx]); ++idx)
                        {
                        }

                        // intersect
                        if (idx < m_IntervalList.Count &&
                            m_IntervalList[idx].IntersectsWith(intv))
                        {
                            intv = intv.Union(m_IntervalList[idx]);
                            ++idx;
                        }

                        result.m_IntervalList.Add(intv);

                        // 1
                        for ( ; idx < m_IntervalList.Count; ++idx)
                        {
                            result.m_IntervalList.Add(m_IntervalList[idx]);
                        }
                    }
                    else
                    {
                        // 6
                        result.m_IntervalList.Add(interval);
                    }
                }

                result.CheckSimple();

                return(result);
            }
        }