mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-28 18:20:14 +01:00
[apps/graph/values] Create a class Interval
Change-Id: Ie05a9887c0f3d4146b9e90a139f57e6eec7981b1
This commit is contained in:
@@ -12,6 +12,7 @@ app_objs += $(addprefix apps/graph/,\
|
||||
list/list_controller.o\
|
||||
list/parameter_controller.o\
|
||||
values/float_to_string.o\
|
||||
values/interval.o\
|
||||
values/title_cell.o\
|
||||
values/value_cell.o\
|
||||
values/values_controller.o\
|
||||
|
||||
22
apps/graph/values/interval.cpp
Normal file
22
apps/graph/values/interval.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "interval.h"
|
||||
#include <assert.h>
|
||||
|
||||
Graph::Interval::Interval(float start, float end, float step) :
|
||||
m_start(start),
|
||||
m_end(end),
|
||||
m_step(step)
|
||||
{
|
||||
}
|
||||
|
||||
int Graph::Interval::numberOfElements() {
|
||||
if (m_start > m_end) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1 + (m_end - m_start)/m_step;
|
||||
}
|
||||
}
|
||||
|
||||
float Graph::Interval::element(int i) {
|
||||
assert(i >= 0 && i < numberOfElements());
|
||||
return m_start + i*m_step;
|
||||
}
|
||||
20
apps/graph/values/interval.h
Normal file
20
apps/graph/values/interval.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef GRAPH_VALUES_INTERVAL_H
|
||||
#define GRAPH_VALUES_INTERVAL_H
|
||||
|
||||
namespace Graph {
|
||||
|
||||
class Interval {
|
||||
public:
|
||||
Interval(float start, float end, float step);
|
||||
|
||||
int numberOfElements();
|
||||
float element(int i);
|
||||
private:
|
||||
float m_start;
|
||||
float m_end;
|
||||
float m_step;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user