- return (float)sqrt(bestsquareddeviation);
-}
-
-int QuadraticBSplinePatchSubdivisionLevelForDeviation(float deviation, float level1tolerance, int levellimit)
-{
- int level;
- // count the automatic flatten step which reduces deviation by 50%
- deviation *= 0.5f;
- // count the levels to subdivide to come under the tolerance
- for (level = 0;level < levellimit && deviation > level1tolerance;level++)
- deviation *= 0.25f;
- return level;
-}
-
-int QuadraticBSplinePatchSubdivisionLevelOnX(int cpwidth, int cpheight, int components, const float *in, float level1tolerance, int levellimit)
-{
- return QuadraticBSplinePatchSubdivisionLevelForDeviation(QuadraticBSplinePatchLargestDeviationOnX(cpwidth, cpheight, components, in), level1tolerance, levellimit);
-}
-
-int QuadraticBSplinePatchSubdivisionLevelOnY(int cpwidth, int cpheight, int components, const float *in, float level1tolerance, int levellimit)
-{
- return QuadraticBSplinePatchSubdivisionLevelForDeviation(QuadraticBSplinePatchLargestDeviationOnY(cpwidth, cpheight, components, in), level1tolerance, levellimit);
-}
-
-/*
- // 1: flat (0th dimension)
- o = a
- // 2: linear (1st dimension)
- o = a * (1 - t) + b * t
- // 3: quadratic bspline (2nd dimension)
- o = a * (1 - t) * (1 - t) + 2 * b * (1 - t) * t + c * t * t
- // 4: cubic (bezier) bspline (3rd dimension)
- o = a * (1 - t) * (1 - t) * (1 - t) + 3 * b * (1 - t) * (1 - t) * t + 3 * c * (1 - t) * t * t + d * t * t * t
- // 5: quartic bspline (4th dimension)
- o = a * (1 - t) * (1 - t) * (1 - t) * (1 - t) + 4 * b * (1 - t) * (1 - t) * (1 - t) * t + 6 * c * (1 - t) * (1 - t) * t * t + 4 * d * (1 - t) * t * t * t + e * t * t * t * t
-
- // n: arbitrary dimension bspline
-double factorial(int n)
-{
- int i;
- double f;
- f = 1;
- for (i = 1;i < n;i++)
- f = f * i;
- return f;
-}
-double bsplinesample(int dimensions, double t, double *param)
-{
- double o = 0;
- for (i = 0;i < dimensions + 1;i++)
- o += param[i] * factorial(dimensions)/(factorial(i)*factorial(dimensions-i)) * pow(t, i) * pow(1 - t, dimensions - i);