Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Variables calculations overwritten #906

Open
slspencer opened this issue Mar 24, 2023 · 5 comments
Open

BUG: Variables calculations overwritten #906

slspencer opened this issue Mar 24, 2023 · 5 comments
Labels

Comments

@slspencer
Copy link
Collaborator

slspencer commented Mar 24, 2023

  • Describe the bug

In the Variables Table, a Variable's calculated value can be overwritten from a formula farther down in the Variables table. The updated calculated value is then used to draw the pattern.
The Variables Table should not allow backward updates, this creates recursion. I can provide example of this, but the base problem is ability to update variables that are defined earlier in the table.

In this example, the variable is overwritten directly with a constant, even though the formula wasn't overwritten.
3-RewriteVariableValue

@slspencer slspencer added the bug label Mar 24, 2023
@slspencer slspencer changed the title BUG: Variables calculations incorrect BUG: Variables calculations overwritten Mar 24, 2023
@pmjherman
Copy link
Contributor

Isn't this logical behaviour? By inserting the formula "#LegTaperOffset=6", the program will execute the formula #LegTaperOffset2=#LegTaperOffset=6, which is a double assignment that changes both #LegTaperOffset and #LegTaperOffset2, both to the value 6.
Maybe the formula editor should refuse a formula that contains an assignment, because there is normally no reason to use this. If you would have used another operator, e.g. "#LegTaperOffset * 6", it would have worked normally

@DSCaskey
Copy link
Contributor

Maybe the formula editor should refuse a formula that contains an assignment, because there is normally no reason to use this.

No. Don't assume anything. The math parser allows for conditional expressions... meaning you should be able to set a variable based on a condition. Removing the use of = breaks this functionality, and most likely some existing patterns.

@DSCaskey
Copy link
Contributor

DSCaskey commented Apr 1, 2023

I've found a fix. Just need to clean up some commits.
vtable

@slspencer
Copy link
Collaborator Author

This issue is about whether we want to allow assignment using Variable formulas.
So @DSCaskey if you think we should be able to set values of variables in formulas then this isn't an issue.

Here's an example of where it works properly:
Var X formula is '3'
Var Y formula is '2'
Var Z formula is '((Y>1) ? (X=X + Y) : Y)
The result is that X = 5, Y = 2, Z = 5
Saving this file and reopening it has the same result. X=5, Y =2, Z = 5
test_VariableOverwriteInFormula

Here's an example of where it doesn't work properly, where the '==' is typo'd as '=' in an IF statement:
Var Strange = '((X=1)?(X=2):(X=3))

test_VariableOverwriteInFormula-2

@slspencer
Copy link
Collaborator Author

slspencer commented Apr 1, 2023

@DSCaskey - this is good that you've found out how to prevent the backward variable assignment.
But is it really a fix when Var2's formula assigns a value to Var1 but the result is that the value is actually assigned to Var2? The results don't match the formula, which may make the pattern difficult to troubleshoot.
This may not be a good result overall.

Is there a way to validate the operator of an IF statement condition in qmuparser? This may be the problem we want to solve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants