mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/shared/curve_view] New boolean parameter controls whether drawCurve draws straight lines early
This commit is contained in:
committed by
Léa Saviot
parent
965ad60583
commit
0f7aebb045
@@ -502,7 +502,7 @@ const uint8_t stampMask[stampSize+1][stampSize+1] = {
|
||||
|
||||
constexpr static int k_maxNumberOfIterations = 10;
|
||||
|
||||
void CurveView::drawCurve(KDContext * ctx, KDRect rect, EvaluateModelWithParameter xEvaluation, EvaluateModelWithParameter yEvaluation, void * model, void * context, KDColor color, bool colorUnderCurve, float colorLowerBound, float colorUpperBound) const {
|
||||
void CurveView::drawCurve(KDContext * ctx, KDRect rect, EvaluateModelWithParameter xEvaluation, EvaluateModelWithParameter yEvaluation, void * model, void * context, bool drawStraightLinesEarly, KDColor color, bool colorUnderCurve, float colorLowerBound, float colorUpperBound) const {
|
||||
const float xStep = pixelWidth();
|
||||
float rectMin = pixelToFloat(Axis::Horizontal, rect.left() - k_externRectMargin);
|
||||
float rectMax = pixelToFloat(Axis::Horizontal, rect.right() + k_externRectMargin);
|
||||
@@ -527,14 +527,14 @@ void CurveView::drawCurve(KDContext * ctx, KDRect rect, EvaluateModelWithParamet
|
||||
if (colorUnderCurve && colorLowerBound < x && x < colorUpperBound) {
|
||||
drawSegment(ctx, rect, Axis::Vertical, x, minFloat(0.0f, y), maxFloat(0.0f, y), color, 1);
|
||||
}
|
||||
jointDots(ctx, rect, xEvaluation, yEvaluation, model, context, t - xStep, previousX, previousY, t, x, y, color, k_maxNumberOfIterations);
|
||||
jointDots(ctx, rect, xEvaluation, yEvaluation, model, context, drawStraightLinesEarly, t - xStep, previousX, previousY, t, x, y, color, k_maxNumberOfIterations);
|
||||
}
|
||||
}
|
||||
|
||||
void CurveView::drawCartesianCurve(KDContext * ctx, KDRect rect, EvaluateModelWithParameter yEvaluation, void * model, void * context, KDColor color, bool colorUnderCurve, float colorLowerBound, float colorUpperBound) const {
|
||||
drawCurve(ctx, rect, [](float t, void * model, void * context) {
|
||||
return t;
|
||||
}, yEvaluation, model, context, color, colorUnderCurve, colorLowerBound, colorUpperBound);
|
||||
}, yEvaluation, model, context, true, color, colorUnderCurve, colorLowerBound, colorUpperBound);
|
||||
}
|
||||
|
||||
void CurveView::drawHistogram(KDContext * ctx, KDRect rect, EvaluateModelWithParameter evaluation, void * model, void * context, float firstBarAbscissa, float barWidth,
|
||||
@@ -575,7 +575,7 @@ void CurveView::drawHistogram(KDContext * ctx, KDRect rect, EvaluateModelWithPar
|
||||
}
|
||||
}
|
||||
|
||||
void CurveView::jointDots(KDContext * ctx, KDRect rect, EvaluateModelWithParameter xEvaluation, EvaluateModelWithParameter yEvaluation, void * model, void * context, float t, float x, float y, float s, float u, float v, KDColor color, int maxNumberOfRecursion) const {
|
||||
void CurveView::jointDots(KDContext * ctx, KDRect rect, EvaluateModelWithParameter xEvaluation, EvaluateModelWithParameter yEvaluation, void * model, void * context, bool drawStraightLinesEarly, float t, float x, float y, float s, float u, float v, KDColor color, int maxNumberOfRecursion) const {
|
||||
float pxf = floatToPixel(Axis::Horizontal, x);
|
||||
float pyf = floatToPixel(Axis::Vertical, y);
|
||||
float puf = floatToPixel(Axis::Horizontal, u);
|
||||
@@ -591,15 +591,15 @@ void CurveView::jointDots(KDContext * ctx, KDRect rect, EvaluateModelWithParamet
|
||||
float ct = (t + s)/2.0f;
|
||||
float cx = xEvaluation(ct, model, context);
|
||||
float cy = yEvaluation(ct, model, context);
|
||||
if (((x <= cx && cx <= u) || (u <= cx && cx <= x)) && ((y <= cy && cy <= v) || (v <= cy && cy <= y))) {
|
||||
if ((drawStraightLinesEarly || maxNumberOfRecursion == 0) && ((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);
|
||||
return;
|
||||
}
|
||||
if (maxNumberOfRecursion > 0) {
|
||||
jointDots(ctx, rect, xEvaluation, yEvaluation, model, context, t, x, y, ct, cx, cy, color, maxNumberOfRecursion-1);
|
||||
jointDots(ctx, rect, xEvaluation, yEvaluation, model, context, ct, cx, cy, s, u, v, color, maxNumberOfRecursion-1);
|
||||
jointDots(ctx, rect, xEvaluation, yEvaluation, model, context, drawStraightLinesEarly, t, x, y, ct, cx, cy, color, maxNumberOfRecursion-1);
|
||||
jointDots(ctx, rect, xEvaluation, yEvaluation, model, context, drawStraightLinesEarly, ct, cx, cy, s, u, v, color, maxNumberOfRecursion-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ 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, EvaluateModelWithParameter xEvaluation, EvaluateModelWithParameter yEvaluation, void * model, void * context, KDColor color, bool colorUnderCurve = false, float colorLowerBound = 0.0f, float colorUpperBound = 0.0f) const;
|
||||
void drawCurve(KDContext * ctx, KDRect rect, EvaluateModelWithParameter xEvaluation, EvaluateModelWithParameter yEvaluation, void * model, void * context, bool drawStraightLinesEarly, KDColor color, bool colorUnderCurve = false, float colorLowerBound = 0.0f, float colorUpperBound = 0.0f) const;
|
||||
void drawCartesianCurve(KDContext * ctx, KDRect rect, EvaluateModelWithParameter yEvaluation, void * model, void * context, KDColor color, bool colorUnderCurve = false, float colorLowerBound = 0.0f, float colorUpperBound = 0.0f) const;
|
||||
void drawHistogram(KDContext * ctx, KDRect rect, EvaluateModelWithParameter evaluation, void * model, void * context, float firstBarAbscissa, float barWidth,
|
||||
bool fillBar, KDColor defaultColor, KDColor highlightColor, float highlightLowerBound = INFINITY, float highlightUpperBound = -INFINITY) const;
|
||||
@@ -83,7 +83,7 @@ private:
|
||||
int numberOfLabels(Axis axis) const;
|
||||
/* Recursively join two dots (dichotomy). The method stops when the
|
||||
* maxNumberOfRecursion in reached. */
|
||||
void jointDots(KDContext * ctx, KDRect rect, EvaluateModelWithParameter xEvaluation, EvaluateModelWithParameter yEvaluation, void * model, void * context, float t, float x, float y, float s, float u, float v, KDColor color, int maxNumberOfRecursion) const;
|
||||
void jointDots(KDContext * ctx, KDRect rect, EvaluateModelWithParameter xEvaluation, EvaluateModelWithParameter yEvaluation, void * model, void * context, bool drawStraightLinesEarly, float t, float x, float y, float s, float u, float v, KDColor color, int maxNumberOfRecursion) const;
|
||||
/* Join two dots with a straight line. */
|
||||
void straightJoinDots(KDContext * ctx, KDRect rect, float pxf, float pyf, float puf, float pvf, KDColor color) const;
|
||||
/* Stamp centered around (pxf, pyf). If pxf and pyf are not round number, the
|
||||
|
||||
Reference in New Issue
Block a user