diff --git a/apps/shared/curve_view.cpp b/apps/shared/curve_view.cpp index 54565a58f..5c767f516 100644 --- a/apps/shared/curve_view.cpp +++ b/apps/shared/curve_view.cpp @@ -527,10 +527,11 @@ void CurveView::drawCurve(KDContext * ctx, KDRect rect, float tStart, float tEnd Coordinate2D xy = xyEvaluation(t, model, context); x = xy.x1(); y = xy.x2(); - if (std::isnan(x) || std::isinf(x) || std::isnan(y) || std::isinf(y)) { + if (std::isnan(previousT)) { + // Happens at the first iteration only. continue; } - if (colorUnderCurve && colorLowerBound < x && x < colorUpperBound) { + if (colorUnderCurve && !std::isnan(x) && colorLowerBound < x && x < colorUpperBound && !(std::isnan(y) || std::isinf(y))) { drawSegment(ctx, rect, Axis::Vertical, x, minFloat(0.0f, y), maxFloat(0.0f, y), color, 1); } jointDots(ctx, rect, xyEvaluation, model, context, drawStraightLinesEarly, previousT, previousX, previousY, t, x, y, color, k_maxNumberOfIterations); @@ -589,23 +590,31 @@ void CurveView::drawHistogram(KDContext * ctx, KDRect rect, EvaluateYForX yEvalu } void CurveView::jointDots(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, int maxNumberOfRecursion) const { + const bool areCoordinatesValid = !( + std::isnan(x) || std::isinf(x) || + std::isnan(y) || std::isinf(y) || + std::isnan(u) || std::isinf(u) || + std::isnan(v) || std::isinf(v)); float pxf = floatToPixel(Axis::Horizontal, x); float pyf = floatToPixel(Axis::Vertical, y); float puf = floatToPixel(Axis::Horizontal, u); float pvf = floatToPixel(Axis::Vertical, v); - const float deltaX = pxf - puf; - const float deltaY = pyf - pvf; - if (std::isnan(x) || std::isnan(y) || deltaX*deltaX + deltaY*deltaY < circleDiameter * circleDiameter / 4.0f) { - // the dots are already joined - stampAtLocation(ctx, rect, puf, pvf, color); - return; + if (areCoordinatesValid) { + const float deltaX = pxf - puf; + const float deltaY = pyf - pvf; + if (deltaX*deltaX + deltaY*deltaY < circleDiameter * circleDiameter / 4.0f) { + // the dots are already joined + stampAtLocation(ctx, rect, puf, pvf, color); + return; + } } // Middle point float ct = (t + s)/2.0f; Coordinate2D cxy = xyEvaluation(ct, model, context); float cx = cxy.x1(); float cy = cxy.x2(); - if ((drawStraightLinesEarly || maxNumberOfRecursion == 0) && ((x <= cx && cx <= u) || (u <= cx && cx <= x)) && ((y <= cy && cy <= v) || (v <= cy && cy <= y))) { + if ((drawStraightLinesEarly || maxNumberOfRecursion == 0) && areCoordinatesValid && + ((x <= cx && cx <= u) || (u <= cx && cx <= x)) && ((y <= cy && cy <= v) || (v <= cy && cy <= y))) { /* As the middle dot is between the two dots, we assume that we * can draw a 'straight' line between the two */ straightJoinDots(ctx, rect, pxf, pyf, puf, pvf, color);