mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[poincare/multiplication] Imperial volume display
With the imperial system selected, volumes are expressed as volume in Calculation's results, instead of cubic lengths. Change-Id: Ib6c0a1a595dce8ae8db6371b41af818b3fdc6236
This commit is contained in:
committed by
Émilie Feral
parent
860ce558c2
commit
ec6ee82b81
@@ -534,7 +534,21 @@ Expression Multiplication::shallowBeautify(ExpressionNode::ReductionContext redu
|
||||
} else {
|
||||
if (unitConversionMode == ExpressionNode::UnitConversion::Default) {
|
||||
// Find the right unit prefix
|
||||
Unit::ChooseBestRepresentativeAndPrefixForValue(units, &value, reductionContext);
|
||||
/* In most cases, unit composition works the same for imperial and
|
||||
* metric units. However, in imperial, we want volumes to be displayed
|
||||
* using volume units instead of cubic length. */
|
||||
const bool forceVolumeRepresentative = reductionContext.unitFormat() == Preferences::UnitFormat::Imperial && UnitNode::Vector<int>::FromBaseUnits(units) == UnitNode::VolumeRepresentative::Default().dimensionVector();
|
||||
const UnitNode::Representative * repr;
|
||||
if (forceVolumeRepresentative) {
|
||||
/* The choice of representative doesn't matter, as it will be tuned to a
|
||||
* system appropriate one in Step 2b. */
|
||||
repr = UnitNode::VolumeRepresentative::Default().representativesOfSameDimension();
|
||||
units = Unit::Builder(repr, UnitNode::Prefix::EmptyPrefix());
|
||||
value /= repr->ratio();
|
||||
Unit::ChooseBestRepresentativeAndPrefixForValue(units, &value, reductionContext);
|
||||
} else {
|
||||
Unit::ChooseBestRepresentativeAndPrefixForValue(units, &value, reductionContext);
|
||||
}
|
||||
}
|
||||
// Build final Expression
|
||||
result = Multiplication::Builder(Number::FloatNumber(value), units);
|
||||
|
||||
@@ -341,6 +341,8 @@ QUIZ_CASE(poincare_simplification_units) {
|
||||
assert_parsed_expression_simplify_to("_in", "1×_in", User, Radian, Imperial);
|
||||
assert_parsed_expression_simplify_to("_ft", "1×_ft", User, Radian, Imperial);
|
||||
assert_parsed_expression_simplify_to("_yd", "1×_yd", User, Radian, Imperial);
|
||||
assert_parsed_expression_simplify_to("1_qt", "1×_qt", User, Radian, Imperial);
|
||||
assert_parsed_expression_simplify_to("1_qt", "946.352946×_cm^3");
|
||||
|
||||
/* Unit sum/subtract */
|
||||
assert_parsed_expression_simplify_to("_m+_m", "2×_m");
|
||||
|
||||
Reference in New Issue
Block a user