[apps/shared] Rename methods and Factorize comparison logic

This commit is contained in:
Hugo Saint-Vignes
2020-12-16 15:59:12 +01:00
committed by LeaNumworks
parent 10c296e671
commit 479f34502f
7 changed files with 15 additions and 15 deletions

View File

@@ -2,6 +2,7 @@
#include "../shared/poincare_helpers.h"
#include "../shared/text_helpers.h"
#include "../apps_container.h"
#include "../shared/poincare_helpers.h"
#include <poincare/preferences.h>
#include <cmath>
#include <algorithm>
@@ -259,9 +260,9 @@ void GraphController::initCursorParameters() {
*m_selectedDotIndex = m_store->numberOfPairsOfSeries(*m_selectedSeriesIndex);
}
bool GraphController::isCursorHanging() {
bool GraphController::cursorMatchesModel() {
if (m_store->seriesIsEmpty(*m_selectedSeriesIndex)) {
return true;
return false;
}
Coordinate2D<double> xy;
if (*m_selectedDotIndex == -1) {
@@ -271,9 +272,7 @@ bool GraphController::isCursorHanging() {
} else {
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 (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())));
return PoincareHelpers::equalOrBothNan(xy.x1(), m_cursor->x()) && PoincareHelpers::equalOrBothNan(xy.x2(), m_cursor->y());
}
bool GraphController::moveCursorVertically(int direction) {

View File

@@ -40,7 +40,7 @@ private:
// InteractiveCurveViewController
void initCursorParameters() override;
bool isCursorHanging() override;
bool cursorMatchesModel() override;
uint32_t rangeVersion() override;
int selectedCurveIndex() const override { return *m_selectedSeriesIndex; }
bool closestCurveIndexIsSuitable(int newIndex, int currentIndex) const override;

View File

@@ -1,5 +1,6 @@
#include "function_graph_controller.h"
#include "function_app.h"
#include "poincare_helpers.h"
#include "../apps_container.h"
#include <poincare/coordinate_2D.h>
#include <assert.h>
@@ -123,16 +124,14 @@ bool FunctionGraphController::moveCursorVertically(int direction) {
return true;
}
bool FunctionGraphController::isCursorHanging() {
bool FunctionGraphController::cursorMatchesModel() {
Poincare::Context * context = textFieldDelegateApp()->localContext();
if (indexFunctionSelectedByCursor() >= functionStore()->numberOfActiveFunctions()) {
return true;
return false;
}
ExpiringPointer<Function> f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(indexFunctionSelectedByCursor()));
Coordinate2D<double> xy = f->evaluateXYAtParameter(m_cursor->t(), context);
// NaN != Nan returns true, but cursor is not hanging if both values are NaN
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())));
return PoincareHelpers::equalOrBothNan(xy.x1(), m_cursor->x()) && PoincareHelpers::equalOrBothNan(xy.x2(), m_cursor->y());
}
CurveView * FunctionGraphController::curveView() {

View File

@@ -37,7 +37,7 @@ protected:
Poincare::Coordinate2D<double> xyValues(int curveIndex, double t, Poincare::Context * context) const override;
int numberOfCurves() const override;
void initCursorParameters() override;
bool isCursorHanging() override;
bool cursorMatchesModel() override;
CurveView * curveView() override;
void yRangeForCursorFirstMove(Shared::InteractiveCurveViewRange * range) const;

View File

@@ -136,7 +136,7 @@ void InteractiveCurveViewController::viewWillAppear() {
/* Warning: init cursor parameter before reloading banner view. Indeed,
* reloading banner view needs an updated cursor to load the right data. */
uint32_t newRangeVersion = rangeVersion();
if ((*m_rangeVersion != newRangeVersion && !isCursorVisible()) || isCursorHanging()) {
if ((*m_rangeVersion != newRangeVersion && !isCursorVisible()) || !cursorMatchesModel()) {
initCursorParameters();
}
*m_rangeVersion = newRangeVersion;

View File

@@ -41,8 +41,8 @@ protected:
virtual bool moveCursorVertically(int direction) = 0;
virtual uint32_t rangeVersion() = 0;
bool isCursorVisible();
// The cursor is hanging if the selected function has been edited or deleted
virtual bool isCursorHanging() = 0;
// The cursor does not match if selected model has been edited or deleted
virtual bool cursorMatchesModel() = 0;
// Closest vertical curve helper
int closestCurveIndexVertically(bool goingUp, int currentSelectedCurve, Poincare::Context * context) const;

View File

@@ -108,6 +108,8 @@ inline typename Poincare::Coordinate2D<double> NextIntersection(const Poincare::
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)); }
}
}