mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-20 09:17:23 +01:00
48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
#include "law_curve_view.h"
|
|
#include <assert.h>
|
|
#include <math.h>
|
|
|
|
namespace Probability {
|
|
|
|
LawCurveView::LawCurveView() :
|
|
CurveView(nullptr, nullptr, nullptr, nullptr, 0.2f, 0.1f, 0.2f, 0.1f),
|
|
m_law(nullptr),
|
|
m_calculation(nullptr)
|
|
{
|
|
}
|
|
|
|
void LawCurveView::setLaw(Law * law) {
|
|
setCurveViewRange(law);
|
|
m_law = law;
|
|
}
|
|
|
|
void LawCurveView::setCalculation(Calculation * calculation) {
|
|
m_calculation = calculation;
|
|
}
|
|
|
|
void LawCurveView::drawRect(KDContext * ctx, KDRect rect) const {
|
|
float lowerBound = m_calculation->lowerBound();
|
|
float upperBound = m_calculation->upperBound();
|
|
ctx->fillRect(bounds(), KDColorWhite);
|
|
drawAxes(ctx, rect, Axis::Horizontal);
|
|
drawLabels(ctx, rect, Axis::Horizontal, false);
|
|
if (m_law->isContinuous()) {
|
|
drawCurve(ctx, rect, m_law, KDColorRed, true, lowerBound, upperBound, true);
|
|
} else {
|
|
drawHistogram(ctx, rect, m_law, 0, 1, false, KDColorBlue, KDColorRed, 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);
|
|
}
|
|
|
|
}
|