mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/probability] Create a class law curve view inheriting from curve
view Change-Id: I3a6aacd3532c4eb9303b9970765e08f546850439
This commit is contained in:
@@ -4,6 +4,7 @@ app_objs += $(addprefix apps/probability/,\
|
||||
evaluate_context.o\
|
||||
law.o\
|
||||
law_controller.o\
|
||||
law_curve_view.o\
|
||||
parameters_controller.o\
|
||||
)
|
||||
|
||||
|
||||
33
apps/probability/law_curve_view.cpp
Normal file
33
apps/probability/law_curve_view.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "law_curve_view.h"
|
||||
#include <assert.h>
|
||||
|
||||
namespace Probability {
|
||||
|
||||
LawCurveView::LawCurveView(Law * law) :
|
||||
CurveView(),
|
||||
m_law(law)
|
||||
{
|
||||
}
|
||||
|
||||
void LawCurveView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
ctx->fillRect(bounds(), KDColorWhite);
|
||||
drawAxes(Axis::Horizontal, ctx, rect);
|
||||
drawExpression(m_law->expression(), KDColorRed, ctx, rect);
|
||||
}
|
||||
|
||||
float LawCurveView::min(Axis axis) const {
|
||||
assert(axis == Axis::Horizontal || axis == Axis::Vertical);
|
||||
return (axis == Axis::Horizontal ? m_law->xMin() : m_law->yMin());
|
||||
}
|
||||
|
||||
float LawCurveView::max(Axis axis) const {
|
||||
assert(axis == Axis::Horizontal || axis == Axis::Vertical);
|
||||
return (axis == Axis::Horizontal ? m_law->xMax() : m_law->yMax());
|
||||
}
|
||||
|
||||
float LawCurveView::evaluateExpressionAtAbscissa(Expression * expression, float abscissa) const {
|
||||
m_law->evaluateContext()->setOverridenValueForSymbolT(abscissa);
|
||||
return expression->approximate(*(m_law->evaluateContext()));
|
||||
}
|
||||
|
||||
}
|
||||
25
apps/probability/law_curve_view.h
Normal file
25
apps/probability/law_curve_view.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef PROBABILITY_LAW_CURVE_VIEW_H
|
||||
#define PROBABILITY_LAW_CURVE_VIEW_H
|
||||
|
||||
#include "../curve_view.h"
|
||||
#include "law.h"
|
||||
#include <escher.h>
|
||||
#include <poincare.h>
|
||||
|
||||
namespace Probability {
|
||||
|
||||
class LawCurveView : public CurveView {
|
||||
public:
|
||||
LawCurveView(Law * law);
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
protected:
|
||||
float min(Axis axis) const override;
|
||||
float max(Axis axis) const override;
|
||||
private:
|
||||
float evaluateExpressionAtAbscissa(Expression * expression, float abscissa) const override;
|
||||
Law * m_law;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user