mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/function] Factorize zoom in Function class
The new zoom implemented for ContinuousFunction is now factorized inside Function to benefit the Sequence class. The same things is done to code added to Graph::GraphController, which is moved into FunctionGraphController. This removes the reimplementation of several methods, most notably computeYRange, as the implementation for function is general enough to work on sequences. Change-Id: I9b8211354064f46c3fa3dde3191dcb39d627a1d2
This commit is contained in:
committed by
Émilie Feral
parent
33f9bb50a3
commit
a6db9688cd
@@ -152,4 +152,53 @@ int FunctionGraphController::numberOfCurves() const {
|
||||
return functionStore()->numberOfActiveFunctions();
|
||||
}
|
||||
|
||||
void FunctionGraphController::interestingRanges(InteractiveCurveViewRange * range) const {
|
||||
privateComputeRanges(true, range);
|
||||
}
|
||||
|
||||
Shared::InteractiveCurveViewRangeDelegate::Range FunctionGraphController::computeYRange(Shared::InteractiveCurveViewRange * interactiveCurveViewRange) {
|
||||
InteractiveCurveViewRange tempRange = *interactiveCurveViewRange;
|
||||
tempRange.setYAuto(false);
|
||||
privateComputeRanges(false, &tempRange);
|
||||
return Shared::InteractiveCurveViewRangeDelegate::Range{.min = tempRange.yMin(), .max = tempRange.yMax()};
|
||||
}
|
||||
|
||||
void FunctionGraphController::privateComputeRanges(bool tuneXRange, InteractiveCurveViewRange * range) const {
|
||||
Poincare::Context * context = textFieldDelegateApp()->localContext();
|
||||
float resultXMin = tuneXRange ? FLT_MAX : range->xMin();
|
||||
float resultXMax = tuneXRange ? -FLT_MAX : range->xMax();
|
||||
float resultYMin = FLT_MAX;
|
||||
float resultYMax = -FLT_MAX;
|
||||
assert(functionStore()->numberOfActiveFunctions() > 0);
|
||||
int functionsCount = functionStore()->numberOfActiveFunctions();
|
||||
for (int i = 0; i < functionsCount; i++) {
|
||||
ExpiringPointer<Function> f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(i));
|
||||
f->rangeForDisplay(&resultXMin, &resultXMax, &resultYMin, &resultYMax, context, tuneXRange);
|
||||
}
|
||||
|
||||
range->setXMin(resultXMin);
|
||||
range->setXMax(resultXMax);
|
||||
range->setYMin(resultYMin);
|
||||
range->setYMax(resultYMax);
|
||||
/* We can only call this method once the X range has been fully computed. */
|
||||
yRangeForCursorFirstMove(range);
|
||||
}
|
||||
|
||||
void FunctionGraphController::yRangeForCursorFirstMove(InteractiveCurveViewRange * range) const {
|
||||
Poincare::Context * context = textFieldDelegateApp()->localContext();
|
||||
assert(functionStore()->numberOfActiveFunctions() > 0);
|
||||
int functionsCount = functionStore()->numberOfActiveFunctions();
|
||||
|
||||
float cursorStep = range->xGridUnit() / k_numberOfCursorStepsInGradUnit;
|
||||
float yN, yP;
|
||||
|
||||
for (int i = 0; i < functionsCount; i++) {
|
||||
ExpiringPointer<Function> f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(i));
|
||||
yN = f->evaluateXYAtParameter(range->xCenter() - cursorStep, context).x2();
|
||||
yP = f->evaluateXYAtParameter(range->xCenter() + cursorStep, context).x2();
|
||||
range->setYMin(std::min(range->yMin(), std::min(yN, yP)));
|
||||
range->setYMax(std::max(range->yMax(), std::max(yN, yP)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user