Skip to content
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

Fix: rename all the IS by SI... because even in english we say "SI" a… #1621

Merged
merged 4 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/calculation/additional_outputs/unit_list_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void UnitListController::setExpression(Poincare::Expression e) {
bool requireSimplification = false;
bool canChangeUnitPrefix = false;

if (Unit::IsISSpeed(units)) {
if (Unit::IsSISpeed(units)) {
// 1.a. Turn speed into km/h
m_memoizedExpressions[numberOfMemoizedExpressions++] = UnitConvert::Builder(
m_expression.clone(),
Expand All @@ -43,15 +43,15 @@ void UnitListController::setExpression(Poincare::Expression e) {
)
);
requireSimplification = true; // Simplify the conversion
} else if (Unit::IsISVolume(units)) {
} else if (Unit::IsSIVolume(units)) {
// 1.b. Turn volume into L
m_memoizedExpressions[numberOfMemoizedExpressions++] = UnitConvert::Builder(
m_expression.clone(),
Unit::Liter()
);
requireSimplification = true; // Simplify the conversion
canChangeUnitPrefix = true; // Pick best prefix (mL)
} else if (Unit::IsISEnergy(units)) {
} else if (Unit::IsSIEnergy(units)) {
// 1.c. Turn energy into Wh
m_memoizedExpressions[numberOfMemoizedExpressions++] = UnitConvert::Builder(
m_expression.clone(),
Expand All @@ -66,7 +66,7 @@ void UnitListController::setExpression(Poincare::Expression e) {
);
requireSimplification = true; // Simplify the conversion
canChangeUnitPrefix = true; // Pick best prefix (kWh)
} else if (Unit::IsISTime(units)) {
} else if (Unit::IsSITime(units)) {
// Turn time into ? year + ? month + ? day + ? h + ? min + ? s
double value = Shared::PoincareHelpers::ApproximateToScalar<double>(copy, App::app()->localContext());
m_memoizedExpressions[numberOfMemoizedExpressions++] = Unit::BuildTimeSplit(value, App::app()->localContext(), Preferences::sharedPreferences()->complexFormat(), Preferences::sharedPreferences()->angleUnit());
Expand Down
6 changes: 3 additions & 3 deletions apps/calculation/calculation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,13 @@ Calculation::AdditionalInformationType Calculation::additionalInformationType(Co
Expression unit;
PoincareHelpers::Reduce(&o, App::app()->localContext(), ExpressionNode::ReductionTarget::User,ExpressionNode::SymbolicComputation::ReplaceAllSymbolsWithDefinitionsOrUndefined, ExpressionNode::UnitConversion::None);
o = o.removeUnit(&unit);
if (Unit::IsIS(unit)) {
if (Unit::IsISSpeed(unit) || Unit::IsISVolume(unit) || Unit::IsISEnergy(unit)) {
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::IsISTime(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());
Expand Down
12 changes: 6 additions & 6 deletions poincare/include/poincare/unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -767,11 +767,11 @@ class Unit final : public Expression {
static Unit Watt() { return Builder(PowerDimension, WattRepresentative, &EmptyPrefix); }
static Expression BuildTimeSplit(double seconds, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);

static bool IsIS(Expression & e);
static bool IsISSpeed(Expression & e);
static bool IsISVolume(Expression & e);
static bool IsISEnergy(Expression & e);
static bool IsISTime(Expression & e);
static bool IsSI(Expression & e);
static bool IsSISpeed(Expression & e);
static bool IsSIVolume(Expression & e);
static bool IsSIEnergy(Expression & e);
static bool IsSITime(Expression & e);
bool isMeter() const;
bool isSecond() const;
bool isKilogram() const;
Expand All @@ -791,7 +791,7 @@ class Unit final : public Expression {
static constexpr double MonthPerYear = 12.0;
static constexpr double DaysPerMonth = DaysPerYear/MonthPerYear;
UnitNode * node() const { return static_cast<UnitNode *>(Expression::node()); }
bool isIS() const;
bool isSI() const;
static void ChooseBestMultipleForValue(Expression * units, double * value, bool tuneRepresentative, ExpressionNode::ReductionContext reductionContext);
void chooseBestMultipleForValue(double * value, const int exponent, bool tuneRepresentative, ExpressionNode::ReductionContext reductionContext);
Expression removeUnit(Expression * unit);
Expand Down
18 changes: 9 additions & 9 deletions poincare/src/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ bool Unit::isKilogram() const {
return node()->dimension() == MassDimension && node()->representative() == KilogramRepresentative && node()->prefix() == &KiloPrefix;
}

bool Unit::isIS() const {
bool Unit::isSI() const {
UnitNode * unitNode = node();
const Dimension * dim = unitNode->dimension();
const Representative * rep = unitNode->representative();
Expand All @@ -430,12 +430,12 @@ bool Unit::isIS() const {
unitNode->prefix() == dim->stdRepresentativePrefix();
}

bool Unit::IsIS(Expression & e) {
bool Unit::IsSI(Expression & e) {
if (e.type() == ExpressionNode::Type::Multiplication) {
for (int i = 0; i < e.numberOfChildren(); i++) {
Expression child = e.childAtIndex(i);
assert(child.type() == ExpressionNode::Type::Power || child.type() == ExpressionNode::Type::Unit);
if (!IsIS(child)) {
if (!IsSI(child)) {
return false;
}
}
Expand All @@ -445,13 +445,13 @@ bool Unit::IsIS(Expression & e) {
assert(e.childAtIndex(1).type() == ExpressionNode::Type::Rational && e.childAtIndex(1).convert<Rational>().isInteger());
Expression child = e.childAtIndex(0);
assert(child.type() == ExpressionNode::Type::Unit);
return IsIS(child);
return IsSI(child);
}
assert(e.type() == ExpressionNode::Type::Unit);
return static_cast<Unit &>(e).isIS();
return static_cast<Unit &>(e).isSI();
}

bool Unit::IsISSpeed(Expression & e) {
bool Unit::IsSISpeed(Expression & e) {
// Form m*s^-1
return e.type() == ExpressionNode::Type::Multiplication && e.numberOfChildren() == 2 &&
e.childAtIndex(0).type() == ExpressionNode::Type::Unit && e.childAtIndex(0).convert<Unit>().isMeter() &&
Expand All @@ -460,14 +460,14 @@ bool Unit::IsISSpeed(Expression & e) {
e.childAtIndex(1).childAtIndex(0).type() == ExpressionNode::Type::Unit && e.childAtIndex(1).childAtIndex(0).convert<Unit>().isSecond();
}

bool Unit::IsISVolume(Expression & e) {
bool Unit::IsSIVolume(Expression & e) {
// Form m^3
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>().isThree();
}

bool Unit::IsISEnergy(Expression & e) {
bool Unit::IsSIEnergy(Expression & e) {
// Form _kg*_m^2*_s^-2
return e.type() == ExpressionNode::Type::Multiplication && e.numberOfChildren() == 3 &&
e.childAtIndex(0).type() == ExpressionNode::Type::Unit && e.childAtIndex(0).convert<Unit>().isKilogram() &&
Expand All @@ -479,7 +479,7 @@ bool Unit::IsISEnergy(Expression & e) {
e.childAtIndex(2).childAtIndex(1).type() == ExpressionNode::Type::Rational && e.childAtIndex(2).childAtIndex(1).convert<const Rational>().isMinusTwo();
}

bool Unit::IsISTime(Expression & e) {
bool Unit::IsSITime(Expression & e) {
return e.type() == ExpressionNode::Type::Unit && static_cast<Unit &>(e).isSecond();
}

Expand Down
16 changes: 8 additions & 8 deletions poincare/test/expression_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,22 +420,22 @@ QUIZ_CASE(poincare_expression_unit_helper) {

// 2. Speed
Expression meterPerSecond = extract_unit("_m×_s^-1");
quiz_assert(Unit::IsISSpeed(meterPerSecond));
quiz_assert(Unit::IsSISpeed(meterPerSecond));

// 3. Volume
Expression meter3 = extract_unit("_m^3");
quiz_assert(Unit::IsISVolume(meter3));
quiz_assert(Unit::IsSIVolume(meter3));

// 4. Energy
Expression kilogramMeter2PerSecond2 = extract_unit("_kg×_m^2×_s^-2");
quiz_assert(Unit::IsISEnergy(kilogramMeter2PerSecond2));
quiz_assert(Unit::IsSIEnergy(kilogramMeter2PerSecond2));
Expression kilogramMeter3PerSecond2 = extract_unit("_kg×_m^3×_s^-2");
quiz_assert(!Unit::IsISEnergy(kilogramMeter3PerSecond2));
quiz_assert(!Unit::IsSIEnergy(kilogramMeter3PerSecond2));

// 5. International System
quiz_assert(Unit::IsIS(kilogramMeter2PerSecond2));
quiz_assert(Unit::IsIS(meter3));
quiz_assert(Unit::IsIS(meterPerSecond));
quiz_assert(Unit::IsSI(kilogramMeter2PerSecond2));
quiz_assert(Unit::IsSI(meter3));
quiz_assert(Unit::IsSI(meterPerSecond));
Expression joule = extract_unit("_J");
quiz_assert(!Unit::IsIS(joule));
quiz_assert(!Unit::IsSI(joule));
}