Files
Upsilon/apps/probability/law_curve_view.cpp
Émilie Feral 1cc75e5d76 [apps/probability] Move Calculation model to snapshot
Change-Id: If04e331a7ee81667c7aa8c302479d054189dd63a
2017-05-18 17:49:59 +02:00

44 lines
1.2 KiB
C++

#include "law_curve_view.h"
#include <assert.h>
#include <math.h>
using namespace Shared;
namespace Probability {
LawCurveView::LawCurveView(Law * law, Calculation * calculation) :
CurveView(law, nullptr, nullptr, nullptr),
m_labels{},
m_law(law),
m_calculation(calculation)
{
assert(law != nullptr);
assert(calculation != nullptr);
}
void LawCurveView::drawRect(KDContext * ctx, KDRect rect) const {
float lowerBound = m_calculation->lowerBound();
float upperBound = m_calculation->upperBound();
ctx->fillRect(bounds(), Palette::WallScreen);
drawAxes(ctx, rect, Axis::Horizontal);
drawLabels(ctx, rect, Axis::Horizontal, false);
if (m_law->isContinuous()) {
drawCurve(ctx, rect, m_law, Palette::YellowDark, true, lowerBound, upperBound, true);
} else {
drawHistogram(ctx, rect, m_law, 0, 1, false, Palette::GreyMiddle, Palette::YellowDark, lowerBound, upperBound);
}
}
char * LawCurveView::label(Axis axis, int index) const {
if (axis == Axis::Vertical) {
return nullptr;
}
return (char *)m_labels[index];
}
float LawCurveView::evaluateModelWithParameter(void * law, float abscissa) const {
return m_law->evaluateAtAbscissa(abscissa);
}
}