From 26fdfcd25c26c375695c2b82e31e65b95dc38153 Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Thu, 22 Oct 2020 14:05:31 +0200 Subject: [PATCH] [curve_view] Fixed variable names Change-Id: I8aad13c6bce719ba8f3a30cd86f06f7c89ec041e --- apps/shared/curve_view.cpp | 36 ++++++++++++++++-------------------- apps/shared/curve_view.h | 10 +++++----- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/apps/shared/curve_view.cpp b/apps/shared/curve_view.cpp index 0dacaba14..5672bc562 100644 --- a/apps/shared/curve_view.cpp +++ b/apps/shared/curve_view.cpp @@ -602,7 +602,7 @@ const uint8_t thickStampMask[(thickStampSize+1)*(thickStampSize+1)] = { constexpr static int k_maxNumberOfIterations = 10; -void CurveView::drawCurve(KDContext * ctx, KDRect rect, float tStart, float tEnd, float tStep, EvaluateXYForParameter xyEvaluation, void * model, void * context, bool drawStraightLinesEarly, KDColor color, bool thick, bool colorUnderCurve, float colorLowerBound, float colorUpperBound, EvaluateXYForParameterDouble xyEvaluationDouble) const { +void CurveView::drawCurve(KDContext * ctx, KDRect rect, float tStart, float tEnd, float tStep, EvaluateXYForFloatParameter xyFloatEvaluation, void * model, void * context, bool drawStraightLinesEarly, KDColor color, bool thick, bool colorUnderCurve, float colorLowerBound, float colorUpperBound, EvaluateXYForDoubleParameter xyDoubleEvaluation) const { float previousT = NAN; float t = NAN; float previousX = NAN; @@ -624,17 +624,17 @@ void CurveView::drawCurve(KDContext * ctx, KDRect rect, float tStart, float tEnd } previousX = x; previousY = y; - Coordinate2D xy = xyEvaluation(t, model, context); + Coordinate2D xy = xyFloatEvaluation(t, model, context); 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, 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, xyEvaluationDouble); + joinDots(ctx, rect, xyFloatEvaluation, model, context, drawStraightLinesEarly, previousT, previousX, previousY, t, x, y, color, thick, k_maxNumberOfIterations, xyDoubleEvaluation); } while (true); } -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, EvaluateXYForParameterDouble xyEvaluationDouble) const { +void CurveView::drawCartesianCurve(KDContext * ctx, KDRect rect, float xMin, float xMax, EvaluateXYForFloatParameter xyFloatEvaluation, void * model, void * context, KDColor color, bool thick, bool colorUnderCurve, float colorLowerBound, float colorUpperBound, EvaluateXYForDoubleParameter xyDoubleEvaluation) 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 : std::max(xMin, rectLeft); @@ -644,7 +644,7 @@ void CurveView::drawCartesianCurve(KDContext * ctx, KDRect rect, float xMin, flo return; } float tStep = pixelWidth(); - drawCurve(ctx, rect, tStart, tEnd, tStep, xyEvaluation, model, context, true, color, thick, colorUnderCurve, colorLowerBound, colorUpperBound, xyEvaluationDouble); + drawCurve(ctx, rect, tStart, tEnd, tStep, xyFloatEvaluation, model, context, true, color, thick, colorUnderCurve, colorLowerBound, colorUpperBound, xyDoubleEvaluation); } void CurveView::drawHistogram(KDContext * ctx, KDRect rect, EvaluateYForX yEvaluation, void * model, void * context, float firstBarAbscissa, float barWidth, @@ -685,7 +685,7 @@ void CurveView::drawHistogram(KDContext * ctx, KDRect rect, EvaluateYForX yEvalu } } -void CurveView::joinDots(KDContext * ctx, KDRect rect, EvaluateXYForParameter xyEvaluation , void * model, void * context, bool drawStraightLinesEarly, float t, float x, float y, float s, float u, float v, KDColor color, bool thick, int maxNumberOfRecursion, EvaluateXYForParameterDouble xyEvaluationDouble) const { +void CurveView::joinDots(KDContext * ctx, KDRect rect, EvaluateXYForFloatParameter xyFloatEvaluation , void * model, void * context, bool drawStraightLinesEarly, float t, float x, float y, float s, float u, float v, KDColor color, bool thick, int maxNumberOfRecursion, EvaluateXYForDoubleParameter xyDoubleEvaluation) const { const bool isFirstDot = std::isnan(t); const bool isLeftDotValid = !( std::isnan(x) || std::isinf(x) || @@ -709,19 +709,15 @@ void CurveView::joinDots(KDContext * ctx, KDRect rect, EvaluateXYForParameter xy || (isLeftDotValid && deltaX*deltaX + deltaY*deltaY < circleDiameter * circleDiameter / 4.0f)) { // the dots are already close enough // the dots are already joined /* We need to be sure that the point is not an artifact caused by error - * in float approximation. The value of pixelTolerance matters little, - * as wrong points will be off by a large margin. */ - constexpr float pixelTolerance = 1.f; - float pvD = xyEvaluationDouble ? floatToPixel(Axis::Vertical, static_cast(xyEvaluationDouble(u, model, context).x2())) : pvf; - if (std::fabs(pvf - pvD) < pixelTolerance) { - stampAtLocation(ctx, rect, puf, pvf, color, thick); - } + * in float approximation. */ + float pvd = xyDoubleEvaluation ? floatToPixel(Axis::Vertical, static_cast(xyDoubleEvaluation(u, model, context).x2())) : pvf; + stampAtLocation(ctx, rect, puf, pvd, color, thick); return; } } // Middle point float ct = (t + s)/2.0f; - Coordinate2D cxy = xyEvaluation(ct, model, context); + Coordinate2D cxy = xyFloatEvaluation(ct, model, context); float cx = cxy.x1(); float cy = cxy.x2(); if ((drawStraightLinesEarly || maxNumberOfRecursion == 0) && isRightDotValid && isLeftDotValid && @@ -730,12 +726,12 @@ void CurveView::joinDots(KDContext * ctx, KDRect rect, EvaluateXYForParameter xy * can draw a 'straight' line between the two */ constexpr float dangerousSlope = 1e6f; - if (xyEvaluationDouble && std::fabs((v-y) / (u-x)) > dangerousSlope) { + if (xyDoubleEvaluation && std::fabs((v-y) / (u-x)) > dangerousSlope) { /* We need to make sure we're not drawing a vertical asymptote because of * rounding errors. */ - Coordinate2D xyD = xyEvaluationDouble(static_cast(t), model, context); - Coordinate2D uvD = xyEvaluationDouble(static_cast(s), model, context); - Coordinate2D cxyD = xyEvaluationDouble(static_cast(ct), model, context); + Coordinate2D xyD = xyDoubleEvaluation(static_cast(t), model, context); + Coordinate2D uvD = xyDoubleEvaluation(static_cast(s), model, context); + Coordinate2D cxyD = xyDoubleEvaluation(static_cast(ct), model, context); if (((xyD.x1() <= cxyD.x1() && cxyD.x1() <= uvD.x1()) || (uvD.x1() <= cxyD.x1() && cxyD.x1() <= xyD.x1())) && ((xyD.x2() <= cxyD.x2() && cxyD.x2() <= uvD.x2()) || (uvD.x2() <= cxyD.x2() && cxyD.x2() <= xyD.x2()))) { @@ -748,8 +744,8 @@ void CurveView::joinDots(KDContext * ctx, KDRect rect, EvaluateXYForParameter xy } } if (maxNumberOfRecursion > 0) { - joinDots(ctx, rect, xyEvaluation, model, context, drawStraightLinesEarly, t, x, y, ct, cx, cy, color, thick, maxNumberOfRecursion-1, xyEvaluationDouble); - joinDots(ctx, rect, xyEvaluation, model, context, drawStraightLinesEarly, ct, cx, cy, s, u, v, color, thick, maxNumberOfRecursion-1, xyEvaluationDouble); + joinDots(ctx, rect, xyFloatEvaluation, model, context, drawStraightLinesEarly, t, x, y, ct, cx, cy, color, thick, maxNumberOfRecursion-1, xyDoubleEvaluation); + joinDots(ctx, rect, xyFloatEvaluation, model, context, drawStraightLinesEarly, ct, cx, cy, s, u, v, color, thick, maxNumberOfRecursion-1, xyDoubleEvaluation); } } diff --git a/apps/shared/curve_view.h b/apps/shared/curve_view.h index 746814892..00a3119a0 100644 --- a/apps/shared/curve_view.h +++ b/apps/shared/curve_view.h @@ -16,8 +16,8 @@ public: /* We want a 3 characters margin before the first label tick, so that most * labels appear completely. This gives 3*charWidth/320 = 3*7/320= 0.066 */ static constexpr float k_labelsHorizontalMarginRatio = 0.066f; - typedef Poincare::Coordinate2D (*EvaluateXYForParameter)(float t, void * model, void * context); - typedef Poincare::Coordinate2D (*EvaluateXYForParameterDouble)(double t, void * model, void * context); + typedef Poincare::Coordinate2D (*EvaluateXYForFloatParameter)(float t, void * model, void * context); + typedef Poincare::Coordinate2D (*EvaluateXYForDoubleParameter)(double t, void * model, void * context); typedef float (*EvaluateYForX)(float x, void * model, void * context); enum class Axis { Horizontal = 0, @@ -107,8 +107,8 @@ protected: void drawGrid(KDContext * ctx, KDRect rect) const; void drawAxes(KDContext * ctx, KDRect rect) const; void drawAxis(KDContext * ctx, KDRect rect, Axis axis) const; - void drawCurve(KDContext * ctx, KDRect rect, float tStart, float tEnd, float tStep, EvaluateXYForParameter xyEvaluation, void * model, void * context, bool drawStraightLinesEarly, KDColor color, bool thick = true, bool colorUnderCurve = false, float colorLowerBound = 0.0f, float colorUpperBound = 0.0f, EvaluateXYForParameterDouble xyEvaluationDouble = nullptr) const; - void drawCartesianCurve(KDContext * ctx, KDRect rect, float xMin, float xMax, EvaluateXYForParameter xyEvaluation, void * model, void * context, KDColor color, bool thick = true, bool colorUnderCurve = false, float colorLowerBound = 0.0f, float colorUpperBound = 0.0f, EvaluateXYForParameterDouble xyEvaluationDouble = nullptr) const; + void drawCurve(KDContext * ctx, KDRect rect, float tStart, float tEnd, float tStep, EvaluateXYForFloatParameter xyFloatEvaluation, void * model, void * context, bool drawStraightLinesEarly, KDColor color, bool thick = true, bool colorUnderCurve = false, float colorLowerBound = 0.0f, float colorUpperBound = 0.0f, EvaluateXYForDoubleParameter xyDoubleEvaluation = nullptr) const; + void drawCartesianCurve(KDContext * ctx, KDRect rect, float xMin, float xMax, EvaluateXYForFloatParameter xyFloatEvaluation, void * model, void * context, KDColor color, bool thick = true, bool colorUnderCurve = false, float colorLowerBound = 0.0f, float colorUpperBound = 0.0f, EvaluateXYForDoubleParameter xyDoubleEvaluation = nullptr) const; void drawHistogram(KDContext * ctx, KDRect rect, EvaluateYForX yEvaluation, void * model, void * context, float firstBarAbscissa, float barWidth, bool fillBar, KDColor defaultColor, KDColor highlightColor, float highlightLowerBound = INFINITY, float highlightUpperBound = -INFINITY) const; void computeLabels(Axis axis); @@ -138,7 +138,7 @@ private: int numberOfLabels(Axis axis) const; /* Recursively join two dots (dichotomy). The method stops when the * maxNumberOfRecursion in reached. */ - void joinDots(KDContext * ctx, KDRect rect, EvaluateXYForParameter xyEvaluation, void * model, void * context, bool drawStraightLinesEarly, float t, float x, float y, float s, float u, float v, KDColor color, bool thick, int maxNumberOfRecursion, EvaluateXYForParameterDouble xyEvaluationDouble = nullptr) const; + void joinDots(KDContext * ctx, KDRect rect, EvaluateXYForFloatParameter xyFloatEvaluation, void * model, void * context, bool drawStraightLinesEarly, float t, float x, float y, float s, float u, float v, KDColor color, bool thick, int maxNumberOfRecursion, EvaluateXYForDoubleParameter xyDoubleEvaluation = nullptr) const; /* Join two dots with a straight line. */ void straightJoinDots(KDContext * ctx, KDRect rect, float pxf, float pyf, float puf, float pvf, KDColor color, bool thick) const; /* Stamp centered around (pxf, pyf). If pxf and pyf are not round number, the