Numworks Epsilon  1.4.1
Graphing Calculator Operating System
interval.cpp
Go to the documentation of this file.
1 #include "interval.h"
2 #include <assert.h>
3 
4 namespace Shared {
5 
7  m_numberOfElements(0),
8  m_start(0),
9  m_end(0),
10  m_step(0),
11  m_needCompute(false)
12 {
13 }
14 
16  computeElements();
17  return m_numberOfElements;
18 }
19 
21  m_numberOfElements--;
22  for (int k = index; k < m_numberOfElements; k++) {
23  m_intervalBuffer[k] = m_intervalBuffer[k+1];
24  }
25  m_intervalBuffer[m_numberOfElements] = 0.0f;
26 }
27 
28 double Interval::element(int i) {
29  assert(i >= 0 && i < numberOfElements());
30  computeElements();
31  return m_intervalBuffer[i];
32 }
33 
34 double Interval::start() {
35  return m_start;
36 }
37 
38 double Interval::end() {
39  return m_end;
40 }
41 
42 double Interval::step() {
43  return m_step;
44 }
45 
46 void Interval::setStart(double f) {
47  m_start = f;
48  m_needCompute = true;
49 }
50 
51 void Interval::setEnd(double f) {
52  m_end = f;
53  m_needCompute = true;
54 }
55 
56 void Interval::setStep(double f) {
57  m_step = f;
58  m_needCompute = true;
59 }
60 
61 void Interval::setElement(int i, double f) {
63  computeElements();
64  m_intervalBuffer[i] = f;
65  if (i == numberOfElements()) {
66  m_numberOfElements++;
67  }
68 }
69 
70 void Interval::computeElements() {
71  if (!m_needCompute) {
72  return;
73  }
74  if ( m_start > m_end) {
75  m_numberOfElements = 0;
76  } else {
77  m_numberOfElements = m_step > 0 ? 1 + (m_end - m_start)/m_step : k_maxNumberOfElements;
78  m_numberOfElements = m_numberOfElements > k_maxNumberOfElements || m_numberOfElements < 0 ? k_maxNumberOfElements : m_numberOfElements;
79  }
80  for (int i = 0; i < m_numberOfElements; i += 1) {
81  m_intervalBuffer[i] = m_start + i * m_step;
82  }
83  m_needCompute = false;
84 }
85 
86 }
void setStep(double f)
Definition: interval.cpp:56
#define assert(e)
Definition: assert.h:9
double element(int i)
Definition: interval.cpp:28
void setElement(int i, double f)
Definition: interval.cpp:61
int numberOfElements()
Definition: interval.cpp:15
static constexpr int k_maxNumberOfElements
Definition: interval.h:22
double start()
Definition: interval.cpp:34
#define false
Definition: stdbool.h:9
void setStart(double f)
Definition: interval.cpp:46
double end()
Definition: interval.cpp:38
void deleteElementAtIndex(int index)
Definition: interval.cpp:20
void setEnd(double f)
Definition: interval.cpp:51
double step()
Definition: interval.cpp:42