-
Notifications
You must be signed in to change notification settings - Fork 213
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
Added math equation support for plus and minus signs. #6969
Added math equation support for plus and minus signs. #6969
Conversation
correcting typeo 'substraction' -> 'subtraction' Co-authored-by: Nam Le <[email protected]>
In cases like these where multiple metrics are supplied (yd, ft, in, m, cm, ...) how do you decide on which to go with? |
There are 2 cases : |
Test default to first unit when no unit defined in Format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want to hold this PR and discuss motivations before merging this in
…/mathieu-fournier/itwinjs-core into mathf/add-math-equations-parsing
…/mathieu-fournier/itwinjs-core into mathf/add-math-equations-parsing
Co-authored-by: Anmol Shrestha <[email protected]>
Co-authored-by: Anmol Shrestha <[email protected]>
Updated _allowMathematicEquations variable comment
Co-authored-by: Arun George <[email protected]>
common/changes/@itwin/core-quantity/pr-mathieu-fournier-6969_2024-07-29-18-30.json
Outdated
Show resolved
Hide resolved
…024-07-29-18-30.json Co-authored-by: Arun George <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, maybe this is just an issue of wording or mu interpretation,
should it be mathematic operations not equations ? if so all references to the boolean flag you added need to be updated
## Mathematical equations formatting | ||
|
||
The formatter now supports parsing mathematical equations. Ex : | ||
```Typescript |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is the actual ts code for this? what does it look like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's in the tests.
It looks like this :
// Async version
const quantityProps = await Parser.parseIntoQuantity("2 FT 6 in + 9", format, unitsProvider);
// Sync version
const parseResult = Parser.parseToQuantityValue("2 FT 6 in + 9", format, meterConversionSpecs);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consumers will not be looking at the tests, theyll look at the the changelog here, and this should probably have a ts snippet of the change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users will use the quantity formatter with the boolean flag.
They will not call these directly. Should I add an example anyway ?
Co-authored-by: Arun George <[email protected]>
Co-authored-by: Arun George <[email protected]>
Co-authored-by: Arun George <[email protected]>
Co-authored-by: Arun George <[email protected]>
Moved to #7019 |
Pull request for the issue feature #6935
Added initial support for parsing math equations. + and -
Plus and minus signs are supported.
Ex:
5 ft + 12 in + 1 yd -1 ft 6 in = 7.5 ft
(5 + 1 + 3 - 1.5)
Multiplication and division are not supported yet.
Special case + Refactoring
I noticed that the functions
createQuantityFromParseTokens
andgetQuantityValueFromParseTokens
where doing the same "tokens to value" logic. So I de-duplicated them.There was one inconsistent output between these methods.
The case where only the unit label was specified. <- See line 601 in
Parser.ts
.The output for the 2 methods where : 'FT' = 1 and 'FT' = 0
I opted to assume that the magnitude is 1.
Another special case, which I assume was a bug, is the parsing of
2'-6"
. <- See line 218 in the fileParsing.test.ts
.The minus sign was threated like a formatTraits
fractionDash
, but the format did not specifiedfractionDash
, so it should've been 0 or error.Now it's treated like a minus sign when fractionDash is NOT specified, and a fractionDash when fractionDah is specified.