Expressions: Fixed parsing of unit expressions similar to 1/unit.
This commit is contained in:
parent
1626c69494
commit
909727ade8
|
@ -1833,6 +1833,20 @@ UnitExpression * ExpressionParser::parseUnit(const App::DocumentObject *owner, c
|
|||
|
||||
// Simplify expression
|
||||
Expression * simplified = ScanResult->simplify();
|
||||
|
||||
if (!unitExpression) {
|
||||
OperatorExpression * fraction = freecad_dynamic_cast<OperatorExpression>(ScanResult);
|
||||
|
||||
if (fraction && fraction->getOperator() == OperatorExpression::DIV) {
|
||||
NumberExpression * nom = freecad_dynamic_cast<NumberExpression>(fraction->getLeft());
|
||||
UnitExpression * denom = freecad_dynamic_cast<UnitExpression>(fraction->getRight());
|
||||
const double epsilon = std::numeric_limits<double>::epsilon();
|
||||
|
||||
// If not initially a unit expression, but value is equal to 1, it means the expression is something like 1/unit
|
||||
if (denom && nom && essentiallyEqual(nom->getValue(), 1.0, epsilon))
|
||||
unitExpression = true;
|
||||
}
|
||||
}
|
||||
delete ScanResult;
|
||||
|
||||
if (unitExpression) {
|
||||
|
|
|
@ -246,6 +246,12 @@ public:
|
|||
|
||||
virtual void visit(ExpressionVisitor & v);
|
||||
|
||||
Operator getOperator() const { return op; }
|
||||
|
||||
Expression * getLeft() const { return left; }
|
||||
|
||||
Expression * getRight() const { return right; }
|
||||
|
||||
protected:
|
||||
Operator op; /**< Operator working on left and right */
|
||||
Expression * left; /**< Left operand */
|
||||
|
|
Loading…
Reference in New Issue
Block a user