From 79f6208544493d15bb8d4050701c2fe7539104ab Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 22 Nov 2021 15:50:10 +0700 Subject: [PATCH 1/5] Path Distance Measurement Inconsistency Issue: https://github.com/fabricjs/fabric.js/issues/7327 --- src/util/path.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/path.js b/src/util/path.js index a187ea65387..57ba46a8dd5 100644 --- a/src/util/path.js +++ b/src/util/path.js @@ -507,7 +507,9 @@ p, nextLen, nextStep = 0.01, angleFinder = segInfo.angleFinder, lastPerc; // nextStep > 0.0001 covers 0.00015625 that 1/64th of 1/100 // the path - while (tmpLen < distance && perc <= 1 && nextStep > 0.0001) { + + // floating point made perc <= 1 ignore some calculation, so perc < 1.1 do the trick + while (tmpLen < distance && perc < 1.1 && nextStep > 0.0001) { p = iterator(perc); lastPerc = perc; nextLen = calcLineLength(tempP.x, tempP.y, p.x, p.y); From 1e499ad7275a798b8ec576458db1f5be48d3524f Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 23 Nov 2021 13:42:13 +0700 Subject: [PATCH 2/5] Update path.js for the lint! --- src/util/path.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util/path.js b/src/util/path.js index 57ba46a8dd5..52cf8933493 100644 --- a/src/util/path.js +++ b/src/util/path.js @@ -507,7 +507,6 @@ p, nextLen, nextStep = 0.01, angleFinder = segInfo.angleFinder, lastPerc; // nextStep > 0.0001 covers 0.00015625 that 1/64th of 1/100 // the path - // floating point made perc <= 1 ignore some calculation, so perc < 1.1 do the trick while (tmpLen < distance && perc < 1.1 && nextStep > 0.0001) { p = iterator(perc); From 8f387fa5d6c56d57922049f018aa1f58d2d29788 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 23 Nov 2021 17:46:49 +0700 Subject: [PATCH 3/5] Update path.js --- src/util/path.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/util/path.js b/src/util/path.js index 52cf8933493..fec58092914 100644 --- a/src/util/path.js +++ b/src/util/path.js @@ -507,8 +507,7 @@ p, nextLen, nextStep = 0.01, angleFinder = segInfo.angleFinder, lastPerc; // nextStep > 0.0001 covers 0.00015625 that 1/64th of 1/100 // the path - // floating point made perc <= 1 ignore some calculation, so perc < 1.1 do the trick - while (tmpLen < distance && perc < 1.1 && nextStep > 0.0001) { + while (tmpLen < distance && perc < (perc + nextStep) && nextStep > 0.0001) { p = iterator(perc); lastPerc = perc; nextLen = calcLineLength(tempP.x, tempP.y, p.x, p.y); From 5684ec4017bbd98d4f3480b16711f081bfe990cf Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 24 Nov 2021 02:31:03 +0700 Subject: [PATCH 4/5] Update path.js --- src/util/path.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/path.js b/src/util/path.js index fec58092914..8d9e9bf425d 100644 --- a/src/util/path.js +++ b/src/util/path.js @@ -507,7 +507,7 @@ p, nextLen, nextStep = 0.01, angleFinder = segInfo.angleFinder, lastPerc; // nextStep > 0.0001 covers 0.00015625 that 1/64th of 1/100 // the path - while (tmpLen < distance && perc < (perc + nextStep) && nextStep > 0.0001) { + while (tmpLen < distance && perc < (1 + nextStep) && nextStep > 0.0001) { p = iterator(perc); lastPerc = perc; nextLen = calcLineLength(tempP.x, tempP.y, p.x, p.y); From 1b8306f03f3d647596187a66bafc0bc815010437 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 24 Nov 2021 03:40:27 +0700 Subject: [PATCH 5/5] Update path.js --- src/util/path.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/path.js b/src/util/path.js index 8d9e9bf425d..705e732fa62 100644 --- a/src/util/path.js +++ b/src/util/path.js @@ -507,15 +507,15 @@ p, nextLen, nextStep = 0.01, angleFinder = segInfo.angleFinder, lastPerc; // nextStep > 0.0001 covers 0.00015625 that 1/64th of 1/100 // the path - while (tmpLen < distance && perc < (1 + nextStep) && nextStep > 0.0001) { + while (tmpLen < distance && nextStep > 0.0001) { p = iterator(perc); lastPerc = perc; nextLen = calcLineLength(tempP.x, tempP.y, p.x, p.y); // compare tmpLen each cycle with distance, decide next perc to test. if ((nextLen + tmpLen) > distance) { // we discard this step and we make smaller steps. - nextStep /= 2; perc -= nextStep; + nextStep /= 2; } else { tempP = p;