Use std::min and std::max

This commit is contained in:
Romain Goyet
2020-04-12 15:43:39 -04:00
committed by Ecco
parent 77ee5126e1
commit 950862f8d0
79 changed files with 297 additions and 406 deletions

View File

@@ -1,4 +1,5 @@
#include "plot_store.h"
#include <algorithm>
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);
}
}

View File

@@ -1,4 +1,5 @@
#include "plot_view.h"
#include <algorithm>
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());