Beispiel #1
0
        public void IntersectsWithDomain()
        {
            FltDomain a  = new FltDomain(new double[] { 0, 10, 20, 30 });
            FltDomain a1 = new FltDomain(new double[] { -10, Epsilon.Prev(0), Epsilon.Next(10), Epsilon.Prev(20), Epsilon.Next(30), 40 });

            Assert.IsFalse(a.IntersectsWith(a1));
            Assert.IsFalse(a1.IntersectsWith(a));
        }
Beispiel #2
0
        public override void Update()
        {
            double min0 = Math.Min(Var0.Min, Epsilon.Prev(Var1.Min));
            double max0 = Math.Min(Var0.Max, Epsilon.Prev(Var1.Max));

            double min1 = Math.Max(Epsilon.Next(Var0.Min), Var1.Min);
            double max1 = Math.Max(Epsilon.Next(Var0.Max), Var1.Max);

            Var0.Intersect(min0, max0);
            Var1.Intersect(min1, max1);
        }
Beispiel #3
0
        public void IntersectsWith4()
        {
            FltDomain a = new FltDomain(new double[] { 0, 15, 48, 63 });

            Assert.IsFalse(a.IntersectsWith(new FltInterval(-10, Epsilon.Prev(0))));
            Assert.IsFalse(a.IntersectsWith(new FltInterval(Epsilon.Next(15), Epsilon.Prev(48))));
            Assert.IsFalse(a.IntersectsWith(new FltInterval(Epsilon.Next(63), 80)));

            Assert.IsTrue(a.IntersectsWith(new FltInterval(15, Epsilon.Prev(48))));
            Assert.IsTrue(a.IntersectsWith(new FltInterval(Epsilon.Next(15), 48)));
        }
Beispiel #4
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);
        }
Beispiel #5
0
        public void DifferenceInterval()
        {
            FltDomain a  = new FltDomain(new double[] { 0, 10, 20, 30 });
            FltDomain a1 = a.Difference(a.Interval);                                                                                                   Assert.AreEqual(FltDomain.Empty, a1);
            FltDomain a2 = a.Difference(new FltInterval(-10, Epsilon.Prev(0)));                                    Assert.AreEqual(a, a2);                      // 6
            FltDomain a3 = a.Difference(new FltInterval(Epsilon.Next(10), Epsilon.Prev(20)));    Assert.AreEqual(a, a3);                                        // 4
            FltDomain a4 = a.Difference(new FltInterval(Epsilon.Next(30), 40));                                    Assert.AreEqual(a, a4);                      // 1
            FltDomain a5 = a.Difference(new FltInterval(-10, 0));                                                                    AssertEqual(a5, new double[] { Epsilon.Next(0), 10, 20, 30 });

            FltDomain b  = new FltDomain(new double[] { 0, 30 });
            FltDomain b1 = b.Difference(new FltInterval(10, 20));            AssertEqual(b1, new FltInterval[] { new FltInterval(0, Epsilon.Prev(10)), new FltInterval(Epsilon.Next(20), 30) });
            FltDomain b2 = b.Difference(new FltInterval(-10, 10));           AssertEqual(b2, new FltInterval[] { new FltInterval(Epsilon.Next(10), 30) });
            FltDomain b3 = b.Difference(new FltInterval(20, 40));            AssertEqual(b3, new FltInterval[] { new FltInterval(0, Epsilon.Prev(20)) });
        }
Beispiel #6
0
        public FltInterval Inflate()
        {
            if (IsEmpty())
            {
                return(m_Empty);
            }

            double min = m_Min;
            double max = m_Max;

            if (!double.IsNegativeInfinity(min))
            {
                min = Epsilon.Prev(min);
            }

            if (!double.IsPositiveInfinity(max))
            {
                max = Epsilon.Next(max);
            }

            return(new FltInterval(min, max));
        }
Beispiel #7
0
 public override void Update()
 {
     Var0.Intersect(double.MinValue, Epsilon.Prev(m_Value));
 }
Beispiel #8
0
        public FltDomain Difference(FltDomain domain)
        {
            if (ReferenceEquals(domain, this))
            {
                return(m_Empty);
            }

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

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

            //1, 6
            if (!IntersectsWith(domain.m_Interval))
            {
                return(this);
            }

            // Need to be a bit smart, put our interval in a list, in case it gets chopped up.
            List <FltInterval> intervalList;

            if (IsSimple())
            {
                intervalList = new List <FltInterval>(1);
                intervalList.Add(m_Interval);
            }
            else
            {
                intervalList = m_IntervalList;
            }

            FltDomain result = new FltDomain();

            result.m_IntervalList = new List <FltInterval>(intervalList.Count + domain.m_IntervalList.Count);

            int idx    = 0;
            int domIdx = 0;

            while (idx < intervalList.Count ||
                   domIdx < domain.m_IntervalList.Count)
            {
                // 6
                if (idx == intervalList.Count)
                {
                    domIdx = domain.m_IntervalList.Count;
                }
                // 1
                else if (domIdx == domain.m_IntervalList.Count)
                {
                    idx = intervalList.Count;
                }
                else
                {
                    FltInterval intv    = intervalList[idx];
                    FltInterval domIntv = domain.m_IntervalList[domIdx];

                    // 1 : completely before
                    if (domIntv.Max < intv.Min)
                    {
                        ++domIdx;
                    }
                    // 6 : completely after
                    else if (domIntv.Min > intv.Max)
                    {
                        result.m_IntervalList.Add(intv);
                        ++idx;
                    }
                    // 3
                    else if (domIntv.Contains(intv))
                    {
                        ++idx;
                    }
                    // 4 : divide into two intervals...
                    else if (I4_Divide(intv, domIntv))
                    {
                        while (domIdx < domain.m_IntervalList.Count &&
                               I4_Divide(intv, domIntv))
                        {
                            result.m_IntervalList.Add(new FltInterval(intv.Min, Epsilon.Prev(domIntv.Min)));

                            intv = new FltInterval(Epsilon.Next(domIntv.Max), intv.Max);

                            ++domIdx;

                            if (domIdx < domain.m_IntervalList.Count)
                            {
                                domIntv = domain.m_IntervalList[domIdx];
                            }
                        }

                        result.m_IntervalList.Add(intv);
                    }
                    // 2
                    else if (I2_IntersectMin(intv, domIntv))
                    {
                        result.m_IntervalList.Add(intv.Difference(domIntv));

                        ++domIdx;
                    }
                    // 5
                    else if (I5_IntersectMax(intv, domIntv))
                    {
                        result.m_IntervalList.Add(intv.Difference(domIntv));

                        ++idx;
                    }
                }
            }

            result.UpdateInterval();

            return(result);
        }
Beispiel #9
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);
        }