mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare/unit] Restructure Unit
1. Information about a unit's dimension now uses inheritance. _m is an instance of DistanceAlias, which is derived from Alias. A UnitNode now keeps a pointer to an Alias and one to a Prefix. All aliases are still defined as constexpr. This cleans up a lot of the code used namely for computing the additional outputs in Calculation. 2. Instead of being defined with a string, each unit is described by its ratio with the base SI unit (ex: _L is 0.001 instead of "0.001_m^3"). This greatly speeds up the calculations using units, as the algorithm to find the best unit used to parse the definition. Change-Id: I4d6ed6ad4cb967026a3f01a335aec270066e2b9f
This commit is contained in:
committed by
Émilie Feral
parent
e48e826536
commit
52dcd8e749
@@ -254,32 +254,13 @@ Calculation::AdditionalInformationType Calculation::additionalInformationType(Co
|
||||
}
|
||||
if (o.hasUnit()) {
|
||||
Expression unit;
|
||||
PoincareHelpers::Reduce(&o,
|
||||
App::app()->localContext(),
|
||||
ExpressionNode::ReductionTarget::User,
|
||||
ExpressionNode::SymbolicComputation::ReplaceAllSymbolsWithDefinitionsOrUndefined,
|
||||
ExpressionNode::UnitConversion::None);
|
||||
/* FIXME : When this method is accessed via leaving the additional outputs,
|
||||
* ie via a press on BACK, the reduction is interrupted, and removeUnit
|
||||
* goes badly.*/
|
||||
PoincareHelpers::Reduce(&o, App::app()->localContext(), ExpressionNode::ReductionTarget::User, ExpressionNode::SymbolicComputation::ReplaceAllSymbolsWithDefinitionsOrUndefined);
|
||||
o = o.removeUnit(&unit);
|
||||
// There might be no unit in the end, if the reduction was interrupted.
|
||||
if (!unit.isUninitialized()) {
|
||||
if (Unit::IsSI(unit)) {
|
||||
if (Unit::IsSISpeed(unit) || Unit::IsSIVolume(unit) || Unit::IsSIEnergy(unit)) {
|
||||
/* All these units will provide misc. classic representatives in
|
||||
* addition to the SI unit in additional information. */
|
||||
return AdditionalInformationType::Unit;
|
||||
}
|
||||
if (Unit::IsSITime(unit)) {
|
||||
/* If the number of seconds is above 60s, we can write it in the form
|
||||
* of an addition: 23_min + 12_s for instance. */
|
||||
double value = Shared::PoincareHelpers::ApproximateToScalar<double>(o, App::app()->localContext());
|
||||
if (value > Unit::SecondsPerMinute) {
|
||||
return AdditionalInformationType::Unit;
|
||||
}
|
||||
}
|
||||
return AdditionalInformationType::None;
|
||||
}
|
||||
return AdditionalInformationType::Unit;
|
||||
}
|
||||
double value = PoincareHelpers::ApproximateToScalar<double>(o, App::app()->localContext());
|
||||
return (Unit::ShouldDisplayAdditionalOutputs(value, unit)) ? AdditionalInformationType::Unit : AdditionalInformationType::None;
|
||||
}
|
||||
if (o.isBasedIntegerCappedBy(k_maximalIntegerWithAdditionalInformation)) {
|
||||
return AdditionalInformationType::Integer;
|
||||
|
||||
Reference in New Issue
Block a user