[apps/shared] computeYRange clips tMin..tMax to xMin..xMax if possible

This commit is contained in:
Léa Saviot
2019-08-30 10:17:12 +02:00
parent 8c7819306a
commit 850170e33b
4 changed files with 7 additions and 0 deletions

View File

@@ -42,6 +42,7 @@ public:
int derivativeNameWithArgument(char * buffer, size_t bufferSize);
double approximateDerivative(double x, Poincare::Context * context) const;
// tMin and tMax
bool shouldClipTRangeToXRange() const override { return plotType() == PlotType::Cartesian; }
double tMin() const override;
double tMax() const override;
void setTMin(double tMin);

View File

@@ -531,6 +531,7 @@ void CurveView::drawCurve(KDContext * ctx, KDRect rect, float tStart, float tEnd
void CurveView::drawCartesianCurve(KDContext * ctx, KDRect rect, float xMin, float xMax, EvaluateXYForParameter xyEvaluation, void * model, void * context, KDColor color, bool colorUnderCurve, float colorLowerBound, float colorUpperBound) const {
float tStart = maxFloat(xMin, pixelToFloat(Axis::Horizontal, rect.left() - k_externRectMargin));
float tEnd = minFloat(xMax, pixelToFloat(Axis::Horizontal, rect.right() + k_externRectMargin));
assert(!std::isinf(tStart) && !std::isnan(tStart) && !std::isinf(tEnd) && !std::isnan(tEnd) );
if (tStart > tEnd) {
return;
}

View File

@@ -34,6 +34,7 @@ public:
void setActive(bool active);
// Definition Interval
virtual bool shouldClipTRangeToXRange() const { return true; } // Returns true if the function will not be displayed if t is outside x range.
virtual double tMin() const { return NAN; }
virtual double tMax() const { return NAN; }

View File

@@ -92,10 +92,14 @@ InteractiveCurveViewRangeDelegate::Range FunctionGraphController::computeYRange(
double tMin = f->tMin();
if (std::isnan(tMin)) {
tMin = xMin;
} else if (f->shouldClipTRangeToXRange()) {
tMin = maxFloat(tMin, xMin);
}
double tMax = f->tMax();
if (std::isnan(tMax)) {
tMax = xMax;
} else if (f->shouldClipTRangeToXRange()) {
tMax = minFloat(tMax, xMax);
}
const int balancedBound = std::floor((tMax-tMin)/2/step);
for (int j = -balancedBound; j <= balancedBound ; j++) {