mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[apps/shared] Rename methods and Factorize comparison logic
This commit is contained in:
committed by
LeaNumworks
parent
10c296e671
commit
479f34502f
@@ -2,6 +2,7 @@
|
|||||||
#include "../shared/poincare_helpers.h"
|
#include "../shared/poincare_helpers.h"
|
||||||
#include "../shared/text_helpers.h"
|
#include "../shared/text_helpers.h"
|
||||||
#include "../apps_container.h"
|
#include "../apps_container.h"
|
||||||
|
#include "../shared/poincare_helpers.h"
|
||||||
#include <poincare/preferences.h>
|
#include <poincare/preferences.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -259,9 +260,9 @@ void GraphController::initCursorParameters() {
|
|||||||
*m_selectedDotIndex = m_store->numberOfPairsOfSeries(*m_selectedSeriesIndex);
|
*m_selectedDotIndex = m_store->numberOfPairsOfSeries(*m_selectedSeriesIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GraphController::isCursorHanging() {
|
bool GraphController::cursorMatchesModel() {
|
||||||
if (m_store->seriesIsEmpty(*m_selectedSeriesIndex)) {
|
if (m_store->seriesIsEmpty(*m_selectedSeriesIndex)) {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
Coordinate2D<double> xy;
|
Coordinate2D<double> xy;
|
||||||
if (*m_selectedDotIndex == -1) {
|
if (*m_selectedDotIndex == -1) {
|
||||||
@@ -271,9 +272,7 @@ bool GraphController::isCursorHanging() {
|
|||||||
} else {
|
} else {
|
||||||
xy = Coordinate2D<double>(m_store->get(*m_selectedSeriesIndex, 0, *m_selectedDotIndex), m_store->get(*m_selectedSeriesIndex, 1, *m_selectedDotIndex));
|
xy = Coordinate2D<double>(m_store->get(*m_selectedSeriesIndex, 0, *m_selectedDotIndex), m_store->get(*m_selectedSeriesIndex, 1, *m_selectedDotIndex));
|
||||||
}
|
}
|
||||||
// NaN != Nan returns true, but cursor is not hanging if both values are NaN
|
return PoincareHelpers::equalOrBothNan(xy.x1(), m_cursor->x()) && PoincareHelpers::equalOrBothNan(xy.x2(), m_cursor->y());
|
||||||
return (xy.x1() != m_cursor->x() && !(std::isnan(xy.x1()) && std::isnan(m_cursor->x())))
|
|
||||||
|| (xy.x2() != m_cursor->y() && !(std::isnan(xy.x2()) && std::isnan(m_cursor->y())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GraphController::moveCursorVertically(int direction) {
|
bool GraphController::moveCursorVertically(int direction) {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ private:
|
|||||||
|
|
||||||
// InteractiveCurveViewController
|
// InteractiveCurveViewController
|
||||||
void initCursorParameters() override;
|
void initCursorParameters() override;
|
||||||
bool isCursorHanging() override;
|
bool cursorMatchesModel() override;
|
||||||
uint32_t rangeVersion() override;
|
uint32_t rangeVersion() override;
|
||||||
int selectedCurveIndex() const override { return *m_selectedSeriesIndex; }
|
int selectedCurveIndex() const override { return *m_selectedSeriesIndex; }
|
||||||
bool closestCurveIndexIsSuitable(int newIndex, int currentIndex) const override;
|
bool closestCurveIndexIsSuitable(int newIndex, int currentIndex) const override;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "function_graph_controller.h"
|
#include "function_graph_controller.h"
|
||||||
#include "function_app.h"
|
#include "function_app.h"
|
||||||
|
#include "poincare_helpers.h"
|
||||||
#include "../apps_container.h"
|
#include "../apps_container.h"
|
||||||
#include <poincare/coordinate_2D.h>
|
#include <poincare/coordinate_2D.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@@ -123,16 +124,14 @@ bool FunctionGraphController::moveCursorVertically(int direction) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FunctionGraphController::isCursorHanging() {
|
bool FunctionGraphController::cursorMatchesModel() {
|
||||||
Poincare::Context * context = textFieldDelegateApp()->localContext();
|
Poincare::Context * context = textFieldDelegateApp()->localContext();
|
||||||
if (indexFunctionSelectedByCursor() >= functionStore()->numberOfActiveFunctions()) {
|
if (indexFunctionSelectedByCursor() >= functionStore()->numberOfActiveFunctions()) {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
ExpiringPointer<Function> f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(indexFunctionSelectedByCursor()));
|
ExpiringPointer<Function> f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(indexFunctionSelectedByCursor()));
|
||||||
Coordinate2D<double> xy = f->evaluateXYAtParameter(m_cursor->t(), context);
|
Coordinate2D<double> xy = f->evaluateXYAtParameter(m_cursor->t(), context);
|
||||||
// NaN != Nan returns true, but cursor is not hanging if both values are NaN
|
return PoincareHelpers::equalOrBothNan(xy.x1(), m_cursor->x()) && PoincareHelpers::equalOrBothNan(xy.x2(), m_cursor->y());
|
||||||
return (xy.x1() != m_cursor->x() && !(std::isnan(xy.x1()) && std::isnan(m_cursor->x())))
|
|
||||||
|| (xy.x2() != m_cursor->y() && !(std::isnan(xy.x2()) && std::isnan(m_cursor->y())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CurveView * FunctionGraphController::curveView() {
|
CurveView * FunctionGraphController::curveView() {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ protected:
|
|||||||
Poincare::Coordinate2D<double> xyValues(int curveIndex, double t, Poincare::Context * context) const override;
|
Poincare::Coordinate2D<double> xyValues(int curveIndex, double t, Poincare::Context * context) const override;
|
||||||
int numberOfCurves() const override;
|
int numberOfCurves() const override;
|
||||||
void initCursorParameters() override;
|
void initCursorParameters() override;
|
||||||
bool isCursorHanging() override;
|
bool cursorMatchesModel() override;
|
||||||
CurveView * curveView() override;
|
CurveView * curveView() override;
|
||||||
|
|
||||||
void yRangeForCursorFirstMove(Shared::InteractiveCurveViewRange * range) const;
|
void yRangeForCursorFirstMove(Shared::InteractiveCurveViewRange * range) const;
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ void InteractiveCurveViewController::viewWillAppear() {
|
|||||||
/* Warning: init cursor parameter before reloading banner view. Indeed,
|
/* Warning: init cursor parameter before reloading banner view. Indeed,
|
||||||
* reloading banner view needs an updated cursor to load the right data. */
|
* reloading banner view needs an updated cursor to load the right data. */
|
||||||
uint32_t newRangeVersion = rangeVersion();
|
uint32_t newRangeVersion = rangeVersion();
|
||||||
if ((*m_rangeVersion != newRangeVersion && !isCursorVisible()) || isCursorHanging()) {
|
if ((*m_rangeVersion != newRangeVersion && !isCursorVisible()) || !cursorMatchesModel()) {
|
||||||
initCursorParameters();
|
initCursorParameters();
|
||||||
}
|
}
|
||||||
*m_rangeVersion = newRangeVersion;
|
*m_rangeVersion = newRangeVersion;
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ protected:
|
|||||||
virtual bool moveCursorVertically(int direction) = 0;
|
virtual bool moveCursorVertically(int direction) = 0;
|
||||||
virtual uint32_t rangeVersion() = 0;
|
virtual uint32_t rangeVersion() = 0;
|
||||||
bool isCursorVisible();
|
bool isCursorVisible();
|
||||||
// The cursor is hanging if the selected function has been edited or deleted
|
// The cursor does not match if selected model has been edited or deleted
|
||||||
virtual bool isCursorHanging() = 0;
|
virtual bool cursorMatchesModel() = 0;
|
||||||
|
|
||||||
// Closest vertical curve helper
|
// Closest vertical curve helper
|
||||||
int closestCurveIndexVertically(bool goingUp, int currentSelectedCurve, Poincare::Context * context) const;
|
int closestCurveIndexVertically(bool goingUp, int currentSelectedCurve, Poincare::Context * context) const;
|
||||||
|
|||||||
@@ -108,6 +108,8 @@ inline typename Poincare::Coordinate2D<double> NextIntersection(const Poincare::
|
|||||||
return e.nextIntersection(symbol, start, step, max, context, complexFormat, preferences->angleUnit(), expression);
|
return e.nextIntersection(symbol, start, step, max, context, complexFormat, preferences->angleUnit(), expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool equalOrBothNan(double a, double b) { return a == b || (std::isnan(a) && std::isnan(b)); }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user