/// <summary>
 /// Computes the coefficients of the B-spline recursive formula.
 /// Based on the Cox - De Boor algorithm. 'The NURBS Book' page 50.
 /// </summary>
 /// <param name="a">u_j / (u_j - u_(j+p))</param>
 /// <param name="b">u_(j+p+1) / (u_(j+p+1) - u_(j+1))</param>
 /// <param name="c">1 / (u_(j+p) - u_j)</param>
 /// <param name="d">1 / (u_(j+1) - u_(j+p+1))</param>
 /// <param name="nurbsValues">NurbsValues class with the knots vector and degree</param>
 /// <param name="degree">degree of the iteration of the recursive formula</param>
 /// <param name="j">knot index</param>
 public void EvaluateMuliplyingValues(ref double a,
                                      ref double b,
                                      ref double c,
                                      ref double d,
                                      NurbsValues nurbsValues,
                                      int degree,
                                      int j)
 {
     a = nurbsValues.KnotVector[j] / (nurbsValues.KnotVector[j] - nurbsValues.KnotVector[j + degree]);
     a = ModifyIfNotValid(a);
     b = nurbsValues.KnotVector[j + degree + 1] / (nurbsValues.KnotVector[j + degree + 1] - nurbsValues.KnotVector[j + 1]);
     b = ModifyIfNotValid(b);
     c = 1.0 / (nurbsValues.KnotVector[j + degree] - nurbsValues.KnotVector[j]);
     c = ModifyIfNotValid(c);
     d = 1.0 / (nurbsValues.KnotVector[j + 1] - nurbsValues.KnotVector[j + degree + 1]);
     d = ModifyIfNotValid(d);
 }
        /// <summary>
        /// Constructor used to evaluate the coefficients of the non vanishing
        /// B-splines over the knot span, and to evaluate the limits of the knot span,
        /// mapped to the non parametric space.
        /// </summary>
        /// <param name="nurbsValues">NurbsValues class with the NURBS charachteristic values</param>
        /// <param name="knotIndex">Index of the lower limit knot</param>
        public BSplinesCoefficients(NurbsValues nurbsValues, int knotIndex)
        {
            LowerLimit = nurbsValues.KnotVector[knotIndex] * nurbsValues.MaxValue;
            UpperLimit = nurbsValues.KnotVector[knotIndex + 1] * nurbsValues.MaxValue;

            Coefficients = new double[nurbsValues.Degree + 1, nurbsValues.Degree + 2];
            if (nurbsValues.KnotVector[knotIndex] != nurbsValues.KnotVector[knotIndex + 1])
            {
                Coefficients[0, nurbsValues.Degree] = 1.0;
                double[,] tempCoefficients          = Coefficients;
                double a = 0.0;
                double b = 0.0;
                double c = 0.0;
                double d = 0.0;

                for (int degree = 1; degree <= nurbsValues.Degree; degree++)
                {
                    tempCoefficients = new double[nurbsValues.Degree + 1, nurbsValues.Degree + 2];
                    for (int column = nurbsValues.Degree - degree; column <= nurbsValues.Degree; column++)
                    {
                        int j = knotIndex + (column - nurbsValues.Degree);
                        EvaluateMuliplyingValues(ref a, ref b, ref c, ref d, nurbsValues, degree, j);

                        for (int row = 0; row < degree; row++)
                        {
                            tempCoefficients[row, column] +=
                                Coefficients[row, column] * a + Coefficients[row, column + 1] * b;
                            tempCoefficients[row + 1, column] +=
                                Coefficients[row, column] * c + Coefficients[row, column + 1] * d;
                        }
                    }
                    Coefficients = tempCoefficients;
                }
                Coefficients = Normalize(Coefficients, nurbsValues.MaxValue);
            }
        }