From f4b316f0117ef507758dfa5c5a1038e0870eded6 Mon Sep 17 00:00:00 2001 From: hdu Date: Fri, 23 Oct 2009 11:02:48 +0200 Subject: #i106127# perf: ignore multiplicit solutions in maxdist calculation --- basegfx/source/curve/b2dcubicbezier.cxx | 34 +++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'basegfx') diff --git a/basegfx/source/curve/b2dcubicbezier.cxx b/basegfx/source/curve/b2dcubicbezier.cxx index 38d783e9651d..83c620df7870 100644 --- a/basegfx/source/curve/b2dcubicbezier.cxx +++ b/basegfx/source/curve/b2dcubicbezier.cxx @@ -1060,6 +1060,7 @@ namespace basegfx const double fC = (maControlPointA.getX() - maStartPoint.getX()) * aRelativeEndPoint.getY() - (maControlPointA.getY() - maStartPoint.getY()) * aRelativeEndPoint.getX(); + // test for degenerated case: non-cubic curve if( fTools::equalZero(fA) ) { // test for degenerated case: straight line @@ -1068,25 +1069,34 @@ namespace basegfx // degenerated case: quadratic bezier pResult[0] = -fC / (2*fB); - if( pResult[0] < 0 || pResult[0]>1) - return 0; - return 1; + + // test root: ignore it when it is outside the curve + int nCount = ((pResult[0] > 0) && (pResult[0] < 1)); + return nCount; } - // derivative is polynomial of order 2 => use binomial formula + // derivative is polynomial of order 2 + // check if the polynomial has non-imaginary roots const double fD = fB*fB - fA*fC; - if( fD >= 0.0 ) + if( fD >= 0.0 ) // TODO: is this test needed? geometrically not IMHO { + // calculate the first root const double fS = sqrt(fD); const double fQ = fB + ((fB >= 0) ? +fS : -fS); pResult[0] = fQ / fA; - pResult[1] = fC / fQ; - int nCount = 2; - if( pResult[1] < 0 || pResult[1]>1) - --nCount; - if( pResult[0] < 0 || pResult[0]>1) - if( --nCount) - pResult[0] = pResult[1]; + // test root: ignore it when it is outside the curve + int nCount = ((pResult[0] > 0) && (pResult[0] < 1)); + + // ignore multiplicit roots + if( !fTools::equalZero(fD) ) + { + // calculate the second root + const double fRoot = fC / fQ; + pResult[ nCount ] = fC / fQ; + // test root: ignore it when it is outside the curve + nCount += ((fRoot > 0) && (fRoot < 1)); + } + return nCount; } -- cgit