X-Git-Url: https://git.yukkurigames.com/?p=string-lerp.git;a=blobdiff_plain;f=string-lerp.js;h=3a304886374373c3471aaf530a92f2615ea5544d;hp=5e8201c942e8afa1d29b1949c7e47813ff95acd0;hb=dd1c5bcbe8357a8bc2b83fc711ee16d0c7c8eaac;hpb=a2ba0c21bc1e59f8269051458266896cb928f905 diff --git a/string-lerp.js b/string-lerp.js index 5e8201c..3a30488 100644 --- a/string-lerp.js +++ b/string-lerp.js @@ -88,9 +88,14 @@ compute the edits. It is not recommended for strings longer than a few hundred characters. */ - var edits = diff(a, b); - var partial = edits.slice(0, Math.round(p * edits.length)); - return patch(partial, a); + + // The edit path works from the string end, forwards, because + // that's how Levenshtein edits work. To match LTR reading + // direction (and the behavior of fastLerp), swap the strings + // and invert the parameter when editing. + var edits = diff(b, a); + var partial = edits.slice(0, Math.round((1 - p) * edits.length)); + return patch(partial, b); } var NUMBERS = /(-?\d+(?:\.\d+)?)/g;