mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/graph] If only cartesians, jump to next curve when out of range
Scenario:
-----------• ->press "right": the cursor goes on the lower curve
-*-*-*-*-*-
This commit is contained in:
committed by
EmilieNumworks
parent
f037df0ab5
commit
e9974a216d
@@ -8,6 +8,8 @@ namespace Graph {
|
||||
|
||||
static inline float minFloat(float x, float y) { return x < y ? x : y; }
|
||||
static inline float maxFloat(float x, float y) { return x > y ? x : y; }
|
||||
static inline double minDouble(double x, double y) { return x < y ? x : y; }
|
||||
static inline double maxDouble(double x, double y) { return x > y ? x : y; }
|
||||
|
||||
GraphController::GraphController(Responder * parentResponder, ::InputEventHandlerDelegate * inputEventHandlerDelegate, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header) :
|
||||
FunctionGraphController(parentResponder, inputEventHandlerDelegate, header, curveViewRange, &m_view, cursor, indexFunctionSelectedByCursor, modelVersion, rangeVersion, angleUnitVersion),
|
||||
@@ -172,4 +174,50 @@ bool GraphController::shouldSetDefaultOnModelChange() const {
|
||||
return functionStore()->displaysNonCartesianFunctions();
|
||||
}
|
||||
|
||||
void GraphController::jumpToLeftRightCurve(double t, int direction, int functionsCount, Ion::Storage::Record record) {
|
||||
if (functionsCount == 1) {
|
||||
return;
|
||||
}
|
||||
int nextCurveIndex = -1;
|
||||
double xDelta = DBL_MAX;
|
||||
for (int i = 0; i < functionsCount; i++) {
|
||||
Ion::Storage::Record currentRecord = functionStore()->activeRecordAtIndex(i);
|
||||
if (currentRecord == record) {
|
||||
continue;
|
||||
}
|
||||
ExpiringPointer<ContinuousFunction> f = functionStore()->modelForRecord(currentRecord);
|
||||
assert(f->plotType() == ContinuousFunction::PlotType::Cartesian);
|
||||
// Select the closest horizontal curve
|
||||
double currentTMin = f->tMin();
|
||||
double currentTMax = f->tMax();
|
||||
assert(!std::isnan(currentTMin));
|
||||
assert(!std::isnan(currentTMax));
|
||||
if ((direction > 0 && currentTMax > t)
|
||||
||(direction < 0 && currentTMin < t))
|
||||
{
|
||||
double currentXDelta = direction > 0 ?
|
||||
(t >= currentTMin ? 0.0 : currentTMin - t) :
|
||||
(t <= currentTMax ? 0.0 : t - currentTMax);
|
||||
assert(currentXDelta >= 0.0);
|
||||
if (currentXDelta < xDelta) {
|
||||
nextCurveIndex = i;
|
||||
xDelta = currentXDelta;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nextCurveIndex < 0) {
|
||||
return;
|
||||
}
|
||||
Ion::Storage::Record currentRecord = functionStore()->activeRecordAtIndex(nextCurveIndex);
|
||||
ExpiringPointer<ContinuousFunction> f = functionStore()->modelForRecord(currentRecord);
|
||||
|
||||
double nextTMin = f->tMin();
|
||||
double nextTMax = f->tMax();
|
||||
double nextT = maxDouble(nextTMin, minDouble(nextTMax, t));
|
||||
Coordinate2D<double> xy = f->evaluateXYAtParameter(nextT, App::app()->localContext());
|
||||
m_cursor->moveTo(nextT, xy.x1(), xy.x2());
|
||||
selectFunctionWithCursor(nextCurveIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ private:
|
||||
bool defautRangeIsNormalized() const override;
|
||||
void interestingFunctionRange(Shared::ExpiringPointer<Shared::ContinuousFunction> f, float tMin, float tMax, float step, float * xm, float * xM, float * ym, float * yM) const;
|
||||
bool shouldSetDefaultOnModelChange() const override;
|
||||
void jumpToLeftRightCurve(double t, int direction, int functionsCount, Ion::Storage::Record record) override;
|
||||
|
||||
Shared::RoundCursorView m_cursorView;
|
||||
BannerView m_bannerView;
|
||||
|
||||
@@ -19,6 +19,14 @@ bool GraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCurso
|
||||
double t = tCursorPosition;
|
||||
double tMin = function->tMin();
|
||||
double tMax = function->tMax();
|
||||
int functionsCount = -1;
|
||||
if (((direction > 0 && std::abs(t-tMax) < DBL_EPSILON)
|
||||
|| (direction < 0 && std::abs(t-tMin) < DBL_EPSILON))
|
||||
&& !App::app()->functionStore()->displaysNonCartesianFunctions(&functionsCount))
|
||||
{
|
||||
jumpToLeftRightCurve(t, direction, functionsCount, record);
|
||||
return true;
|
||||
}
|
||||
double dir = (direction > 0 ? 1.0 : -1.0);
|
||||
ContinuousFunction::PlotType type = function->plotType();
|
||||
if (type == ContinuousFunction::PlotType::Cartesian) {
|
||||
|
||||
@@ -16,6 +16,7 @@ protected:
|
||||
virtual BannerView * bannerView() = 0;
|
||||
private:
|
||||
static constexpr double k_definitionDomainDivisor = 96.0;
|
||||
virtual void jumpToLeftRightCurve(double t, int direction, int functionsCount, Ion::Storage::Record record) {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -157,9 +157,9 @@ bool FunctionGraphController::moveCursorVertically(int direction) {
|
||||
if (nextActiveFunctionIndex < 0) {
|
||||
return false;
|
||||
}
|
||||
selectFunctionWithCursor(nextActiveFunctionIndex);
|
||||
Poincare::Coordinate2D<double> cursorPosition = xyValues(nextActiveFunctionIndex, m_cursor->t(), context);
|
||||
m_cursor->moveTo(m_cursor->t(), cursorPosition.x1(), cursorPosition.x2());
|
||||
selectFunctionWithCursor(nextActiveFunctionIndex);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user