mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps/graph/graph] create a class for the model axis interval
Change-Id: I7da8441c282ba44e67855ea494c79ebb8c762a2f
This commit is contained in:
@@ -6,7 +6,6 @@ public:
|
||||
constexpr static int FloatBufferSizeInScientificMode = 14;
|
||||
constexpr static int NumberOfDigitsInMantissaInScientificMode = 7;
|
||||
constexpr static int NumberOfDigitsInMantissaForDerivativeNumberInScientificMode = 3;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,6 +5,7 @@ app_objs += $(addprefix apps/graph/,\
|
||||
function.o\
|
||||
function_store.o\
|
||||
function_title_cell.o\
|
||||
graph/axis_interval.o\
|
||||
graph/cursor_view.o\
|
||||
graph/graph_controller.o\
|
||||
graph/graph_view.o\
|
||||
|
||||
92
apps/graph/graph/axis_interval.cpp
Normal file
92
apps/graph/graph/axis_interval.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
#include "axis_interval.h"
|
||||
#include "../../constant.h"
|
||||
#include <assert.h>
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <ion.h>
|
||||
|
||||
namespace Graph {
|
||||
|
||||
AxisInterval::AxisInterval(FunctionStore * functionStore) :
|
||||
m_xMin(-10.0f),
|
||||
m_xMax(10.0f),
|
||||
m_yMin(-10.0f),
|
||||
m_yMax(10.0f),
|
||||
m_yAuto(true),
|
||||
m_functionStore(functionStore),
|
||||
m_evaluateContext(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
float AxisInterval::xMin() {
|
||||
return m_xMin;
|
||||
}
|
||||
|
||||
float AxisInterval::xMax() {
|
||||
return m_xMax;
|
||||
}
|
||||
|
||||
float AxisInterval::yMin() {
|
||||
return m_yMin;
|
||||
}
|
||||
|
||||
float AxisInterval::yMax() {
|
||||
return m_yMax;
|
||||
}
|
||||
|
||||
bool AxisInterval::yAuto() {
|
||||
return m_yAuto;
|
||||
}
|
||||
|
||||
void AxisInterval::setXMin(float xMin) {
|
||||
m_xMin = xMin;
|
||||
computeYaxes();
|
||||
}
|
||||
|
||||
void AxisInterval::setXMax(float xMax) {
|
||||
m_xMax = xMax;
|
||||
computeYaxes();
|
||||
}
|
||||
|
||||
void AxisInterval::setYMin(float yMin) {
|
||||
m_yMin = yMin;
|
||||
}
|
||||
|
||||
void AxisInterval::setYMax(float yMax) {
|
||||
m_yMax = yMax;
|
||||
}
|
||||
|
||||
void AxisInterval::setYAuto(bool yAuto) {
|
||||
m_yAuto = yAuto;
|
||||
computeYaxes();
|
||||
}
|
||||
|
||||
void AxisInterval::computeYaxes() {
|
||||
if (!m_yAuto) {
|
||||
return;
|
||||
}
|
||||
if (m_functionStore->numberOfActiveFunctions() > 0) {
|
||||
float min = FLT_MAX;
|
||||
float max = -FLT_MAX;
|
||||
float step = (m_xMax - m_xMin)/Ion::Display::Width;
|
||||
for (int i=0; i<m_functionStore->numberOfActiveFunctions(); i++) {
|
||||
Function * f = m_functionStore->activeFunctionAtIndex(i);
|
||||
float y = 0.0f;
|
||||
for (float x = m_xMin; x <= m_xMax; x += step) {
|
||||
y = f->evaluateAtAbscissa(x, m_evaluateContext);
|
||||
if (!isnan(y) && !isinf(y)) {
|
||||
min = min < y ? min : y;
|
||||
max = max > y ? max : y;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_yMin = min;
|
||||
m_yMax = max;
|
||||
}
|
||||
}
|
||||
|
||||
void AxisInterval::setContext(Context * context) {
|
||||
m_evaluateContext = (EvaluateContext *)context;
|
||||
}
|
||||
|
||||
}
|
||||
40
apps/graph/graph/axis_interval.h
Normal file
40
apps/graph/graph/axis_interval.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef GRAPH_GRAPH_AXIS_INTERVAL_H
|
||||
#define GRAPH_GRAPH_AXIS_INTERVAL_H
|
||||
|
||||
#include "../function_store.h"
|
||||
#include "../evaluate_context.h"
|
||||
|
||||
namespace Graph {
|
||||
|
||||
class AxisInterval {
|
||||
public:
|
||||
AxisInterval(FunctionStore * functionStore);
|
||||
float xMin();
|
||||
float xMax();
|
||||
float yMin();
|
||||
float yMax();
|
||||
bool yAuto();
|
||||
void setXMin(float f);
|
||||
void setXMax(float f);
|
||||
void setYMin(float f);
|
||||
void setYMax(float f);
|
||||
void setYAuto(bool yAuto);
|
||||
/* Need to be public to be called when a function is added to the function
|
||||
* store. */
|
||||
void computeYaxes();
|
||||
void setContext(Context * context);
|
||||
private:
|
||||
float m_xMin;
|
||||
float m_xMax;
|
||||
float m_yMin;
|
||||
float m_yMax;
|
||||
bool m_yAuto;
|
||||
//float xScale;
|
||||
//float yScale;
|
||||
FunctionStore * m_functionStore;
|
||||
EvaluateContext * m_evaluateContext;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
6
liba/include/float.h
Normal file
6
liba/include/float.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef LIBA_FLOAT_H
|
||||
#define LIBA_FLOAT_H
|
||||
|
||||
#define FLT_MAX 1E+37
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user