[apps] Implement InteractiveCurveViewController::isCursorVisible

It was a pure virtual method implemented in derived classes
  Shared::FunctionGraphController,
  Regression::GraphController.
InteractiveCurveViewRange does not need anymore to hold CurveViewCursor
* m_cursor.
This commit is contained in:
Ruben Dashyan
2019-03-20 11:31:33 +01:00
committed by Émilie Feral
parent 8629254d9a
commit 67f9f79322
14 changed files with 21 additions and 33 deletions

View File

@@ -23,7 +23,7 @@ const Image * App::Descriptor::icon() {
App::Snapshot::Snapshot() :
Shared::FunctionApp::Snapshot::Snapshot(),
m_functionStore(),
m_graphRange(&m_cursor)
m_graphRange()
{
}

View File

@@ -2,9 +2,8 @@
#define GRAPH_GRAPH_CONTROLLER_HELPER_H
#include "banner_view.h"
#include "../../shared/text_field_delegate_app.h"
#include "../../shared/curve_view_cursor.h"
#include "../../shared/interactive_curve_view_range.h"
#include "../cartesian_function_store.h"
namespace Graph {

View File

@@ -28,7 +28,6 @@ GraphController::GraphController(Responder * parentResponder, InputEventHandlerD
for (int i = 0; i < Store::k_numberOfSeries; i++) {
m_modelType[i] = (Model::Type) -1;
}
m_store->setCursor(m_cursor);
m_store->setDelegate(this);
}
@@ -349,10 +348,6 @@ uint32_t GraphController::rangeVersion() {
return m_store->rangeChecksum();
}
bool GraphController::isCursorVisible() {
return interactiveCurveViewRange()->isCursorVisible(cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio);
}
bool GraphController::closestCurveIndexIsSuitable(int newIndex, int currentIndex) const {
return newIndex != currentIndex && !m_store->seriesIsEmpty(newIndex);
}

View File

@@ -44,7 +44,6 @@ private:
void initCursorParameters() override;
uint32_t modelVersion() override;
uint32_t rangeVersion() override;
bool isCursorVisible() override;
bool closestCurveIndexIsSuitable(int newIndex, int currentIndex) const override;
double yValue(int curveIndex, double x, Poincare::Context * context) const override;
bool suitableYValue(double y) const override;

View File

@@ -17,7 +17,7 @@ static_assert(Model::k_numberOfModels == 9, "Number of models changed, Regressio
static_assert(Store::k_numberOfSeries == 3, "Number of series changed, Regression::Store() needs to adapt (m_seriesChecksum)");
Store::Store() :
InteractiveCurveViewRange(nullptr),
InteractiveCurveViewRange(),
DoublePairStore(),
m_seriesChecksum{0, 0, 0},
m_angleUnit(Poincare::Preferences::AngleUnit::Degree)

View File

@@ -21,7 +21,7 @@ const Image * App::Descriptor::icon() {
App::Snapshot::Snapshot() :
Shared::FunctionApp::Snapshot::Snapshot(),
m_sequenceStore(),
m_graphRange(&m_cursor)
m_graphRange()
{
}

View File

@@ -8,8 +8,8 @@ using namespace Poincare;
namespace Sequence {
CurveViewRange::CurveViewRange(CurveViewCursor * cursor, InteractiveCurveViewRangeDelegate * delegate) :
InteractiveCurveViewRange(cursor, delegate)
CurveViewRange::CurveViewRange(InteractiveCurveViewRangeDelegate * delegate) :
InteractiveCurveViewRange(delegate)
{
m_xMin = -k_displayLeftMarginRatio * m_xMax;
}

View File

@@ -7,7 +7,7 @@ namespace Sequence {
class CurveViewRange : public Shared::InteractiveCurveViewRange {
public:
CurveViewRange(Shared::CurveViewCursor * cursor, Shared::InteractiveCurveViewRangeDelegate * delegate = nullptr);
CurveViewRange(Shared::InteractiveCurveViewRangeDelegate * delegate = nullptr);
void roundAbscissa() override;
void normalize() override;
void setTrigonometric() override;

View File

@@ -148,10 +148,6 @@ uint32_t FunctionGraphController::rangeVersion() {
return interactiveCurveViewRange()->rangeChecksum();
}
bool FunctionGraphController::isCursorVisible() {
return interactiveCurveViewRange()->isCursorVisible(cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio);
}
bool FunctionGraphController::closestCurveIndexIsSuitable(int newIndex, int currentIndex) const {
return newIndex != currentIndex;
}

View File

@@ -40,7 +40,6 @@ private:
CurveView * curveView() override;
uint32_t modelVersion() override;
uint32_t rangeVersion() override;
bool isCursorVisible() override;
bool closestCurveIndexIsSuitable(int newIndex, int currentIndex) const override;
double yValue(int curveIndex, double x, Poincare::Context * context) const override;
int numberOfCurves() const override;

View File

@@ -194,6 +194,17 @@ StackViewController * InteractiveCurveViewController::stackController() const{
return (StackViewController *)(parentResponder()->parentResponder()->parentResponder());
}
bool InteractiveCurveViewController::isCursorVisible() {
InteractiveCurveViewRange * range = interactiveCurveViewRange();
float xRange = range->xMax() - range->xMin();
float yRange = range->yMax() - range->yMin();
return
m_cursor->x() >= range->xMin() + k_cursorLeftMarginRatio * xRange &&
m_cursor->x() <= range->xMax() - k_cursorRightMarginRatio * xRange &&
m_cursor->y() >= range->yMin() + cursorBottomMarginRatio() * yRange &&
m_cursor->y() <= range->yMax() - cursorTopMarginRatio() * yRange;
}
int InteractiveCurveViewController::closestCurveIndexVertically(bool goingUp, int currentCurveIndex, Poincare::Context * context) const {
double x = m_cursor->x();
double y = m_cursor->y();

View File

@@ -37,7 +37,7 @@ protected:
virtual bool moveCursorVertically(int direction) = 0;
virtual uint32_t modelVersion() = 0;
virtual uint32_t rangeVersion() = 0;
virtual bool isCursorVisible() = 0;
bool isCursorVisible();
// Closest vertical curve helper
int closestCurveIndexVertically(bool goingUp, int currentSelectedCurve, Poincare::Context * context) const;

View File

@@ -208,12 +208,6 @@ void InteractiveCurveViewRange::panToMakePointVisible(float x, float y, float to
}
}
bool InteractiveCurveViewRange::isCursorVisible(float topMarginRatio, float rightMarginRatio, float bottomMarginRation, float leftMarginRation) {
float xRange = m_xMax - m_xMin;
float yRange = m_yMax - m_yMin;
return m_cursor->x() >= m_xMin + leftMarginRation*xRange && m_cursor->x() <= m_xMax - rightMarginRatio*xRange && m_cursor->y() >= m_yMin + bottomMarginRation*yRange && m_cursor->y() <= m_yMax - topMarginRatio*yRange;
}
float InteractiveCurveViewRange::clipped(float x, bool isMax) {
float maxF = isMax ? k_upperMaxFloat : k_lowerMaxFloat;
float minF = isMax ? -k_lowerMaxFloat : -k_upperMaxFloat;

View File

@@ -3,7 +3,6 @@
#include <stdint.h>
#include "memoized_curve_view_range.h"
#include "curve_view_cursor.h"
#include "interactive_curve_view_range_delegate.h"
#include <ion/display.h>
#include <float.h>
@@ -13,15 +12,13 @@ namespace Shared {
class InteractiveCurveViewRange : public MemoizedCurveViewRange {
public:
constexpr static float k_minFloat = 1E-4f;
InteractiveCurveViewRange(CurveViewCursor * cursor, InteractiveCurveViewRangeDelegate * delegate = nullptr) :
InteractiveCurveViewRange(InteractiveCurveViewRangeDelegate * delegate = nullptr) :
MemoizedCurveViewRange(),
m_yAuto(true),
m_delegate(delegate),
m_cursor(cursor)
m_delegate(delegate)
{}
void setDelegate(InteractiveCurveViewRangeDelegate * delegate) { m_delegate = delegate; }
void setCursor(CurveViewCursor * cursor) { m_cursor = cursor; }
uint32_t rangeChecksum() override;
bool yAuto() const { return m_yAuto; }
@@ -42,7 +39,6 @@ public:
virtual void setDefault();
void centerAxisAround(Axis axis, float position);
void panToMakePointVisible(float x, float y, float topMarginRatio, float rightMarginRatio, float bottomMarginRation, float leftMarginRation);
bool isCursorVisible(float topMarginRatio, float rightMarginRatio, float bottomMarginRation, float leftMarginRation);
protected:
bool m_yAuto;
/* In normalized settings, we put each axis so that 1cm = 2 units. For now,
@@ -64,7 +60,6 @@ private:
constexpr static float k_lowerMaxFloat = 9E+7f;
constexpr static float k_maxRatioPositionRange = 1E5f;
void notifyRangeChange();
CurveViewCursor * m_cursor;
};
static_assert(InteractiveCurveViewRange::k_minFloat >= FLT_EPSILON, "InteractiveCurveViewRange's minimal float range is lower than float precision, it might draw uglily curves such as cos(x)^2+sin(x)^2");