about summary refs log tree commit diff
path: root/converter/other/pamtosvg/fit.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-09-24 17:17:10 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-09-24 17:17:10 +0000
commit513edda8124b0376c32a2a92c8c7a4342892f079 (patch)
tree87266a841bbb2bd05b021638f81e517a396ee41d /converter/other/pamtosvg/fit.c
parent16e02f6e91a7a8be2d3d4067ad36195e01fc5b92 (diff)
downloadnetpbm-mirror-513edda8124b0376c32a2a92c8c7a4342892f079.tar.gz
netpbm-mirror-513edda8124b0376c32a2a92c8c7a4342892f079.tar.xz
netpbm-mirror-513edda8124b0376c32a2a92c8c7a4342892f079.zip
Release 11.02.04
git-svn-id: http://svn.code.sf.net/p/netpbm/code/stable@4686 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other/pamtosvg/fit.c')
-rw-r--r--converter/other/pamtosvg/fit.c42
1 files changed, 33 insertions, 9 deletions
diff --git a/converter/other/pamtosvg/fit.c b/converter/other/pamtosvg/fit.c
index 179b3bdf..06e708c2 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;
 }