diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2023-09-06 23:17:18 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2023-09-06 23:17:18 +0000 |
commit | 24ef77c17672db9412323197f0f4f6f632534cfb (patch) | |
tree | a5b1913cd8093a651280f0d5e0587316bd941fcf /converter/other/pamtosvg/fit.c | |
parent | de1d329358a406932f09f383c42b320d33b94ed8 (diff) | |
download | netpbm-mirror-24ef77c17672db9412323197f0f4f6f632534cfb.tar.gz netpbm-mirror-24ef77c17672db9412323197f0f4f6f632534cfb.tar.xz netpbm-mirror-24ef77c17672db9412323197f0f4f6f632534cfb.zip |
Fix to previous commit
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4635 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other/pamtosvg/fit.c')
-rw-r--r-- | converter/other/pamtosvg/fit.c | 64 |
1 files changed, 44 insertions, 20 deletions
diff --git a/converter/other/pamtosvg/fit.c b/converter/other/pamtosvg/fit.c index 548d23da..c5a46310 100644 --- a/converter/other/pamtosvg/fit.c +++ b/converter/other/pamtosvg/fit.c @@ -1411,34 +1411,58 @@ findHalfTangent(LineEnd const toWhichEnd, be no slope between those points) -- they're part of the count, but don't contribute to the slope. If _all_ of the points to be considered are identical to the end point, arbitrarily return a horizontal slope. + + Return the slope as an unnormalized vector. (I don't know if that was + intended by the designer, since it isn't sensible unless it's a + computational efficiency thing; it's just how I found the code). + + It is possible for the mean described above to be the zero vector, because + the mean of a vector pointing left and one pointing right is the zero + vector. In that case, we use fewer "tangentSurround" points. -----------------------------------------------------------------------------*/ float_coord const tangentPoint = CURVE_POINT(curveP, toWhichEnd == LINEEND_INIT ? 0 : CURVE_LENGTH(curveP) - 1); vector_type const zeroZero = { 0.0, 0.0 }; - unsigned int const surroundCt = - MIN(CURVE_LENGTH(curveP) / 2, tangentSurround); - unsigned int i; - vector_type sum; - unsigned int n; - vector_type mean; - - for (i = 0, n = 0, sum = zeroZero; i < surroundCt; ++i) { - unsigned int const thisIndex = - toWhichEnd == LINEEND_INIT ? i + 1 : CURVE_LENGTH(curveP) - 1 - i; - float_coord const thisPoint = CURVE_POINT(curveP, thisIndex); - - if (!pointsEqual(thisPoint, tangentPoint)) { - /* Perhaps we should weight the tangent from `thisPoint' by some - factor dependent on the distance from the tangent point. - */ - sum = Vadd(sum, Pdirection(thisPoint, tangentPoint)); - ++n; + unsigned int surroundCt; + bool gotNonzero; + vector_type mean; + + for (surroundCt = MIN(CURVE_LENGTH(curveP) / 2, tangentSurround), + gotNonzero = false; + !gotNonzero; + --surroundCt) { + + unsigned int i; + vector_type sum; + unsigned int n; + + for (i = 0, n = 0, sum = zeroZero; i < surroundCt; ++i) { + unsigned int const thisIndex = + toWhichEnd == LINEEND_INIT ? + i + 1 : CURVE_LENGTH(curveP) - 1 - i; + float_coord const thisPoint = CURVE_POINT(curveP, thisIndex); + + if (!pointsEqual(thisPoint, tangentPoint)) { + /* Perhaps we should weight the tangent from `thisPoint' by + some factor dependent on the distance from the tangent + point. + */ + sum = Vadd(sum, Pdirection(thisPoint, tangentPoint)); + ++n; + } } - } + mean = n > 0 ? Vmult_scalar(sum, 1.0 / n) : Vhorizontal(); - mean = n > 0 ? Vmult_scalar(sum, 1.0 / n) : Vhorizontal(); + if (Vequal(mean, Vzero())) { + /* We have points on multiple sides of the endpoint whose vectors + happen to add up to zero, which is not usable. + */ + assert(surroundCt > 0); + } else + gotNonzero = true; + } return mean; } |