Fix step-wise formulas causing issues with reactivity

This commit is contained in:
thepaperpilot 2023-05-12 01:39:06 -05:00
parent 213bdd6005
commit 8284baa1a0

View file

@ -229,15 +229,16 @@ export abstract class InternalFormula<T extends [FormulaSource] | FormulaSource[
start: Computable<DecimalSource>, start: Computable<DecimalSource>,
formulaModifier: (value: InvertibleIntegralFormula) => GenericFormula formulaModifier: (value: InvertibleIntegralFormula) => GenericFormula
) { ) {
const lhsRef = ref<DecimalSource>(0); const formula = formulaModifier(Formula.variable(0));
const formula = formulaModifier(Formula.variable(lhsRef));
const processedStart = convertComputable(start); const processedStart = convertComputable(start);
function evalStep(lhs: DecimalSource) { function evalStep(lhs: DecimalSource) {
if (Decimal.lt(lhs, unref(processedStart))) { if (Decimal.lt(lhs, unref(processedStart))) {
return lhs; return lhs;
} }
lhsRef.value = Decimal.sub(lhs, unref(processedStart)); return Decimal.add(
return Decimal.add(formula.evaluate(), unref(processedStart)); formula.evaluate(Decimal.sub(lhs, unref(processedStart))),
unref(processedStart)
);
} }
function invertStep(value: DecimalSource, lhs: FormulaSource) { function invertStep(value: DecimalSource, lhs: FormulaSource) {
if (hasVariable(lhs) && formula.isInvertible()) { if (hasVariable(lhs) && formula.isInvertible()) {