[apps/probability] Color the integral under the curve

Change-Id: I157ee8ed180dab366f89fcdcec82d4329f46a82b
This commit is contained in:
Émilie Feral
2016-12-16 16:58:13 +01:00
parent 7c27ce5ec0
commit 1f4fad1f52
4 changed files with 24 additions and 4 deletions

View File

@@ -6,7 +6,7 @@ namespace Probability {
FiniteIntegralCalculation::FiniteIntegralCalculation() :
Calculation(),
m_lowerBound(-1.0f),
m_lowerBound(0.0f),
m_upperBound(1.0f),
m_result(0.0f)
{

View File

@@ -24,6 +24,7 @@ void CalculationController::ContentView::setLaw(Law * law) {
void CalculationController::ContentView::setCalculation(Calculation * calculation) {
m_calculation = calculation;
m_lawCurveView.setCalculation(calculation);
m_imageTableView.setCalculation(calculation);
}

View File

@@ -1,11 +1,13 @@
#include "law_curve_view.h"
#include <assert.h>
#include <math.h>
namespace Probability {
LawCurveView::LawCurveView() :
CurveView(),
m_law(nullptr)
m_law(nullptr),
m_calculation(nullptr)
{
}
@@ -13,19 +15,33 @@ void LawCurveView::setLaw(Law * law) {
m_law = law;
}
void LawCurveView::setCalculation(Calculation * calculation) {
m_calculation = calculation;
}
void LawCurveView::reload() {
markRectAsDirty(bounds());
computeLabels(Axis::Horizontal);
}
void LawCurveView::drawRect(KDContext * ctx, KDRect rect) const {
float lowerBound = - INFINITY;
float upperBound = m_calculation->parameterAtIndex(0);
if (m_calculation->type() == Calculation::Type::RightIntegral) {
lowerBound = m_calculation->parameterAtIndex(0);
upperBound = +INFINITY;
}
if (m_calculation->type() == Calculation::Type::FiniteIntegral) {
lowerBound = m_calculation->parameterAtIndex(0);
upperBound = m_calculation->parameterAtIndex(1);
}
ctx->fillRect(bounds(), KDColorWhite);
drawAxes(Axis::Horizontal, ctx, rect);
drawLabels(Axis::Horizontal, false, ctx, rect);
if (m_law->isContinuous()) {
drawCurve(m_law, KDColorRed, ctx, rect);
drawCurve(m_law, KDColorRed, ctx, rect, true, lowerBound, upperBound);
} else {
drawHistogram(m_law, KDColorRed, ctx, rect);
drawHistogram(m_law, KDColorBlue, ctx, rect, true, KDColorRed, lowerBound, upperBound);
}
}

View File

@@ -4,6 +4,7 @@
#include "../curve_view.h"
#include "../constant.h"
#include "law/law.h"
#include "calculation/calculation.h"
#include <escher.h>
#include <poincare.h>
@@ -13,6 +14,7 @@ class LawCurveView : public CurveView {
public:
LawCurveView();
void setLaw(Law * law);
void setCalculation(Calculation * calculation);
void reload();
void drawRect(KDContext * ctx, KDRect rect) const override;
protected:
@@ -24,6 +26,7 @@ private:
char m_labels[k_maxNumberOfXLabels][Constant::FloatBufferSizeInScientificMode];
float evaluateCurveAtAbscissa(void * law, float abscissa) const override;
Law * m_law;
Calculation * m_calculation;
};
}