mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps/graph/graph] Merge two redundant methods in graph view
Change-Id: Icc154656143e81696abba18574c3806bcfdd4c7a
This commit is contained in:
@@ -158,7 +158,7 @@ bool GraphController::handleEvent(Ion::Events::Event event) {
|
||||
return true;
|
||||
}
|
||||
if (event == Ion::Events::Up) {
|
||||
Function * f = m_view.moveCursorUp();
|
||||
Function * f = m_view.moveCursorVertically(1.0f);
|
||||
if (f == nullptr) {
|
||||
m_view.initCursorPosition();
|
||||
m_view.setCursorVisible(false);
|
||||
@@ -168,7 +168,7 @@ bool GraphController::handleEvent(Ion::Events::Event event) {
|
||||
return true;
|
||||
}
|
||||
if (event == Ion::Events::Down) {
|
||||
Function * f = m_view.moveCursorDown();
|
||||
Function * f = m_view.moveCursorVertically(-1.0f);
|
||||
if (f == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -99,43 +99,17 @@ void GraphView::moveCursorHorizontally(KDCoordinate xOffset) {
|
||||
reload();
|
||||
}
|
||||
|
||||
Function * GraphView::moveCursorUp() {
|
||||
Function * GraphView::moveCursorVertically(int direction) {
|
||||
float x = pixelToFloat(Axis::Horizontal, m_xCursorPosition);
|
||||
Function * actualFunction = m_functionStore->activeFunctionAtIndex(m_indexFunctionSelectedByCursor);
|
||||
float y = actualFunction->evaluateAtAbscissa(x, m_evaluateContext);
|
||||
Function * nextFunction = actualFunction;
|
||||
float nextY = FLT_MAX;
|
||||
float nextY = direction > 0 ? FLT_MAX : -FLT_MAX;
|
||||
for (int i = 0; i < m_functionStore->numberOfActiveFunctions(); i++) {
|
||||
Function * f = m_functionStore->activeFunctionAtIndex(i);
|
||||
float newY = f->evaluateAtAbscissa(x, m_evaluateContext);
|
||||
if (newY > y && newY < nextY) {
|
||||
m_indexFunctionSelectedByCursor = i;
|
||||
nextY = newY;
|
||||
nextFunction = f;
|
||||
}
|
||||
}
|
||||
if (nextFunction == actualFunction) {
|
||||
return nullptr;
|
||||
}
|
||||
float xMargin = pixelToFloat(Axis::Horizontal, k_cursorMarginToBorder) - pixelToFloat(Axis::Horizontal, 0);
|
||||
float yMargin = pixelToFloat(Axis::Vertical, 0) - pixelToFloat(Axis::Vertical, k_cursorMarginToBorder);
|
||||
m_graphWindow->panToMakePointVisible(x, nextY, xMargin, yMargin);
|
||||
m_xCursorPosition = floatToPixel(Axis::Horizontal, x);
|
||||
m_yCursorPosition = floatToPixel(Axis::Vertical, nextY);
|
||||
reload();
|
||||
return nextFunction;
|
||||
}
|
||||
|
||||
Function * GraphView::moveCursorDown() {
|
||||
float x = pixelToFloat(Axis::Horizontal, m_xCursorPosition);
|
||||
Function * actualFunction = m_functionStore->activeFunctionAtIndex(m_indexFunctionSelectedByCursor);
|
||||
float y = actualFunction->evaluateAtAbscissa(x, m_evaluateContext);
|
||||
Function * nextFunction = actualFunction;
|
||||
float nextY = -FLT_MAX;
|
||||
for (int i = 0; i < m_functionStore->numberOfActiveFunctions(); i++) {
|
||||
Function * f = m_functionStore->activeFunctionAtIndex(i);
|
||||
float newY = f->evaluateAtAbscissa(x, m_evaluateContext);
|
||||
if (newY < y && newY > nextY) {
|
||||
bool isNextFunction = direction > 0 ? (newY > y && newY < nextY) : (newY < y && newY > nextY);
|
||||
if (isNextFunction) {
|
||||
m_indexFunctionSelectedByCursor = i;
|
||||
nextY = newY;
|
||||
nextFunction = f;
|
||||
|
||||
@@ -22,8 +22,7 @@ public:
|
||||
void setCursorVisible(bool visibleCursor);
|
||||
void initCursorPosition();
|
||||
void moveCursorHorizontally(KDCoordinate xOffset);
|
||||
Function * moveCursorUp();
|
||||
Function * moveCursorDown();
|
||||
Function * moveCursorVertically(int direction);
|
||||
void setContext(Context * evaluateContext);
|
||||
Context * context() const;
|
||||
int indexFunctionSelectedByCursor();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifndef LIBA_FLOAT_H
|
||||
#define LIBA_FLOAT_H
|
||||
|
||||
#define FLT_MAX 1E+37
|
||||
#define FLT_MAX 1E+37f
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user