Exemplo n.º 1
0
        public static Rectangle2D QuadraticBezierBounds0(
            double ax, double ay,
            double bx, double by,
            double cx, double cy)
        {
            var sortOfCloseLength = QuadraticBezierSegmentLengthTests.QuadraticBezierArcLength(ax, ay, bx, by, cx, cy);

            // ToDo: Need to make this more efficient. Don't need to rebuild the point array every time.
            var points = new List <(double X, double Y)>(FunctionalInterpolationTests.Interpolate0to1((int)(sortOfCloseLength / 3), (i) => InterpolateBezierQuadratic2DTests.QuadraticBezierInterpolate2D(i, ax, ay, bx, by, cx, cy)));

            var left   = points[0].X;
            var top    = points[0].Y;
            var right  = points[0].X;
            var bottom = points[0].Y;

            foreach (var(X, Y) in points)
            {
                // ToDo: Measure performance impact of overwriting each time.
                left   = X <= left ? X : left;
                top    = Y <= top ? Y : top;
                right  = X >= right ? X : right;
                bottom = Y >= bottom ? Y : bottom;
            }

            return(Rectangle2D.FromLTRB(left, top, right, bottom));
        }
Exemplo n.º 2
0
        public static Rectangle2D CubicBezierBounds1(
            double ax, double ay,
            double bx, double by,
            double cx, double cy,
            double dx, double dy)
        {
            var sortOfCloseLength = (int)CubicBezierSegmentLengthTests.CubicBezierArcLength(ax, ay, bx, by, cx, cy, dx, dy);
            var points            = new List <(double X, double Y)>(FunctionalInterpolationTests.Interpolate0to1(sortOfCloseLength, (i) => InterpolateCubic2DTests.CubicInterpolate2D(i, ax, ay, bx, by, cx, cy, dx, dy)));

            var left   = points[0].X;
            var top    = points[0].Y;
            var right  = points[0].X;
            var bottom = points[0].Y;

            foreach (var(X, Y) in points)
            {
                // ToDo: Measure performance impact of overwriting each time.
                left   = X <= left ? X : left;
                top    = Y <= top ? Y : top;
                right  = X >= right ? X : right;
                bottom = Y >= bottom ? Y : bottom;
            }

            return(Rectangle2D.FromLTRB(left, top, right, bottom));
        }