mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-26 17:20:53 +01:00
[apps] Change curve view API
Change-Id: I77984536d1a8b4197b02e2f005590537a46d8084
This commit is contained in:
@@ -132,19 +132,19 @@ const uint8_t stampMask[stampSize+1][stampSize+1] = {
|
||||
constexpr static int k_maxNumberOfIterations = 10;
|
||||
constexpr static int k_resolution = 320.0f;
|
||||
|
||||
void CurveView::drawExpression(Expression * expression, KDColor color, KDContext * ctx, KDRect rect) const {
|
||||
void CurveView::drawCurve(void * curve, KDColor color, KDContext * ctx, KDRect rect) const {
|
||||
float xMin = min(Axis::Horizontal);
|
||||
float xMax = max(Axis::Horizontal);
|
||||
float xStep = (xMax-xMin)/k_resolution;
|
||||
float rectMin = pixelToFloat(Axis::Horizontal, rect.left());
|
||||
float rectMax = pixelToFloat(Axis::Horizontal, rect.right());
|
||||
for (float x = rectMin; x < rectMax; x += xStep) {
|
||||
float y = evaluateExpressionAtAbscissa(expression, x);
|
||||
float y = evaluateCurveAtAbscissa(curve, x);
|
||||
float pxf = floatToPixel(Axis::Horizontal, x);
|
||||
float pyf = floatToPixel(Axis::Vertical, y);
|
||||
stampAtLocation(pxf, pyf, color, ctx, rect);
|
||||
if (x > xMin) {
|
||||
jointDots(expression, x - xStep, evaluateExpressionAtAbscissa(expression, x-xStep), x, y, color, k_maxNumberOfIterations, ctx, rect);
|
||||
jointDots(curve, x - xStep, evaluateCurveAtAbscissa(curve, x-xStep), x, y, color, k_maxNumberOfIterations, ctx, rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -176,7 +176,7 @@ void CurveView::stampAtLocation(float pxf, float pyf, KDColor color, KDContext *
|
||||
ctx->blendRectWithMask(stampRect, color, (const uint8_t *)shiftedMask, workingBuffer);
|
||||
}
|
||||
|
||||
void CurveView::jointDots(Expression * expression, float x, float y, float u, float v, KDColor color, int maxNumberOfRecursion, KDContext * ctx, KDRect rect) const {
|
||||
void CurveView::jointDots(void * curve, float x, float y, float u, float v, KDColor color, int maxNumberOfRecursion, KDContext * ctx, KDRect rect) const {
|
||||
float pyf = floatToPixel(Axis::Vertical, y);
|
||||
float pvf = floatToPixel(Axis::Vertical, v);
|
||||
// No need to draw if both dots are outside visible area
|
||||
@@ -196,7 +196,7 @@ void CurveView::jointDots(Expression * expression, float x, float y, float u, fl
|
||||
}
|
||||
// C is the dot whose abscissa is between x and u
|
||||
float cx = (x + u)/2.0f;
|
||||
float cy = evaluateExpressionAtAbscissa(expression, cx);
|
||||
float cy = evaluateCurveAtAbscissa(curve, cx);
|
||||
if ((y < cy && cy < v) || (v < cy && cy < y)) {
|
||||
/* As the middle dot is vertically between the two dots, we assume that we
|
||||
* can draw a 'straight' line between the two */
|
||||
@@ -209,8 +209,8 @@ void CurveView::jointDots(Expression * expression, float x, float y, float u, fl
|
||||
float pcyf = floatToPixel(Axis::Vertical, cy);
|
||||
if (maxNumberOfRecursion > 0) {
|
||||
stampAtLocation(pcxf, pcyf, color, ctx, rect);
|
||||
jointDots(expression, x, y, cx, cy, color, maxNumberOfRecursion-1, ctx, rect);
|
||||
jointDots(expression, cx, cy, u, v, color, maxNumberOfRecursion-1, ctx, rect);
|
||||
jointDots(curve, x, y, cx, cy, color, maxNumberOfRecursion-1, ctx, rect);
|
||||
jointDots(curve, cx, cy, u, v, color, maxNumberOfRecursion-1, ctx, rect);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,15 +27,15 @@ protected:
|
||||
void drawLine(KDContext * ctx, KDRect rect, Axis axis,
|
||||
float coordinate, KDColor color, KDCoordinate thickness = 1) const;
|
||||
void drawAxes(Axis axis, KDContext * ctx, KDRect rect) const;
|
||||
void drawExpression(Expression * expression, KDColor color, KDContext * ctx, KDRect rect) const;
|
||||
void drawCurve(void * curve, KDColor color, KDContext * ctx, KDRect rect) const;
|
||||
void computeLabels(Axis axis);
|
||||
void drawLabels(Axis axis, KDContext * ctx, KDRect rect) const;
|
||||
private:
|
||||
int numberOfLabels(Axis axis) const;
|
||||
virtual float evaluateExpressionAtAbscissa(Expression * expression, float abscissa) const = 0;
|
||||
virtual float evaluateCurveAtAbscissa(void * curve, float t) const = 0;
|
||||
/* Recursively join two dots (dichotomy). The method stops when the
|
||||
* maxNumberOfRecursion in reached. */
|
||||
void jointDots(Expression * expression, float x, float y, float u, float v, KDColor color, int maxNumberOfRecursion, KDContext * ctx, KDRect rect) const;
|
||||
void jointDots(void * curve, float x, float y, float u, float v, KDColor color, int maxNumberOfRecursion, KDContext * ctx, KDRect rect) const;
|
||||
/* Join two dots with a straight line. */
|
||||
void straightJoinDots(float pxf, float pyf, float puf, float pvf, KDColor color, KDContext * ctx, KDRect rect) const;
|
||||
/* Stamp centered around (pxf, pyf). If pxf and pyf are not round number, the
|
||||
|
||||
@@ -159,7 +159,7 @@ void GraphView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
drawLabels(Axis::Vertical, ctx, rect);
|
||||
for (int i = 0; i < m_functionStore->numberOfActiveFunctions(); i++) {
|
||||
Function * f = m_functionStore->activeFunctionAtIndex(i);
|
||||
drawExpression(f->expression(), f->color(), ctx, rect);
|
||||
drawCurve(f, f->color(), ctx, rect);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,11 +194,9 @@ float GraphView::max(Axis axis) const {
|
||||
return (axis == Axis::Horizontal ? m_graphWindow->xMax() : m_graphWindow->yMax());
|
||||
}
|
||||
|
||||
float GraphView::evaluateExpressionAtAbscissa(Expression * expression, float abscissa) const {
|
||||
Symbol xSymbol = Symbol('x');
|
||||
Float e = Float(abscissa);
|
||||
m_context->setExpressionForSymbolName(&e, &xSymbol);
|
||||
return expression->approximate(*m_context);
|
||||
float GraphView::evaluateCurveAtAbscissa(void * curve, float abscissa) const {
|
||||
Function * f = (Function *)curve;
|
||||
return f->evaluateAtAbscissa(abscissa, m_context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ private:
|
||||
float max(Axis axis) const override;
|
||||
float gridUnit(Axis axis) const override;
|
||||
char * label(Axis axis, int index) const override;
|
||||
float evaluateExpressionAtAbscissa(Expression * expression, float abscissa) const override;
|
||||
float evaluateCurveAtAbscissa(void * expression, float abscissa) const override;
|
||||
void drawGrid(KDContext * ctx, KDRect rect) const;
|
||||
void drawGridLines(KDContext * ctx, KDRect rect, Axis axis, float step, KDColor color) const;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ void LawCurveView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
ctx->fillRect(bounds(), KDColorWhite);
|
||||
drawAxes(Axis::Horizontal, ctx, rect);
|
||||
drawLabels(Axis::Horizontal, ctx, rect);
|
||||
drawExpression(m_law->expression(), KDColorRed, ctx, rect);
|
||||
drawCurve(m_law, KDColorRed, ctx, rect);
|
||||
}
|
||||
|
||||
float LawCurveView::min(Axis axis) const {
|
||||
@@ -45,7 +45,7 @@ char * LawCurveView::label(Axis axis, int index) const {
|
||||
return (char *)m_labels[index];
|
||||
}
|
||||
|
||||
float LawCurveView::evaluateExpressionAtAbscissa(Expression * expression, float abscissa) const {
|
||||
float LawCurveView::evaluateCurveAtAbscissa(void * law, float abscissa) const {
|
||||
return m_law->evaluateAtAbscissa(abscissa);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ protected:
|
||||
char * label(Axis axis, int index) const override;
|
||||
private:
|
||||
char m_labels[k_maxNumberOfXLabels][Constant::FloatBufferSizeInScientificMode];
|
||||
float evaluateExpressionAtAbscissa(Expression * expression, float abscissa) const override;
|
||||
float evaluateCurveAtAbscissa(void * law, float abscissa) const override;
|
||||
Law * m_law;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user