Skip to content

Commit db1895b

Browse files
committed
Fix bugs in equation parsing
1 parent ef92ed5 commit db1895b

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/core/sceneObjs/BaseGrinGlass.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,14 @@ class BaseGrinGlass extends BaseGlass {
467467
* @returns {string}
468468
*/
469469
shiftOrigin(equation) {
470-
// Replace standalone x (including `ex`/`xe` implicit multiplication), but avoid names like `exp`/`max`.
471-
return equation.replaceAll(/(^|[^a-zA-Z0-9_]|e)x(?=$|[^a-zA-Z0-9_]|e)/g, "$1(x-" + this.origin.x + ")").replaceAll("y", "(y-" + this.origin.y + ")");
470+
// Protect `\exp` and `\max` so their `x` is not replaced; restore them after.
471+
return equation
472+
.replaceAll("\\exp", "\\EXP")
473+
.replaceAll("\\max", "\\MAX")
474+
.replaceAll("x", "(x-" + this.origin.x + ")")
475+
.replaceAll("\\EXP", "\\exp")
476+
.replaceAll("\\MAX", "\\max")
477+
.replaceAll("y", "(y-" + this.origin.y + ")");
472478
}
473479

474480
/**

0 commit comments

Comments
 (0)