diff --git a/apps/calculation/calculation.cpp b/apps/calculation/calculation.cpp index ae3367ff0..160770b77 100644 --- a/apps/calculation/calculation.cpp +++ b/apps/calculation/calculation.cpp @@ -7,14 +7,13 @@ #include #include #include +#include using namespace Poincare; using namespace Shared; namespace Calculation { -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } - bool Calculation::operator==(const Calculation& c) { return strcmp(inputText(), c.inputText()) == 0 && strcmp(approximateOutputText(NumberOfSignificantDigits::Maximal), c.approximateOutputText(NumberOfSignificantDigits::Maximal)) == 0 @@ -158,7 +157,7 @@ KDCoordinate Calculation::height(Context * context, bool expanded, bool allExpre KDCoordinate exactOutputHeight = exactLayout.layoutSize().height(); if (allExpressionsInline) { KDCoordinate exactOutputBaseline = exactLayout.baseline(); - result = maxCoordinate(inputBaseline, exactOutputBaseline) + maxCoordinate(inputHeight - inputBaseline, exactOutputHeight-exactOutputBaseline); + result = std::max(inputBaseline, exactOutputBaseline) + std::max(inputHeight - inputBaseline, exactOutputHeight-exactOutputBaseline); } else { result = inputHeight+exactOutputHeight; } @@ -185,7 +184,7 @@ KDCoordinate Calculation::height(Context * context, bool expanded, bool allExpre if (displayOutput(context) == DisplayOutput::ApproximateOnly || (!expanded && displayOutput(context) == DisplayOutput::ExactAndApproximateToggle)) { if (allExpressionsInline) { KDCoordinate approximateOutputBaseline = approximateLayout.baseline(); - result = maxCoordinate(inputBaseline, approximateOutputBaseline) + maxCoordinate(inputHeight - inputBaseline, approximateOutputHeight-approximateOutputBaseline); + result = std::max(inputBaseline, approximateOutputBaseline) + std::max(inputHeight - inputBaseline, approximateOutputHeight-approximateOutputBaseline); } else { result = inputHeight+approximateOutputHeight; } @@ -195,9 +194,9 @@ KDCoordinate Calculation::height(Context * context, bool expanded, bool allExpre KDCoordinate exactOutputBaseline = exactLayout.baseline(); KDCoordinate approximateOutputBaseline = approximateLayout.baseline(); if (allExpressionsInline) { - result = maxCoordinate(inputBaseline, maxCoordinate(exactOutputBaseline, approximateOutputBaseline)) + maxCoordinate(inputHeight - inputBaseline, maxCoordinate(exactOutputHeight - exactOutputBaseline, approximateOutputHeight-approximateOutputBaseline)); + result = std::max(inputBaseline, std::max(exactOutputBaseline, approximateOutputBaseline)) + std::max(inputHeight - inputBaseline, std::max(exactOutputHeight - exactOutputBaseline, approximateOutputHeight-approximateOutputBaseline)); } else { - KDCoordinate outputHeight = maxCoordinate(exactOutputBaseline, approximateOutputBaseline) + maxCoordinate(exactOutputHeight-exactOutputBaseline, approximateOutputHeight-approximateOutputBaseline); + KDCoordinate outputHeight = std::max(exactOutputBaseline, approximateOutputBaseline) + std::max(exactOutputHeight-exactOutputBaseline, approximateOutputHeight-approximateOutputBaseline); result = inputHeight + outputHeight; } } diff --git a/apps/calculation/history_view_cell.cpp b/apps/calculation/history_view_cell.cpp index 9210a2984..0c35fb688 100644 --- a/apps/calculation/history_view_cell.cpp +++ b/apps/calculation/history_view_cell.cpp @@ -5,12 +5,10 @@ #include #include #include +#include namespace Calculation { -static inline KDCoordinate minCoordinate(KDCoordinate x, KDCoordinate y) { return x < y ? x : y; } -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } - /* HistoryViewCellDataSource */ HistoryViewCellDataSource::HistoryViewCellDataSource() : @@ -182,14 +180,14 @@ void HistoryViewCell::layoutSubviews(bool force) { KDSize inputSize = m_inputView.minimalSizeForOptimalDisplay(); m_inputView.setFrame(KDRect( 0, 0, - minCoordinate(maxFrameWidth, inputSize.width()), + std::min(maxFrameWidth, inputSize.width()), inputSize.height()), force); KDSize outputSize = m_scrollableOutputView.minimalSizeForOptimalDisplay(); m_scrollableOutputView.setFrame(KDRect( - maxCoordinate(0, maxFrameWidth - outputSize.width()), + std::max(0, maxFrameWidth - outputSize.width()), inputSize.height(), - minCoordinate(maxFrameWidth, outputSize.width()), + std::min(maxFrameWidth, outputSize.width()), outputSize.height()), force); } diff --git a/apps/code/console_controller.cpp b/apps/code/console_controller.cpp index 477dda7c3..cb0f06f23 100644 --- a/apps/code/console_controller.cpp +++ b/apps/code/console_controller.cpp @@ -3,6 +3,7 @@ #include "script.h" #include "variable_box_controller.h" #include +#include #include #include #include @@ -15,8 +16,6 @@ extern "C" { namespace Code { -static inline int minInt(int x, int y) { return x < y ? x : y; } - static const char * sStandardPromptText = ">>> "; ConsoleController::ConsoleController(Responder * parentResponder, App * pythonDelegate, ScriptStore * scriptStore @@ -487,7 +486,7 @@ void ConsoleController::autoImportScript(Script script, bool force) { /* Copy the script name without the extension ".py". The '.' is overwritten * by the null terminating char. */ - int copySizeWithNullTerminatingZero = minInt(k_maxImportCommandSize - currentChar, strlen(scriptName) - strlen(ScriptStore::k_scriptExtension)); + int copySizeWithNullTerminatingZero = std::min(k_maxImportCommandSize - currentChar, strlen(scriptName) - strlen(ScriptStore::k_scriptExtension)); assert(copySizeWithNullTerminatingZero >= 0); assert(copySizeWithNullTerminatingZero <= k_maxImportCommandSize - currentChar); strlcpy(command+currentChar, scriptName, copySizeWithNullTerminatingZero); diff --git a/apps/code/console_edit_cell.cpp b/apps/code/console_edit_cell.cpp index f938f52dc..f82d5d596 100644 --- a/apps/code/console_edit_cell.cpp +++ b/apps/code/console_edit_cell.cpp @@ -4,11 +4,10 @@ #include #include #include +#include namespace Code { -static inline int minInt(int x, int y) { return x < y ? x : y; } - ConsoleEditCell::ConsoleEditCell(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, TextFieldDelegate * delegate) : HighlightCell(), Responder(parentResponder), @@ -70,7 +69,7 @@ const char * ConsoleEditCell::shiftCurrentTextAndClear() { char * textFieldBuffer = const_cast(m_textField.text()); char * newTextPosition = textFieldBuffer + 1; assert(previousBufferSize > 0); - size_t copyLength = minInt(previousBufferSize - 1, strlen(textFieldBuffer)); + size_t copyLength = std::min(previousBufferSize - 1, strlen(textFieldBuffer)); memmove(newTextPosition, textFieldBuffer, copyLength); newTextPosition[copyLength] = 0; textFieldBuffer[0] = 0; diff --git a/apps/code/console_store.cpp b/apps/code/console_store.cpp index 390ba860e..528d90bcb 100644 --- a/apps/code/console_store.cpp +++ b/apps/code/console_store.cpp @@ -1,10 +1,9 @@ #include "console_store.h" #include +#include namespace Code { -static inline int minInt(int x, int y) { return x < y ? x : y; } - void ConsoleStore::startNewSession() { if (k_historySize < 1) { return; @@ -103,7 +102,7 @@ const char * ConsoleStore::push(const char marker, const char * text) { i = indexOfNullMarker(); } m_history[i] = marker; - strlcpy(&m_history[i+1], text, minInt(k_historySize-(i+1),textLength+1)); + strlcpy(&m_history[i+1], text, std::min(k_historySize-(i+1),textLength+1)); m_history[i+1+textLength+1] = 0; return &m_history[i+1]; } diff --git a/apps/code/python_text_area.cpp b/apps/code/python_text_area.cpp index 7236dbc3a..b1a243af1 100644 --- a/apps/code/python_text_area.cpp +++ b/apps/code/python_text_area.cpp @@ -9,6 +9,7 @@ extern "C" { #include "py/lexer.h" } #include +#include namespace Code { @@ -21,8 +22,6 @@ constexpr KDColor StringColor = KDColor::RGB24(0x032f62); constexpr KDColor BackgroundColor = KDColorWhite; constexpr KDColor HighlightColor = Palette::Select; -static inline const char * minPointer(const char * x, const char * y) { return x < y ? x : y; } - static inline KDColor TokenColor(mp_token_kind_t tokenKind) { if (tokenKind == MP_TOKEN_STRING) { return StringColor; @@ -84,7 +83,7 @@ void PythonTextArea::ContentView::drawLine(KDContext * ctx, int line, const char line, fromColumn, lineStart, - minPointer(text + byteLength, lineEnd) - lineStart, + std::min(text + byteLength, lineEnd) - lineStart, StringColor, BackgroundColor, selectionStart, @@ -107,7 +106,7 @@ void PythonTextArea::ContentView::drawLine(KDContext * ctx, int line, const char line, fromColumn, spacesStart, - minPointer(text + byteLength, firstNonSpace) - spacesStart, + std::min(text + byteLength, firstNonSpace) - spacesStart, StringColor, BackgroundColor, selectionStart, @@ -135,7 +134,7 @@ void PythonTextArea::ContentView::drawLine(KDContext * ctx, int line, const char line, UTF8Helper::GlyphOffsetAtCodePoint(text, tokenEnd), tokenEnd, - minPointer(text + byteLength, tokenFrom) - tokenEnd, + std::min(text + byteLength, tokenFrom) - tokenEnd, StringColor, BackgroundColor, selectionStart, diff --git a/apps/graph/graph/graph_controller.cpp b/apps/graph/graph/graph_controller.cpp index 74cc400dc..5bd7a3004 100644 --- a/apps/graph/graph/graph_controller.cpp +++ b/apps/graph/graph/graph_controller.cpp @@ -1,16 +1,12 @@ #include "graph_controller.h" #include "../app.h" +#include using namespace Poincare; using namespace Shared; namespace Graph { -static inline float minFloat(float x, float y) { return x < y ? x : y; } -static inline float maxFloat(float x, float y) { return x > y ? x : y; } -static inline double minDouble(double x, double y) { return x < y ? x : y; } -static inline double maxDouble(double x, double y) { return x > y ? x : y; } - GraphController::GraphController(Responder * parentResponder, ::InputEventHandlerDelegate * inputEventHandlerDelegate, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * previousModelsVersions, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header) : FunctionGraphController(parentResponder, inputEventHandlerDelegate, header, curveViewRange, &m_view, cursor, indexFunctionSelectedByCursor, modelVersion, previousModelsVersions, rangeVersion, angleUnitVersion), m_bannerView(this, inputEventHandlerDelegate, this), @@ -52,10 +48,10 @@ void GraphController::interestingFunctionRange(ExpiringPointertMin())); assert(!std::isnan(f->tMax())); - const double tMin = maxFloat(f->tMin(), resultxMin); - const double tMax = minFloat(f->tMax(), resultxMax); + const double tMin = std::max(f->tMin(), resultxMin); + const double tMax = std::min(f->tMax(), resultxMax); const double step = (tMax - tMin) / (2.0 * (m_view.bounds().width() - 1.0)); interestingFunctionRange(f, tMin, tMax, step, &resultxMin, &resultxMax, &resultyMin, &resultyMax); } @@ -129,12 +125,12 @@ float GraphController::interestingXHalfRange() const { ExpiringPointer f = store->modelForRecord(store->activeRecordAtIndex(i)); float fRange = f->expressionReduced(context).characteristicXRange(context, Poincare::Preferences::sharedPreferences()->angleUnit()); if (!std::isnan(fRange) && !std::isinf(fRange)) { - characteristicRange = maxFloat(fRange, characteristicRange); + characteristicRange = std::max(fRange, characteristicRange); } // Compute the combined range of the functions assert(f->plotType() == ContinuousFunction::PlotType::Cartesian); // So that tMin tMax represents xMin xMax - tMin = minDouble(tMin, f->tMin()); - tMax = maxDouble(tMax, f->tMax()); + tMin = std::min(tMin, f->tMin()); + tMax = std::max(tMax, f->tMax()); } constexpr float rangeMultiplicator = 1.6f; if (characteristicRange > 0.0f ) { @@ -145,7 +141,7 @@ float GraphController::interestingXHalfRange() const { if (tMin >= -defaultXHalfRange && tMax <= defaultXHalfRange) { /* If the combined Range of the functions is smaller than the default range, * use it. */ - float f = rangeMultiplicator * (float)maxDouble(std::fabs(tMin), std::fabs(tMax)); + float f = rangeMultiplicator * (float)std::max(std::fabs(tMin), std::fabs(tMax)); return (std::isnan(f) || std::isinf(f)) ? defaultXHalfRange : f; } return defaultXHalfRange; @@ -226,7 +222,7 @@ void GraphController::jumpToLeftRightCurve(double t, int direction, int function if (currentXDelta <= xDelta) { double potentialNextTMin = f->tMin(); double potentialNextTMax = f->tMax(); - double potentialNextT = maxDouble(potentialNextTMin, minDouble(potentialNextTMax, t)); + double potentialNextT = std::max(potentialNextTMin, std::min(potentialNextTMax, t)); Coordinate2D xy = f->evaluateXYAtParameter(potentialNextT, App::app()->localContext()); if (currentXDelta < xDelta || std::abs(xy.x2() - m_cursor->y()) < std::abs(nextY - m_cursor->y())) { nextCurveIndex = i; diff --git a/apps/graph/graph/graph_controller_helper.cpp b/apps/graph/graph/graph_controller_helper.cpp index 0c21be79c..ad42ac727 100644 --- a/apps/graph/graph/graph_controller_helper.cpp +++ b/apps/graph/graph/graph_controller_helper.cpp @@ -3,15 +3,13 @@ #include "../app.h" #include "../../shared/poincare_helpers.h" #include +#include using namespace Shared; using namespace Poincare; namespace Graph { -static inline double minDouble(double x, double y) { return x < y ? x : y; } -static inline double maxDouble(double x, double y) { return x > y ? x : y; } - bool GraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCursor * cursor, int direction, Shared::InteractiveCurveViewRange * range, int numberOfStepsInGradUnit, Ion::Storage::Record record, bool fast) { ExpiringPointer function = App::app()->functionStore()->modelForRecord(record); double tCursorPosition = cursor->t(); @@ -34,7 +32,7 @@ bool GraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCurso step *= 5.0; } t += dir * step; - t = maxDouble(tMin, minDouble(tMax, t)); + t = std::max(tMin, std::min(tMax, t)); Coordinate2D xy = function->evaluateXYAtParameter(t, App::app()->localContext()); cursor->moveTo(t, xy.x1(), xy.x2()); return true; diff --git a/apps/graph/list/text_field_function_title_cell.cpp b/apps/graph/list/text_field_function_title_cell.cpp index a1d138e24..55c7f6676 100644 --- a/apps/graph/list/text_field_function_title_cell.cpp +++ b/apps/graph/list/text_field_function_title_cell.cpp @@ -1,12 +1,10 @@ #include "text_field_function_title_cell.h" #include "list_controller.h" #include +#include namespace Graph { -static inline float minFloat(float x, float y) { return x < y ? x : y; } -static inline float maxFloat(float x, float y) { return x > y ? x : y; } - TextFieldFunctionTitleCell::TextFieldFunctionTitleCell(ListController * listController, Orientation orientation, const KDFont * font) : Shared::FunctionTitleCell(orientation), Responder(listController), @@ -56,9 +54,9 @@ void TextFieldFunctionTitleCell::layoutSubviews(bool force) { KDRect frame = subviewFrame(); m_textField.setFrame(frame, force); KDCoordinate maxTextFieldX = frame.width() - m_textField.minimalSizeForOptimalDisplay().width(); - float horizontalAlignment = maxFloat( + float horizontalAlignment = std::max( 0.0f, - minFloat( + std::min( 1.0f, ((float)(maxTextFieldX - k_textFieldRightMargin))/((float)maxTextFieldX))); m_textField.setAlignment(horizontalAlignment, verticalAlignment()); diff --git a/apps/probability/calculation_cell.cpp b/apps/probability/calculation_cell.cpp index d073fd537..e8d35cf21 100644 --- a/apps/probability/calculation_cell.cpp +++ b/apps/probability/calculation_cell.cpp @@ -2,12 +2,10 @@ #include "responder_image_cell.h" #include #include +#include namespace Probability { -static inline KDCoordinate minCoordinate(KDCoordinate x, KDCoordinate y) { return x < y ? x : y; } -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } - CalculationCell::CalculationCell(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, TextFieldDelegate * textFieldDelegate) : m_text(KDFont::LargeFont, I18n::Message::Default, 0.5f, 0.5f), m_calculation(parentResponder, inputEventHandlerDelegate, textFieldDelegate), @@ -78,7 +76,7 @@ KDCoordinate CalculationCell::calculationCellWidth() const { KDCoordinate glyphWidth = KDFont::LargeFont->glyphSize().width(); KDCoordinate minTextFieldWidth = 4 * glyphWidth + TextCursorView::k_width; KDCoordinate maxTextFieldWidth = 14 * glyphWidth + TextCursorView::k_width; - return minCoordinate(maxTextFieldWidth, maxCoordinate(minTextFieldWidth, calculationCellWidth)); + return std::min(maxTextFieldWidth, std::max(minTextFieldWidth, calculationCellWidth)); } } diff --git a/apps/probability/calculation_controller.cpp b/apps/probability/calculation_controller.cpp index a19c66ba8..0f8d901b9 100644 --- a/apps/probability/calculation_controller.cpp +++ b/apps/probability/calculation_controller.cpp @@ -15,6 +15,7 @@ #include "images/focused_calcul4_icon.h" #include #include +#include #include using namespace Poincare; @@ -22,8 +23,6 @@ using namespace Shared; namespace Probability { -static inline int minInt(int x, int y) { return x < y ? x : y; } - CalculationController::ContentView::ContentView(SelectableTableView * selectableTableView, Distribution * distribution, Calculation * calculation) : m_titleView(KDFont::SmallFont, I18n::Message::ComputeProbability, 0.5f, 0.5f, Palette::GreyDark, Palette::WallScreen), m_selectableTableView(selectableTableView), @@ -293,7 +292,7 @@ void CalculationController::updateTitle() { } currentChar += UTF8Decoder::CodePointToChars(' ', m_titleBuffer + currentChar, k_titleBufferSize - currentChar); } - m_titleBuffer[minInt(currentChar, k_titleBufferSize) - 1] = 0; + m_titleBuffer[std::min(currentChar, k_titleBufferSize) - 1] = 0; } } diff --git a/apps/probability/distribution/chi_squared_distribution.cpp b/apps/probability/distribution/chi_squared_distribution.cpp index 450d7804a..4f0998fce 100644 --- a/apps/probability/distribution/chi_squared_distribution.cpp +++ b/apps/probability/distribution/chi_squared_distribution.cpp @@ -1,11 +1,10 @@ #include "chi_squared_distribution.h" #include "regularized_gamma.h" #include +#include namespace Probability { -static inline double maxDouble(double x, double y) { return x > y ? x : y; } - float ChiSquaredDistribution::xMin() const { return -k_displayLeftMarginRatio * xMax(); } @@ -79,7 +78,7 @@ double ChiSquaredDistribution::cumulativeDistributiveInverseForProbability(doubl 2.0 * *probability * std::exp(std::lgamma(ceilKOver2)) / (exp(-kOver2Minus1) * std::pow(kOver2Minus1, kOver2Minus1)) : 30.0; // Ad hoc value xmax = std::isnan(xmax) ? 1000000000.0 : xmax; - return cumulativeDistributiveInverseForProbabilityUsingIncreasingFunctionRoot(probability, FLT_EPSILON, maxDouble(xMax(), xmax)); + return cumulativeDistributiveInverseForProbabilityUsingIncreasingFunctionRoot(probability, FLT_EPSILON, std::max(xMax(), xmax)); } } diff --git a/apps/probability/distribution/fisher_distribution.cpp b/apps/probability/distribution/fisher_distribution.cpp index 97e145599..5e76c3fca 100644 --- a/apps/probability/distribution/fisher_distribution.cpp +++ b/apps/probability/distribution/fisher_distribution.cpp @@ -3,11 +3,10 @@ #include #include #include +#include namespace Probability { -static inline double maxDouble(double x, double y) { return x > y ? x : y; } - float FisherDistribution::xMin() const { return -k_displayLeftMarginRatio * xMax(); } @@ -74,7 +73,7 @@ double FisherDistribution::cumulativeDistributiveInverseForProbability(double * if (*probability < DBL_EPSILON) { return 0.0; } - return cumulativeDistributiveInverseForProbabilityUsingIncreasingFunctionRoot(probability, DBL_EPSILON, maxDouble(xMax(), 100.0)); // Ad-hoc value; + return cumulativeDistributiveInverseForProbabilityUsingIncreasingFunctionRoot(probability, DBL_EPSILON, std::max(xMax(), 100.0)); // Ad-hoc value; } float FisherDistribution::mode() const { diff --git a/apps/regression/calculation_controller.cpp b/apps/regression/calculation_controller.cpp index 548241564..f31c836bf 100644 --- a/apps/regression/calculation_controller.cpp +++ b/apps/regression/calculation_controller.cpp @@ -4,7 +4,7 @@ #include #include #include - +#include #include using namespace Poincare; @@ -12,8 +12,6 @@ using namespace Shared; namespace Regression { -static inline int maxInt(int x, int y) { return x > y ? x : y; } - CalculationController::CalculationController(Responder * parentResponder, ButtonRowController * header, Store * store) : TabTableController(parentResponder), ButtonRowDelegate(header, nullptr), @@ -375,7 +373,7 @@ int CalculationController::maxNumberOfCoefficients() const { int numberOfDefinedSeries = m_store->numberOfNonEmptySeries(); for (int i = 0; i < numberOfDefinedSeries; i++) { int currentNumberOfCoefs = m_store->modelForSeries(m_store->indexOfKthNonEmptySeries(i))->numberOfCoefficients(); - maxNumberCoefficients = maxInt(maxNumberCoefficients, currentNumberOfCoefs); + maxNumberCoefficients = std::max(maxNumberCoefficients, currentNumberOfCoefs); } return maxNumberCoefficients; } diff --git a/apps/regression/graph_controller.cpp b/apps/regression/graph_controller.cpp index ebdebbb46..d8c00d067 100644 --- a/apps/regression/graph_controller.cpp +++ b/apps/regression/graph_controller.cpp @@ -4,14 +4,11 @@ #include "../apps_container.h" #include #include +#include using namespace Poincare; using namespace Shared; -static inline float minFloat(float x, float y) { return x < y ? x : y; } -static inline float maxFloat(float x, float y) { return x > y ? x : y; } -static inline int maxInt(int x, int y) { return x > y ? x : y; } - namespace Regression { GraphController::GraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, ButtonRowController * header, Store * store, CurveViewCursor * cursor, uint32_t * modelVersion, uint32_t * previousModelsVersions, uint32_t * rangeVersion, int * selectedDotIndex, int * selectedSeriesIndex) : @@ -165,7 +162,7 @@ void GraphController::reloadBannerView() { } if (!coefficientsAreDefined) { // Force the "Data not suitable" message to be on the next line - int numberOfCharToCompleteLine = maxInt(Ion::Display::Width / BannerView::Font()->glyphSize().width() - strlen(I18n::translate(formula)), 0); + int numberOfCharToCompleteLine = std::max(Ion::Display::Width / BannerView::Font()->glyphSize().width() - strlen(I18n::translate(formula)), 0); numberOfChar = 0; // Padding Shared::TextHelpers::PadWithSpaces(buffer, bufferSize, &numberOfChar, numberOfCharToCompleteLine - 1); @@ -390,8 +387,8 @@ InteractiveCurveViewRangeDelegate::Range GraphController::computeYRange(Interact for (int series = 0; series < Store::k_numberOfSeries; series++) { for (int k = 0; k < m_store->numberOfPairsOfSeries(series); k++) { if (m_store->xMin() <= m_store->get(series, 0, k) && m_store->get(series, 0, k) <= m_store->xMax()) { - minY = minFloat(minY, m_store->get(series, 1, k)); - maxY = maxFloat(maxY, m_store->get(series, 1, k)); + minY = std::min(minY, m_store->get(series, 1, k)); + maxY = std::max(maxY, m_store->get(series, 1, k)); } } } diff --git a/apps/regression/store.cpp b/apps/regression/store.cpp index 98f703bd5..69e7b6729 100644 --- a/apps/regression/store.cpp +++ b/apps/regression/store.cpp @@ -5,14 +5,12 @@ #include #include #include +#include using namespace Shared; namespace Regression { -static inline float maxFloat(float x, float y) { return x > y ? x : y; } -static inline float minFloat(float x, float y) { return x < y ? x : y; } - static_assert(Model::k_numberOfModels == 9, "Number of models changed, Regression::Store() needs to adapt"); static_assert(Store::k_numberOfSeries == 3, "Number of series changed, Regression::Store() needs to adapt (m_seriesChecksum)"); @@ -146,8 +144,8 @@ void Store::setDefault() { float maxX = -FLT_MAX; for (int series = 0; series < k_numberOfSeries; series++) { if (!seriesIsEmpty(series)) { - minX = minFloat(minX, minValueOfColumn(series, 0)); - maxX = maxFloat(maxX, maxValueOfColumn(series, 0)); + minX = std::min(minX, minValueOfColumn(series, 0)); + maxX = std::max(maxX, maxValueOfColumn(series, 0)); } } float range = maxX - minX; @@ -199,7 +197,7 @@ void Store::resetMemoization() { float Store::maxValueOfColumn(int series, int i) const { float maxColumn = -FLT_MAX; for (int k = 0; k < numberOfPairsOfSeries(series); k++) { - maxColumn = maxFloat(maxColumn, m_data[series][i][k]); + maxColumn = std::max(maxColumn, m_data[series][i][k]); } return maxColumn; } @@ -207,7 +205,7 @@ float Store::maxValueOfColumn(int series, int i) const { float Store::minValueOfColumn(int series, int i) const { float minColumn = FLT_MAX; for (int k = 0; k < numberOfPairsOfSeries(series); k++) { - minColumn = minFloat(minColumn, m_data[series][i][k]); + minColumn = std::min(minColumn, m_data[series][i][k]); } return minColumn; } diff --git a/apps/sequence/graph/curve_view_range.cpp b/apps/sequence/graph/curve_view_range.cpp index 85c828d86..a4374164d 100644 --- a/apps/sequence/graph/curve_view_range.cpp +++ b/apps/sequence/graph/curve_view_range.cpp @@ -2,14 +2,13 @@ #include #include #include +#include using namespace Shared; using namespace Poincare; namespace Sequence { -static inline float maxFloat(float x, float y) { return x > y ? x : y; } - CurveViewRange::CurveViewRange(InteractiveCurveViewRangeDelegate * delegate) : InteractiveCurveViewRange(delegate) { @@ -37,7 +36,7 @@ void CurveViewRange::normalize() { float xMean = xCenter(); float yMean = yCenter(); - const float unit = maxFloat(xGridUnit(), yGridUnit()); + const float unit = std::max(xGridUnit(), yGridUnit()); // Compute the X const float newXHalfRange = NormalizedXHalfRange(unit); diff --git a/apps/sequence/graph/graph_controller.cpp b/apps/sequence/graph/graph_controller.cpp index 8e14c64c8..cd4c36fdc 100644 --- a/apps/sequence/graph/graph_controller.cpp +++ b/apps/sequence/graph/graph_controller.cpp @@ -2,15 +2,13 @@ #include #include #include "../app.h" +#include using namespace Shared; using namespace Poincare; namespace Sequence { -static inline int minInt(int x, int y) { return (x < y ? x : y); } -static inline int maxInt(int x, int y) { return (x > y ? x : y); } - GraphController::GraphController(Responder * parentResponder, ::InputEventHandlerDelegate * inputEventHandlerDelegate, SequenceStore * sequenceStore, CurveViewRange * graphRange, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * previousModelsVersions, uint32_t * rangeVersion, Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header) : FunctionGraphController(parentResponder, inputEventHandlerDelegate, header, graphRange, &m_view, cursor, indexFunctionSelectedByCursor, modelVersion, previousModelsVersions, rangeVersion, angleUnitVersion), m_bannerView(this, inputEventHandlerDelegate, this), @@ -39,7 +37,7 @@ float GraphController::interestingXMin() const { int nbOfActiveModels = functionStore()->numberOfActiveFunctions(); for (int i = 0; i < nbOfActiveModels; i++) { Sequence * s = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(i)); - nmin = minInt(nmin, s->initialRank()); + nmin = std::min(nmin, s->initialRank()); } assert(nmin < INT_MAX); return nmin; @@ -53,8 +51,8 @@ float GraphController::interestingXHalfRange() const { for (int i = 0; i < nbOfActiveModels; i++) { Sequence * s = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(i)); int firstInterestingIndex = s->initialRank(); - nmin = minInt(nmin, firstInterestingIndex); - nmax = maxInt(nmax, firstInterestingIndex + standardRange); + nmin = std::min(nmin, firstInterestingIndex); + nmax = std::max(nmax, firstInterestingIndex + standardRange); } assert(nmax - nmin >= standardRange); return nmax - nmin; diff --git a/apps/sequence/list/list_controller.cpp b/apps/sequence/list/list_controller.cpp index 96ad9b5b1..0144c8cd7 100644 --- a/apps/sequence/list/list_controller.cpp +++ b/apps/sequence/list/list_controller.cpp @@ -1,12 +1,11 @@ #include "list_controller.h" #include "../app.h" #include +#include using namespace Shared; using namespace Poincare; -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } - namespace Sequence { ListController::ListController(Responder * parentResponder, ::InputEventHandlerDelegate * inputEventHandlerDelegate, ButtonRowController * header, ButtonRowController * footer) : @@ -55,7 +54,7 @@ KDCoordinate ListController::expressionRowHeight(int j) { return defaultHeight; } KDCoordinate sequenceHeight = layout.layoutSize().height(); - return maxCoordinate(defaultHeight, sequenceHeight + 2*k_expressionCellVerticalMargin); + return std::max(defaultHeight, sequenceHeight + 2*k_expressionCellVerticalMargin); } void ListController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { diff --git a/apps/settings/sub_menu/preferences_controller.cpp b/apps/settings/sub_menu/preferences_controller.cpp index 83e9720de..cb9a22116 100644 --- a/apps/settings/sub_menu/preferences_controller.cpp +++ b/apps/settings/sub_menu/preferences_controller.cpp @@ -7,13 +7,12 @@ #include #include #include +#include using namespace Poincare; namespace Settings { -static inline int maxInt(int x, int y) { return x > y ? x : y; } - PreferencesController::PreferencesController(Responder * parentResponder) : GenericSubController(parentResponder) { @@ -145,7 +144,7 @@ void PreferencesController::setPreferenceWithValueIndex(I18n::Message message, i /* In Engineering mode, the number of significant digits cannot be lower * than 3, because we need to be able to display 100 for instance. */ // TODO: Add warning about signifiant digits change ? - preferences->setNumberOfSignificantDigits(maxInt(preferences->numberOfSignificantDigits(), 3)); + preferences->setNumberOfSignificantDigits(std::max(preferences->numberOfSignificantDigits(), 3)); } } else if (message == I18n::Message::EditionMode) { preferences->setEditionMode((Preferences::EditionMode)valueIndex); diff --git a/apps/settings/sub_menu/selectable_view_with_messages.cpp b/apps/settings/sub_menu/selectable_view_with_messages.cpp index a42248873..e1cb5933c 100644 --- a/apps/settings/sub_menu/selectable_view_with_messages.cpp +++ b/apps/settings/sub_menu/selectable_view_with_messages.cpp @@ -1,13 +1,12 @@ #include "selectable_view_with_messages.h" #include #include +#include using namespace Shared; namespace Settings { -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } - SelectableViewWithMessages::SelectableViewWithMessages(SelectableTableView * selectableTableView) : m_selectableTableView(selectableTableView), m_numberOfMessages(0) @@ -52,7 +51,7 @@ void SelectableViewWithMessages::layoutSubviews(bool force) { // Layout the text KDCoordinate textHeight = KDFont::SmallFont->glyphSize().height(); - KDCoordinate defOrigin = maxCoordinate(bounds().height() - Metric::CommonBottomMargin - m_numberOfMessages*textHeight, tableHeight); + KDCoordinate defOrigin = std::max(bounds().height() - Metric::CommonBottomMargin - m_numberOfMessages*textHeight, tableHeight); for (int i = 0; i < m_numberOfMessages; i++) { m_messageLines[i].setFrame(KDRect(0, defOrigin, bounds().width(), textHeight), force); diff --git a/apps/shared/continuous_function.cpp b/apps/shared/continuous_function.cpp index fdb4fd2cc..5f103363f 100644 --- a/apps/shared/continuous_function.cpp +++ b/apps/shared/continuous_function.cpp @@ -14,14 +14,12 @@ #include #include #include +#include using namespace Poincare; namespace Shared { -static inline double maxDouble(double x, double y) { return x > y ? x : y; } -static inline double minDouble(double x, double y) { return x < y ? x : y; } - void ContinuousFunction::DefaultName(char buffer[], size_t bufferSize) { constexpr int k_maxNumberOfDefaultLetterNames = 4; static constexpr const char k_defaultLetterNames[k_maxNumberOfDefaultLetterNames] = { @@ -312,14 +310,14 @@ Coordinate2D ContinuousFunction::nextIntersectionFrom(double start, doub constexpr int bufferSize = CodePoint::MaxCodePointCharLength + 1; char unknownX[bufferSize]; SerializationHelper::CodePoint(unknownX, bufferSize, UCodePointUnknown); - double domainMin = maxDouble(tMin(), eDomainMin); - double domainMax = minDouble(tMax(), eDomainMax); + double domainMin = std::max(tMin(), eDomainMin); + double domainMax = std::min(tMax(), eDomainMax); if (step > 0.0f) { - start = maxDouble(start, domainMin); - max = minDouble(max, domainMax); + start = std::max(start, domainMin); + max = std::min(max, domainMax); } else { - start = minDouble(start, domainMax); - max = maxDouble(max, domainMin); + start = std::min(start, domainMax); + max = std::max(max, domainMin); } return PoincareHelpers::NextIntersection(expressionReduced(context), unknownX, start, step, max, context, e); } @@ -330,19 +328,19 @@ Coordinate2D ContinuousFunction::nextPointOfInterestFrom(double start, d char unknownX[bufferSize]; SerializationHelper::CodePoint(unknownX, bufferSize, UCodePointUnknown); if (step > 0.0f) { - start = maxDouble(start, tMin()); - max = minDouble(max, tMax()); + start = std::max(start, tMin()); + max = std::min(max, tMax()); } else { - start = minDouble(start, tMax()); - max = maxDouble(max, tMin()); + start = std::min(start, tMax()); + max = std::max(max, tMin()); } return compute(expressionReduced(context), unknownX, start, step, max, context); } Poincare::Expression ContinuousFunction::sumBetweenBounds(double start, double end, Poincare::Context * context) const { assert(plotType() == PlotType::Cartesian); - start = maxDouble(start, tMin()); - end = minDouble(end, tMax()); + start = std::max(start, tMin()); + end = std::min(end, tMax()); return Poincare::Integral::Builder(expressionReduced(context).clone(), Poincare::Symbol::Builder(UCodePointUnknown), Poincare::Float::Builder(start), Poincare::Float::Builder(end)); // Integral takes ownership of args /* TODO: when we approximate integral, we might want to simplify the integral * here. However, we might want to do it once for all x (to avoid lagging in diff --git a/apps/shared/curve_view.cpp b/apps/shared/curve_view.cpp index d0142cce0..f2e6166c1 100644 --- a/apps/shared/curve_view.cpp +++ b/apps/shared/curve_view.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -11,11 +12,6 @@ using namespace Poincare; namespace Shared { -static inline int minInt(int x, int y) { return x < y ? x : y; } - -static inline float minFloat(float x, float y) { return x < y ? x : y; } -static inline float maxFloat(float x, float y) { return x > y ? x : y; } - CurveView::CurveView(CurveViewRange * curveViewRange, CurveViewCursor * curveViewCursor, BannerView * bannerView, CursorView * cursorView, View * okView, bool displayBanner) : View(), @@ -182,8 +178,8 @@ void CurveView::computeLabels(Axis axis) { * them from overprinting one another.*/ int labelMaxGlyphLength = labelMaxGlyphLengthSize(); if (axis == Axis::Horizontal) { - float pixelsPerLabel = maxFloat(0.0f, ((float)Ion::Display::Width)/((float)axisLabelsCount) - k_labelMargin); - labelMaxGlyphLength = minInt(labelMaxGlyphLengthSize(), pixelsPerLabel/k_font->glyphSize().width()); + float pixelsPerLabel = std::max(0.0f, ((float)Ion::Display::Width)/((float)axisLabelsCount) - k_labelMargin); + labelMaxGlyphLength = std::min(labelMaxGlyphLengthSize(), pixelsPerLabel/k_font->glyphSize().width()); } if (labelValue < step && labelValue > -step) { @@ -590,7 +586,7 @@ void CurveView::drawCurve(KDContext * ctx, KDRect rect, float tStart, float tEnd x = xy.x1(); y = xy.x2(); if (colorUnderCurve && !std::isnan(x) && colorLowerBound < x && x < colorUpperBound && !(std::isnan(y) || std::isinf(y))) { - drawHorizontalOrVerticalSegment(ctx, rect, Axis::Vertical, x, minFloat(0.0f, y), maxFloat(0.0f, y), color, 1); + drawHorizontalOrVerticalSegment(ctx, rect, Axis::Vertical, x, std::min(0.0f, y), std::max(0.0f, y), color, 1); } joinDots(ctx, rect, xyEvaluation, model, context, drawStraightLinesEarly, previousT, previousX, previousY, t, x, y, color, thick, k_maxNumberOfIterations); } while (true); @@ -599,8 +595,8 @@ void CurveView::drawCurve(KDContext * ctx, KDRect rect, float tStart, float tEnd void CurveView::drawCartesianCurve(KDContext * ctx, KDRect rect, float xMin, float xMax, EvaluateXYForParameter xyEvaluation, void * model, void * context, KDColor color, bool thick, bool colorUnderCurve, float colorLowerBound, float colorUpperBound) const { float rectLeft = pixelToFloat(Axis::Horizontal, rect.left() - k_externRectMargin); float rectRight = pixelToFloat(Axis::Horizontal, rect.right() + k_externRectMargin); - float tStart = std::isnan(rectLeft) ? xMin : maxFloat(xMin, rectLeft); - float tEnd = std::isnan(rectRight) ? xMax : minFloat(xMax, rectRight); + float tStart = std::isnan(rectLeft) ? xMin : std::max(xMin, rectLeft); + float tEnd = std::isnan(rectRight) ? xMax : std::min(xMax, rectRight); assert(!std::isnan(tStart) && !std::isnan(tEnd)); if (std::isinf(tStart) || std::isinf(tEnd) || tStart > tEnd) { return; @@ -701,8 +697,8 @@ static void clipBarycentricCoordinatesBetweenBounds(float & start, float & end, end = 0; } } else { - start = maxFloat(start, (bounds[(p1f > p2f) ? lower : upper] - p2f)/(p1f-p2f)); - end = minFloat( end , (bounds[(p1f > p2f) ? upper : lower] - p2f)/(p1f-p2f)); + start = std::max(start, (bounds[(p1f > p2f) ? lower : upper] - p2f)/(p1f-p2f)); + end = std::min( end , (bounds[(p1f > p2f) ? upper : lower] - p2f)/(p1f-p2f)); } } diff --git a/apps/shared/editable_cell_table_view_controller.cpp b/apps/shared/editable_cell_table_view_controller.cpp index 6c00a76f8..48365a3f5 100644 --- a/apps/shared/editable_cell_table_view_controller.cpp +++ b/apps/shared/editable_cell_table_view_controller.cpp @@ -3,11 +3,10 @@ #include "../constant.h" #include #include +#include using namespace Poincare; -static inline int maxInt(int x, int y) { return x > y ? x : y; } - namespace Shared { EditableCellTableViewController::EditableCellTableViewController(Responder * parentResponder) : @@ -60,7 +59,7 @@ bool EditableCellTableViewController::textFieldDidFinishEditing(TextField * text int EditableCellTableViewController::numberOfRows() const { int numberOfModelElements = 0; for (int i = 0; i < numberOfColumns(); i++) { - numberOfModelElements = maxInt(numberOfModelElements, numberOfElementsInColumn(i)); + numberOfModelElements = std::max(numberOfModelElements, numberOfElementsInColumn(i)); } return 1 + numberOfModelElements + (numberOfModelElements < maxNumberOfElements()); } diff --git a/apps/shared/expression_model.cpp b/apps/shared/expression_model.cpp index cf698f7c2..307956e02 100644 --- a/apps/shared/expression_model.cpp +++ b/apps/shared/expression_model.cpp @@ -7,14 +7,13 @@ #include #include #include +#include using namespace Ion; using namespace Poincare; namespace Shared { -static inline int maxInt(int x, int y) { return x > y ? x : y; } - ExpressionModel::ExpressionModel() : m_expression(), m_layout(), @@ -126,7 +125,7 @@ Ion::Storage::Record::ErrorStatus ExpressionModel::setExpressionContent(Ion::Sto size_t newDataSize = previousDataSize - previousExpressionSize + newExpressionSize; void * expAddress = expressionAddress(record); // Update size of record to maximal size between previous and new data - newData.size = maxInt(previousDataSize, newDataSize); + newData.size = std::max(previousDataSize, newDataSize); Ion::Storage::Record::ErrorStatus error = record->setValue(newData); if (error != Ion::Storage::Record::ErrorStatus::None) { assert(error == Ion::Storage::Record::ErrorStatus::NotEnoughSpaceAvailable); diff --git a/apps/shared/expression_model_list_controller.cpp b/apps/shared/expression_model_list_controller.cpp index e656ba069..dc1c18d0f 100644 --- a/apps/shared/expression_model_list_controller.cpp +++ b/apps/shared/expression_model_list_controller.cpp @@ -1,11 +1,10 @@ #include "expression_model_list_controller.h" #include #include +#include namespace Shared { -static inline int minInt(int x, int y) { return x < y ? x : y; } - /* Table Data Source */ ExpressionModelListController::ExpressionModelListController(Responder * parentResponder, I18n::Message text) : @@ -121,7 +120,7 @@ int ExpressionModelListController::memoizedIndexFromCumulatedHeight(KDCoordinate KDCoordinate currentCumulatedHeight = memoizedCumulatedHeightFromIndex(currentSelectedRow); if (offsetY > currentCumulatedHeight) { - int iMax = minInt(k_memoizedCellsCount/2 + 1, rowsCount - currentSelectedRow); + int iMax = std::min(k_memoizedCellsCount/2 + 1, rowsCount - currentSelectedRow); for (int i = 0; i < iMax; i++) { currentCumulatedHeight+= memoizedRowHeight(currentSelectedRow + i); if (offsetY <= currentCumulatedHeight) { @@ -129,7 +128,7 @@ int ExpressionModelListController::memoizedIndexFromCumulatedHeight(KDCoordinate } } } else { - int iMax = minInt(k_memoizedCellsCount/2, currentSelectedRow); + int iMax = std::min(k_memoizedCellsCount/2, currentSelectedRow); for (int i = 1; i <= iMax; i++) { currentCumulatedHeight-= memoizedRowHeight(currentSelectedRow-i); if (offsetY > currentCumulatedHeight) { diff --git a/apps/shared/function_graph_controller.cpp b/apps/shared/function_graph_controller.cpp index e1922ef6b..8169bbb04 100644 --- a/apps/shared/function_graph_controller.cpp +++ b/apps/shared/function_graph_controller.cpp @@ -5,16 +5,12 @@ #include #include #include +#include using namespace Poincare; namespace Shared { -static inline float minFloat(float x, float y) { return x < y ? x : y; } -static inline float maxFloat(float x, float y) { return x > y ? x : y; } -static inline double minDouble(double x, double y) { return x < y ? x : y; } -static inline double maxDouble(double x, double y) { return x > y ? x : y; } - FunctionGraphController::FunctionGraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * previousModelsVersions, uint32_t * rangeVersion, Preferences::AngleUnit * angleUnitVersion) : InteractiveCurveViewController(parentResponder, inputEventHandlerDelegate, header, interactiveRange, curveView, cursor, modelVersion, previousModelsVersions, rangeVersion), m_initialisationParameterController(this, interactiveRange), @@ -92,13 +88,13 @@ InteractiveCurveViewRangeDelegate::Range FunctionGraphController::computeYRange( if (std::isnan(tMin)) { tMin = xMin; } else if (f->shouldClipTRangeToXRange()) { - tMin = maxFloat(tMin, xMin); + tMin = std::max(tMin, xMin); } double tMax = f->tMax(); if (std::isnan(tMax)) { tMax = xMax; } else if (f->shouldClipTRangeToXRange()) { - tMax = minFloat(tMax, xMax); + tMax = std::min(tMax, xMax); } /* In practice, a step smaller than a pixel's width is needed for sampling * the values of a function. Otherwise some relevant extremal values may be @@ -113,8 +109,8 @@ InteractiveCurveViewRangeDelegate::Range FunctionGraphController::computeYRange( if (!std::isnan(x) && !std::isinf(x) && x >= xMin && x <= xMax) { float y = xy.x2(); if (!std::isnan(y) && !std::isinf(y)) { - min = minFloat(min, y); - max = maxFloat(max, y); + min = std::min(min, y); + max = std::max(max, y); } } } @@ -167,7 +163,7 @@ bool FunctionGraphController::moveCursorVertically(int direction) { double clippedT = m_cursor->t(); if (!std::isnan(f->tMin())) { assert(!std::isnan(f->tMax())); - clippedT = minDouble(f->tMax(), maxDouble(f->tMin(), clippedT)); + clippedT = std::min(f->tMax(), std::max(f->tMin(), clippedT)); } Poincare::Coordinate2D cursorPosition = f->evaluateXYAtParameter(clippedT, context); m_cursor->moveTo(clippedT, cursorPosition.x1(), cursorPosition.x2()); diff --git a/apps/shared/function_list_controller.cpp b/apps/shared/function_list_controller.cpp index 50aa8832a..7f937525a 100644 --- a/apps/shared/function_list_controller.cpp +++ b/apps/shared/function_list_controller.cpp @@ -1,11 +1,10 @@ #include "function_list_controller.h" #include "function_app.h" #include "function_expression_cell.h" +#include namespace Shared { -static inline int maxInt(int x, int y) { return x > y ? x : y; } - FunctionListController::FunctionListController(Responder * parentResponder, ButtonRowController * header, ButtonRowController * footer, I18n::Message text) : ExpressionModelListController(parentResponder, text), ButtonRowDelegate(header, footer), @@ -243,7 +242,7 @@ void FunctionListController::computeTitlesColumnWidth(bool forceMax) { return; } KDCoordinate maxTitleWidth = maxFunctionNameWidth()+k_functionTitleSumOfMargins; - m_titlesColumnWidth = maxInt(maxTitleWidth, k_minTitleColumnWidth); + m_titlesColumnWidth = std::max(maxTitleWidth, k_minTitleColumnWidth); } TabViewController * FunctionListController::tabController() const { @@ -262,7 +261,7 @@ KDCoordinate FunctionListController::maxFunctionNameWidth() { const char * functionName = record.fullName(); const char * dotPosition = strchr(functionName, Ion::Storage::k_dotChar); assert(dotPosition != nullptr); - maxNameLength = maxInt(maxNameLength, dotPosition-functionName); + maxNameLength = std::max(maxNameLength, dotPosition-functionName); } return nameWidth(maxNameLength + Function::k_parenthesedArgumentCodePointLength); } diff --git a/apps/shared/function_title_cell.cpp b/apps/shared/function_title_cell.cpp index 17e640e3c..007ff7237 100644 --- a/apps/shared/function_title_cell.cpp +++ b/apps/shared/function_title_cell.cpp @@ -1,11 +1,9 @@ #include "function_title_cell.h" #include +#include namespace Shared { -static inline float minFloat(float x, float y) { return x < y ? x : y; } -static inline float maxFloat(float x, float y) { return x > y ? x : y; } - void FunctionTitleCell::setOrientation(Orientation orientation) { m_orientation = orientation; reloadCell(); @@ -51,9 +49,9 @@ KDRect FunctionTitleCell::subviewFrame() const { float FunctionTitleCell::verticalAlignment() const { assert(m_orientation == Orientation::VerticalIndicator); - return maxFloat( + return std::max( 0.0f, - minFloat( + std::min( 1.0f, m_baseline < 0 ? 0.5f : verticalAlignmentGivenExpressionBaselineAndRowHeight(m_baseline, subviewFrame().height()))); } diff --git a/apps/shared/interactive_curve_view_range.cpp b/apps/shared/interactive_curve_view_range.cpp index 2db5afaa2..dc1c6fd78 100644 --- a/apps/shared/interactive_curve_view_range.cpp +++ b/apps/shared/interactive_curve_view_range.cpp @@ -5,13 +5,12 @@ #include #include #include +#include using namespace Poincare; namespace Shared { -static inline float maxFloat(float x, float y) { return x > y ? x : y; } - uint32_t InteractiveCurveViewRange::rangeChecksum() { float data[5] = {xMin(), xMax(), yMin(), yMax(), m_yAuto ? 1.0f : 0.0f}; size_t dataLengthInBytes = 5*sizeof(float); @@ -94,7 +93,7 @@ void InteractiveCurveViewRange::normalize() { * 1cm = 2 current units. */ m_yAuto = false; - const float unit = maxFloat(xGridUnit(), yGridUnit()); + const float unit = std::max(xGridUnit(), yGridUnit()); // Set x range float newXHalfRange = NormalizedXHalfRange(unit); @@ -160,7 +159,7 @@ void InteractiveCurveViewRange::setDefault() { yRange = yMax() - yMin(); float xyRatio = xRange/yRange; - const float unit = maxFloat(xGridUnit(), yGridUnit()); + const float unit = std::max(xGridUnit(), yGridUnit()); const float newXHalfRange = NormalizedXHalfRange(unit); const float newYHalfRange = NormalizedYHalfRange(unit); float normalizedXYRatio = newXHalfRange/newYHalfRange; diff --git a/apps/shared/range_1D.cpp b/apps/shared/range_1D.cpp index 944118474..320d316c7 100644 --- a/apps/shared/range_1D.cpp +++ b/apps/shared/range_1D.cpp @@ -2,12 +2,10 @@ #include #include #include +#include namespace Shared { -static inline float minFloat(float x, float y) { return x < y ? x : y; } -static inline float maxFloat(float x, float y) { return x > y ? x : y; } - void Range1D::setMin(float min, float lowerMaxFloat, float upperMaxFloat) { min = clipped(min, false, lowerMaxFloat, upperMaxFloat); if (std::isnan(min)) { @@ -43,7 +41,7 @@ float Range1D::defaultRangeLengthFor(float position) { float Range1D::clipped(float x, bool isMax, float lowerMaxFloat, float upperMaxFloat) { float maxF = isMax ? upperMaxFloat : lowerMaxFloat; float minF = isMax ? -lowerMaxFloat : -upperMaxFloat; - return maxFloat(minF, minFloat(x, maxF)); + return std::max(minF, std::min(x, maxF)); } } diff --git a/apps/shared/scrollable_multiple_expressions_view.cpp b/apps/shared/scrollable_multiple_expressions_view.cpp index 987a8e220..c86630143 100644 --- a/apps/shared/scrollable_multiple_expressions_view.cpp +++ b/apps/shared/scrollable_multiple_expressions_view.cpp @@ -1,12 +1,11 @@ #include "scrollable_multiple_expressions_view.h" #include #include +#include using namespace Poincare; namespace Shared { -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } - AbstractScrollableMultipleExpressionsView::ContentCell::ContentCell() : m_rightExpressionView(), m_approximateSign(KDFont::LargeFont, I18n::Message::AlmostEqual, 0.5f, 0.5f, Palette::GreyVeryDark), @@ -75,7 +74,7 @@ KDSize AbstractScrollableMultipleExpressionsView::ContentCell::minimalSizeForOpt centeredExpressionSize = m_centeredExpressionView.minimalSizeForOptimalDisplay(); width += centeredExpressionSize.width() + 2*Metric::CommonLargeMargin + m_approximateSign.minimalSizeForOptimalDisplay().width(); } - KDCoordinate height = maxCoordinate(maxCoordinate(centeredBaseline, rightBaseline), leftViewBaseline) + maxCoordinate(maxCoordinate(centeredExpressionSize.height()-centeredBaseline, rightExpressionSize.height()-rightBaseline), leftSize.height()-leftViewBaseline); + KDCoordinate height = std::max(std::max(centeredBaseline, rightBaseline), leftViewBaseline) + std::max(std::max(centeredExpressionSize.height()-centeredBaseline, rightExpressionSize.height()-rightBaseline), leftSize.height()-leftViewBaseline); return KDSize(width, height); } @@ -134,7 +133,7 @@ void AbstractScrollableMultipleExpressionsView::ContentCell::layoutSubviews(bool KDSize rightExpressionSize = m_rightExpressionView.minimalSizeForOptimalDisplay(); KDCoordinate rightBaseline = m_rightExpressionView.layout().isUninitialized() ? 0 : m_rightExpressionView.layout().baseline(); // Compute baseline - KDCoordinate baseline = maxCoordinate(maxCoordinate(leftViewBaseline, rightBaseline), centeredBaseline); + KDCoordinate baseline = std::max(std::max(leftViewBaseline, rightBaseline), centeredBaseline); // Layout left view KDCoordinate currentWidth = 0; if (leftExpressionView()) { diff --git a/apps/shared/store_controller.cpp b/apps/shared/store_controller.cpp index a5e08767f..fc56453c7 100644 --- a/apps/shared/store_controller.cpp +++ b/apps/shared/store_controller.cpp @@ -4,11 +4,10 @@ #include "../constant.h" #include #include +#include using namespace Poincare; -static inline int minInt(int x, int y) { return x < y ? x : y; } - namespace Shared { StoreController::ContentView::ContentView(DoublePairStore * store, Responder * parentResponder, TableViewDataSource * dataSource, SelectableTableViewDataSource * selectionDataSource, InputEventHandlerDelegate * inputEventHandlerDelegate, TextFieldDelegate * textFieldDelegate) : @@ -245,7 +244,7 @@ bool StoreController::privateFillColumnWithFormula(Expression formula, Expressio if (numberOfValuesToCompute == -1) { numberOfValuesToCompute = m_store->numberOfPairsOfSeries(series); } else { - numberOfValuesToCompute = minInt(numberOfValuesToCompute, m_store->numberOfPairsOfSeries(series)); + numberOfValuesToCompute = std::min(numberOfValuesToCompute, m_store->numberOfPairsOfSeries(series)); } index++; } diff --git a/apps/shared/values_controller.cpp b/apps/shared/values_controller.cpp index 2b99d788a..cc6fc984b 100644 --- a/apps/shared/values_controller.cpp +++ b/apps/shared/values_controller.cpp @@ -3,12 +3,12 @@ #include #include #include +#include using namespace Poincare; namespace Shared { -static inline int minInt(int x, int y) { return x < y ? x : y; } static inline int absInt(int x) { return x < 0 ? -x : x; } // Constructor and helpers @@ -338,9 +338,9 @@ char * ValuesController::memoizedBufferForCell(int i, int j) { } // Compute the buffer of the new cells of the memoized table int maxI = numberOfValuesColumns() - m_firstMemoizedColumn; - for (int ii = 0; ii < minInt(nbOfMemoizedColumns, maxI); ii++) { + for (int ii = 0; ii < std::min(nbOfMemoizedColumns, maxI); ii++) { int maxJ = numberOfElementsInColumn(absoluteColumnForValuesColumn(ii+m_firstMemoizedColumn)) - m_firstMemoizedRow; - for (int jj = 0; jj < minInt(k_maxNumberOfDisplayableRows, maxJ); jj++) { + for (int jj = 0; jj < std::min(k_maxNumberOfDisplayableRows, maxJ); jj++) { // Escape if already filled if (ii >= -offsetI && ii < -offsetI + nbOfMemoizedColumns && jj >= -offsetJ && jj < -offsetJ + k_maxNumberOfDisplayableRows) { continue; diff --git a/apps/solver/solutions_controller.cpp b/apps/solver/solutions_controller.cpp index 1afa6220e..22443438b 100644 --- a/apps/solver/solutions_controller.cpp +++ b/apps/solver/solutions_controller.cpp @@ -10,14 +10,13 @@ #include #include #include +#include using namespace Poincare; using namespace Shared; namespace Solver { -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } - constexpr KDColor SolutionsController::ContentView::k_backgroundColor; SolutionsController::ContentView::ContentView(SolutionsController * controller) : @@ -260,7 +259,7 @@ KDCoordinate SolutionsController::rowHeight(int j) { Poincare::Layout approximateLayout = m_equationStore->exactSolutionLayoutAtIndex(j, false); KDCoordinate exactLayoutHeight = exactLayout.layoutSize().height(); KDCoordinate approximateLayoutHeight = approximateLayout.layoutSize().height(); - KDCoordinate layoutHeight = maxCoordinate(exactLayout.baseline(), approximateLayout.baseline()) + maxCoordinate(exactLayoutHeight-exactLayout.baseline(), approximateLayoutHeight-approximateLayout.baseline()); + KDCoordinate layoutHeight = std::max(exactLayout.baseline(), approximateLayout.baseline()) + std::max(exactLayoutHeight-exactLayout.baseline(), approximateLayoutHeight-approximateLayout.baseline()); return layoutHeight + 2 * Metric::CommonSmallMargin; } if (j == rowOfUserVariablesMessage) { diff --git a/apps/statistics/histogram_controller.cpp b/apps/statistics/histogram_controller.cpp index a3ad6decd..1f200e55d 100644 --- a/apps/statistics/histogram_controller.cpp +++ b/apps/statistics/histogram_controller.cpp @@ -4,6 +4,7 @@ #include "app.h" #include #include +#include #include #include #include @@ -13,9 +14,6 @@ using namespace Shared; namespace Statistics { -static inline float minFloat(float x, float y) { return x < y ? x : y; } -static inline float maxFloat(float x, float y) { return x > y ? x : y; } - HistogramController::HistogramController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, ButtonRowController * header, Store * store, uint32_t * storeVersion, uint32_t * barVersion, uint32_t * rangeVersion, int * selectedBarIndex, int * selectedSeriesIndex) : MultipleDataViewController(parentResponder, store, selectedBarIndex, selectedSeriesIndex), ButtonRowDelegate(header, nullptr), @@ -193,8 +191,8 @@ void HistogramController::preinitXRangeParameters() { float maxValue = -FLT_MAX; for (int i = 0; i < Store::k_numberOfSeries; i ++) { if (!m_store->seriesIsEmpty(i)) { - minValue = minFloat(minValue, m_store->minValue(i)); - maxValue = maxFloat(maxValue, m_store->maxValue(i)); + minValue = std::min(minValue, m_store->minValue(i)); + maxValue = std::max(maxValue, m_store->maxValue(i)); } } m_store->setXMin(minValue); diff --git a/apps/variable_box_controller.cpp b/apps/variable_box_controller.cpp index 2d6d09e19..2842ff8c5 100644 --- a/apps/variable_box_controller.cpp +++ b/apps/variable_box_controller.cpp @@ -8,14 +8,12 @@ #include #include #include +#include using namespace Poincare; using namespace Shared; using namespace Ion; -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } -static inline KDCoordinate maxInt(int x, int y) { return x > y ? x : y; } - VariableBoxController::VariableBoxController() : NestedMenuController(nullptr, I18n::Message::Variables), m_currentPage(Page::RootMenu), @@ -129,7 +127,7 @@ KDCoordinate VariableBoxController::rowHeight(int index) { if (m_currentPage != Page::RootMenu) { Layout layoutR = expressionLayoutForRecord(recordAtIndex(index), index); if (!layoutR.isUninitialized()) { - return maxCoordinate(layoutR.layoutSize().height()+k_leafMargin, Metric::ToolboxRowHeight); + return std::max(layoutR.layoutSize().height()+k_leafMargin, Metric::ToolboxRowHeight); } } return NestedMenuController::rowHeight(index); @@ -289,7 +287,7 @@ void VariableBoxController::destroyRecordAtRowIndex(int rowIndex) { // The deleted row is after the memoization return; } - for (int i = maxInt(0, rowIndex - m_firstMemoizedLayoutIndex); i < k_maxNumberOfDisplayedRows - 1; i++) { + for (int i = std::max(0, rowIndex - m_firstMemoizedLayoutIndex); i < k_maxNumberOfDisplayedRows - 1; i++) { m_layouts[i] = m_layouts[i+1]; } m_layouts[k_maxNumberOfDisplayedRows - 1] = Layout(); diff --git a/escher/src/clipboard.cpp b/escher/src/clipboard.cpp index 446211c4b..a8551bc2b 100644 --- a/escher/src/clipboard.cpp +++ b/escher/src/clipboard.cpp @@ -1,15 +1,14 @@ #include +#include static Clipboard s_clipboard; -static inline int minInt(int x, int y) { return x < y ? x : y; } - Clipboard * Clipboard::sharedClipboard() { return &s_clipboard; } void Clipboard::store(const char * storedText, int length) { - strlcpy(m_textBuffer, storedText, length == -1 ? TextField::maxBufferSize() : minInt(TextField::maxBufferSize(), length + 1)); + strlcpy(m_textBuffer, storedText, length == -1 ? TextField::maxBufferSize() : std::min(TextField::maxBufferSize(), length + 1)); } void Clipboard::reset() { diff --git a/escher/src/expression_field.cpp b/escher/src/expression_field.cpp index 1a413ae41..16b77155a 100644 --- a/escher/src/expression_field.cpp +++ b/escher/src/expression_field.cpp @@ -1,9 +1,7 @@ #include #include #include - -static inline KDCoordinate minCoordinate(KDCoordinate x, KDCoordinate y) { return x < y ? x : y; } -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } +#include ExpressionField::ExpressionField(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, TextFieldDelegate * textFieldDelegate, LayoutFieldDelegate * layoutFieldDelegate) : Responder(parentResponder), @@ -117,6 +115,6 @@ bool ExpressionField::handleEventWithText(const char * text, bool indentation, b KDCoordinate ExpressionField::inputViewHeight() const { return k_separatorThickness + (editionIsInTextField() ? k_minimalHeight : - minCoordinate(k_maximalHeight, - maxCoordinate(k_minimalHeight, m_layoutField.minimalSizeForOptimalDisplay().height()))); + std::min(k_maximalHeight, + std::max(k_minimalHeight, m_layoutField.minimalSizeForOptimalDisplay().height()))); } diff --git a/escher/src/expression_view.cpp b/escher/src/expression_view.cpp index dc713c2fa..2f96ed35a 100644 --- a/escher/src/expression_view.cpp +++ b/escher/src/expression_view.cpp @@ -1,10 +1,9 @@ #include #include +#include using namespace Poincare; -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } - ExpressionView::ExpressionView(float horizontalAlignment, float verticalAlignment, KDColor textColor, KDColor backgroundColor, Poincare::Layout * selectionStart, Poincare::Layout * selectionEnd ) : m_layout(), @@ -65,7 +64,7 @@ KDSize ExpressionView::minimalSizeForOptimalDisplay() const { KDPoint ExpressionView::drawingOrigin() const { KDSize expressionSize = m_layout.layoutSize(); - return KDPoint(m_horizontalMargin + m_horizontalAlignment*(m_frame.width() - 2*m_horizontalMargin - expressionSize.width()), maxCoordinate(0, m_verticalAlignment*(m_frame.height() - expressionSize.height()))); + return KDPoint(m_horizontalMargin + m_horizontalAlignment*(m_frame.width() - 2*m_horizontalMargin - expressionSize.width()), std::max(0, m_verticalAlignment*(m_frame.height() - expressionSize.height()))); } KDPoint ExpressionView::absoluteDrawingOrigin() const { diff --git a/escher/src/layout_field.cpp b/escher/src/layout_field.cpp index f72280004..66bed4bc9 100644 --- a/escher/src/layout_field.cpp +++ b/escher/src/layout_field.cpp @@ -5,11 +5,10 @@ #include #include #include +#include using namespace Poincare; -static inline KDCoordinate minCoordinate(KDCoordinate x, KDCoordinate y) { return x < y ? x : y; } - LayoutField::ContentView::ContentView() : m_cursor(), m_expressionView(0.0f, 0.5f, KDColorBlack, KDColorWhite, &m_selectionStart, &m_selectionEnd), @@ -610,8 +609,8 @@ void LayoutField::scrollToBaselinedRect(KDRect rect, KDCoordinate baseline) { scrollToContentRect(rect, true); // Show the rect area around its baseline KDCoordinate underBaseline = rect.height() - baseline; - KDCoordinate minAroundBaseline = minCoordinate(baseline, underBaseline); - minAroundBaseline = minCoordinate(minAroundBaseline, bounds().height() / 2); + KDCoordinate minAroundBaseline = std::min(baseline, underBaseline); + minAroundBaseline = std::min(minAroundBaseline, bounds().height() / 2); KDRect balancedRect(rect.x(), rect.y() + baseline - minAroundBaseline, rect.width(), 2 * minAroundBaseline); scrollToContentRect(balancedRect, true); } diff --git a/escher/src/scroll_view.cpp b/escher/src/scroll_view.cpp index d85e0dbcc..6782f5604 100644 --- a/escher/src/scroll_view.cpp +++ b/escher/src/scroll_view.cpp @@ -4,9 +4,7 @@ extern "C" { #include } - -static inline KDCoordinate minCoordinate(KDCoordinate x, KDCoordinate y) { return x < y ? x : y; } -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } +#include ScrollView::ScrollView(View * contentView, ScrollViewDataSource * dataSource) : View(), @@ -76,8 +74,8 @@ void ScrollView::scrollToContentPoint(KDPoint p, bool allowOverscroll) { // Handle cases when the size of the view has decreased. setContentOffset(KDPoint( - minCoordinate(contentOffset().x(), maxCoordinate(minimalSizeForOptimalDisplay().width() - bounds().width(), 0)), - minCoordinate(contentOffset().y(), maxCoordinate(minimalSizeForOptimalDisplay().height() - bounds().height(), 0)))); + std::min(contentOffset().x(), std::max(minimalSizeForOptimalDisplay().width() - bounds().width(), 0)), + std::min(contentOffset().y(), std::max(minimalSizeForOptimalDisplay().height() - bounds().height(), 0)))); } void ScrollView::scrollToContentRect(KDRect rect, bool allowOverscroll) { diff --git a/escher/src/scrollable_view.cpp b/escher/src/scrollable_view.cpp index 5d5e90f57..af59594af 100644 --- a/escher/src/scrollable_view.cpp +++ b/escher/src/scrollable_view.cpp @@ -1,9 +1,7 @@ #include #include #include - -static inline KDCoordinate minCoordinate(KDCoordinate x, KDCoordinate y) { return x < y ? x : y; } -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } +#include ScrollableView::ScrollableView(Responder * parentResponder, View * view, ScrollViewDataSource * dataSource) : Responder(parentResponder), @@ -17,25 +15,25 @@ bool ScrollableView::handleEvent(Ion::Events::Event event) { if (event == Ion::Events::Left) { KDCoordinate movementToEdge = contentOffset().x(); if (movementToEdge > 0) { - translation = KDPoint(-minCoordinate(Metric::ScrollStep, movementToEdge), 0); + translation = KDPoint(-std::min(Metric::ScrollStep, movementToEdge), 0); } } if (event == Ion::Events::Right) { KDCoordinate movementToEdge = minimalSizeForOptimalDisplay().width() - bounds().width() - contentOffset().x(); if (movementToEdge > 0) { - translation = KDPoint(minCoordinate(Metric::ScrollStep, movementToEdge), 0); + translation = KDPoint(std::min(Metric::ScrollStep, movementToEdge), 0); } } if (event == Ion::Events::Up) { KDCoordinate movementToEdge = contentOffset().y(); if (movementToEdge > 0) { - translation = KDPoint(0, -minCoordinate(Metric::ScrollStep, movementToEdge)); + translation = KDPoint(0, -std::min(Metric::ScrollStep, movementToEdge)); } } if (event == Ion::Events::Down) { KDCoordinate movementToEdge = minimalSizeForOptimalDisplay().height() - bounds().height() - contentOffset().y(); if (movementToEdge > 0) { - translation = KDPoint(0, minCoordinate(Metric::ScrollStep, movementToEdge)); + translation = KDPoint(0, std::min(Metric::ScrollStep, movementToEdge)); } } if (translation != KDPointZero) { @@ -51,7 +49,7 @@ void ScrollableView::reloadScroll(bool forceReLayout) { KDSize ScrollableView::contentSize() const { KDSize viewSize = ScrollView::contentSize(); - KDCoordinate viewWidth = maxCoordinate(viewSize.width(), maxContentWidthDisplayableWithoutScrolling()); - KDCoordinate viewHeight = maxCoordinate(viewSize.height(), maxContentHeightDisplayableWithoutScrolling()); + KDCoordinate viewWidth = std::max(viewSize.width(), maxContentWidthDisplayableWithoutScrolling()); + KDCoordinate viewHeight = std::max(viewSize.height(), maxContentHeightDisplayableWithoutScrolling()); return KDSize(viewWidth, viewHeight); } diff --git a/escher/src/table_cell.cpp b/escher/src/table_cell.cpp index d812f47eb..767601ef7 100644 --- a/escher/src/table_cell.cpp +++ b/escher/src/table_cell.cpp @@ -1,9 +1,7 @@ #include #include #include - -static inline KDCoordinate minCoordinate(KDCoordinate x, KDCoordinate y) { return x < y ? x : y; } -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } +#include TableCell::TableCell(Layout layout) : Bordered(), @@ -95,21 +93,21 @@ void TableCell::layoutSubviews(bool force) { KDCoordinate y = k_separatorThickness; if (label) { y += k_verticalMargin; - KDCoordinate labelHeight = minCoordinate(labelSize.height(), height - y - k_separatorThickness - k_verticalMargin); + KDCoordinate labelHeight = std::min(labelSize.height(), height - y - k_separatorThickness - k_verticalMargin); label->setFrame(KDRect(horizontalMargin, y, width-2*horizontalMargin, labelHeight), force); y += labelHeight + k_verticalMargin; } horizontalMargin = k_separatorThickness + k_horizontalMargin; - y = maxCoordinate(y, height - k_separatorThickness - withMargin(accessorySize.height(), Metric::TableCellVerticalMargin) - withMargin(subAccessorySize.height(), 0)); + y = std::max(y, height - k_separatorThickness - withMargin(accessorySize.height(), Metric::TableCellVerticalMargin) - withMargin(subAccessorySize.height(), 0)); if (subAccessory) { - KDCoordinate subAccessoryHeight = minCoordinate(subAccessorySize.height(), height - y - k_separatorThickness - Metric::TableCellVerticalMargin); + KDCoordinate subAccessoryHeight = std::min(subAccessorySize.height(), height - y - k_separatorThickness - Metric::TableCellVerticalMargin); accessory->setFrame(KDRect(horizontalMargin, y, width - 2*horizontalMargin, subAccessoryHeight), force); y += subAccessoryHeight; } horizontalMargin = k_separatorThickness + accessoryMargin(); - y = maxCoordinate(y, height - k_separatorThickness - withMargin(accessorySize.height(), Metric::TableCellVerticalMargin)); + y = std::max(y, height - k_separatorThickness - withMargin(accessorySize.height(), Metric::TableCellVerticalMargin)); if (accessory) { - KDCoordinate accessoryHeight = minCoordinate(accessorySize.height(), height - y - k_separatorThickness - Metric::TableCellVerticalMargin); + KDCoordinate accessoryHeight = std::min(accessorySize.height(), height - y - k_separatorThickness - Metric::TableCellVerticalMargin); accessory->setFrame(KDRect(horizontalMargin, y, width - 2*horizontalMargin, accessoryHeight), force); } } else { @@ -137,29 +135,29 @@ void TableCell::layoutSubviews(bool force) { KDCoordinate verticalMargin = k_separatorThickness; KDCoordinate x = 0; KDCoordinate labelX = k_separatorThickness + labelMargin(); - KDCoordinate subAccessoryX = maxCoordinate(k_separatorThickness + k_horizontalMargin, width - k_separatorThickness - withMargin(accessorySize.width(), accessoryMargin()) - withMargin(subAccessorySize.width(), 0)); - KDCoordinate accessoryX = maxCoordinate(k_separatorThickness + accessoryMargin(), width - k_separatorThickness - withMargin(accessorySize.width(), accessoryMargin())); + KDCoordinate subAccessoryX = std::max(k_separatorThickness + k_horizontalMargin, width - k_separatorThickness - withMargin(accessorySize.width(), accessoryMargin()) - withMargin(subAccessorySize.width(), 0)); + KDCoordinate accessoryX = std::max(k_separatorThickness + accessoryMargin(), width - k_separatorThickness - withMargin(accessorySize.width(), accessoryMargin())); if (label) { x = labelX; - KDCoordinate labelWidth = minCoordinate(labelSize.width(), width - x - k_separatorThickness - labelMargin()); + KDCoordinate labelWidth = std::min(labelSize.width(), width - x - k_separatorThickness - labelMargin()); if (m_layout == Layout::HorizontalRightOverlap) { - labelWidth = minCoordinate(labelWidth, subAccessoryX - x - labelMargin()); + labelWidth = std::min(labelWidth, subAccessoryX - x - labelMargin()); } label->setFrame(KDRect(x, verticalMargin, labelWidth, height-2*verticalMargin), force); x += labelWidth + labelMargin(); } if (subAccessory) { - x = maxCoordinate(x, subAccessoryX); - KDCoordinate subAccessoryWidth = minCoordinate(subAccessorySize.width(), width - x - k_separatorThickness - k_horizontalMargin); + x = std::max(x, subAccessoryX); + KDCoordinate subAccessoryWidth = std::min(subAccessorySize.width(), width - x - k_separatorThickness - k_horizontalMargin); if (m_layout == Layout::HorizontalRightOverlap) { - subAccessoryWidth = minCoordinate(subAccessoryWidth, accessoryX - x); + subAccessoryWidth = std::min(subAccessoryWidth, accessoryX - x); } subAccessory->setFrame(KDRect(x, verticalMargin, subAccessoryWidth, height-2*verticalMargin), force); x += subAccessoryWidth; } if (accessory) { - x = maxCoordinate(x, accessoryX); - KDCoordinate accessoryWidth = minCoordinate(accessorySize.width(), width - x - k_separatorThickness - accessoryMargin()); + x = std::max(x, accessoryX); + KDCoordinate accessoryWidth = std::min(accessorySize.width(), width - x - k_separatorThickness - accessoryMargin()); accessory->setFrame(KDRect(x, verticalMargin, accessoryWidth, height-2*verticalMargin), force); } } diff --git a/escher/src/table_view.cpp b/escher/src/table_view.cpp index f4c72317e..01ea22a2d 100644 --- a/escher/src/table_view.cpp +++ b/escher/src/table_view.cpp @@ -4,8 +4,7 @@ extern "C" { #include } - -#define MIN(x,y) ((x)<(y) ? (x) : (y)) +#include TableView::TableView(TableViewDataSource * dataSource, ScrollViewDataSource * scrollDataSource) : ScrollView(&m_contentView, scrollDataSource), @@ -200,7 +199,7 @@ int TableView::ContentView::numberOfFullyDisplayableColumns() const { int TableView::ContentView::numberOfDisplayableRows() const { int rowOffset = rowsScrollingOffset(); int displayedHeightWithOffset = m_dataSource->indexFromCumulatedHeight(m_tableView->bounds().height() + m_tableView->contentOffset().y()); - return MIN( + return std::min( m_dataSource->numberOfRows(), displayedHeightWithOffset + 1 ) - rowOffset; @@ -209,7 +208,7 @@ int TableView::ContentView::numberOfDisplayableRows() const { int TableView::ContentView::numberOfDisplayableColumns() const { int columnOffset = columnsScrollingOffset(); int displayedWidthWithOffset = m_dataSource->indexFromCumulatedWidth(m_tableView->bounds().width() + m_tableView->contentOffset().x()); - return MIN( + return std::min( m_dataSource->numberOfColumns(), displayedWidthWithOffset + 1 ) - columnOffset; diff --git a/escher/src/text_area.cpp b/escher/src/text_area.cpp index 13513e1e9..1b413a120 100644 --- a/escher/src/text_area.cpp +++ b/escher/src/text_area.cpp @@ -8,10 +8,7 @@ #include #include #include - -static inline const char * maxPointer(const char * x, const char * y) { return x > y ? x : y; } -static inline const char * minPointer(const char * x, const char * y) { return x < y ? x : y; } -static inline size_t minSizeT(size_t x, size_t y) { return x < y ? x : y; } +#include /* TextArea */ @@ -214,7 +211,7 @@ const char * TextArea::Text::pointerAtPosition(Position p) { for (Line l : *this) { if (p.line() == y) { const char * result = UTF8Helper::CodePointAtGlyphOffset(l.text(), p.column()); - return minPointer(result, l.text() + l.charLength()); + return std::min(result, l.text() + l.charLength()); } y++; } @@ -420,13 +417,13 @@ void TextArea::ContentView::drawStringAt(KDContext * ctx, int line, int column, m_font, textColor, backgroundColor, - drawSelection ? (selectionStart >= text ? minSizeT(length, selectionStart - text) : 0) : length + drawSelection ? (selectionStart >= text ? std::min(length, selectionStart - text) : 0) : length ); if (!drawSelection) { return; } - const char * highlightedDrawStart = maxPointer(selectionStart, text); - size_t highlightedDrawLength = minSizeT(selectionEnd - highlightedDrawStart, length - (highlightedDrawStart - text)); + const char * highlightedDrawStart = std::max(selectionStart, text); + size_t highlightedDrawLength = std::min(selectionEnd - highlightedDrawStart, length - (highlightedDrawStart - text)); nextPoint = ctx->drawString( highlightedDrawStart, diff --git a/escher/src/text_field.cpp b/escher/src/text_field.cpp index afa95ce45..bbabf8756 100644 --- a/escher/src/text_field.cpp +++ b/escher/src/text_field.cpp @@ -5,8 +5,8 @@ #include #include #include +#include -static inline int minInt(int x, int y) { return x < y ? x : y; } static char s_draftTextBuffer[TextField::maxBufferSize()]; /* TextField::ContentView */ @@ -84,7 +84,7 @@ void TextField::ContentView::setText(const char * text) { buffer[0] = 0; return; } - int textLength = minInt(textRealLength, maxBufferSize - 1); + int textLength = std::min(textRealLength, maxBufferSize - 1); // Copy the text strlcpy(buffer, text, maxBufferSize); // Update the draft text length diff --git a/escher/src/text_input.cpp b/escher/src/text_input.cpp index 0bc583bc7..6e573a045 100644 --- a/escher/src/text_input.cpp +++ b/escher/src/text_input.cpp @@ -2,12 +2,10 @@ #include #include #include +#include /* TextInput::ContentView */ -static inline const char * minCharPointer(const char * x, const char * y) { return x < y ? x : y; } -static inline const char * maxCharPointer(const char * x, const char * y) { return x > y ? x : y; } - void TextInput::ContentView::setFont(const KDFont * font) { m_font = font; markRectAsDirty(bounds()); @@ -16,7 +14,7 @@ void TextInput::ContentView::setFont(const KDFont * font) { void TextInput::ContentView::setCursorLocation(const char * location) { assert(location != nullptr); assert(location >= editedText()); - const char * adjustedLocation = minCharPointer(location, editedText() + editedTextLength()); + const char * adjustedLocation = std::min(location, editedText() + editedTextLength()); m_cursorLocation = adjustedLocation; layoutSubviews(); } @@ -131,7 +129,7 @@ bool TextInput::removePreviousGlyph() { bool TextInput::setCursorLocation(const char * location) { assert(location != nullptr); - const char * adjustedLocation = maxCharPointer(location, text()); + const char * adjustedLocation = std::max(location, text()); willSetCursorLocation(&adjustedLocation); contentView()->setCursorLocation(adjustedLocation); scrollToCursor(); diff --git a/escher/src/warning_controller.cpp b/escher/src/warning_controller.cpp index a07c11dbf..372ca169a 100644 --- a/escher/src/warning_controller.cpp +++ b/escher/src/warning_controller.cpp @@ -1,7 +1,6 @@ #include #include - -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } +#include WarningController::ContentView::ContentView() : SolidColorView(KDColorBlack), @@ -46,7 +45,7 @@ KDSize WarningController::ContentView::minimalSizeForOptimalDisplay() const { } assert(numberOfSubviews() == 2); KDSize textSize2 = m_textView2.minimalSizeForOptimalDisplay(); - return KDSize(maxCoordinate(textSize1.width(), textSize2.width()) + k_horizontalMargin, + return KDSize(std::max(textSize1.width(), textSize2.width()) + k_horizontalMargin, textSize1.height() + textSize2.height() + 2*k_topAndBottomMargin + k_middleMargin); } diff --git a/ion/src/device/shared/drivers/internal_flash.cpp b/ion/src/device/shared/drivers/internal_flash.cpp index 9ff5e1432..cd8fa60bd 100644 --- a/ion/src/device/shared/drivers/internal_flash.cpp +++ b/ion/src/device/shared/drivers/internal_flash.cpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace Ion { namespace Device { @@ -96,11 +97,6 @@ static inline ptrdiff_t byte_offset(void * p1, void * p2) { return reinterpret_cast(p2) - reinterpret_cast(p1); } -template -static inline T min(T i, T j) { - return (i( + uint8_t * headerDataEnd = std::min( headerStart + sizeof(MemoryAccessType), // Either at the end of the header headerDataStart + length // or whenever src runs out of data ); diff --git a/ion/src/device/shared/usb/stack/endpoint0.cpp b/ion/src/device/shared/usb/stack/endpoint0.cpp index 4e1d4e980..b97607e1b 100644 --- a/ion/src/device/shared/usb/stack/endpoint0.cpp +++ b/ion/src/device/shared/usb/stack/endpoint0.cpp @@ -4,8 +4,7 @@ #include "device.h" #include "interface.h" #include "request_recipient.h" - -#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#include namespace Ion { namespace Device { @@ -98,7 +97,7 @@ void Endpoint0::readAndDispatchSetupPacket() { }; m_request = SetupPacket(m_largeBuffer); - uint16_t maxBufferLength = MIN(m_request.wLength(), MaxTransferSize); + uint16_t maxBufferLength = std::min(m_request.wLength(), MaxTransferSize); // Forward the request to the request recipient uint8_t type = static_cast(m_request.recipientType()); @@ -261,7 +260,7 @@ void Endpoint0::clearForOutTransactions(uint16_t wLength) { int Endpoint0::receiveSomeData() { // If it is the first chunk of data to be received, m_transferBufferLength is 0. - uint16_t packetSize = MIN(k_maxPacketSize, m_request.wLength() - m_transferBufferLength); + uint16_t packetSize = std::min(k_maxPacketSize, m_request.wLength() - m_transferBufferLength); uint16_t sizeOfPacketRead = readPacket(m_largeBuffer + m_transferBufferLength, packetSize); if (sizeOfPacketRead != packetSize) { stallTransaction(); @@ -273,7 +272,7 @@ int Endpoint0::receiveSomeData() { uint16_t Endpoint0::readPacket(void * buffer, uint16_t length) { uint32_t * buffer32 = (uint32_t *) buffer; - uint16_t buffer32Length = MIN(length, m_receivedPacketSize); + uint16_t buffer32Length = std::min(length, m_receivedPacketSize); int i; // The RX FIFO is read 4 bytes by 4 bytes diff --git a/ion/src/shared/unicode/utf8_helper.cpp b/ion/src/shared/unicode/utf8_helper.cpp index 0f22a1380..6a3a94a8e 100644 --- a/ion/src/shared/unicode/utf8_helper.cpp +++ b/ion/src/shared/unicode/utf8_helper.cpp @@ -2,11 +2,10 @@ #include #include #include +#include namespace UTF8Helper { -static inline size_t minSizeT(size_t x, size_t y) { return x < y ? x : y; } - int CountOccurrences(const char * s, CodePoint c) { assert(c != UCodePointNull); int count = 0; @@ -174,7 +173,7 @@ size_t CopyUntilCodePoint(char * dst, size_t dstSize, const char * src, CodePoin codePointPointer = decoder.stringPosition(); codePoint = decoder.nextCodePoint(); } - size_t copySize = minSizeT(dstSize - 1, codePointPointer - src); + size_t copySize = std::min(dstSize - 1, codePointPointer - src); assert(UTF8Helper::CodePointIs(src + copySize, 0) || UTF8Helper::CodePointIs(src + copySize, c)); memmove(dst, src, copySize); assert(copySize < dstSize); diff --git a/kandinsky/src/rect.cpp b/kandinsky/src/rect.cpp index afad1fe48..f99a09076 100644 --- a/kandinsky/src/rect.cpp +++ b/kandinsky/src/rect.cpp @@ -1,7 +1,5 @@ #include - -static inline KDCoordinate minCoordinate(KDCoordinate x, KDCoordinate y) { return x < y ? x : y; } -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } +#include KDRect::KDRect(KDPoint p, KDSize s) : m_x(p.x()), m_y(p.y()), @@ -38,10 +36,10 @@ KDRect KDRect::intersectedWith(const KDRect & other) const { return KDRectZero; } - KDCoordinate intersectionLeft = maxCoordinate(left(), other.left()); - KDCoordinate intersectionRight = minCoordinate(right(), other.right()); - KDCoordinate intersectionTop = maxCoordinate(top(), other.top()); - KDCoordinate intersectionBottom = minCoordinate(bottom(), other.bottom()); + KDCoordinate intersectionLeft = std::max(left(), other.left()); + KDCoordinate intersectionRight = std::min(right(), other.right()); + KDCoordinate intersectionTop = std::max(top(), other.top()); + KDCoordinate intersectionBottom = std::min(bottom(), other.bottom()); return KDRect( intersectionLeft, @@ -57,8 +55,8 @@ void computeUnionBound(KDCoordinate size1, KDCoordinate size2, { if (size1 != 0) { if (size2 != 0) { - *outputMin = minCoordinate(min1, min2); - *outputMax = maxCoordinate(max1, max2); + *outputMin = std::min(min1, min2); + *outputMax = std::max(max1, max2); } else { *outputMin = min1; *outputMax = max1; diff --git a/poincare/src/binomial_coefficient_layout.cpp b/poincare/src/binomial_coefficient_layout.cpp index 962a42894..dd93b9e2e 100644 --- a/poincare/src/binomial_coefficient_layout.cpp +++ b/poincare/src/binomial_coefficient_layout.cpp @@ -4,11 +4,10 @@ #include #include #include +#include namespace Poincare { -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } - void BinomialCoefficientLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->position() == LayoutCursor::Position::Left && (cursor->layoutNode() == nLayout() @@ -79,7 +78,7 @@ int BinomialCoefficientLayoutNode::serialize(char * buffer, int bufferSize, Pref KDSize BinomialCoefficientLayoutNode::computeSize() { KDSize coefficientsSize = KDSize( - maxCoordinate(nLayout()->layoutSize().width(), kLayout()->layoutSize().width()), + std::max(nLayout()->layoutSize().width(), kLayout()->layoutSize().width()), knHeight()); KDCoordinate width = coefficientsSize.width() + 2*ParenthesisLayoutNode::ParenthesisWidth(); return KDSize(width, coefficientsSize.height()); @@ -90,7 +89,7 @@ KDCoordinate BinomialCoefficientLayoutNode::computeBaseline() { } KDPoint BinomialCoefficientLayoutNode::positionOfChild(LayoutNode * child) { - KDCoordinate horizontalCenter = ParenthesisLayoutNode::ParenthesisWidth() + maxCoordinate(nLayout()->layoutSize().width(), kLayout()->layoutSize().width())/2; + KDCoordinate horizontalCenter = ParenthesisLayoutNode::ParenthesisWidth() + std::max(nLayout()->layoutSize().width(), kLayout()->layoutSize().width())/2; if (child == nLayout()) { return KDPoint(horizontalCenter - nLayout()->layoutSize().width()/2, 0); } @@ -101,9 +100,9 @@ KDPoint BinomialCoefficientLayoutNode::positionOfChild(LayoutNode * child) { void BinomialCoefficientLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor, Layout * selectionStart, Layout * selectionEnd, KDColor selectionColor) { // Render the parentheses. KDCoordinate childHeight = knHeight(); - KDCoordinate rightParenthesisPointX = maxCoordinate(nLayout()->layoutSize().width(), kLayout()->layoutSize().width()) + LeftParenthesisLayoutNode::ParenthesisWidth(); + KDCoordinate rightParenthesisPointX = std::max(nLayout()->layoutSize().width(), kLayout()->layoutSize().width()) + LeftParenthesisLayoutNode::ParenthesisWidth(); LeftParenthesisLayoutNode::RenderWithChildHeight(childHeight, ctx, p, expressionColor, backgroundColor); RightParenthesisLayoutNode::RenderWithChildHeight(childHeight, ctx, p.translatedBy(KDPoint(rightParenthesisPointX, 0)), expressionColor, backgroundColor); } -} \ No newline at end of file +} diff --git a/poincare/src/bracket_layout.cpp b/poincare/src/bracket_layout.cpp index fa883e17c..c6287dc65 100644 --- a/poincare/src/bracket_layout.cpp +++ b/poincare/src/bracket_layout.cpp @@ -2,11 +2,10 @@ #include #include #include +#include namespace Poincare { -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } - void BracketLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { assert(cursor->layoutNode() == this); if (cursor->position() == LayoutCursor::Position::Right) { @@ -84,7 +83,7 @@ KDCoordinate BracketLayoutNode::computeBaseline() { { currentNumberOfOpenBrackets++; } - result = maxCoordinate(result, sibling->baseline()); + result = std::max(result, sibling->baseline()); } return result + (layoutSize().height() - childHeight()) / 2; } @@ -138,10 +137,10 @@ KDCoordinate BracketLayoutNode::computeChildHeight() { } KDCoordinate siblingHeight = sibling->layoutSize().height(); KDCoordinate siblingBaseline = sibling->baseline(); - maxUnderBaseline = maxCoordinate(maxUnderBaseline, siblingHeight - siblingBaseline); - maxAboveBaseline = maxCoordinate(maxAboveBaseline, siblingBaseline); + maxUnderBaseline = std::max(maxUnderBaseline, siblingHeight - siblingBaseline); + maxAboveBaseline = std::max(maxAboveBaseline, siblingBaseline); } - return maxCoordinate(result, maxUnderBaseline + maxAboveBaseline); + return std::max(result, maxUnderBaseline + maxAboveBaseline); } KDPoint BracketLayoutNode::positionOfChild(LayoutNode * child) { diff --git a/poincare/src/condensed_sum_layout.cpp b/poincare/src/condensed_sum_layout.cpp index 096699e9d..c1e72e88f 100644 --- a/poincare/src/condensed_sum_layout.cpp +++ b/poincare/src/condensed_sum_layout.cpp @@ -1,21 +1,20 @@ #include #include #include +#include namespace Poincare { -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } - KDCoordinate CondensedSumLayoutNode::computeBaseline() { - return baseLayout()->baseline() + maxCoordinate(0, superscriptLayout()->layoutSize().height() - baseLayout()->layoutSize().height()/2); + return baseLayout()->baseline() + std::max(0, superscriptLayout()->layoutSize().height() - baseLayout()->layoutSize().height()/2); } KDSize CondensedSumLayoutNode::computeSize() { KDSize baseSize = baseLayout()->layoutSize(); KDSize subscriptSize = subscriptLayout()->layoutSize(); KDSize superscriptSize = superscriptLayout()->layoutSize(); - KDCoordinate sizeWidth = baseSize.width() + maxCoordinate(subscriptSize.width(), superscriptSize.width()); - KDCoordinate sizeHeight = maxCoordinate(baseSize.height()/2, subscriptSize.height()) + maxCoordinate(baseSize.height()/2, superscriptSize.height()); + KDCoordinate sizeWidth = baseSize.width() + std::max(subscriptSize.width(), superscriptSize.width()); + KDCoordinate sizeHeight = std::max(baseSize.height()/2, subscriptSize.height()) + std::max(baseSize.height()/2, superscriptSize.height()); return KDSize(sizeWidth, sizeHeight); } @@ -25,11 +24,11 @@ KDPoint CondensedSumLayoutNode::positionOfChild(LayoutNode * child) { KDSize baseSize = baseLayout()->layoutSize(); KDSize superscriptSize = superscriptLayout()->layoutSize(); if (child == baseLayout()) { - y = maxCoordinate(0, superscriptSize.height() - baseSize.height()/2); + y = std::max(0, superscriptSize.height() - baseSize.height()/2); } if (child == subscriptLayout()) { x = baseSize.width(); - y = maxCoordinate(baseSize.height()/2, superscriptSize.height()); + y = std::max(baseSize.height()/2, superscriptSize.height()); } if (child == superscriptLayout()) { x = baseSize.width(); diff --git a/poincare/src/decimal.cpp b/poincare/src/decimal.cpp index da17e993d..d9abbc982 100644 --- a/poincare/src/decimal.cpp +++ b/poincare/src/decimal.cpp @@ -11,12 +11,10 @@ #include #include #include +#include namespace Poincare { -static inline int maxInt(int x, int y) { return x > y ? x : y; } -static inline int minInt(int x, int y) { return x < y ? x : y; } - void removeZeroAtTheEnd(Integer * i, int minimalNumbersOfDigits = -1) { /* Remove the zeroes at the end of an integer, respecting the minimum number * of digits asked for. @@ -204,7 +202,7 @@ int DecimalNode::convertToText(char * buffer, int bufferSize, Preferences::Print // Stop here if m is undef if (strcmp(tempBuffer, Undefined::Name()) == 0) { currentChar += strlcpy(buffer+currentChar, tempBuffer, bufferSize-currentChar); - return minInt(currentChar, bufferSize-1); + return std::min(currentChar, bufferSize-1); } /* We force scientific mode if the number of digits before the dot is superior @@ -216,7 +214,7 @@ int DecimalNode::convertToText(char * buffer, int bufferSize, Preferences::Print if (exponent < 0) { numberOfRequiredDigits = mantissaLength-exponent; } else { - numberOfRequiredDigits = maxInt(mantissaLength, exponent); + numberOfRequiredDigits = std::max(mantissaLength, exponent); } } @@ -269,7 +267,7 @@ int DecimalNode::convertToText(char * buffer, int bufferSize, Preferences::Print assert(UTF8Decoder::CharSizeOfCodePoint('.') == 1); assert(UTF8Decoder::CharSizeOfCodePoint('0') == 1); int deltaCharMantissa = exponent < 0 ? -exponent+1 : 0; - strlcpy(buffer+currentChar+deltaCharMantissa, tempBuffer, maxInt(0, bufferSize-deltaCharMantissa-currentChar)); + strlcpy(buffer+currentChar+deltaCharMantissa, tempBuffer, std::max(0, bufferSize-deltaCharMantissa-currentChar)); if (exponent < 0) { for (int i = 0; i <= -exponent; i++) { buffer[currentChar++] = i == 1 ? '.' : '0'; diff --git a/poincare/src/fraction_layout.cpp b/poincare/src/fraction_layout.cpp index bbde8cd6e..43dc8f7c3 100644 --- a/poincare/src/fraction_layout.cpp +++ b/poincare/src/fraction_layout.cpp @@ -5,11 +5,10 @@ #include #include #include +#include namespace Poincare { -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } - void FractionLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->position() == LayoutCursor::Position::Left && (cursor->layoutNode() == numeratorLayout() @@ -170,7 +169,7 @@ void FractionLayoutNode::didCollapseSiblings(LayoutCursor * cursor) { } KDSize FractionLayoutNode::computeSize() { - KDCoordinate width = maxCoordinate(numeratorLayout()->layoutSize().width(), denominatorLayout()->layoutSize().width()) + KDCoordinate width = std::max(numeratorLayout()->layoutSize().width(), denominatorLayout()->layoutSize().width()) + 2*Metric::FractionAndConjugateHorizontalOverflow+2*Metric::FractionAndConjugateHorizontalMargin; KDCoordinate height = numeratorLayout()->layoutSize().height() + k_fractionLineMargin + k_fractionLineHeight + k_fractionLineMargin diff --git a/poincare/src/grid_layout.cpp b/poincare/src/grid_layout.cpp index f09097d7b..06f0e0b17 100644 --- a/poincare/src/grid_layout.cpp +++ b/poincare/src/grid_layout.cpp @@ -1,11 +1,10 @@ #include #include #include +#include namespace Poincare { -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } - // LayoutNode void GridLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { @@ -219,7 +218,7 @@ KDCoordinate GridLayoutNode::rowBaseline(int i) { KDCoordinate rowBaseline = 0; int j = 0; for (LayoutNode * l : childrenFromIndex(i*m_numberOfColumns)) { - rowBaseline = maxCoordinate(rowBaseline, l->baseline()); + rowBaseline = std::max(rowBaseline, l->baseline()); j++; if (j >= m_numberOfColumns) { break; @@ -234,8 +233,8 @@ KDCoordinate GridLayoutNode::rowHeight(int i) const { int j = 0; for (LayoutNode * l : const_cast(this)->childrenFromIndex(i*m_numberOfColumns)) { KDCoordinate b = l->baseline(); - underBaseline = maxCoordinate(underBaseline, l->layoutSize().height() - b); - aboveBaseline = maxCoordinate(aboveBaseline, b); + underBaseline = std::max(underBaseline, l->layoutSize().height() - b); + aboveBaseline = std::max(aboveBaseline, b); j++; if (j >= m_numberOfColumns) { break; @@ -259,7 +258,7 @@ KDCoordinate GridLayoutNode::columnWidth(int j) const { int lastIndex = (m_numberOfRows-1)*m_numberOfColumns + j; for (LayoutNode * l : const_cast(this)->childrenFromIndex(j)) { if (childIndex%m_numberOfColumns == j) { - columnWidth = maxCoordinate(columnWidth, l->layoutSize().width()); + columnWidth = std::max(columnWidth, l->layoutSize().width()); if (childIndex >= lastIndex) { break; } diff --git a/poincare/src/horizontal_layout.cpp b/poincare/src/horizontal_layout.cpp index 88fb0bafd..32a974820 100644 --- a/poincare/src/horizontal_layout.cpp +++ b/poincare/src/horizontal_layout.cpp @@ -3,11 +3,10 @@ #include #include #include +#include namespace Poincare { -static inline KDCoordinate maxCoordinate(KDCoordinate c1, KDCoordinate c2) { return c1 > c2 ? c1 : c2; } - // LayoutNode void HorizontalLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { @@ -259,8 +258,8 @@ KDSize HorizontalLayoutNode::computeSize() { for (LayoutNode * l : children()) { KDSize childSize = l->layoutSize(); totalWidth += childSize.width(); - maxUnderBaseline = maxCoordinate(maxUnderBaseline, childSize.height() - l->baseline()); - maxAboveBaseline = maxCoordinate(maxAboveBaseline, l->baseline()); + maxUnderBaseline = std::max(maxUnderBaseline, childSize.height() - l->baseline()); + maxAboveBaseline = std::max(maxAboveBaseline, l->baseline()); } return KDSize(totalWidth, maxUnderBaseline + maxAboveBaseline); } @@ -268,7 +267,7 @@ KDSize HorizontalLayoutNode::computeSize() { KDCoordinate HorizontalLayoutNode::computeBaseline() { KDCoordinate result = 0; for (LayoutNode * l : children()) { - result = maxCoordinate(result, l->baseline()); + result = std::max(result, l->baseline()); } return result; } @@ -311,8 +310,8 @@ KDRect HorizontalLayoutNode::relativeSelectionRect(const Layout * selectionStart for (int i = firstSelectedNodeIndex; i <= secondSelectedNodeIndex; i++) { Layout childi = thisLayout.childAtIndex(i); KDSize childSize = childi.layoutSize(); - maxUnderBaseline = maxCoordinate(maxUnderBaseline, childSize.height() - childi.baseline()); - maxAboveBaseline = maxCoordinate(maxAboveBaseline, childi.baseline()); + maxUnderBaseline = std::max(maxUnderBaseline, childSize.height() - childi.baseline()); + maxAboveBaseline = std::max(maxAboveBaseline, childi.baseline()); } return KDRect(KDPoint(selectionXStart, const_cast(this)->baseline() - maxAboveBaseline), KDSize(drawWidth, maxUnderBaseline + maxAboveBaseline)); } diff --git a/poincare/src/integer.cpp b/poincare/src/integer.cpp index d442edce8..8eb8dc0c6 100644 --- a/poincare/src/integer.cpp +++ b/poincare/src/integer.cpp @@ -21,10 +21,9 @@ extern "C" { #if POINCARE_INTEGER_LOG #include #endif -namespace Poincare { +#include -static inline int minInt(int x, int y) { return x < y ? x : y; } -static inline int maxInt(int x, int y) { return x > y ? x : y; } +namespace Poincare { /* To compute operations between Integers, we need an array where to store the * result digits. Instead of allocating it on the stack which would eventually @@ -483,7 +482,7 @@ Integer Integer::multiplication(const Integer & a, const Integer & b, bool oneDi return Integer::Overflow(a.m_negative != b.m_negative); } - uint8_t size = minInt(a.numberOfDigits() + b.numberOfDigits(), k_maxNumberOfDigits + oneDigitOverflow); // Enable overflowing of 1 digit + uint8_t size = std::min(a.numberOfDigits() + b.numberOfDigits(), k_maxNumberOfDigits + oneDigitOverflow); // Enable overflowing of 1 digit memset(s_workingBuffer, 0, size*sizeof(native_uint_t)); @@ -552,7 +551,7 @@ Integer Integer::usum(const Integer & a, const Integer & b, bool subtract, bool return Overflow(a.m_negative != b.m_negative); } - uint8_t size = maxInt(a.numberOfDigits(), b.numberOfDigits()); + uint8_t size = std::max(a.numberOfDigits(), b.numberOfDigits()); if (!subtract) { // Addition can overflow size++; @@ -576,7 +575,7 @@ Integer Integer::usum(const Integer & a, const Integer & b, bool subtract, bool carry = (aDigit > result) || (bDigit > result); // There's been an overflow } } - size = minInt(size, k_maxNumberOfDigits+oneDigitOverflow); + size = std::min(size, k_maxNumberOfDigits+oneDigitOverflow); while (size>0 && s_workingBuffer[size-1] == 0) { size--; } @@ -655,7 +654,7 @@ IntegerDivision Integer::udiv(const Integer & numerator, const Integer & denomin // qDigits is a half_native_uint_t array and enable one digit overflow half_native_uint_t * qDigits = reinterpret_cast(s_workingBufferDivision); // The quotient q has at maximum m+1 half digits but we set an extra half digit to 0 to enable to easily convert it from half digits to digits - memset(qDigits, 0, maxInt(m+1+1,2*k_maxNumberOfDigits)*sizeof(half_native_uint_t)); + memset(qDigits, 0, std::max(m+1+1,2*k_maxNumberOfDigits)*sizeof(half_native_uint_t)); // betaMB = B*beta^m Integer betaMB = B.multiplyByPowerOfBase(m); if (Integer::NaturalOrder(A,betaMB) >= 0) { // A >= B*beta^m @@ -666,7 +665,7 @@ IntegerDivision Integer::udiv(const Integer & numerator, const Integer & denomin for (int j = m-1; j >= 0; j--) { native_uint_t qj2 = ((native_uint_t)A.halfDigit(n+j)*base+(native_uint_t)A.halfDigit(n+j-1))/(native_uint_t)B.halfDigit(n-1); // (a[n+j]*beta+a[n+j-1])/b[n-1] half_native_uint_t baseMinus1 = (1 << 16) -1; // beta-1 - qDigits[j] = qj2 < (native_uint_t)baseMinus1 ? (half_native_uint_t)qj2 : baseMinus1; // minInt(qj2, beta -1) + qDigits[j] = qj2 < (native_uint_t)baseMinus1 ? (half_native_uint_t)qj2 : baseMinus1; // std::min(qj2, beta -1) A = Integer::addition(A, multiplication(qDigits[j], B.multiplyByPowerOfBase(j), true), true, true); // A-q[j]*beta^j*B if (A.isNegative()) { Integer betaJM = B.multiplyByPowerOfBase(j); // betaJM = B*beta^j diff --git a/poincare/src/integral_layout.cpp b/poincare/src/integral_layout.cpp index ca5416202..b9524c489 100644 --- a/poincare/src/integral_layout.cpp +++ b/poincare/src/integral_layout.cpp @@ -4,11 +4,10 @@ #include #include #include +#include namespace Poincare { -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } - const uint8_t topSymbolPixel[IntegralLayoutNode::k_symbolHeight][IntegralLayoutNode::k_symbolWidth] = { {0x00, 0x00, 0xFF, 0xFF}, {0xFF, 0xFF, 0x00, 0xFF}, @@ -215,14 +214,14 @@ KDSize IntegralLayoutNode::computeSize() { KDSize differentialSize = differentialLayout()->layoutSize(); KDSize lowerBoundSize = lowerBoundLayout()->layoutSize(); KDSize upperBoundSize = upperBoundLayout()->layoutSize(); - KDCoordinate width = k_symbolWidth+k_lineThickness+k_boundWidthMargin+maxCoordinate(lowerBoundSize.width(), upperBoundSize.width())+k_integrandWidthMargin+integrandSize.width()+2*k_differentialWidthMargin+dSize.width()+differentialSize.width(); + KDCoordinate width = k_symbolWidth+k_lineThickness+k_boundWidthMargin+std::max(lowerBoundSize.width(), upperBoundSize.width())+k_integrandWidthMargin+integrandSize.width()+2*k_differentialWidthMargin+dSize.width()+differentialSize.width(); KDCoordinate baseline = computeBaseline(); - KDCoordinate height = baseline + k_integrandHeigthMargin+maxCoordinate(integrandSize.height()-integrandLayout()->baseline(), differentialSize.height()-differentialLayout()->baseline())+lowerBoundSize.height(); + KDCoordinate height = baseline + k_integrandHeigthMargin+std::max(integrandSize.height()-integrandLayout()->baseline(), differentialSize.height()-differentialLayout()->baseline())+lowerBoundSize.height(); return KDSize(width, height); } KDCoordinate IntegralLayoutNode::computeBaseline() { - return upperBoundLayout()->layoutSize().height() + k_integrandHeigthMargin + maxCoordinate(integrandLayout()->baseline(), differentialLayout()->baseline()); + return upperBoundLayout()->layoutSize().height() + k_integrandHeigthMargin + std::max(integrandLayout()->baseline(), differentialLayout()->baseline()); } KDPoint IntegralLayoutNode::positionOfChild(LayoutNode * child) { @@ -237,7 +236,7 @@ KDPoint IntegralLayoutNode::positionOfChild(LayoutNode * child) { x = k_symbolWidth+k_lineThickness+k_boundWidthMargin;; y = 0; } else if (child == integrandLayout()) { - x = k_symbolWidth +k_lineThickness+ k_boundWidthMargin+maxCoordinate(lowerBoundSize.width(), upperBoundSize.width())+k_integrandWidthMargin; + x = k_symbolWidth +k_lineThickness+ k_boundWidthMargin+std::max(lowerBoundSize.width(), upperBoundSize.width())+k_integrandWidthMargin; y = computeBaseline()-integrandLayout()->baseline(); } else if (child == differentialLayout()) { x = computeSize().width() - k_differentialWidthMargin - differentialLayout()->layoutSize().width(); @@ -252,7 +251,7 @@ void IntegralLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionCo KDSize integrandSize = integrandLayout()->layoutSize(); KDSize differentialSize = differentialLayout()->layoutSize(); KDSize upperBoundSize = upperBoundLayout()->layoutSize(); - KDCoordinate centralArgumentHeight = maxCoordinate(integrandLayout()->baseline(), differentialLayout()->baseline()) + maxCoordinate(integrandSize.height()-integrandLayout()->baseline(), differentialSize.height()-differentialLayout()->baseline()); + KDCoordinate centralArgumentHeight = std::max(integrandLayout()->baseline(), differentialLayout()->baseline()) + std::max(integrandSize.height()-integrandLayout()->baseline(), differentialSize.height()-differentialLayout()->baseline()); KDColor workingBuffer[k_symbolWidth*k_symbolHeight]; diff --git a/poincare/src/layout_cursor.cpp b/poincare/src/layout_cursor.cpp index d8dd73ca4..b4a4d7181 100644 --- a/poincare/src/layout_cursor.cpp +++ b/poincare/src/layout_cursor.cpp @@ -10,14 +10,13 @@ #include #include #include +#include #include namespace Poincare { /* Getters and setters */ -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } - KDCoordinate LayoutCursor::cursorHeightWithoutSelection() { KDCoordinate height = layoutHeight(); return height == 0 ? k_cursorHeight : height; @@ -35,7 +34,7 @@ KDCoordinate LayoutCursor::baselineWithoutSelection() { if (m_layout.hasChild(equivalentLayout)) { return equivalentLayout.baseline(); } else if (m_layout.hasSibling(equivalentLayout)) { - return maxCoordinate(layoutBaseline, equivalentLayout.baseline()); + return std::max(layoutBaseline, equivalentLayout.baseline()); } return layoutBaseline; } @@ -233,8 +232,8 @@ KDCoordinate LayoutCursor::layoutHeight() { KDCoordinate equivalentLayoutHeight = equivalentLayout.layoutSize().height(); KDCoordinate pointedLayoutBaseline = m_layout.baseline(); KDCoordinate equivalentLayoutBaseline = equivalentLayout.baseline(); - return maxCoordinate(pointedLayoutBaseline, equivalentLayoutBaseline) - + maxCoordinate(pointedLayoutHeight - pointedLayoutBaseline, equivalentLayoutHeight - equivalentLayoutBaseline); + return std::max(pointedLayoutBaseline, equivalentLayoutBaseline) + + std::max(pointedLayoutHeight - pointedLayoutBaseline, equivalentLayoutHeight - equivalentLayoutBaseline); } return pointedLayoutHeight; } diff --git a/poincare/src/matrix.cpp b/poincare/src/matrix.cpp index e37aeafcd..b310b1ef0 100644 --- a/poincare/src/matrix.cpp +++ b/poincare/src/matrix.cpp @@ -15,11 +15,10 @@ #include #include #include +#include namespace Poincare { -static inline int minInt(int x, int y) { return x < y ? x : y; } - bool MatrixNode::hasMatrixChild(Context * context) const { for (ExpressionNode * c : children()) { if (Expression(c).deepIsMatrix(context)) { @@ -93,7 +92,7 @@ int MatrixNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloat } } currentChar += SerializationHelper::CodePoint(buffer + currentChar, bufferSize - currentChar, ']'); - return minInt(currentChar, bufferSize-1); + return std::min(currentChar, bufferSize-1); } template diff --git a/poincare/src/matrix_layout.cpp b/poincare/src/matrix_layout.cpp index cd08c0e17..bb1b05a01 100644 --- a/poincare/src/matrix_layout.cpp +++ b/poincare/src/matrix_layout.cpp @@ -4,11 +4,10 @@ #include #include #include +#include namespace Poincare { -static inline int minInt(int x, int y) { return x < y ? x : y; } - // MatrixLayoutNode void MatrixLayoutNode::addGreySquares() { @@ -164,7 +163,7 @@ int MatrixLayoutNode::serialize(char * buffer, int bufferSize, Preferences::Prin // Write the final closing bracket numberOfChar += SerializationHelper::CodePoint(buffer + numberOfChar, bufferSize - numberOfChar, ']'); - return minInt(numberOfChar, bufferSize-1); + return std::min(numberOfChar, bufferSize-1); } // Protected diff --git a/poincare/src/multiplication.cpp b/poincare/src/multiplication.cpp index 63f2d35be..382b9e2e9 100644 --- a/poincare/src/multiplication.cpp +++ b/poincare/src/multiplication.cpp @@ -19,6 +19,7 @@ #include #include #include +#include namespace Poincare { @@ -90,8 +91,6 @@ Expression MultiplicationNode::setSign(Sign s, ReductionContext reductionContext return Multiplication(this).setSign(s, reductionContext); } -static inline int maxInt(int x, int y) { return x > y ? x : y; } - /* Operative symbol between two expressions depends on the layout shape on the * left and the right of the operator: * @@ -181,7 +180,7 @@ CodePoint MultiplicationNode::operatorSymbol() const { for (int i = 0; i < numberOfChildren() - 1; i++) { /* The operator symbol must be the same for all operands of the multiplication. * If one operator has to be '×', they will all be '×'. Idem for '·'. */ - sign = maxInt(sign, operatorSymbolBetween(childAtIndex(i)->rightLayoutShape(), childAtIndex(i+1)->leftLayoutShape())); + sign = std::max(sign, operatorSymbolBetween(childAtIndex(i)->rightLayoutShape(), childAtIndex(i+1)->leftLayoutShape())); } switch (sign) { case 0: diff --git a/poincare/src/nth_root_layout.cpp b/poincare/src/nth_root_layout.cpp index 807c15449..0ac4e4c98 100644 --- a/poincare/src/nth_root_layout.cpp +++ b/poincare/src/nth_root_layout.cpp @@ -4,11 +4,10 @@ #include #include #include +#include namespace Poincare { -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } - const uint8_t radixPixel[NthRootLayoutNode::k_leftRadixHeight][NthRootLayoutNode::k_leftRadixWidth] = { {0x51, 0xCC, 0xFF, 0xFF, 0xFF}, {0x96, 0x37, 0xFD, 0xFF, 0xFF}, @@ -180,7 +179,7 @@ KDSize NthRootLayoutNode::computeSize() { } KDCoordinate NthRootLayoutNode::computeBaseline() { - return maxCoordinate( + return std::max( radicandLayout()->baseline() + k_radixLineThickness + k_heightMargin, adjustedIndexSize().height()); } @@ -204,7 +203,7 @@ KDPoint NthRootLayoutNode::positionOfChild(LayoutNode * child) { KDSize NthRootLayoutNode::adjustedIndexSize() { return indexLayout() == nullptr ? KDSize(k_leftRadixWidth, 0) : - KDSize(maxCoordinate(k_leftRadixWidth, indexLayout()->layoutSize().width()), indexLayout()->layoutSize().height()); + KDSize(std::max(k_leftRadixWidth, indexLayout()->layoutSize().width()), indexLayout()->layoutSize().height()); } void NthRootLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor, Layout * selectionStart, Layout * selectionEnd, KDColor selectionColor) { diff --git a/poincare/src/parsing/parser.cpp b/poincare/src/parsing/parser.cpp index 1f7d63d90..2b8873bd1 100644 --- a/poincare/src/parsing/parser.cpp +++ b/poincare/src/parsing/parser.cpp @@ -1,11 +1,10 @@ #include "parser.h" #include #include +#include namespace Poincare { -static inline Token::Type maxToken(Token::Type x, Token::Type y) { return ((int)x > (int) y ? x : y); } - constexpr const Expression::FunctionHelper * Parser::s_reservedFunctions[]; Expression Parser::parse() { @@ -185,7 +184,7 @@ void Parser::parseEmpty(Expression & leftHandSide, Token::Type stoppingType) { void Parser::parseMinus(Expression & leftHandSide, Token::Type stoppingType) { if (leftHandSide.isUninitialized()) { - Expression rightHandSide = parseUntil(maxToken(stoppingType, Token::Minus)); + Expression rightHandSide = parseUntil(std::max(stoppingType, Token::Minus)); if (m_status != Status::Progress) { return; } diff --git a/poincare/src/print_float.cpp b/poincare/src/print_float.cpp index fefad549d..3957a1a53 100644 --- a/poincare/src/print_float.cpp +++ b/poincare/src/print_float.cpp @@ -15,11 +15,10 @@ extern "C" { #include } #include +#include namespace Poincare { -static inline int minInt(int x, int y) { return x < y ? x : y; } - PrintFloat::Long::Long(int64_t i) : m_negative(i < 0) { @@ -79,7 +78,7 @@ int PrintFloat::Long::serialize(char * buffer, int bufferSize) const { * terminating char. */ return wantedNumberOfChars; } - numberOfChars+= PrintInt::Right(m_digits[1], buffer + numberOfChars, minInt(k_maxNumberOfCharsForDigit, bufferSize - numberOfChars - 1)); + numberOfChars+= PrintInt::Right(m_digits[1], buffer + numberOfChars, std::min(k_maxNumberOfCharsForDigit, bufferSize - numberOfChars - 1)); } else { numberOfChars+= PrintInt::Left(m_digits[1], buffer + numberOfChars, bufferSize - numberOfChars - 1); } @@ -167,7 +166,7 @@ PrintFloat::TextLengths PrintFloat::ConvertFloatToTextPrivate(T f, char * buffer assert(numberOfSignificantDigits > 0); assert(bufferSize > 0); assert(glyphLength > 0 && glyphLength <= k_maxFloatGlyphLength); - int availableCharLength = minInt(bufferSize-1, glyphLength); + int availableCharLength = std::min(bufferSize-1, glyphLength); TextLengths exceptionResult = {.CharLength = bufferSize, .GlyphLength = glyphLength+1}; //TODO: accelerate for f between 0 and 10 ? if (std::isinf(f)) { diff --git a/poincare/src/product_layout.cpp b/poincare/src/product_layout.cpp index 6333c6735..190916813 100644 --- a/poincare/src/product_layout.cpp +++ b/poincare/src/product_layout.cpp @@ -1,11 +1,10 @@ #include #include #include +#include namespace Poincare { -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } - int ProductLayoutNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return SequenceLayoutNode::writeDerivedClassInBuffer("product", buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits); } @@ -16,14 +15,14 @@ void ProductLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionCol KDSize lowerBoundNEqualsSize = lowerBoundSizeWithVariableEquals(); // Render the Product symbol. - ctx->fillRect(KDRect(p.x() + maxCoordinate(maxCoordinate(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundNEqualsSize.width()-k_symbolWidth)/2), - p.y() + maxCoordinate(upperBoundSize.height()+k_boundHeightMargin, argumentLayout()->baseline()-(k_symbolHeight+1)/2), + ctx->fillRect(KDRect(p.x() + std::max(std::max(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundNEqualsSize.width()-k_symbolWidth)/2), + p.y() + std::max(upperBoundSize.height()+k_boundHeightMargin, argumentLayout()->baseline()-(k_symbolHeight+1)/2), k_lineThickness, k_symbolHeight), expressionColor); - ctx->fillRect(KDRect(p.x() + maxCoordinate(maxCoordinate(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundNEqualsSize.width()-k_symbolWidth)/2), - p.y() + maxCoordinate(upperBoundSize.height()+k_boundHeightMargin, argumentLayout()->baseline()-(k_symbolHeight+1)/2), + ctx->fillRect(KDRect(p.x() + std::max(std::max(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundNEqualsSize.width()-k_symbolWidth)/2), + p.y() + std::max(upperBoundSize.height()+k_boundHeightMargin, argumentLayout()->baseline()-(k_symbolHeight+1)/2), k_symbolWidth, k_lineThickness), expressionColor); - ctx->fillRect(KDRect(p.x() + maxCoordinate(maxCoordinate(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundNEqualsSize.width()-k_symbolWidth)/2)+k_symbolWidth, - p.y() + maxCoordinate(upperBoundSize.height()+k_boundHeightMargin, argumentLayout()->baseline()-(k_symbolHeight+1)/2), + ctx->fillRect(KDRect(p.x() + std::max(std::max(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundNEqualsSize.width()-k_symbolWidth)/2)+k_symbolWidth, + p.y() + std::max(upperBoundSize.height()+k_boundHeightMargin, argumentLayout()->baseline()-(k_symbolHeight+1)/2), k_lineThickness, k_symbolHeight), expressionColor); // Render the "n=" and the parentheses. diff --git a/poincare/src/sequence_layout.cpp b/poincare/src/sequence_layout.cpp index 9ada97de5..348719612 100644 --- a/poincare/src/sequence_layout.cpp +++ b/poincare/src/sequence_layout.cpp @@ -4,11 +4,10 @@ #include #include #include +#include namespace Poincare { -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } - void SequenceLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->layoutNode() == upperBoundLayout()) { @@ -160,7 +159,7 @@ KDSize SequenceLayoutNode::lowerBoundSizeWithVariableEquals() { KDSize equalSize = k_font->stringSize(k_equal); return KDSize( variableSize.width() + equalSize.width() + lowerBoundSize.width(), - subscriptBaseline() + maxCoordinate(maxCoordinate(variableSize.height() - variableLayout()->baseline(), lowerBoundSize.height() - lowerBoundLayout()->baseline()), equalSize.height()/2)); + subscriptBaseline() + std::max(std::max(variableSize.height() - variableLayout()->baseline(), lowerBoundSize.height() - lowerBoundLayout()->baseline()), equalSize.height()/2)); } KDSize SequenceLayoutNode::computeSize() { @@ -171,13 +170,13 @@ KDSize SequenceLayoutNode::computeSize() { argumentSize.width() + 2*ParenthesisLayoutNode::ParenthesisWidth(), ParenthesisLayoutNode::HeightGivenChildHeight(argumentSize.height())); KDSize result = KDSize( - maxCoordinate(maxCoordinate(k_symbolWidth, totalLowerBoundSize.width()), upperBoundSize.width())+k_argumentWidthMargin+argumentSizeWithParentheses.width(), - baseline() + maxCoordinate(k_symbolHeight/2+k_boundHeightMargin+totalLowerBoundSize.height(), argumentSizeWithParentheses.height() - argumentLayout()->baseline())); + std::max(std::max(k_symbolWidth, totalLowerBoundSize.width()), upperBoundSize.width())+k_argumentWidthMargin+argumentSizeWithParentheses.width(), + baseline() + std::max(k_symbolHeight/2+k_boundHeightMargin+totalLowerBoundSize.height(), argumentSizeWithParentheses.height() - argumentLayout()->baseline())); return result; } KDCoordinate SequenceLayoutNode::computeBaseline() { - return maxCoordinate(upperBoundLayout()->layoutSize().height()+k_boundHeightMargin+(k_symbolHeight+1)/2, argumentLayout()->baseline()); + return std::max(upperBoundLayout()->layoutSize().height()+k_boundHeightMargin+(k_symbolHeight+1)/2, argumentLayout()->baseline()); } KDPoint SequenceLayoutNode::positionOfChild(LayoutNode * l) { @@ -193,10 +192,10 @@ KDPoint SequenceLayoutNode::positionOfChild(LayoutNode * l) { x = completeLowerBoundX() + equalSize.width() + variableSize.width(); y = baseline() + k_symbolHeight/2 + k_boundHeightMargin + subscriptBaseline() - lowerBoundLayout()->baseline(); } else if (l == upperBoundLayout()) { - x = maxCoordinate(maxCoordinate(0, (k_symbolWidth-upperBoundSize.width())/2), (lowerBoundSizeWithVariableEquals().width()-upperBoundSize.width())/2); + x = std::max(std::max(0, (k_symbolWidth-upperBoundSize.width())/2), (lowerBoundSizeWithVariableEquals().width()-upperBoundSize.width())/2); y = baseline() - (k_symbolHeight+1)/2- k_boundHeightMargin-upperBoundSize.height(); } else if (l == argumentLayout()) { - x = maxCoordinate(maxCoordinate(k_symbolWidth, lowerBoundSizeWithVariableEquals().width()), upperBoundSize.width())+k_argumentWidthMargin+ParenthesisLayoutNode::ParenthesisWidth(); + x = std::max(std::max(k_symbolWidth, lowerBoundSizeWithVariableEquals().width()), upperBoundSize.width())+k_argumentWidthMargin+ParenthesisLayoutNode::ParenthesisWidth(); y = baseline() - argumentLayout()->baseline(); } else { assert(false); @@ -267,12 +266,12 @@ void SequenceLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionCo KDCoordinate SequenceLayoutNode::completeLowerBoundX() { KDSize upperBoundSize = upperBoundLayout()->layoutSize(); - return maxCoordinate(maxCoordinate(0, (k_symbolWidth-lowerBoundSizeWithVariableEquals().width())/2), + return std::max(std::max(0, (k_symbolWidth-lowerBoundSizeWithVariableEquals().width())/2), (upperBoundSize.width()-lowerBoundSizeWithVariableEquals().width())/2); } KDCoordinate SequenceLayoutNode::subscriptBaseline() { - return maxCoordinate(maxCoordinate(variableLayout()->baseline(), lowerBoundLayout()->baseline()), k_font->stringSize(k_equal).height()/2); + return std::max(std::max(variableLayout()->baseline(), lowerBoundLayout()->baseline()), k_font->stringSize(k_equal).height()/2); } } diff --git a/poincare/src/sum_layout.cpp b/poincare/src/sum_layout.cpp index 9d7cda716..64e27437c 100644 --- a/poincare/src/sum_layout.cpp +++ b/poincare/src/sum_layout.cpp @@ -1,11 +1,10 @@ #include #include #include +#include namespace Poincare { -static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } - const uint8_t symbolPixel[SumLayoutNode::k_symbolHeight][SumLayoutNode::k_symbolWidth] = { {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, @@ -36,8 +35,8 @@ void SumLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionColor, // Render the Sum symbol. KDColor workingBuffer[k_symbolWidth*k_symbolHeight]; - KDRect symbolFrame(p.x() + maxCoordinate(maxCoordinate(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundNEqualsSize.width()-k_symbolWidth)/2), - p.y() + maxCoordinate(upperBoundSize.height()+k_boundHeightMargin, argumentLayout()->baseline()-(k_symbolHeight+1)/2), + KDRect symbolFrame(p.x() + std::max(std::max(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundNEqualsSize.width()-k_symbolWidth)/2), + p.y() + std::max(upperBoundSize.height()+k_boundHeightMargin, argumentLayout()->baseline()-(k_symbolHeight+1)/2), k_symbolWidth, k_symbolHeight); ctx->blendRectWithMask(symbolFrame, expressionColor, (const uint8_t *)symbolPixel, (KDColor *)workingBuffer); diff --git a/poincare/src/symbol_abstract.cpp b/poincare/src/symbol_abstract.cpp index a6708fdee..998c88620 100644 --- a/poincare/src/symbol_abstract.cpp +++ b/poincare/src/symbol_abstract.cpp @@ -9,10 +9,11 @@ #include #include #include +#include namespace Poincare { -static inline int minInt(int x, int y) { return x < y ? x : y; } +static inline int std::min(int x, int y) { return x < y ? x : y; } size_t SymbolAbstractNode::size() const { return nodeSize() + strlen(name()) + 1; @@ -41,7 +42,7 @@ int SymbolAbstractNode::simplificationOrderSameType(const ExpressionNode * e, bo } int SymbolAbstractNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { - return minInt(strlcpy(buffer, name(), bufferSize), bufferSize - 1); + return std::min(strlcpy(buffer, name(), bufferSize), bufferSize - 1); } template diff --git a/poincare/src/undefined.cpp b/poincare/src/undefined.cpp index 0a7a8c1a6..c322d8c13 100644 --- a/poincare/src/undefined.cpp +++ b/poincare/src/undefined.cpp @@ -1,6 +1,7 @@ #include #include #include +#include extern "C" { #include @@ -9,8 +10,6 @@ extern "C" { namespace Poincare { -static inline int minInt(int x, int y) { return x < y ? x : y; } - int UndefinedNode::polynomialDegree(Context * context, const char * symbolName) const { return -1; } @@ -25,7 +24,7 @@ Layout UndefinedNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, } int UndefinedNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { - return minInt(strlcpy(buffer, Undefined::Name(), bufferSize), bufferSize - 1); + return std::min(strlcpy(buffer, Undefined::Name(), bufferSize), bufferSize - 1); } template Evaluation UndefinedNode::templatedApproximate() const { diff --git a/poincare/src/unit.cpp b/poincare/src/unit.cpp index ff31c1cdb..0ffc4a2f6 100644 --- a/poincare/src/unit.cpp +++ b/poincare/src/unit.cpp @@ -10,15 +10,15 @@ #include #include #include +#include namespace Poincare { static inline int absInt(int x) { return x >= 0 ? x : -x; } -static inline int minInt(int x, int y) { return x < y ? x : y; } int UnitNode::Prefix::serialize(char * buffer, int bufferSize) const { assert(bufferSize >= 0); - return minInt(strlcpy(buffer, m_symbol, bufferSize), bufferSize - 1); + return std::min(strlcpy(buffer, m_symbol, bufferSize), bufferSize - 1); } bool UnitNode::Representative::canParse(const char * symbol, size_t length, @@ -51,7 +51,7 @@ int UnitNode::Representative::serialize(char * buffer, int bufferSize, const Pre bufferSize -= length; } assert(bufferSize >= 0); - length += minInt(strlcpy(buffer, m_rootSymbol, bufferSize), bufferSize - 1); + length += std::min(strlcpy(buffer, m_rootSymbol, bufferSize), bufferSize - 1); return length; } @@ -134,7 +134,7 @@ Layout UnitNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int int UnitNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { assert(bufferSize >= 0); - int underscoreLength = minInt(strlcpy(buffer, "_", bufferSize), bufferSize - 1); + int underscoreLength = std::min(strlcpy(buffer, "_", bufferSize), bufferSize - 1); buffer += underscoreLength; bufferSize -= underscoreLength; return underscoreLength + m_representative->serialize(buffer, bufferSize, m_prefix); diff --git a/poincare/src/unreal.cpp b/poincare/src/unreal.cpp index ca2a9ddd8..c71721f0f 100644 --- a/poincare/src/unreal.cpp +++ b/poincare/src/unreal.cpp @@ -1,5 +1,6 @@ #include #include +#include extern "C" { #include @@ -8,14 +9,12 @@ extern "C" { namespace Poincare { -static inline int minInt(int x, int y) { return x < y ? x : y; } - Layout UnrealNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::String(Unreal::Name(), Unreal::NameSize()-1); } int UnrealNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { - return minInt(strlcpy(buffer, Unreal::Name(), bufferSize), bufferSize - 1); + return std::min(strlcpy(buffer, Unreal::Name(), bufferSize), bufferSize - 1); } } diff --git a/poincare/src/vertical_offset_layout.cpp b/poincare/src/vertical_offset_layout.cpp index df163f402..40d6571ff 100644 --- a/poincare/src/vertical_offset_layout.cpp +++ b/poincare/src/vertical_offset_layout.cpp @@ -5,11 +5,10 @@ #include #include #include +#include namespace Poincare { -static inline int minInt(int x, int y) { return x < y ? x : y; } - void VerticalOffsetLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->layoutNode() == indiceLayout() && cursor->position() == LayoutCursor::Position::Left) @@ -165,7 +164,7 @@ int VerticalOffsetLayoutNode::serialize(char * buffer, int bufferSize, Preferenc if (numberOfChar >= bufferSize-1) { return bufferSize-1; } numberOfChar += SerializationHelper::CodePoint(buffer+numberOfChar, bufferSize-numberOfChar, '}'); - return minInt(numberOfChar, bufferSize-1); + return std::min(numberOfChar, bufferSize-1); } assert(m_position == Position::Superscript); @@ -177,7 +176,7 @@ int VerticalOffsetLayoutNode::serialize(char * buffer, int bufferSize, Preferenc numberOfChar += const_cast(this)->indiceLayout()->serialize(buffer+numberOfChar, bufferSize-numberOfChar, floatDisplayMode, numberOfSignificantDigits); if (numberOfChar >= bufferSize-1) { return bufferSize-1; } numberOfChar += SerializationHelper::CodePoint(buffer+numberOfChar, bufferSize-numberOfChar, UCodePointRightSystemParenthesis); - return minInt(numberOfChar, bufferSize-1); + return std::min(numberOfChar, bufferSize-1); } KDSize VerticalOffsetLayoutNode::computeSize() { diff --git a/python/port/mod/matplotlib/pyplot/plot_store.cpp b/python/port/mod/matplotlib/pyplot/plot_store.cpp index 9647044b6..de5996894 100644 --- a/python/port/mod/matplotlib/pyplot/plot_store.cpp +++ b/python/port/mod/matplotlib/pyplot/plot_store.cpp @@ -1,4 +1,5 @@ #include "plot_store.h" +#include namespace Matplotlib { @@ -160,15 +161,12 @@ void PlotStore::addLabel(mp_obj_t x, mp_obj_t y, mp_obj_t string) { // Axes -static inline float minFloat(float x, float y) { return x < y ? x : y; } -static inline float maxFloat(float x, float y) { return x > y ? x : y; } - void updateRange(float * xMin, float * xMax, float * yMin, float * yMax, float x, float y) { if (!std::isnan(x) && !std::isinf(x) && !std::isnan(y) && !std::isinf(y)) { - *xMin = minFloat(*xMin, x); - *xMax = maxFloat(*xMax, x); - *yMin = minFloat(*yMin, y); - *yMax = maxFloat(*yMax, y); + *xMin = std::min(*xMin, x); + *xMax = std::max(*xMax, x); + *yMin = std::min(*yMin, y); + *yMax = std::max(*yMax, y); } } diff --git a/python/port/mod/matplotlib/pyplot/plot_view.cpp b/python/port/mod/matplotlib/pyplot/plot_view.cpp index 76daa005a..2d7ae9c50 100644 --- a/python/port/mod/matplotlib/pyplot/plot_view.cpp +++ b/python/port/mod/matplotlib/pyplot/plot_view.cpp @@ -1,4 +1,5 @@ #include "plot_view.h" +#include namespace Matplotlib { @@ -52,7 +53,6 @@ void PlotView::traceSegment(KDContext * ctx, KDRect r, PlotStore::Segment segmen } } -static inline KDCoordinate maxKDCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } void PlotView::traceRect(KDContext * ctx, KDRect r, PlotStore::Rect rect) const { KDCoordinate left = std::round(floatToPixel(Axis::Horizontal, rect.left())); KDCoordinate right = std::round(floatToPixel(Axis::Horizontal, rect.right())); @@ -61,7 +61,7 @@ void PlotView::traceRect(KDContext * ctx, KDRect r, PlotStore::Rect rect) const KDRect pixelRect( left, top, - maxKDCoordinate(right - left, 1), // Rectangle should at least be visible + std::max(right - left, 1), // Rectangle should at least be visible bottom - top ); ctx->fillRect(pixelRect, rect.color());