[apps/sequence] Use first ranks when computing graph range

Put two sequences u(n+1)=u(n) and v(n+1) = v(n), u(100) = 50, v(50) = 8.
Basic settings computed the x range as [0,10] before, now it is
[50,110].
This commit is contained in:
Léa Saviot
2019-01-04 12:09:25 +01:00
parent 6720ad7b38
commit 5d1ef0f3f0
5 changed files with 71 additions and 29 deletions

View File

@@ -1,11 +1,15 @@
#include "graph_controller.h"
#include <cmath>
#include <limits.h>
using namespace Shared;
using namespace Poincare;
namespace Sequence {
static inline int minInt(int x, int y) { return (x < y ? x : y); }
static inline int maxInt(int x, int y) { return (x > y ? x : y); }
GraphController::GraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, SequenceStore * sequenceStore, CurveViewRange * graphRange, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header) :
FunctionGraphController(parentResponder, inputEventHandlerDelegate, header, graphRange, &m_view, cursor, indexFunctionSelectedByCursor, modelVersion, rangeVersion, angleUnitVersion),
m_bannerView(),
@@ -25,6 +29,34 @@ I18n::Message GraphController::emptyMessage() {
return I18n::Message::NoActivatedSequence;
}
float GraphController::interestingXMin() {
int nmin = INT_MAX;
for (int i = 0; i < m_sequenceStore->numberOfModels(); i++) {
Sequence * s = m_sequenceStore->modelAtIndex(i);
if (s->isDefined() && s->isActive()) {
nmin = minInt(nmin, s->initialRank());
}
}
assert(nmin < INT_MAX);
return nmin;
}
float GraphController::interestingXHalfRange() {
float standardRange = Shared::FunctionGraphController::interestingXHalfRange();
int nmin = INT_MAX;
int nmax = 0;
for (int i = 0; i < m_sequenceStore->numberOfModels(); i++) {
Sequence * s = m_sequenceStore->modelAtIndex(i);
if (s->isDefined() && s->isActive()) {
int firstInterestingIndex = s->initialRank();
nmin = minInt(nmin, firstInterestingIndex);
nmax = maxInt(nmax, firstInterestingIndex + standardRange);
}
}
assert(nmax - nmin >= standardRange);
return nmax - nmin;
}
bool GraphController::handleEnter() {
m_termSumController.setFunction(m_sequenceStore->activeFunctionAtIndex(indexFunctionSelectedByCursor()));
return FunctionGraphController::handleEnter();