Example #1
0
        /// <summary>
        /// Cox-de Boor recursion formula implementation.
        /// </summary>
        protected Func <double, double> GetBasis(int i, int j, KnotSet knots)
        {
            Func <double, double> func = (t) =>
            {
                double t_i      = knots.GetIndexOf(i);
                double t_iplus1 = knots.GetIndexOf(i + 1);

                if (j == 0)
                {
                    if (t_i <= t && t < t_iplus1)
                    {
                        return(1);
                    }
                    else
                    {
                        return(0);
                    }
                }
                double coef1 = GetCoef(i, j, t, knots);
                double coef2 = 1 - GetCoef(i + 1, j, t, knots);

                Func <double, double> firstTerm  = GetBasis(i, j - 1, knots);
                Func <double, double> secondTerm = GetBasis(i + 1, j - 1, knots);

                double first  = firstTerm(t);
                double second = secondTerm(t);

                return(coef1 * first + coef2 * second);
            };

            return(func);
        }
Example #2
0
        /// <summary>
        /// Cox-de Boor recursion formula implementation.
        /// </summary>
        protected double GetCoef(int i, int j, double t, KnotSet knots)
        {
            if (knots.GetIndexOf(i + j) == knots.GetIndexOf(i))
            {
                return(0);
            }

            return((double)(t - knots.GetIndexOf(i)) / (double)(knots.GetIndexOf(i + j) - knots.GetIndexOf(i)));
        }
Example #3
0
        public void GetIndexOf()
        {
            double[] knots   = null;
            KnotSet  knotSet = null;
            double   r;
            double   a;

            knots   = new double[] { 1, 2, 3, 4 };
            knotSet = new KnotSet(knots);
            r       = knotSet.GetIndexOf(1);
            a       = 2;
            Assert.IsTrue(r == a);

            knots   = new double[] { 1, 2, 3, 4 };
            knotSet = new KnotSet(knots);
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => knotSet.GetIndexOf(-1));

            knots   = new double[] { 1, 2, 3, 4 };
            knotSet = new KnotSet(knots);
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => knotSet.GetIndexOf(5));

            knots   = new double[] { 1, 2, 3, 4 };
            knotSet = new KnotSet(knots, false);
            r       = knotSet.GetIndexOf(-1);
            a       = 1;
            Assert.IsTrue(r == a);

            knots   = new double[] { 1, 2, 3, 4 };
            knotSet = new KnotSet(knots, false);
            r       = knotSet.GetIndexOf(7);
            a       = 4;
            Assert.IsTrue(r == a);
        }