mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps] In cuve view, always put KDContext and KDRect as first parameters
Change-Id: I606f6bbe798fba9c75cd98e8857cd020b0eb0ca0
This commit is contained in:
@@ -74,7 +74,7 @@ void CurveView::computeLabels(Axis axis) {
|
||||
}
|
||||
}
|
||||
|
||||
void CurveView::drawLabels(Axis axis, bool shiftOrigin, KDContext * ctx, KDRect rect) const {
|
||||
void CurveView::drawLabels(KDContext * ctx, KDRect rect, Axis axis, bool shiftOrigin) const {
|
||||
float step = gridUnit(axis);
|
||||
float start = 2.0f*step*(ceilf(min(axis)/(2.0f*step)));
|
||||
float end = max(axis);
|
||||
@@ -140,7 +140,7 @@ void CurveView::drawSegment(KDContext * ctx, KDRect rect, Axis axis, float coord
|
||||
}
|
||||
}
|
||||
|
||||
void CurveView::drawAxes(Axis axis, KDContext * ctx, KDRect rect) const {
|
||||
void CurveView::drawAxes(KDContext * ctx, KDRect rect, Axis axis) const {
|
||||
drawLine(ctx, rect, axis, 0.0f, k_axisColor, 2);
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ constexpr static int k_maxNumberOfIterations = 10;
|
||||
constexpr static int k_resolution = 320.0f;
|
||||
constexpr static int k_externRectMargin = 1;
|
||||
|
||||
void CurveView::drawCurve(void * curve, KDColor color, KDContext * ctx, KDRect rect, bool colorUnderCurve, float colorLowerBound, float colorUpperBound, bool continuously) const {
|
||||
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);
|
||||
float xMax = max(Axis::Horizontal);
|
||||
float xStep = (xMax-xMin)/k_resolution;
|
||||
@@ -196,21 +196,21 @@ void CurveView::drawCurve(void * curve, KDColor color, KDContext * ctx, KDRect r
|
||||
}
|
||||
ctx->fillRect(colorRect, color);
|
||||
}
|
||||
stampAtLocation(pxf, pyf, color, ctx, rect);
|
||||
stampAtLocation(ctx, rect, pxf, pyf, color);
|
||||
if (x > rectMin && !isnan(evaluateCurveAtAbscissa(curve, x-xStep))) {
|
||||
if (continuously) {
|
||||
float puf = floatToPixel(Axis::Horizontal, x - xStep);
|
||||
float pvf = floatToPixel(Axis::Vertical, evaluateCurveAtAbscissa(curve, x-xStep));
|
||||
straightJoinDots(puf, pvf, pxf, pyf, color, ctx, rect);
|
||||
straightJoinDots(ctx, rect, puf, pvf, pxf, pyf, color);
|
||||
} else {
|
||||
jointDots(curve, x - xStep, evaluateCurveAtAbscissa(curve, x-xStep), x, y, color, k_maxNumberOfIterations, ctx, rect);
|
||||
jointDots(ctx, rect, curve, x - xStep, evaluateCurveAtAbscissa(curve, x-xStep), x, y, color, k_maxNumberOfIterations);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CurveView::drawDiscreteHistogram(KDColor color, KDContext * ctx, KDRect rect, bool colorUnderCurve, KDColor highlightColor, float colorLowerBound, float colorUpperBound) const {
|
||||
void CurveView::drawDiscreteHistogram(KDContext * ctx, KDRect rect, KDColor color, bool colorUnderCurve, KDColor highlightColor, float colorLowerBound, float colorUpperBound) const {
|
||||
int rectMin = ceilf(pixelToFloat(Axis::Horizontal, rect.left()));
|
||||
int rectMax = pixelToFloat(Axis::Horizontal, rect.right());
|
||||
for (int x = rectMin; x < rectMax; x += 1) {
|
||||
@@ -231,7 +231,7 @@ void CurveView::drawDiscreteHistogram(KDColor color, KDContext * ctx, KDRect rec
|
||||
}
|
||||
}
|
||||
|
||||
void CurveView::drawHistogram(float barStart, float barWidth, KDColor color, KDContext * ctx, KDRect rect, KDColor highlightColor, float coloredBin) const {
|
||||
void CurveView::drawHistogram(KDContext * ctx, KDRect rect, float barStart, float barWidth, KDColor color, KDColor highlightColor, float coloredBin) const {
|
||||
KDCoordinate pixelBarWidth = floatToPixel(Axis::Horizontal, barWidth) - floatToPixel(Axis::Horizontal, 0.0f);
|
||||
float rectMin = pixelToFloat(Axis::Horizontal, rect.left());
|
||||
int rectMinBinNumber = floorf((rectMin - barStart)/barWidth);
|
||||
@@ -257,7 +257,7 @@ void CurveView::drawHistogram(float barStart, float barWidth, KDColor color, KDC
|
||||
}
|
||||
}
|
||||
|
||||
void CurveView::stampAtLocation(float pxf, float pyf, KDColor color, KDContext * ctx, KDRect rect) const {
|
||||
void CurveView::stampAtLocation(KDContext * ctx, KDRect rect, float pxf, float pyf, KDColor color) const {
|
||||
// We avoid drawing when no part of the stamp is visible
|
||||
if (pyf < -stampSize || pyf > pixelLength(Axis::Vertical)+stampSize) {
|
||||
return;
|
||||
@@ -284,7 +284,11 @@ void CurveView::stampAtLocation(float pxf, float pyf, KDColor color, KDContext *
|
||||
ctx->blendRectWithMask(stampRect, color, (const uint8_t *)shiftedMask, workingBuffer);
|
||||
}
|
||||
|
||||
void CurveView::jointDots(void * curve, float x, float y, float u, float v, KDColor color, int maxNumberOfRecursion, KDContext * ctx, KDRect rect) const {
|
||||
float CurveView::evaluateCurveAtAbscissa(Model * curve, float t) const {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
void CurveView::jointDots(KDContext * ctx, KDRect rect, Model * curve, float x, float y, float u, float v, KDColor color, int maxNumberOfRecursion) const {
|
||||
float pyf = floatToPixel(Axis::Vertical, y);
|
||||
float pvf = floatToPixel(Axis::Vertical, v);
|
||||
// No need to draw if both dots are outside visible area
|
||||
@@ -310,25 +314,25 @@ void CurveView::jointDots(void * curve, float x, float y, float u, float v, KDCo
|
||||
* can draw a 'straight' line between the two */
|
||||
float pxf = floatToPixel(Axis::Horizontal, x);
|
||||
float puf = floatToPixel(Axis::Horizontal, u);
|
||||
straightJoinDots(pxf, pyf, puf, pvf, color, ctx, rect);
|
||||
straightJoinDots(ctx, rect, pxf, pyf, puf, pvf, color);
|
||||
return;
|
||||
}
|
||||
float pcxf = floatToPixel(Axis::Horizontal, cx);
|
||||
float pcyf = floatToPixel(Axis::Vertical, cy);
|
||||
if (maxNumberOfRecursion > 0) {
|
||||
stampAtLocation(pcxf, pcyf, color, ctx, rect);
|
||||
jointDots(curve, x, y, cx, cy, color, maxNumberOfRecursion-1, ctx, rect);
|
||||
jointDots(curve, cx, cy, u, v, color, maxNumberOfRecursion-1, ctx, rect);
|
||||
stampAtLocation(ctx, rect, pcxf, pcyf, color);
|
||||
jointDots(ctx, rect, curve, x, y, cx, cy, color, maxNumberOfRecursion-1);
|
||||
jointDots(ctx, rect, curve, cx, cy, u, v, color, maxNumberOfRecursion-1);
|
||||
}
|
||||
}
|
||||
|
||||
void CurveView::straightJoinDots(float pxf, float pyf, float puf, float pvf, KDColor color, KDContext * ctx, KDRect rect) const {
|
||||
void CurveView::straightJoinDots(KDContext * ctx, KDRect rect, float pxf, float pyf, float puf, float pvf, KDColor color) const {
|
||||
if (pyf <= pvf) {
|
||||
for (float pnf = pyf; pnf<pvf; pnf+= 1.0f) {
|
||||
float pmf = pxf + (pnf - pyf)*(puf - pxf)/(pvf - pyf);
|
||||
stampAtLocation(pmf, pnf, color, ctx, rect);
|
||||
stampAtLocation(ctx, rect, pmf, pnf, color);
|
||||
}
|
||||
return;
|
||||
}
|
||||
straightJoinDots(puf, pvf, pxf, pyf, color, ctx, rect);
|
||||
straightJoinDots(ctx, rect, puf, pvf, pxf, pyf, color);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
class CurveView : public View {
|
||||
public:
|
||||
typedef void Model;
|
||||
enum class Axis {
|
||||
Horizontal = 0,
|
||||
Vertical = 1
|
||||
@@ -33,25 +34,25 @@ protected:
|
||||
void drawSegment(KDContext * ctx, KDRect rect, Axis axis,
|
||||
float coordinate, float lowerBound, float upperBound,
|
||||
KDColor color, KDCoordinate thickness = 1) const;
|
||||
void drawAxes(Axis axis, KDContext * ctx, KDRect rect) const;
|
||||
void drawCurve(void * curve, KDColor color, KDContext * ctx, KDRect rect, bool colorUnderCurve = false, float colorLowerBound = 0.0f, float colorUpperBound = 0.0f, bool continuously = false) const;
|
||||
void drawDiscreteHistogram(KDColor color, KDContext * ctx, KDRect rect, bool colorHighlightBin = false, KDColor highlightColor = KDColorBlack, float colorLowerBound = 0.0f, float colorUpperBound = 0.0f) const;
|
||||
void drawHistogram(float barStart, float barWidth, KDColor color, KDContext * ctx, KDRect rect, KDColor highlightColor, float coloredBin) 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 drawDiscreteHistogram(KDContext * ctx, KDRect rect, KDColor color, bool colorHighlightBin = false, KDColor highlightColor = KDColorBlack, float colorLowerBound = 0.0f, float colorUpperBound = 0.0f) const;
|
||||
void drawHistogram(KDContext * ctx, KDRect rect, float barStart, float barWidth, KDColor color, KDColor highlightColor, float coloredBin) const;
|
||||
void computeLabels(Axis axis);
|
||||
void drawLabels(Axis axis, bool shiftOrigin, KDContext * ctx, KDRect rect) const;
|
||||
void drawLabels(KDContext * ctx, KDRect rect, Axis axis, bool shiftOrigin) const;
|
||||
private:
|
||||
constexpr static float k_marginFactor = 0.2f;
|
||||
int numberOfLabels(Axis axis) const;
|
||||
virtual float evaluateCurveAtAbscissa(void * curve, float t) const = 0;
|
||||
virtual float evaluateCurveAtAbscissa(Model * curve, float t) const;
|
||||
/* Recursively join two dots (dichotomy). The method stops when the
|
||||
* maxNumberOfRecursion in reached. */
|
||||
void jointDots(void * curve, float x, float y, float u, float v, KDColor color, int maxNumberOfRecursion, KDContext * ctx, KDRect rect) const;
|
||||
void jointDots(KDContext * ctx, KDRect rect, Model * curve, float x, float y, float u, float v, KDColor color, int maxNumberOfRecursion) 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;
|
||||
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
|
||||
* function shifts the stamp (by blending adjacent pixel colors) to draw with
|
||||
* anti alising. */
|
||||
void stampAtLocation(float pxf, float pyf, KDColor color, KDContext * ctx, KDRect rect) const;
|
||||
void stampAtLocation(KDContext * ctx, KDRect rect, float pxf, float pyf, KDColor color) const;
|
||||
CurveViewWindow * m_curveViewWindow;
|
||||
};
|
||||
|
||||
|
||||
@@ -164,13 +164,13 @@ void GraphView::layoutSubviews() {
|
||||
void GraphView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
ctx->fillRect(rect, KDColorWhite);
|
||||
drawGrid(ctx, rect);
|
||||
drawAxes(Axis::Horizontal, ctx, rect);
|
||||
drawAxes(Axis::Vertical, ctx, rect);
|
||||
drawLabels(Axis::Horizontal, true, ctx, rect);
|
||||
drawLabels(Axis::Vertical, true, ctx, rect);
|
||||
drawAxes(ctx, rect, Axis::Horizontal);
|
||||
drawAxes(ctx, rect, Axis::Vertical);
|
||||
drawLabels(ctx, rect, Axis::Horizontal, true);
|
||||
drawLabels(ctx, rect, Axis::Vertical, true);
|
||||
for (int i = 0; i < m_functionStore->numberOfActiveFunctions(); i++) {
|
||||
Function * f = m_functionStore->activeFunctionAtIndex(i);
|
||||
drawCurve(f, f->color(), ctx, rect);
|
||||
drawCurve(ctx, rect, f, f->color());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ void GraphView::drawGrid(KDContext * ctx, KDRect rect) const {
|
||||
drawGridLines(ctx, rect, Axis::Vertical, m_graphWindow->yGridUnit(), k_gridColor);
|
||||
}
|
||||
|
||||
float GraphView::evaluateCurveAtAbscissa(void * curve, float abscissa) const {
|
||||
float GraphView::evaluateCurveAtAbscissa(Model * curve, float abscissa) const {
|
||||
Function * f = (Function *)curve;
|
||||
return f->evaluateAtAbscissa(abscissa, m_context);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ private:
|
||||
void layoutSubviews() override;
|
||||
|
||||
char * label(Axis axis, int index) const override;
|
||||
float evaluateCurveAtAbscissa(void * expression, float abscissa) const override;
|
||||
float evaluateCurveAtAbscissa(Model * 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;
|
||||
void updateBannerView(Function * function);
|
||||
|
||||
@@ -37,12 +37,12 @@ void LawCurveView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
upperBound = m_calculation->parameterAtIndex(1);
|
||||
}
|
||||
ctx->fillRect(bounds(), KDColorWhite);
|
||||
drawAxes(Axis::Horizontal, ctx, rect);
|
||||
drawLabels(Axis::Horizontal, false, ctx, rect);
|
||||
drawAxes(ctx, rect, Axis::Horizontal);
|
||||
drawLabels(ctx, rect, Axis::Horizontal, false);
|
||||
if (m_law->isContinuous()) {
|
||||
drawCurve(m_law, KDColorRed, ctx, rect, true, lowerBound, upperBound, true);
|
||||
drawCurve(ctx, rect, m_law, KDColorRed, true, lowerBound, upperBound, true);
|
||||
} else {
|
||||
drawDiscreteHistogram(KDColorBlue, ctx, rect, true, KDColorRed, lowerBound, upperBound);
|
||||
drawDiscreteHistogram(ctx, rect, KDColorBlue, true, KDColorRed, lowerBound, upperBound);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ protected:
|
||||
char * label(Axis axis, int index) const override;
|
||||
private:
|
||||
char m_labels[k_maxNumberOfXLabels][Constant::FloatBufferSizeInScientificMode];
|
||||
float evaluateCurveAtAbscissa(void * law, float abscissa) const override;
|
||||
float evaluateCurveAtAbscissa(Model * law, float abscissa) const override;
|
||||
Law * m_law;
|
||||
Calculation * m_calculation;
|
||||
};
|
||||
|
||||
@@ -55,8 +55,8 @@ void BoxView::selectAnyQuantile(bool anyQuantileSelected) {
|
||||
|
||||
void BoxView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
ctx->fillRect(rect, KDColorWhite);
|
||||
drawAxes(Axis::Horizontal, ctx, rect);
|
||||
drawLabels(Axis::Horizontal, false, ctx, rect);
|
||||
drawAxes(ctx, rect, Axis::Horizontal);
|
||||
drawLabels(ctx, rect, Axis::Horizontal, false);
|
||||
float calculations[5] = {m_data->minValue(), m_data->firstQuartile(), m_data->median(), m_data->thirdQuartile(), m_data->maxValue()};
|
||||
float lowBounds[5] = {0.4f, 0.2f, 0.2f, 0.2f, 0.4f};
|
||||
float upBounds[5] = {0.6f, 0.8f, 0.8f, 0.8f, 0.6f};
|
||||
@@ -79,8 +79,4 @@ char * BoxView::label(Axis axis, int index) const {
|
||||
return (char *)m_labels[index];
|
||||
}
|
||||
|
||||
float BoxView::evaluateCurveAtAbscissa(void * curve, float t) const {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ public:
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
private:
|
||||
char * label(Axis axis, int index) const override;
|
||||
float evaluateCurveAtAbscissa(void * curve, float t) const override;
|
||||
Data * m_data;
|
||||
BoxWindow m_boxWindow;
|
||||
char m_labels[k_maxNumberOfXLabels][Constant::FloatBufferSizeInScientificMode];
|
||||
|
||||
@@ -42,12 +42,12 @@ void HistogramView::selectBins(bool selectedBins) {
|
||||
|
||||
void HistogramView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
ctx->fillRect(rect, KDColorWhite);
|
||||
drawAxes(Axis::Horizontal, ctx, rect);
|
||||
drawLabels(Axis::Horizontal, true, ctx, rect);
|
||||
drawAxes(ctx, rect, Axis::Horizontal);
|
||||
drawLabels(ctx, rect, Axis::Horizontal, true);
|
||||
if (m_selectedBins) {
|
||||
drawHistogram(m_data->barStart(), m_data->barWidth(), KDColorBlack, ctx, rect, KDColorRed, m_data->selectedBar());
|
||||
drawHistogram(ctx, rect, m_data->barStart(), m_data->barWidth(), KDColorBlack, KDColorRed, m_data->selectedBar());
|
||||
} else {
|
||||
drawHistogram(m_data->barStart(), m_data->barWidth(), KDColorBlack, ctx, rect, KDColorRed, NAN);
|
||||
drawHistogram(ctx, rect, m_data->barStart(), m_data->barWidth(), KDColorBlack, KDColorRed, NAN);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ char * HistogramView::label(Axis axis, int index) const {
|
||||
return (char *)m_labels[index];
|
||||
}
|
||||
|
||||
float HistogramView::evaluateCurveAtAbscissa(void * curve, float t) const {
|
||||
float HistogramView::evaluateCurveAtAbscissa(Model * curve, float t) const {
|
||||
return (float)m_data->heightForBarAtValue(t)/(float)m_data->totalSize();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ private:
|
||||
View * subviewAtIndex(int index) override;
|
||||
void layoutSubviews() override;
|
||||
char * label(Axis axis, int index) const override;
|
||||
float evaluateCurveAtAbscissa(void * curve, float t) const override;
|
||||
float evaluateCurveAtAbscissa(Model * curve, float t) const override;
|
||||
Data * m_data;
|
||||
char m_labels[k_maxNumberOfXLabels][Constant::FloatBufferSizeInScientificMode];
|
||||
bool m_selectedBins;
|
||||
|
||||
Reference in New Issue
Block a user