Numworks Epsilon  1.4.1
Graphing Calculator Operating System
law_curve_view.cpp
Go to the documentation of this file.
1 #include "law_curve_view.h"
2 #include <assert.h>
3 
4 using namespace Shared;
5 
6 namespace Probability {
7 
8 LawCurveView::LawCurveView(Law * law, Calculation * calculation) :
9  CurveView(law, nullptr, nullptr, nullptr),
10  m_labels{},
11  m_law(law),
12  m_calculation(calculation)
13 {
14  assert(law != nullptr);
15  assert(calculation != nullptr);
16 }
17 
19  CurveView::reload();
21 }
22 
23 void LawCurveView::drawRect(KDContext * ctx, KDRect rect) const {
24  float lowerBound = m_calculation->lowerBound();
25  float upperBound = m_calculation->upperBound();
27  drawAxes(ctx, rect, Axis::Horizontal);
28  drawLabels(ctx, rect, Axis::Horizontal, false);
29  if (m_law->isContinuous()) {
30  drawCurve(ctx, rect, EvaluateAtAbscissa, m_law, nullptr, Palette::YellowDark, true, lowerBound, upperBound, true);
31  } else {
32  drawHistogram(ctx, rect, EvaluateAtAbscissa, m_law, nullptr, 0, 1, false, Palette::GreyMiddle, Palette::YellowDark, lowerBound, upperBound+0.5f);
33  }
34 }
35 
36 char * LawCurveView::label(Axis axis, int index) const {
37  if (axis == Axis::Vertical) {
38  return nullptr;
39  }
40  return (char *)m_labels[index];
41 }
42 
43 float LawCurveView::EvaluateAtAbscissa(float abscissa, void * model, void * context) {
44  Law * law = (Law *)model;
45  return law->evaluateAtAbscissa(abscissa);
46 }
47 
48 }
virtual bool isContinuous() const =0
static constexpr KDColor YellowDark
Definition: palette.h:8
#define assert(e)
Definition: assert.h:9
const SettingsMessageTree model
void markRectAsDirty(KDRect rect)
Definition: view.cpp:39
void drawAxes(KDContext *ctx, KDRect rect, Axis axis) const
Definition: curve_view.cpp:282
void drawCurve(KDContext *ctx, KDRect rect, EvaluateModelWithParameter evaluation, void *model, void *context, KDColor color, bool colorUnderCurve=false, float colorLowerBound=0.0f, float colorUpperBound=0.0f, bool continuously=false) const
Definition: curve_view.cpp:339
void drawLabels(KDContext *ctx, KDRect rect, Axis axis, bool shiftOrigin) const
Definition: curve_view.cpp:146
virtual double lowerBound()
Definition: calculation.cpp:21
static constexpr KDColor GreyMiddle
Definition: palette.h:14
virtual float evaluateAtAbscissa(float x) const =0
void drawHistogram(KDContext *ctx, KDRect rect, EvaluateModelWithParameter evaluation, void *model, void *context, float firstBarAbscissa, float barWidth, bool fillBar, KDColor defaultColor, KDColor highlightColor, float highlightLowerBound=INFINITY, float highlightUpperBound=-INFINITY) const
Definition: curve_view.cpp:382
static constexpr KDColor WallScreen
Definition: palette.h:19
Definition: rect.h:26
void fillRect(KDRect rect, KDColor color)
Definition: context_rect.cpp:8
virtual double upperBound()
Definition: calculation.cpp:25
void drawRect(KDContext *ctx, KDRect rect) const override
KDRect bounds() const
Definition: view.cpp:157
char * label(Axis axis, int index) const override