diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2023-09-28 02:26:12 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2023-09-28 02:26:12 +0000 |
commit | 1a04fa9529619b1bd59424fda68a76c8a4a59332 (patch) | |
tree | ec7d9e28278c7de6baf519d2d44f52a9edcd7ee7 /converter/other/pamtosvg/fit.c | |
parent | 0d513aca5cbbb8db0a9d127e101ac3b534cc8bf0 (diff) | |
download | netpbm-mirror-1a04fa9529619b1bd59424fda68a76c8a4a59332.tar.gz netpbm-mirror-1a04fa9529619b1bd59424fda68a76c8a4a59332.tar.xz netpbm-mirror-1a04fa9529619b1bd59424fda68a76c8a4a59332.zip |
Release 10.86.39
git-svn-id: http://svn.code.sf.net/p/netpbm/code/super_stable@4696 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other/pamtosvg/fit.c')
-rw-r--r-- | converter/other/pamtosvg/fit.c | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/converter/other/pamtosvg/fit.c b/converter/other/pamtosvg/fit.c index 5ba7a2f6..2e4e8588 100644 --- a/converter/other/pamtosvg/fit.c +++ b/converter/other/pamtosvg/fit.c @@ -1379,14 +1379,26 @@ findHalfTangentBeg(curve * const curveP, unsigned int const thisIndex = p + 1; float_coord const thisPoint = CURVE_POINT(curveP, thisIndex); - /* 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; + if (epsilon_equal(thisPoint.x, tangentPoint.x) && + epsilon_equal(thisPoint.y, tangentPoint.y) && + epsilon_equal(thisPoint.z, tangentPoint.z)) { + /* It's the same point; can't compute a slope */ + } else { + /* 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 = Vmult_scalar(sum, 1.0 / n); + if (n >= 1) + mean = Vmult_scalar(sum, 1.0 / n); + else { + mean.dx = 1.0; + mean.dy = 0.0; + mean.dz = 0.0; + } return mean; } @@ -1418,11 +1430,23 @@ findHalfTangentEnd(curve * const curveP, unsigned int const thisIndex = CURVE_LENGTH(curveP) - 1 - p; float_coord const thisPoint = CURVE_POINT(curveP, thisIndex); - sum = Vadd(sum, Pdirection(tangentPoint, thisPoint)); - ++n; + if (epsilon_equal(thisPoint.x, tangentPoint.x) && + epsilon_equal(thisPoint.y, tangentPoint.y) && + epsilon_equal(thisPoint.z, tangentPoint.z)) { + /* It's the same point; can't compute a slope */ + } else { + sum = Vadd(sum, Pdirection(tangentPoint, thisPoint)); + ++n; + } } - mean = Vmult_scalar(sum, 1.0 / n); + if (n >= 1) + mean = Vmult_scalar(sum, 1.0 / n); + else { + mean.dx = 1.0; + mean.dy = 0.0; + mean.dz = 0.0; + } return mean; } |