Numworks Epsilon  1.4.1
Graphing Calculator Operating System
curve_view_range.cpp
Go to the documentation of this file.
1 #include "curve_view_range.h"
2 #include <cmath>
3 #include <ion.h>
4 #include <poincare.h>
5 
6 using namespace Shared;
7 using namespace Poincare;
8 
9 namespace Sequence {
10 
11 CurveViewRange::CurveViewRange(CurveViewCursor * cursor, InteractiveCurveViewRangeDelegate * delegate) :
12  InteractiveCurveViewRange(cursor, delegate)
13 {
14  m_xMin = -k_displayLeftMarginRatio*m_xMax;
15 }
16 
18  float xMin = m_xMin;
19  float xMax = m_xMax;
20  float newXMin = clipped(std::round((xMin+xMax)/2) - (float)Ion::Display::Width/2.0f, false);
21  float newXMax = clipped(std::round((xMin+xMax)/2) + (float)Ion::Display::Width/2.0f-1.0f, true);
22  if (std::isnan(newXMin) || std::isnan(newXMax)) {
23  return;
24  }
25  m_xMin = newXMin;
26  m_xMax = newXMax;
27  if (m_xMin < 0.0f) {
28  m_xMin = -k_displayLeftMarginRatio*(float)Ion::Display::Width;
30  }
32  if (m_delegate) {
34  }
35 }
36 
38  float xMin = m_xMin;
39  float xMax = m_xMax;
40  float yMin = m_yMin;
41  float yMax = m_yMax;
42  float newXMin = clipped((xMin+xMax)/2 - 5.3f, false);
43  float newXMax = clipped((xMin+xMax)/2 + 5.3f, true);
44  if (!std::isnan(newXMin) && !std::isnan(newXMax)) {
45  m_xMin = newXMin;
46  m_xMax = newXMax;
48  }
49  if (m_xMin < 0.0f) {
50  m_xMin = -k_displayLeftMarginRatio*2.0f*5.3f;
51  m_xMax = m_xMin + 2.0f*5.3f;
52  }
53  m_yAuto = false;
54  float newYMin = clipped((yMin+yMax)/2 - 3.1f, false);
55  float newYMax = clipped((yMin+yMax)/2 + 3.1f, true);
56  if (!std::isnan(newYMin) && !std::isnan(newYMax)) {
57  m_yMin = newYMin;
58  m_yMax = newYMax;
60  }
61 }
62 
64  m_xMin = -k_displayLeftMarginRatio*21.0f;
65  m_xMax = 21.0f;
66  if (Preferences::sharedPreferences()->angleUnit() == Expression::AngleUnit::Degree) {
67  m_xMin = -k_displayLeftMarginRatio*1200;
68  m_xMax = 1200;
69  }
71  m_yAuto = false;
72  m_yMin = -1.6f;
73  m_yMax = 1.6f;
75 }
76 
78  if (m_delegate == nullptr) {
79  return;
80  }
82  m_xMin = -k_displayLeftMarginRatio*m_xMax;
84  setYAuto(true);
85 }
86 
87 }
constexpr int Width
Definition: display.h:26
InteractiveCurveViewRangeDelegate * m_delegate
#define round(x)
Definition: math.h:192
#define isnan(x)
Definition: math.h:43
Definition: app.cpp:7
float computeGridUnit(Axis axis, float min, float max)
bool didChangeRange(InteractiveCurveViewRange *interactiveCurveViewRange)
void setTrigonometric() override
constexpr Poincare::Expression::AngleUnit Degree
Definition: helper.h:3
static float clipped(float f, bool isMax)