DistanceSquared() private method

private DistanceSquared ( System.Windows.Vector a, System.Windows.Vector b ) : System.Double
a System.Windows.Vector
b System.Windows.Vector
return System.Double
Exemplo n.º 1
0
        /// <summary>
        /// Computes the maximum squared distance from a point to the curve using the current parameterization.
        /// </summary>
        protected FLOAT FindMaxSquaredError(int first, int last, CubicBezier curve, out int split)
        {
            List <VECTOR> pts  = _pts;
            List <FLOAT>  u    = _u;
            int           s    = (last - first + 1) / 2;
            int           nPts = last - first + 1;
            FLOAT         max  = 0;

            for (int i = 1; i < nPts; i++)
            {
                VECTOR v0 = pts[first + i];
                VECTOR v1 = curve.Sample(u[i]);
                FLOAT  d  = VectorHelper.DistanceSquared(v0, v1);
                if (d > max)
                {
                    max = d;
                    s   = i;
                }
            }

            // split at point of maximum error
            split = s + first;
            if (split <= first)
            {
                split = first + 1;
            }
            if (split >= last)
            {
                split = last - 1;
            }
            return(max);
        }