[apps/calculation] New additional results on units

The additional results on units now include conversions into both unit
systems (metric and imperial).

Change-Id: Ie0f12eb3735e775560b66c2cbd78bc9a659145bb
This commit is contained in:
Gabriel Ozouf
2020-07-21 13:14:20 +02:00
committed by Émilie Feral
parent 3ff25fb5c1
commit 6c676782aa
3 changed files with 72 additions and 63 deletions

View File

@@ -883,6 +883,9 @@ public:
static bool IsSIVolume(Expression & e);
static bool IsSIEnergy(Expression & e);
static bool IsSITime(Expression & e);
static bool IsSIDistance(Expression & e);
static bool IsSIMass(Expression & e);
static bool IsSISurface(Expression & e);
bool isMeter() const;
bool isSecond() const;
bool isKilogram() const;

View File

@@ -515,6 +515,19 @@ bool Unit::IsSITime(Expression & e) {
return e.type() == ExpressionNode::Type::Unit && static_cast<Unit &>(e).isSecond();
}
bool Unit::IsSIDistance(Expression & e) {
return e.type() == ExpressionNode::Type::Unit && static_cast<Unit &>(e).isMeter();
}
bool Unit::IsSIMass(Expression & e) {
return e.type() == ExpressionNode::Type::Unit && static_cast<Unit &>(e).isKilogram();
}
bool Unit::IsSISurface(Expression & e) {
return e.type() == ExpressionNode::Type::Power &&
e.childAtIndex(0).type() == ExpressionNode::Type::Unit && e.childAtIndex(0).convert<Unit>().isMeter() &&
e.childAtIndex(1).type() == ExpressionNode::Type::Rational && e.childAtIndex(1).convert<const Rational>().isTwo();
}
double Unit::ConvertedValueInUnit(Expression e, Unit unit, Context * context) {
Expression conversion = UnitConvert::Builder(e.clone(), unit);