diff options
Diffstat (limited to 'basegfx/source/workbench/bezierclip.cxx')
-rw-r--r-- | basegfx/source/workbench/bezierclip.cxx | 546 |
1 files changed, 273 insertions, 273 deletions
diff --git a/basegfx/source/workbench/bezierclip.cxx b/basegfx/source/workbench/bezierclip.cxx index 5aaea7c63efa..0d0717668c9d 100644 --- a/basegfx/source/workbench/bezierclip.cxx +++ b/basegfx/source/workbench/bezierclip.cxx @@ -2,7 +2,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -59,7 +59,7 @@ // ----------------------------------------------------------------------------- -/* Implementation of the so-called 'Fat-Line Bezier Clipping Algorithm' by Sederberg et al. +/* Implementation of the so-called 'Fat-Line Bezier Clipping Algorithm' by Sederberg et al. * * Actual reference is: T. W. Sederberg and T Nishita: Curve * intersection using Bezier clipping. In Computer Aided Design, 22 @@ -143,9 +143,9 @@ void Impl_calcFatLine( FatLine& line, const Bezier& c ) } } -void Impl_calcBounds( Point2D& leftTop, - Point2D& rightBottom, - const Bezier& c1 ) +void Impl_calcBounds( Point2D& leftTop, + Point2D& rightBottom, + const Bezier& c1 ) { leftTop.x = ::std::min( c1.p0.x, ::std::min( c1.p1.x, ::std::min( c1.p2.x, c1.p3.x ) ) ); leftTop.y = ::std::min( c1.p0.y, ::std::min( c1.p1.y, ::std::min( c1.p2.y, c1.p3.y ) ) ); @@ -181,11 +181,11 @@ bool Impl_doBBoxIntersect( const Bezier& c1, * the left, the second is the intersection of the max value line with * the convex hull from the right. */ -bool Impl_calcSafeParams( double& t1, - double& t2, - const Polygon2D& rPoly, - double lowerYBound, - double upperYBound ) +bool Impl_calcSafeParams( double& t1, + double& t2, + const Polygon2D& rPoly, + double lowerYBound, + double upperYBound ) { // need the convex hull of the control polygon, as this is // guaranteed to completely bound the curve @@ -194,7 +194,7 @@ bool Impl_calcSafeParams( double& t1, // init min and max buffers t1 = 0.0 ; double currLowerT( 1.0 ); - + t2 = 1.0; double currHigherT( 0.0 ); @@ -237,7 +237,7 @@ bool Impl_calcSafeParams( double& t1, // one of the horizontal bounds lines const double r_x( p1.x - p0.x ); const double r_y( p1.y - p0.y ); - + if( tolZero(r_y) ) { // r_y is virtually zero, thus we've got a horizontal @@ -258,7 +258,7 @@ bool Impl_calcSafeParams( double& t1, // calc intersection with horizontal dMin line const double currTLow( (lowerYBound - p0.y) * r_x / r_y + p0.x ); - + // calc intersection with horizontal dMax line const double currTHigh( (upperYBound - p0.y) * r_x / r_y + p0.x ); @@ -269,7 +269,7 @@ bool Impl_calcSafeParams( double& t1, // set flag that at least one segment is contained or // intersects given horizontal band. bIntersection = true; - } + } } #ifndef WITH_SAFEPARAMBASE_TEST @@ -290,20 +290,20 @@ bool Impl_calcSafeParams( double& t1, * The polynomial coefficients c0 to c3 given to this method * must correspond to t values of 0, 1/3, 2/3 and 1, respectively. */ -bool Impl_calcSafeParams_clip( double& t1, - double& t2, - const FatLine& bounds, - double c0, - double c1, - double c2, - double c3 ) +bool Impl_calcSafeParams_clip( double& t1, + double& t2, + const FatLine& bounds, + double c0, + double c1, + double c2, + double c3 ) { /* first of all, determine convex hull of c0-c3 */ Polygon2D poly(4); - poly[0] = Point2D(0, c0); - poly[1] = Point2D(1.0/3.0, c1); - poly[2] = Point2D(2.0/3.0, c2); - poly[3] = Point2D(1, c3); + poly[0] = Point2D(0, c0); + poly[1] = Point2D(1.0/3.0, c1); + poly[2] = Point2D(2.0/3.0, c2); + poly[3] = Point2D(1, c3); #ifndef WITH_SAFEPARAM_DETAILED_TEST @@ -314,14 +314,14 @@ bool Impl_calcSafeParams_clip( double& t1, Polygon2D convHull( convexHull( poly ) ); - cout << "# convex hull testing" << endl + cout << "# convex hull testing" << endl << "plot [t=0:1] "; - cout << " bez(" - << poly[0].x << "," + cout << " bez(" + << poly[0].x << "," << poly[1].x << "," << poly[2].x << "," << poly[3].x << ",t),bez(" - << poly[0].y << "," + << poly[0].y << "," << poly[1].y << "," << poly[2].y << "," << poly[3].y << ",t), " @@ -353,10 +353,10 @@ bool Impl_calcSafeParams_clip( double& t1, // ----------------------------------------------------------------------------- -void Impl_deCasteljauAt( Bezier& part1, - Bezier& part2, - const Bezier& input, - double t ) +void Impl_deCasteljauAt( Bezier& part1, + Bezier& part2, + const Bezier& input, + double t ) { // deCasteljau bezier arc, scheme is: // @@ -388,26 +388,26 @@ void Impl_deCasteljauAt( Bezier& part1, } else { - part1.p0.x = input.p0.x; part1.p0.y = input.p0.y; - part1.p1.x = (1.0 - t)*part1.p0.x + t*input.p1.x; part1.p1.y = (1.0 - t)*part1.p0.y + t*input.p1.y; - const double Hx ( (1.0 - t)*input.p1.x + t*input.p2.x ), Hy ( (1.0 - t)*input.p1.y + t*input.p2.y ); - part1.p2.x = (1.0 - t)*part1.p1.x + t*Hx; part1.p2.y = (1.0 - t)*part1.p1.y + t*Hy; - part2.p3.x = input.p3.x; part2.p3.y = input.p3.y; - part2.p2.x = (1.0 - t)*input.p2.x + t*input.p3.x; part2.p2.y = (1.0 - t)*input.p2.y + t*input.p3.y; - part2.p1.x = (1.0 - t)*Hx + t*part2.p2.x; part2.p1.y = (1.0 - t)*Hy + t*part2.p2.y; - part2.p0.x = (1.0 - t)*part1.p2.x + t*part2.p1.x; part2.p0.y = (1.0 - t)*part1.p2.y + t*part2.p1.y; - part1.p3.x = part2.p0.x; part1.p3.y = part2.p0.y; + part1.p0.x = input.p0.x; part1.p0.y = input.p0.y; + part1.p1.x = (1.0 - t)*part1.p0.x + t*input.p1.x; part1.p1.y = (1.0 - t)*part1.p0.y + t*input.p1.y; + const double Hx ( (1.0 - t)*input.p1.x + t*input.p2.x ), Hy ( (1.0 - t)*input.p1.y + t*input.p2.y ); + part1.p2.x = (1.0 - t)*part1.p1.x + t*Hx; part1.p2.y = (1.0 - t)*part1.p1.y + t*Hy; + part2.p3.x = input.p3.x; part2.p3.y = input.p3.y; + part2.p2.x = (1.0 - t)*input.p2.x + t*input.p3.x; part2.p2.y = (1.0 - t)*input.p2.y + t*input.p3.y; + part2.p1.x = (1.0 - t)*Hx + t*part2.p2.x; part2.p1.y = (1.0 - t)*Hy + t*part2.p2.y; + part2.p0.x = (1.0 - t)*part1.p2.x + t*part2.p1.x; part2.p0.y = (1.0 - t)*part1.p2.y + t*part2.p1.y; + part1.p3.x = part2.p0.x; part1.p3.y = part2.p0.y; } } // ----------------------------------------------------------------------------- -void printCurvesWithSafeRange( const Bezier& c1, const Bezier& c2, double t1_c1, double t2_c1, +void printCurvesWithSafeRange( const Bezier& c1, const Bezier& c2, double t1_c1, double t2_c1, const Bezier& c2_part, const FatLine& bounds_c2 ) { static int offset = 0; - cout << "# safe param range testing" << endl + cout << "# safe param range testing" << endl << "plot [t=0.0:1.0] "; // clip safe ranges off c1 @@ -422,41 +422,41 @@ void printCurvesWithSafeRange( const Bezier& c1, const Bezier& c2, double t1_c1, // output remaining segment (c1_part1) - cout << "bez(" - << c1.p0.x+offset << "," + cout << "bez(" + << c1.p0.x+offset << "," << c1.p1.x+offset << "," << c1.p2.x+offset << "," << c1.p3.x+offset << ",t),bez(" - << c1.p0.y << "," + << c1.p0.y << "," << c1.p1.y << "," << c1.p2.y << "," << c1.p3.y << ",t), bez(" - << c2.p0.x+offset << "," + << c2.p0.x+offset << "," << c2.p1.x+offset << "," << c2.p2.x+offset << "," << c2.p3.x+offset << ",t),bez(" - << c2.p0.y << "," + << c2.p0.y << "," << c2.p1.y << "," << c2.p2.y << "," << c2.p3.y << ",t), " #if 1 << "bez(" - << c1_part1.p0.x+offset << "," + << c1_part1.p0.x+offset << "," << c1_part1.p1.x+offset << "," << c1_part1.p2.x+offset << "," << c1_part1.p3.x+offset << ",t),bez(" - << c1_part1.p0.y << "," + << c1_part1.p0.y << "," << c1_part1.p1.y << "," << c1_part1.p2.y << "," << c1_part1.p3.y << ",t), " #endif #if 1 << "bez(" - << c2_part.p0.x+offset << "," + << c2_part.p0.x+offset << "," << c2_part.p1.x+offset << "," << c2_part.p2.x+offset << "," << c2_part.p3.x+offset << ",t),bez(" - << c2_part.p0.y << "," + << c2_part.p0.y << "," << c2_part.p1.y << "," << c2_part.p2.y << "," << c2_part.p3.y << ",t), " @@ -464,9 +464,9 @@ void printCurvesWithSafeRange( const Bezier& c1, const Bezier& c2, double t1_c1, << "linex(" << bounds_c2.a << "," << bounds_c2.b << "," - << bounds_c2.c << ",t)+" << offset << ", liney(" - << bounds_c2.a << "," - << bounds_c2.b << "," + << bounds_c2.c << ",t)+" << offset << ", liney(" + << bounds_c2.a << "," + << bounds_c2.b << "," << bounds_c2.c << ",t) title \"fat line (center)\", linex(" << bounds_c2.a << "," << bounds_c2.b << "," @@ -480,82 +480,82 @@ void printCurvesWithSafeRange( const Bezier& c1, const Bezier& c2, double t1_c1, << bounds_c2.a << "," << bounds_c2.b << "," << bounds_c2.c-bounds_c2.dMax << ",t) title \"fat line (max) \"" << endl; - + offset += 1; } // ----------------------------------------------------------------------------- -void printResultWithFinalCurves( const Bezier& c1, const Bezier& c1_part, - const Bezier& c2, const Bezier& c2_part, +void printResultWithFinalCurves( const Bezier& c1, const Bezier& c1_part, + const Bezier& c2, const Bezier& c2_part, double t1_c1, double t2_c1 ) { static int offset = 0; - cout << "# final result" << endl + cout << "# final result" << endl << "plot [t=0.0:1.0] "; - cout << "bez(" - << c1.p0.x+offset << "," + cout << "bez(" + << c1.p0.x+offset << "," << c1.p1.x+offset << "," << c1.p2.x+offset << "," << c1.p3.x+offset << ",t),bez(" - << c1.p0.y << "," + << c1.p0.y << "," << c1.p1.y << "," << c1.p2.y << "," << c1.p3.y << ",t), bez(" - << c1_part.p0.x+offset << "," + << c1_part.p0.x+offset << "," << c1_part.p1.x+offset << "," << c1_part.p2.x+offset << "," << c1_part.p3.x+offset << ",t),bez(" - << c1_part.p0.y << "," + << c1_part.p0.y << "," << c1_part.p1.y << "," << c1_part.p2.y << "," - << c1_part.p3.y << ",t), " + << c1_part.p3.y << ",t), " << " pointmarkx(bez(" - << c1.p0.x+offset << "," + << c1.p0.x+offset << "," << c1.p1.x+offset << "," << c1.p2.x+offset << "," << c1.p3.x+offset << "," << t1_c1 << "),t), " - << " pointmarky(bez(" - << c1.p0.y << "," + << " pointmarky(bez(" + << c1.p0.y << "," << c1.p1.y << "," << c1.p2.y << "," << c1.p3.y << "," << t1_c1 << "),t), " << " pointmarkx(bez(" - << c1.p0.x+offset << "," + << c1.p0.x+offset << "," << c1.p1.x+offset << "," << c1.p2.x+offset << "," << c1.p3.x+offset << "," << t2_c1 << "),t), " - << " pointmarky(bez(" - << c1.p0.y << "," + << " pointmarky(bez(" + << c1.p0.y << "," << c1.p1.y << "," << c1.p2.y << "," << c1.p3.y << "," << t2_c1 << "),t), " << "bez(" - << c2.p0.x+offset << "," + << c2.p0.x+offset << "," << c2.p1.x+offset << "," << c2.p2.x+offset << "," << c2.p3.x+offset << ",t),bez(" - << c2.p0.y << "," + << c2.p0.y << "," << c2.p1.y << "," << c2.p2.y << "," << c2.p3.y << ",t), " << "bez(" - << c2_part.p0.x+offset << "," + << c2_part.p0.x+offset << "," << c2_part.p1.x+offset << "," << c2_part.p2.x+offset << "," << c2_part.p3.x+offset << ",t),bez(" - << c2_part.p0.y << "," + << c2_part.p0.y << "," << c2_part.p1.y << "," << c2_part.p2.y << "," << c2_part.p3.y << ",t)" << endl; - + offset += 1; } @@ -563,8 +563,8 @@ void printResultWithFinalCurves( const Bezier& c1, const Bezier& c1_part, /** determine parameter ranges [0,t1) and (t2,1] on c1, where c1 is guaranteed to lie outside c2. Returns false, if the two curves don't even intersect. - - @param t1 + + @param t1 Range [0,t1) on c1 is guaranteed to lie outside c2 @param t2 @@ -582,51 +582,51 @@ void printResultWithFinalCurves( const Bezier& c1, const Bezier& c1_part, @param c2_part Subdivided current part of c2 */ -bool Impl_calcClipRange( double& t1, - double& t2, - const Bezier& c1_orig, - const Bezier& c1_part, - const Bezier& c2_orig, - const Bezier& c2_part ) +bool Impl_calcClipRange( double& t1, + double& t2, + const Bezier& c1_orig, + const Bezier& c1_part, + const Bezier& c2_orig, + const Bezier& c2_part ) { - // TODO: Maybe also check fat line orthogonal to P0P3, having P0 + // TODO: Maybe also check fat line orthogonal to P0P3, having P0 // and P3 as the extremal points - + if( Impl_doBBoxIntersect(c1_part, c2_part) ) { // Calculate fat lines around c1 - FatLine bounds_c2; + FatLine bounds_c2; // must use the subdivided version of c2, since the fat line // algorithm works implicitely with the convex hull bounding // box. Impl_calcFatLine(bounds_c2, c2_part); - + // determine clip positions on c2. Can use original c1 (which // is necessary anyway, to get the t's on the original curve), // since the distance calculations work directly in the // Bernstein polynom parameter domain. - if( Impl_calcSafeParams_clip( t1, t2, bounds_c2, + if( Impl_calcSafeParams_clip( t1, t2, bounds_c2, calcLineDistance( bounds_c2.a, bounds_c2.b, bounds_c2.c, c1_orig.p0.x, - c1_orig.p0.y ), + c1_orig.p0.y ), calcLineDistance( bounds_c2.a, bounds_c2.b, bounds_c2.c, c1_orig.p1.x, - c1_orig.p1.y ), + c1_orig.p1.y ), calcLineDistance( bounds_c2.a, bounds_c2.b, bounds_c2.c, c1_orig.p2.x, - c1_orig.p2.y ), + c1_orig.p2.y ), calcLineDistance( bounds_c2.a, bounds_c2.b, bounds_c2.c, c1_orig.p3.x, - c1_orig.p3.y ) ) ) + c1_orig.p3.y ) ) ) { //printCurvesWithSafeRange(c1_orig, c2_orig, t1, t2, c2_part, bounds_c2); @@ -650,14 +650,14 @@ bool Impl_calcClipRange( double& t1, void Impl_calcFocus( Bezier& res, const Bezier& c ) { // arbitrary small value, for now - // TODO: find meaningful value + // TODO: find meaningful value const double minPivotValue( 1.0e-20 ); Point2D::value_type fMatrix[6]; Point2D::value_type fRes[2]; // calc new curve from hodograph, c and linear blend - + // Coefficients for derivative of c are (C_i=n(C_{i+1} - C_i)): // // 3(P1 - P0), 3(P2 - P1), 3(P3 - P2) (bezier curve of degree 2) @@ -665,7 +665,7 @@ void Impl_calcFocus( Bezier& res, const Bezier& c ) // The hodograph is then (bezier curve of 2nd degree is P0(1-t)^2 + 2P1(1-t)t + P2t^2): // // 3(P1 - P0)(1-t)^2 + 6(P2 - P1)(1-t)t + 3(P3 - P2)t^2 - // + // // rotate by 90 degrees: x=-y, y=x and you get the normal vector function N(t): // // x(t) = -(3(P1.y - P0.y)(1-t)^2 + 6(P2.y - P1.y)(1-t)t + 3(P3.y - P2.y)t^2) @@ -676,11 +676,11 @@ void Impl_calcFocus( Bezier& res, const Bezier& c ) // // This results in the following expression for F(t): // - // x(t) = P0.x (1-t)^3 + 3 P1.x (1-t)^2t + 3 P2.x (1.t)t^2 + P3.x t^3 - - // (c0(1-t) + c1 t)(3(P1.y - P0.y)(1-t)^2 + 6(P2.y - P1.y)(1-t)t + 3(P3.y - P2.y)t^2) + // x(t) = P0.x (1-t)^3 + 3 P1.x (1-t)^2t + 3 P2.x (1.t)t^2 + P3.x t^3 - + // (c0(1-t) + c1 t)(3(P1.y - P0.y)(1-t)^2 + 6(P2.y - P1.y)(1-t)t + 3(P3.y - P2.y)t^2) // - // y(t) = P0.y (1-t)^3 + 3 P1.y (1-t)^2t + 3 P2.y (1.t)t^2 + P3.y t^3 + - // (c0(1-t) + c1 t)(3(P1.x - P0.x)(1-t)^2 + 6(P2.x - P1.x)(1-t)t + 3(P3.x - P2.x)t^2) + // y(t) = P0.y (1-t)^3 + 3 P1.y (1-t)^2t + 3 P2.y (1.t)t^2 + P3.y t^3 + + // (c0(1-t) + c1 t)(3(P1.x - P0.x)(1-t)^2 + 6(P2.x - P1.x)(1-t)t + 3(P3.x - P2.x)t^2) // // As a heuristic, we set F(0)=F(1) (thus, the curve is closed and _tends_ to be small): // @@ -713,7 +713,7 @@ void Impl_calcFocus( Bezier& res, const Bezier& c ) fMatrix[4] = c.p3.y - c.p2.y; fMatrix[5] = (c.p3.x - c.p0.x)/3.0; - // TODO: determine meaningful value for + // TODO: determine meaningful value for if( !solve(fMatrix, 2, 3, fRes, minPivotValue) ) { // TODO: generate meaningful values here @@ -728,38 +728,38 @@ void Impl_calcFocus( Bezier& res, const Bezier& c ) // now, the reordered and per-coefficient collected focus curve is // the following third degree bezier curve F(t): // - // x(t) = P0.x (1-t)^3 + 3 P1.x (1-t)^2t + 3 P2.x (1.t)t^2 + P3.x t^3 - - // (c0(1-t) + c1 t)(3(P1.y - P0.y)(1-t)^2 + 6(P2.y - P1.y)(1-t)t + 3(P3.y - P2.y)t^2) - // = P0.x (1-t)^3 + 3 P1.x (1-t)^2t + 3 P2.x (1.t)t^2 + P3.x t^3 - - // (3c0P1.y(1-t)^3 - 3c0P0.y(1-t)^3 + 6c0P2.y(1-t)^2t - 6c0P1.y(1-t)^2t + - // 3c0P3.y(1-t)t^2 - 3c0P2.y(1-t)t^2 + - // 3c1P1.y(1-t)^2t - 3c1P0.y(1-t)^2t + 6c1P2.y(1-t)t^2 - 6c1P1.y(1-t)t^2 + - // 3c1P3.yt^3 - 3c1P2.yt^3) - // = (P0.x - 3 c0 P1.y + 3 c0 P0.y)(1-t)^3 + - // 3(P1.x - c1 P1.y + c1 P0.y - 2 c0 P2.y + 2 c0 P1.y)(1-t)^2t + - // 3(P2.x - 2 c1 P2.y + 2 c1 P1.y - c0 P3.y + c0 P2.y)(1-t)t^2 + - // (P3.x - 3 c1 P3.y + 3 c1 P2.y)t^3 - // = (P0.x - 3 c0(P1.y - P0.y))(1-t)^3 + - // 3(P1.x - c1(P1.y - P0.y) - 2c0(P2.y - P1.y))(1-t)^2t + - // 3(P2.x - 2 c1(P2.y - P1.y) - c0(P3.y - P2.y))(1-t)t^2 + - // (P3.x - 3 c1(P3.y - P2.y))t^3 + // x(t) = P0.x (1-t)^3 + 3 P1.x (1-t)^2t + 3 P2.x (1.t)t^2 + P3.x t^3 - + // (c0(1-t) + c1 t)(3(P1.y - P0.y)(1-t)^2 + 6(P2.y - P1.y)(1-t)t + 3(P3.y - P2.y)t^2) + // = P0.x (1-t)^3 + 3 P1.x (1-t)^2t + 3 P2.x (1.t)t^2 + P3.x t^3 - + // (3c0P1.y(1-t)^3 - 3c0P0.y(1-t)^3 + 6c0P2.y(1-t)^2t - 6c0P1.y(1-t)^2t + + // 3c0P3.y(1-t)t^2 - 3c0P2.y(1-t)t^2 + + // 3c1P1.y(1-t)^2t - 3c1P0.y(1-t)^2t + 6c1P2.y(1-t)t^2 - 6c1P1.y(1-t)t^2 + + // 3c1P3.yt^3 - 3c1P2.yt^3) + // = (P0.x - 3 c0 P1.y + 3 c0 P0.y)(1-t)^3 + + // 3(P1.x - c1 P1.y + c1 P0.y - 2 c0 P2.y + 2 c0 P1.y)(1-t)^2t + + // 3(P2.x - 2 c1 P2.y + 2 c1 P1.y - c0 P3.y + c0 P2.y)(1-t)t^2 + + // (P3.x - 3 c1 P3.y + 3 c1 P2.y)t^3 + // = (P0.x - 3 c0(P1.y - P0.y))(1-t)^3 + + // 3(P1.x - c1(P1.y - P0.y) - 2c0(P2.y - P1.y))(1-t)^2t + + // 3(P2.x - 2 c1(P2.y - P1.y) - c0(P3.y - P2.y))(1-t)t^2 + + // (P3.x - 3 c1(P3.y - P2.y))t^3 // - // y(t) = P0.y (1-t)^3 + 3 P1.y (1-t)^2t + 3 P2.y (1-t)t^2 + P3.y t^3 + - // (c0(1-t) + c1 t)(3(P1.x - P0.x)(1-t)^2 + 6(P2.x - P1.x)(1-t)t + 3(P3.x - P2.x)t^2) - // = P0.y (1-t)^3 + 3 P1.y (1-t)^2t + 3 P2.y (1-t)t^2 + P3.y t^3 + - // 3c0(P1.x - P0.x)(1-t)^3 + 6c0(P2.x - P1.x)(1-t)^2t + 3c0(P3.x - P2.x)(1-t)t^2 + - // 3c1(P1.x - P0.x)(1-t)^2t + 6c1(P2.x - P1.x)(1-t)t^2 + 3c1(P3.x - P2.x)t^3 - // = (P0.y + 3 c0 (P1.x - P0.x))(1-t)^3 + - // 3(P1.y + 2 c0 (P2.x - P1.x) + c1 (P1.x - P0.x))(1-t)^2t + - // 3(P2.y + c0 (P3.x - P2.x) + 2 c1 (P2.x - P1.x))(1-t)t^2 + - // (P3.y + 3 c1 (P3.x - P2.x))t^3 + // y(t) = P0.y (1-t)^3 + 3 P1.y (1-t)^2t + 3 P2.y (1-t)t^2 + P3.y t^3 + + // (c0(1-t) + c1 t)(3(P1.x - P0.x)(1-t)^2 + 6(P2.x - P1.x)(1-t)t + 3(P3.x - P2.x)t^2) + // = P0.y (1-t)^3 + 3 P1.y (1-t)^2t + 3 P2.y (1-t)t^2 + P3.y t^3 + + // 3c0(P1.x - P0.x)(1-t)^3 + 6c0(P2.x - P1.x)(1-t)^2t + 3c0(P3.x - P2.x)(1-t)t^2 + + // 3c1(P1.x - P0.x)(1-t)^2t + 6c1(P2.x - P1.x)(1-t)t^2 + 3c1(P3.x - P2.x)t^3 + // = (P0.y + 3 c0 (P1.x - P0.x))(1-t)^3 + + // 3(P1.y + 2 c0 (P2.x - P1.x) + c1 (P1.x - P0.x))(1-t)^2t + + // 3(P2.y + c0 (P3.x - P2.x) + 2 c1 (P2.x - P1.x))(1-t)t^2 + + // (P3.y + 3 c1 (P3.x - P2.x))t^3 // // Therefore, the coefficients F0 to F3 of the focus curve are: // - // F0.x = (P0.x - 3 c0(P1.y - P0.y)) F0.y = (P0.y + 3 c0 (P1.x - P0.x)) - // F1.x = (P1.x - c1(P1.y - P0.y) - 2c0(P2.y - P1.y)) F1.y = (P1.y + 2 c0 (P2.x - P1.x) + c1 (P1.x - P0.x)) - // F2.x = (P2.x - 2 c1(P2.y - P1.y) - c0(P3.y - P2.y)) F2.y = (P2.y + c0 (P3.x - P2.x) + 2 c1 (P2.x - P1.x)) - // F3.x = (P3.x - 3 c1(P3.y - P2.y)) F3.y = (P3.y + 3 c1 (P3.x - P2.x)) + // F0.x = (P0.x - 3 c0(P1.y - P0.y)) F0.y = (P0.y + 3 c0 (P1.x - P0.x)) + // F1.x = (P1.x - c1(P1.y - P0.y) - 2c0(P2.y - P1.y)) F1.y = (P1.y + 2 c0 (P2.x - P1.x) + c1 (P1.x - P0.x)) + // F2.x = (P2.x - 2 c1(P2.y - P1.y) - c0(P3.y - P2.y)) F2.y = (P2.y + c0 (P3.x - P2.x) + 2 c1 (P2.x - P1.x)) + // F3.x = (P3.x - 3 c1(P3.y - P2.y)) F3.y = (P3.y + 3 c1 (P3.x - P2.x)) // res.p0.x = c.p0.x - 3*fRes[0]*(c.p1.y - c.p0.y); res.p1.x = c.p1.x - fRes[1]*(c.p1.y - c.p0.y) - 2*fRes[0]*(c.p2.y - c.p1.y); @@ -774,15 +774,15 @@ void Impl_calcFocus( Bezier& res, const Bezier& c ) // ----------------------------------------------------------------------------- -bool Impl_calcSafeParams_focus( double& t1, - double& t2, - const Bezier& curve, - const Bezier& focus ) +bool Impl_calcSafeParams_focus( double& t1, + double& t2, + const Bezier& curve, + const Bezier& focus ) { // now, we want to determine which normals of the original curve // P(t) intersect with the focus curve F(t). The condition for // this statement is P'(t)(P(t) - F) = 0, i.e. hodograph P'(t) and - // line through P(t) and F are perpendicular. + // line through P(t) and F are perpendicular. // If you expand this equation, you end up with something like // // (\sum_{i=0}^n (P_i - F)B_i^n(t))^T (\sum_{j=0}^{n-1} n(P_{j+1} - P_j)B_j^{n-1}(t)) @@ -795,7 +795,7 @@ bool Impl_calcSafeParams_focus( double& t1, // If we combine the B_i^n(t)B_j^{n-1}(t) product, we arrive at a // Bernstein polynomial of degree 2n-1, as // - // \binom{n}{i}(1-t)^{n-i}t^i) \binom{n-1}{j}(1-t)^{n-1-j}t^j) = + // \binom{n}{i}(1-t)^{n-i}t^i) \binom{n-1}{j}(1-t)^{n-1-j}t^j) = // \binom{n}{i}\binom{n-1}{j}(1-t)^{2n-1-i-j}t^{i+j} // // Thus, with the defining equation for a 2n-1 degree Bernstein @@ -830,7 +830,7 @@ bool Impl_calcSafeParams_focus( double& t1, // u axis, thus simply throw away u coordinate). // // \fallfac are so-called falling factorials (see Concrete - // Mathematics, p. 47 for a definition). + // Mathematics, p. 47 for a definition). // // now, for tensor product bezier curves, the convex hull property @@ -856,7 +856,7 @@ bool Impl_calcSafeParams_focus( double& t1, { // calc single d_{ij} sum: for( d=0.0, k=::std::max(0,i-n); k<=k_max && k<=i; ++k ) - { + { l = i - k; // invariant: k + l = i assert(k>=0 && k<=n-1); // k \in {0,...,n-1} assert(l>=0 && l<=n); // l \in {0,...,n} @@ -864,9 +864,9 @@ bool Impl_calcSafeParams_focus( double& t1, // TODO: find, document and assert proper limits for n and int's max_val. // This becomes important should anybody wants to use // this code for higher-than-cubic beziers - d += static_cast<double>(fallFac(n,l)*fallFac(n-1,k)*fac(i)) / + d += static_cast<double>(fallFac(n,l)*fallFac(n-1,k)*fac(i)) / static_cast<double>(fac(l)*fac(k) * fallFac(2*n-1,i)) * n * - ( (curve[k+1].x - curve[k].x)*(curve[l].x - focus[j].x) + // dot product here + ( (curve[k+1].x - curve[k].x)*(curve[l].x - focus[j].x) + // dot product here (curve[k+1].y - curve[k].y)*(curve[l].y - focus[j].y) ); } @@ -887,7 +887,7 @@ bool Impl_calcSafeParams_focus( double& t1, Polygon2D convHull( convexHull( controlPolygon ) ); - cout << "# convex hull testing (focus)" << endl + cout << "# convex hull testing (focus)" << endl << "plot [t=0:1] "; cout << "'-' using ($1):($2) title \"control polygon\" with lp, " << "'-' using ($1):($2) title \"convex hull\" with lp" << endl; @@ -921,7 +921,7 @@ bool Impl_calcSafeParams_focus( double& t1, determine safe parameter interval on c1 with regard to c2, then the other way around), we call this method recursively with c1 and c2 swapped. - + @param result Output iterator where the final t values are added to. If curves don't intersect, nothing is added. @@ -929,31 +929,31 @@ bool Impl_calcSafeParams_focus( double& t1, @param delta Maximal allowed distance to true critical point (measured in the original curve's coordinate system) - + @param safeRangeFunctor Functor object, that must provide the following operator(): - bool safeRangeFunctor( double& t1, - double& t2, - const Bezier& c1_orig, - const Bezier& c1_part, - const Bezier& c2_orig, + bool safeRangeFunctor( double& t1, + double& t2, + const Bezier& c1_orig, + const Bezier& c1_part, + const Bezier& c2_orig, const Bezier& c2_part ); This functor must calculate the safe ranges [0,t1] and [t2,1] on c1_orig, where c1_orig is 'safe' from c2_part. If the whole c1_orig is safe, false must be returned, true otherwise. */ -template <class Functor> void Impl_applySafeRanges_rec( ::std::back_insert_iterator< ::std::vector< ::std::pair<double, double> > >& result, - double delta, - const Functor& safeRangeFunctor, - int recursionLevel, - const Bezier& c1_orig, - const Bezier& c1_part, - double last_t1_c1, - double last_t2_c1, - const Bezier& c2_orig, - const Bezier& c2_part, - double last_t1_c2, - double last_t2_c2 ) +template <class Functor> void Impl_applySafeRanges_rec( ::std::back_insert_iterator< ::std::vector< ::std::pair<double, double> > >& result, + double delta, + const Functor& safeRangeFunctor, + int recursionLevel, + const Bezier& c1_orig, + const Bezier& c1_part, + double last_t1_c1, + double last_t2_c1, + const Bezier& c2_orig, + const Bezier& c2_part, + double last_t1_c2, + double last_t2_c2 ) { // check end condition // =================== @@ -972,7 +972,7 @@ template <class Functor> void Impl_applySafeRanges_rec( ::std::back_insert_itera for( int i=0; i<recursionLevel; ++i ) cerr << " "; if( recursionLevel % 2 ) { - cerr << "level: " << recursionLevel + cerr << "level: " << recursionLevel << " t: " << last_t1_c2 + (last_t2_c2 - last_t1_c2)/2.0 << ", c1: " << last_t1_c2 << " " << last_t2_c2 @@ -981,7 +981,7 @@ template <class Functor> void Impl_applySafeRanges_rec( ::std::back_insert_itera } else { - cerr << "level: " << recursionLevel + cerr << "level: " << recursionLevel << " t: " << last_t1_c1 + (last_t2_c1 - last_t1_c1)/2.0 << ", c1: " << last_t1_c1 << " " << last_t2_c1 @@ -1028,10 +1028,10 @@ template <class Functor> void Impl_applySafeRanges_rec( ::std::back_insert_itera #if 1 if( fabs(last_t2_c1 - last_t1_c1) < 0.0001 && - fabs(last_t2_c2 - last_t1_c2) < 0.0001 ) + fabs(last_t2_c2 - last_t1_c2) < 0.0001 ) #else if( fabs(last_t2_c1 - last_t1_c1) < 0.01 && - fabs(last_t2_c2 - last_t1_c2) < 0.01 ) + fabs(last_t2_c2 - last_t1_c2) < 0.01 ) #endif { // done. Add to result @@ -1076,7 +1076,7 @@ template <class Functor> void Impl_applySafeRanges_rec( ::std::back_insert_itera Bezier part2; double intervalMiddle; - + if( last_t2_c1 - last_t1_c1 > last_t2_c2 - last_t1_c2 ) { // subdivide c1 @@ -1111,7 +1111,7 @@ template <class Functor> void Impl_applySafeRanges_rec( ::std::back_insert_itera // curve, this simply amounts to subdivision // at 0.5) Impl_deCasteljauAt( part1, part2, c2_part, 0.5 ); - + // and descend recursively with swapped curves Impl_applySafeRanges_rec( result, delta, safeRangeFunctor, recursionLevel+1, c2_orig, part1, last_t1_c2, intervalMiddle, @@ -1159,14 +1159,14 @@ template <class Functor> void Impl_applySafeRanges_rec( ::std::back_insert_itera struct ClipBezierFunctor { - bool operator()( double& t1_c1, - double& t2_c1, + bool operator()( double& t1_c1, + double& t2_c1, const Bezier& c1_orig, const Bezier& c1_part, const Bezier& c2_orig, const Bezier& c2_part ) const - { - return Impl_calcClipRange( t1_c1, t2_c1, c1_orig, c1_part, c2_orig, c2_part ); + { + return Impl_calcClipRange( t1_c1, t2_c1, c1_orig, c1_part, c2_orig, c2_part ); } }; @@ -1174,13 +1174,13 @@ struct ClipBezierFunctor struct BezierTangencyFunctor { - bool operator()( double& t1_c1, - double& t2_c1, + bool operator()( double& t1_c1, + double& t2_c1, const Bezier& c1_orig, const Bezier& c1_part, const Bezier& c2_orig, const Bezier& c2_part ) const - { + { // calc focus curve of c2 Bezier focus; Impl_calcFocus(focus, c2_part); // need to use subdivided c2 @@ -1201,7 +1201,7 @@ struct BezierTangencyFunctor // ----------------------------------------------------------------------------- /** Perform a bezier clip (curve against curve) - + @param result Output iterator where the final t values are added to. This iterator will remain empty, if there are no intersections. @@ -1210,10 +1210,10 @@ struct BezierTangencyFunctor Maximal allowed distance to true intersection (measured in the original curve's coordinate system) */ -void clipBezier( ::std::back_insert_iterator< ::std::vector< ::std::pair<double, double> > >& result, - double delta, - const Bezier& c1, - const Bezier& c2 ) +void clipBezier( ::std::back_insert_iterator< ::std::vector< ::std::pair<double, double> > >& result, + double delta, + const Bezier& c1, + const Bezier& c2 ) { #if 0 // first of all, determine list of collinear normals. Collinear @@ -1257,7 +1257,7 @@ void clipBezier( ::std::back_insert_iterator< ::std::vector< ::std::pair<double, } c1_segments[i] = c1_remainder; c2_segments[i] = c2_remainder; - + // now, c1/c2_segments contain all segments, then // clip every resulting segment against every other unsigned int c1_curr, c2_curr; @@ -1267,10 +1267,10 @@ void clipBezier( ::std::back_insert_iterator< ::std::vector< ::std::pair<double, { if( c1_curr != c2_curr ) { - Impl_clipBezier_rec(result, delta, 0, - c1_segments[c1_curr], c1_segments[c1_curr], + Impl_clipBezier_rec(result, delta, 0, + c1_segments[c1_curr], c1_segments[c1_curr], 0.0, 1.0, - c2_segments[c2_curr], c2_segments[c2_curr], + c2_segments[c2_curr], c2_segments[c2_curr], 0.0, 1.0); } } @@ -1287,8 +1287,8 @@ int main(int argc, const char *argv[]) double curr_Offset( 0 ); unsigned int i,j,k; - Bezier someCurves[] = - { + Bezier someCurves[] = + { // {Point2D(0.0,0.0),Point2D(0.0,1.0),Point2D(1.0,1.0),Point2D(1.0,0.0)}, // {Point2D(0.0,0.0),Point2D(0.0,1.0),Point2D(1.0,1.0),Point2D(1.0,0.5)}, // {Point2D(1.0,0.0),Point2D(0.0,0.0),Point2D(0.0,1.0),Point2D(1.0,1.0)} @@ -1352,7 +1352,7 @@ int main(int argc, const char *argv[]) }; // output gnuplot setup - cout << "#!/usr/bin/gnuplot -persist" << endl + cout << "#!/usr/bin/gnuplot -persist" << endl << "#" << endl << "# automatically generated by bezierclip, don't change!" << endl << "#" << endl @@ -1363,13 +1363,13 @@ int main(int argc, const char *argv[]) << "pointmarky(c,t) = c+0.03*t" << endl << "linex(a,b,c,t) = a*-c + t*-b" << endl << "liney(a,b,c,t) = b*-c + t*a" << endl << endl - << "# end of setup" << endl << endl; + << "# end of setup" << endl << endl; #ifdef WITH_CONVEXHULL_TEST // test convex hull algorithm const double convHull_xOffset( curr_Offset ); curr_Offset += 20; - cout << "# convex hull testing" << endl + cout << "# convex hull testing" << endl << "plot [t=0:1] "; for( i=0; i<sizeof(someCurves)/sizeof(Bezier); ++i ) { @@ -1378,18 +1378,18 @@ int main(int argc, const char *argv[]) aTestPoly[1] = someCurves[i].p1; aTestPoly[2] = someCurves[i].p2; aTestPoly[3] = someCurves[i].p3; - + aTestPoly[0].x += convHull_xOffset; aTestPoly[1].x += convHull_xOffset; aTestPoly[2].x += convHull_xOffset; aTestPoly[3].x += convHull_xOffset; - cout << " bez(" - << aTestPoly[0].x << "," + cout << " bez(" + << aTestPoly[0].x << "," << aTestPoly[1].x << "," << aTestPoly[2].x << "," << aTestPoly[3].x << ",t),bez(" - << aTestPoly[0].y << "," + << aTestPoly[0].y << "," << aTestPoly[1].y << "," << aTestPoly[2].y << "," << aTestPoly[3].y << ",t), '-' using ($1):($2) title \"convex hull " << i << "\" with lp"; @@ -1406,14 +1406,14 @@ int main(int argc, const char *argv[]) aTestPoly[1] = someCurves[i].p1; aTestPoly[2] = someCurves[i].p2; aTestPoly[3] = someCurves[i].p3; - + aTestPoly[0].x += convHull_xOffset; aTestPoly[1].x += convHull_xOffset; aTestPoly[2].x += convHull_xOffset; aTestPoly[3].x += convHull_xOffset; Polygon2D convHull( convexHull(aTestPoly) ); - + for( k=0; k<convHull.size(); ++k ) { cout << convHull[k].x << " " << convHull[k].y << endl; @@ -1427,7 +1427,7 @@ int main(int argc, const char *argv[]) // test convex hull algorithm const double multiSubdivide_xOffset( curr_Offset ); curr_Offset += 20; - cout << "# multi subdivide testing" << endl + cout << "# multi subdivide testing" << endl << "plot [t=0:1] "; for( i=0; i<sizeof(someCurves)/sizeof(Bezier); ++i ) { @@ -1459,30 +1459,30 @@ int main(int argc, const char *argv[]) // subdivide at t2 Impl_deCasteljauAt( c1_part3, c1_part2, c, t2 ); - cout << " bez(" - << c1_part1.p0.x << "," + cout << " bez(" + << c1_part1.p0.x << "," << c1_part1.p1.x << "," << c1_part1.p2.x << "," << c1_part1.p3.x << ",t), bez(" - << c1_part1.p0.y+0.01 << "," + << c1_part1.p0.y+0.01 << "," << c1_part1.p1.y+0.01 << "," << c1_part1.p2.y+0.01 << "," << c1_part1.p3.y+0.01 << ",t) title \"middle " << i << "\", " - << " bez(" - << c1_part2.p0.x << "," + << " bez(" + << c1_part2.p0.x << "," << c1_part2.p1.x << "," << c1_part2.p2.x << "," << c1_part2.p3.x << ",t), bez(" - << c1_part2.p0.y << "," + << c1_part2.p0.y << "," << c1_part2.p1.y << "," << c1_part2.p2.y << "," << c1_part2.p3.y << ",t) title \"right " << i << "\", " - << " bez(" - << c1_part3.p0.x << "," + << " bez(" + << c1_part3.p0.x << "," << c1_part3.p1.x << "," << c1_part3.p2.x << "," << c1_part3.p3.x << ",t), bez(" - << c1_part3.p0.y << "," + << c1_part3.p0.y << "," << c1_part3.p1.y << "," << c1_part3.p2.y << "," << c1_part3.p3.y << ",t) title \"left " << i << "\""; @@ -1499,12 +1499,12 @@ int main(int argc, const char *argv[]) // test fatline algorithm const double fatLine_xOffset( curr_Offset ); curr_Offset += 20; - cout << "# fat line testing" << endl + cout << "# fat line testing" << endl << "plot [t=0:1] "; for( i=0; i<sizeof(someCurves)/sizeof(Bezier); ++i ) { Bezier c( someCurves[i] ); - + c.p0.x += fatLine_xOffset; c.p1.x += fatLine_xOffset; c.p2.x += fatLine_xOffset; @@ -1514,20 +1514,20 @@ int main(int argc, const char *argv[]) Impl_calcFatLine(line, c); - cout << " bez(" - << c.p0.x << "," + cout << " bez(" + << c.p0.x << "," << c.p1.x << "," << c.p2.x << "," << c.p3.x << ",t), bez(" - << c.p0.y << "," + << c.p0.y << "," << c.p1.y << "," << c.p2.y << "," << c.p3.y << ",t) title \"bezier " << i << "\", linex(" << line.a << "," << line.b << "," - << line.c << ",t), liney(" - << line.a << "," - << line.b << "," + << line.c << ",t), liney(" + << line.a << "," + << line.b << "," << line.c << ",t) title \"fat line (center) on " << i << "\", linex(" << line.a << "," << line.b << "," @@ -1553,12 +1553,12 @@ int main(int argc, const char *argv[]) // test focus curve algorithm const double focus_xOffset( curr_Offset ); curr_Offset += 20; - cout << "# focus line testing" << endl + cout << "# focus line testing" << endl << "plot [t=0:1] "; for( i=0; i<sizeof(someCurves)/sizeof(Bezier); ++i ) { Bezier c( someCurves[i] ); - + c.p0.x += focus_xOffset; c.p1.x += focus_xOffset; c.p2.x += focus_xOffset; @@ -1568,20 +1568,20 @@ int main(int argc, const char *argv[]) Bezier focus; Impl_calcFocus(focus, c); - cout << " bez(" - << c.p0.x << "," + cout << " bez(" + << c.p0.x << "," << c.p1.x << "," << c.p2.x << "," << c.p3.x << ",t), bez(" - << c.p0.y << "," + << c.p0.y << "," << c.p1.y << "," << c.p2.y << "," - << c.p3.y << ",t) title \"bezier " << i << "\", bez(" - << focus.p0.x << "," + << c.p3.y << ",t) title \"bezier " << i << "\", bez(" + << focus.p0.x << "," << focus.p1.x << "," << focus.p2.x << "," << focus.p3.x << ",t), bez(" - << focus.p0.y << "," + << focus.p0.y << "," << focus.p1.y << "," << focus.p2.y << "," << focus.p3.y << ",t) title \"focus " << i << "\""; @@ -1597,12 +1597,12 @@ int main(int argc, const char *argv[]) #ifdef WITH_SAFEPARAMBASE_TEST // test safe params base method double safeParamsBase_xOffset( curr_Offset ); - cout << "# safe param base method testing" << endl + cout << "# safe param base method testing" << endl << "plot [t=0:1] "; for( i=0; i<sizeof(someCurves)/sizeof(Bezier); ++i ) { Bezier c( someCurves[i] ); - + c.p0.x += safeParamsBase_xOffset; c.p1.x += safeParamsBase_xOffset; c.p2.x += safeParamsBase_xOffset; @@ -1619,13 +1619,13 @@ int main(int argc, const char *argv[]) bool bRet( Impl_calcSafeParams( t1, t2, poly, 0, 1 ) ); Polygon2D convHull( convexHull( poly ) ); - - cout << " bez(" - << poly[0].x << "," + + cout << " bez(" + << poly[0].x << "," << poly[1].x << "," << poly[2].x << "," << poly[3].x << ",t),bez(" - << poly[0].y << "," + << poly[0].y << "," << poly[1].y << "," << poly[2].y << "," << poly[3].y << ",t), " @@ -1651,7 +1651,7 @@ int main(int argc, const char *argv[]) for( i=0; i<sizeof(someCurves)/sizeof(Bezier); ++i ) { Bezier c( someCurves[i] ); - + c.p0.x += safeParamsBase_xOffset; c.p1.x += safeParamsBase_xOffset; c.p2.x += safeParamsBase_xOffset; @@ -1668,7 +1668,7 @@ int main(int argc, const char *argv[]) Impl_calcSafeParams( t1, t2, poly, 0, 1 ); Polygon2D convHull( convexHull( poly ) ); - + unsigned int k; for( k=0; k<poly.size(); ++k ) { @@ -1693,7 +1693,7 @@ int main(int argc, const char *argv[]) // test safe parameter range algorithm const double safeParams_xOffset( curr_Offset ); curr_Offset += 20; - cout << "# safe param range testing" << endl + cout << "# safe param range testing" << endl << "plot [t=0.0:1.0] "; for( i=0; i<sizeof(someCurves)/sizeof(Bezier); ++i ) { @@ -1701,7 +1701,7 @@ int main(int argc, const char *argv[]) { Bezier c1( someCurves[i] ); Bezier c2( someCurves[j] ); - + c1.p0.x += safeParams_xOffset; c1.p1.x += safeParams_xOffset; c1.p2.x += safeParams_xOffset; @@ -1727,28 +1727,28 @@ int main(int argc, const char *argv[]) // output remaining segment (c1_part1) - cout << " bez(" - << c1.p0.x << "," + cout << " bez(" + << c1.p0.x << "," << c1.p1.x << "," << c1.p2.x << "," << c1.p3.x << ",t),bez(" - << c1.p0.y << "," + << c1.p0.y << "," << c1.p1.y << "," << c1.p2.y << "," << c1.p3.y << ",t), bez(" - << c2.p0.x << "," + << c2.p0.x << "," << c2.p1.x << "," << c2.p2.x << "," << c2.p3.x << ",t),bez(" - << c2.p0.y << "," + << c2.p0.y << "," << c2.p1.y << "," << c2.p2.y << "," << c2.p3.y << ",t), bez(" - << c1_part1.p0.x << "," + << c1_part1.p0.x << "," << c1_part1.p1.x << "," << c1_part1.p2.x << "," << c1_part1.p3.x << ",t),bez(" - << c1_part1.p0.y << "," + << c1_part1.p0.y << "," << c1_part1.p1.y << "," << c1_part1.p2.y << "," << c1_part1.p3.y << ",t)"; @@ -1770,7 +1770,7 @@ int main(int argc, const char *argv[]) { Bezier c1( someCurves[0] ); Bezier c2( someCurves[1] ); - + c1.p0.x += safeParams2_xOffset; c1.p1.x += safeParams2_xOffset; c1.p2.x += safeParams2_xOffset; @@ -1791,7 +1791,7 @@ int main(int argc, const char *argv[]) // test safe parameter range from focus algorithm const double safeParamsFocus_xOffset( curr_Offset ); curr_Offset += 20; - cout << "# safe param range from focus testing" << endl + cout << "# safe param range from focus testing" << endl << "plot [t=0.0:1.0] "; for( i=0; i<sizeof(someCurves)/sizeof(Bezier); ++i ) { @@ -1799,7 +1799,7 @@ int main(int argc, const char *argv[]) { Bezier c1( someCurves[i] ); Bezier c2( someCurves[j] ); - + c1.p0.x += safeParamsFocus_xOffset; c1.p1.x += safeParamsFocus_xOffset; c1.p2.x += safeParamsFocus_xOffset; @@ -1819,10 +1819,10 @@ int main(int argc, const char *argv[]) Bezier c1_part1; Bezier c1_part2; Bezier c1_part3; - + // subdivide at t1_c1 Impl_deCasteljauAt( c1_part1, c1_part2, c2, 0.30204 ); - + // subdivide at t2_c1. As we're working on // c1_part2 now, we have to adapt t2_c1 since // we're no longer in the original parameter @@ -1831,7 +1831,7 @@ int main(int argc, const char *argv[]) // relates the t2 value into the new parameter // range [0,1] of c1_part2. Impl_deCasteljauAt( c1_part1, c1_part3, c1_part2, (0.57151-0.30204)/(1.0-0.30204) ); - + c2 = c1_part1; Impl_calcFocus( focus, c2 ); } @@ -1851,49 +1851,49 @@ int main(int argc, const char *argv[]) Bezier c1_part1; Bezier c1_part2; Bezier c1_part3; - + // subdivide at t1_c1 Impl_deCasteljauAt( c1_part1, c1_part2, c1, t1 ); // subdivide at t2_c1 Impl_deCasteljauAt( c1_part1, c1_part3, c1_part2, (t2-t1)/(1.0-t1) ); - + // output remaining segment (c1_part1) - - cout << " bez(" - << c1.p0.x << "," + + cout << " bez(" + << c1.p0.x << "," << c1.p1.x << "," << c1.p2.x << "," << c1.p3.x << ",t),bez(" - << c1.p0.y << "," + << c1.p0.y << "," << c1.p1.y << "," << c1.p2.y << "," << c1.p3.y << ",t) title \"c1\", " #ifdef WITH_SAFEFOCUSPARAM_CALCFOCUS << "bez(" - << c2.p0.x << "," + << c2.p0.x << "," << c2.p1.x << "," << c2.p2.x << "," << c2.p3.x << ",t),bez(" - << c2.p0.y << "," + << c2.p0.y << "," << c2.p1.y << "," << c2.p2.y << "," << c2.p3.y << ",t) title \"c2\", " << "bez(" - << focus.p0.x << "," + << focus.p0.x << "," << focus.p1.x << "," << focus.p2.x << "," << focus.p3.x << ",t),bez(" - << focus.p0.y << "," + << focus.p0.y << "," << focus.p1.y << "," << focus.p2.y << "," << focus.p3.y << ",t) title \"focus\""; #else << "bez(" - << c2.p0.x << "," + << c2.p0.x << "," << c2.p1.x << "," << c2.p2.x << "," << c2.p3.x << ",t),bez(" - << c2.p0.y << "," + << c2.p0.y << "," << c2.p1.y << "," << c2.p2.y << "," << c2.p3.y << ",t) title \"focus\""; @@ -1901,11 +1901,11 @@ int main(int argc, const char *argv[]) if( bRet ) { cout << ", bez(" - << c1_part1.p0.x << "," + << c1_part1.p0.x << "," << c1_part1.p1.x << "," << c1_part1.p2.x << "," << c1_part1.p3.x << ",t),bez(" - << c1_part1.p0.y+0.01 << "," + << c1_part1.p0.y+0.01 << "," << c1_part1.p1.y+0.01 << "," << c1_part1.p2.y+0.01 << "," << c1_part1.p3.y+0.01 << ",t) title \"part\""; @@ -1927,7 +1927,7 @@ int main(int argc, const char *argv[]) { Bezier c1( someCurves[0] ); Bezier c2( someCurves[1] ); - + c1.p0.x += safeParams3_xOffset; c1.p1.x += safeParams3_xOffset; c1.p2.x += safeParams3_xOffset; @@ -1938,7 +1938,7 @@ int main(int argc, const char *argv[]) c2.p3.x += safeParams3_xOffset; double t1, t2; - + Bezier focus; #ifdef WITH_SAFEFOCUSPARAM_CALCFOCUS Impl_calcFocus( focus, c2 ); @@ -1953,13 +1953,13 @@ int main(int argc, const char *argv[]) #endif #ifdef WITH_BEZIERCLIP_TEST - ::std::vector< ::std::pair<double, double> > result; + ::std::vector< ::std::pair<double, double> > result; ::std::back_insert_iterator< ::std::vector< ::std::pair<double, double> > > ii(result); // test full bezier clipping const double bezierClip_xOffset( curr_Offset ); curr_Offset += 20; - cout << endl << endl << "# bezier clip testing" << endl + cout << endl << endl << "# bezier clip testing" << endl << "plot [t=0:1] "; for( i=0; i<sizeof(someCurves)/sizeof(Bezier); ++i ) { @@ -1977,39 +1977,39 @@ int main(int argc, const char *argv[]) c2.p2.x += bezierClip_xOffset; c2.p3.x += bezierClip_xOffset; - cout << " bez(" - << c1.p0.x << "," + cout << " bez(" + << c1.p0.x << "," << c1.p1.x << "," << c1.p2.x << "," << c1.p3.x << ",t),bez(" - << c1.p0.y << "," + << c1.p0.y << "," << c1.p1.y << "," << c1.p2.y << "," << c1.p3.y << ",t), bez(" - << c2.p0.x << "," + << c2.p0.x << "," << c2.p1.x << "," << c2.p2.x << "," << c2.p3.x << ",t),bez(" - << c2.p0.y << "," + << c2.p0.y << "," << c2.p1.y << "," << c2.p2.y << "," - << c2.p3.y << ",t), '-' using (bez(" - << c1.p0.x << "," + << c2.p3.y << ",t), '-' using (bez(" + << c1.p0.x << "," << c1.p1.x << "," << c1.p2.x << "," - << c1.p3.x + << c1.p3.x << ",$1)):(bez(" - << c1.p0.y << "," + << c1.p0.y << "," << c1.p1.y << "," << c1.p2.y << "," << c1.p3.y << ",$1)) title \"bezier " << i << " clipped against " << j << " (t on " << i << ")\", " - << " '-' using (bez(" - << c2.p0.x << "," + << " '-' using (bez(" + << c2.p0.x << "," << c2.p1.x << "," << c2.p2.x << "," - << c2.p3.x + << c2.p3.x << ",$1)):(bez(" - << c2.p0.y << "," + << c2.p0.y << "," << c2.p1.y << "," << c2.p2.y << "," << c2.p3.y << ",$1)) title \"bezier " << i << " clipped against " << j << " (t on " << j << ")\""; |