morphologica icon indicating copy to clipboard operation
morphologica copied to clipboard

There's a bug in BezCurve::computePointsBySearch()

Open sebjameswml opened this issue 3 years ago • 0 comments

@jmartinbrooke found this. Sometimes, t exceeds 1, triggering the runtime error in BezCurve::checkt. I think better runtime checking is required in computePointBySearch. Perhaps somethign like:

diff --git a/morph/BezCurve.h b/morph/BezCurve.h
index d5e246d..b8c79a7 100644
--- a/morph/BezCurve.h
+++ b/morph/BezCurve.h
@@ -1086,6 +1086,14 @@ namespace morph
          */
         BezCoord<Flt> computePointBySearch (Flt t, Flt l) const
         {
+            // This may be necessary, to fix the intermittent bug discovered by John
+            if (t >= Flt{1}) {
+                BezCoord<Flt> rtn (true);
+                rtn.setRemaining (0);
+                rtn.setParam (t);
+                return rtn;
+            }
+
             // Min and max of possible range for dt to make a step of length l in posn space
             Flt dtmin = Flt{0};
             Flt dtmax = Flt{1} - t;

Also, why is this a != rather than <? (Also BezCurve.h):

            // This searches forward to try to find a point which is 'l' further on. If
            // at any point t exceeds 1.0, we have to break out.
            while (t != Flt{1} && lastnull == false) {

sebjameswml avatar Mar 31 '21 14:03 sebjameswml