[apps] Add a method drawDot in curve view

Change-Id: Ic6b421ebe094aeeaa110a009d9251f0464941db1
This commit is contained in:
Émilie Feral
2016-12-30 12:21:20 +01:00
parent 280fe277ca
commit 11787aee4e
2 changed files with 14 additions and 1 deletions

View File

@@ -147,6 +147,18 @@ void CurveView::drawSegment(KDContext * ctx, KDRect rect, Axis axis, float coord
}
}
void CurveView::drawDot(KDContext * ctx, KDRect rect, float x, float y, KDColor color, KDSize size) const {
KDCoordinate px = roundf(floatToPixel(Axis::Horizontal, x));
KDCoordinate py = roundf(floatToPixel(Axis::Vertical, y));
if ((px - size.width() < rect.left() - k_externRectMargin || px + size.width() > rect.right() + k_externRectMargin) &&
(py - size.height() < rect.top() - k_externRectMargin || py + size.height() > rect.bottom() + k_externRectMargin)) {
return;
}
KDRect dotRect = KDRect(px - size.width()/2, py-size.height()/2, size.width(), size.height());
ctx->fillRect(dotRect, color);
}
void CurveView::drawAxes(KDContext * ctx, KDRect rect, Axis axis) const {
drawLine(ctx, rect, axis, 0.0f, k_axisColor, 2);
}
@@ -183,7 +195,6 @@ const uint8_t stampMask[stampSize+1][stampSize+1] = {
constexpr static int k_maxNumberOfIterations = 10;
constexpr static int k_resolution = 320.0f;
constexpr static int k_externRectMargin = 1;
void CurveView::drawCurve(KDContext * ctx, KDRect rect, Model * curve, KDColor color, bool colorUnderCurve, float colorLowerBound, float colorUpperBound, bool continuously) const {
float xMin = min(Axis::Horizontal);

View File

@@ -36,6 +36,7 @@ protected:
void drawSegment(KDContext * ctx, KDRect rect, Axis axis,
float coordinate, float lowerBound, float upperBound,
KDColor color, KDCoordinate thickness = 1) const;
void drawDot(KDContext * ctx, KDRect rect, float x, float y, KDColor color, KDSize size) const;
void drawAxes(KDContext * ctx, KDRect rect, Axis axis) const;
void drawCurve(KDContext * ctx, KDRect rect, Model * curve, KDColor color, bool colorUnderCurve = false, float colorLowerBound = 0.0f, float colorUpperBound = 0.0f, bool continuously = false) const;
void drawHistogram(KDContext * ctx, KDRect rect, Model * model, float firstBarAbscissa, float barWidth,
@@ -43,6 +44,7 @@ protected:
void computeLabels(Axis axis);
void drawLabels(KDContext * ctx, KDRect rect, Axis axis, bool shiftOrigin) const;
private:
constexpr static int k_externRectMargin = 1;
int numberOfLabels(Axis axis) const;
virtual float evaluateModelWithParameter(Model * curve, float t) const;
/* Recursively join two dots (dichotomy). The method stops when the