Beispiel #1
0
        /// <summary>
        /// Trace the path quickly through to determine its length
        /// </summary>
        /// <param name="p_points">
        /// A <see cref="Point"/> array of 4 points specifying Bezier curve
        /// </param>
        /// <returns>
        /// A <see cref="System.Int32"/> as the length of the given curve
        /// </returns>
        static public int CalculateCurveLength(Point [] p_points)
        {
            if (p_points.Length != 4)
            {
                throw new Exception("p_points array passed to CalculateCurveLength must have exactly 4 items, this one has " + p_points.Length);
            }

            PointF pA  = p_points[0];
            double rtn = 0.0d;

            // determine what ratio gives up about 1 pixel of distance
            double accuracyRatio = BezierSprite.CalculateRatioSizeToPixelAccuracy(p_points, 1);

            // set an incrementer
            double currentRatio = accuracyRatio;

            // set a limit for when we reach the end of the path - allow some overshoot
            double topLimit = 1.0 + accuracyRatio;

            // traverse path one fraction bit at a time calculating distances between points
            while (currentRatio < topLimit)
            {
                PointF pB = CalculatePoint(p_points, currentRatio);
                rtn          += Math.Sqrt(Math.Pow(pA.X - pB.X, 2) + Math.Pow(pA.Y - pB.Y, 2));
                pA            = pB;
                currentRatio += accuracyRatio;
            }

            return((int)Math.Round(rtn));
        }