Numworks Epsilon  1.4.1
Graphing Calculator Operating System
graph_view.cpp
Go to the documentation of this file.
1 #include "graph_view.h"
2 #include <cmath>
3 
4 using namespace Shared;
5 
6 namespace Sequence {
7 
8 GraphView::GraphView(SequenceStore * sequenceStore, InteractiveCurveViewRange * graphRange,
9  CurveViewCursor * cursor, BannerView * bannerView, View * cursorView) :
10  FunctionGraphView(graphRange, cursor, bannerView, cursorView),
11  m_sequenceStore(sequenceStore)
12 {
13 }
14 
15 void GraphView::drawRect(KDContext * ctx, KDRect rect) const {
16  FunctionGraphView::drawRect(ctx, rect);
17  for (int i = 0; i < m_sequenceStore->numberOfActiveFunctions(); i++) {
18  Sequence * s = m_sequenceStore->activeFunctionAtIndex(i);
19  float rectXMin = pixelToFloat(Axis::Horizontal, rect.left() - k_externRectMargin);
20  rectXMin = rectXMin < 0 ? 0 : rectXMin;
21  float rectXMax = pixelToFloat(Axis::Horizontal, rect.right() + k_externRectMargin);
22  /* We draw a dot at every integer if WindowRange/Resolution < 1. Otherwise,
23  * we draw a dot at every step where step is an integer wider than 1. */
24  float windowRange = pixelToFloat(Axis::Horizontal, bounds().width()) - pixelToFloat(Axis::Horizontal, 0);
25  int step = std::ceil(windowRange/resolution());
26  for (int x = rectXMin; x < rectXMax; x += step) {
27  float y = s->evaluateAtAbscissa((float)x, context());
28  if (std::isnan(y)) {
29  continue;
30  }
31  drawDot(ctx, rect, x, y, s->color());
32  if (x >= m_highlightedStart && x <= m_highlightedEnd && s == m_selectedFunction) {
33  KDColor color = m_shouldColorHighlighted ? s->color() : KDColorBlack;
34  if (y >= 0.0f) {
35  drawSegment(ctx, rect, Axis::Vertical, x, 0.0f, y, color, 1);
36  } else {
37  drawSegment(ctx, rect, Axis::Vertical, x, y, 0.0f, color, 1);
38  }
39  }
40  }
41  }
42 }
43 
44 float GraphView::samplingRatio() const {
45  return 5.0f;
46 }
47 
48 }
void drawSegment(KDContext *ctx, KDRect rect, Axis axis, float coordinate, float lowerBound, float upperBound, KDColor color, KDCoordinate thickness=1) const
Definition: curve_view.cpp:196
float resolution() const
Definition: curve_view.cpp:83
virtual float samplingRatio() const
Definition: curve_view.cpp:87
KDCoordinate right() const
Definition: rect.h:43
static constexpr int k_externRectMargin
Definition: curve_view.h:39
KDCoordinate left() const
Definition: rect.h:45
constexpr KDColor KDColorBlack
Definition: color.h:41
#define ceil(x)
Definition: math.h:170
#define isnan(x)
Definition: math.h:43
Definition: rect.h:26
Definition: color.h:6
Definition: app.cpp:7
Definition: view.h:23
void drawDot(KDContext *ctx, KDRect rect, float x, float y, KDColor color, bool oversize=false) const
Definition: curve_view.cpp:241
KDRect bounds() const
Definition: view.cpp:157
void drawRect(KDContext *ctx, KDRect rect) const override
Definition: graph_view.cpp:16
float pixelToFloat(Axis axis, KDCoordinate p) const
Definition: curve_view.cpp:110