mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[apps/graph] Move function min and max computation from the controller
to the model CartesianFunction and take into account function domain
This commit is contained in:
@@ -16,11 +16,7 @@ const char * MinimumGraphController::title() {
|
||||
}
|
||||
|
||||
Coordinate2D<double> MinimumGraphController::computeNewPointOfInterest(double start, double step, double max, Poincare::Context * context) {
|
||||
// TODO The following three lines should be factored.
|
||||
constexpr int bufferSize = CodePoint::MaxCodePointCharLength + 1;
|
||||
char unknownX[bufferSize];
|
||||
Poincare::SerializationHelper::CodePoint(unknownX, bufferSize, UCodePointUnknownX);
|
||||
return Shared::PoincareHelpers::NextMinimum(functionStore()->modelForRecord(m_record)->expressionReduced(context), unknownX, start, step, max, context);
|
||||
return functionStore()->modelForRecord(m_record)->nextMinimumFrom(start, step, max, context);
|
||||
}
|
||||
|
||||
MaximumGraphController::MaximumGraphController(Responder * parentResponder, GraphView * graphView, BannerView * bannerView, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor) :
|
||||
@@ -33,11 +29,7 @@ const char * MaximumGraphController::title() {
|
||||
}
|
||||
|
||||
Coordinate2D<double> MaximumGraphController::computeNewPointOfInterest(double start, double step, double max, Poincare::Context * context) {
|
||||
// TODO The following three lines should be factored.
|
||||
constexpr int bufferSize = CodePoint::MaxCodePointCharLength + 1;
|
||||
char unknownX[bufferSize];
|
||||
Poincare::SerializationHelper::CodePoint(unknownX, bufferSize, UCodePointUnknownX);
|
||||
return Shared::PoincareHelpers::NextMaximum(functionStore()->modelForRecord(m_record)->expressionReduced(context), unknownX, start, step, max, context);
|
||||
return functionStore()->modelForRecord(m_record)->nextMaximumFrom(start, step, max, context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -274,6 +274,14 @@ Coordinate2D<T> CartesianFunction::templatedApproximateAtParameter(T t, Poincare
|
||||
PoincareHelpers::ApproximateWithValueForSymbol(e.childAtIndex(1), unknown, t, context));
|
||||
}
|
||||
|
||||
Coordinate2D<double> CartesianFunction::nextMinimumFrom(double start, double step, double max, Context * context) const {
|
||||
return nextPointOfInterestFrom(start, step, max, context, [](Expression e, char * symbol, double start, double step, double max, Context * context) { return PoincareHelpers::NextMinimum(e, symbol, start, step, max, context); });
|
||||
}
|
||||
|
||||
Coordinate2D<double> CartesianFunction::nextMaximumFrom(double start, double step, double max, Context * context) const {
|
||||
return nextPointOfInterestFrom(start, step, max, context, [](Expression e, char * symbol, double start, double step, double max, Context * context) { return PoincareHelpers::NextMaximum(e, symbol, start, step, max, context); });
|
||||
}
|
||||
|
||||
Coordinate2D<double> CartesianFunction::nextRootFrom(double start, double step, double max, Context * context) const {
|
||||
return nextPointOfInterestFrom(start, step, max, context, [](Expression e, char * symbol, double start, double step, double max, Context * context) { return Coordinate2D<double>(PoincareHelpers::NextRoot(e, symbol, start, step, max, context), 0.0); });
|
||||
}
|
||||
|
||||
@@ -57,9 +57,12 @@ public:
|
||||
void setTMax(float tMax);
|
||||
float rangeStep() const override { return plotType() == PlotType::Cartesian ? NAN : (tMax() - tMin())/k_polarParamRangeSearchNumberOfPoints; }
|
||||
|
||||
// Cartesian calculation
|
||||
Poincare::Coordinate2D<double> nextIntersectionFrom(double start, double step, double max, Poincare::Context * context, CartesianFunction * f) const;
|
||||
// Extremum
|
||||
Poincare::Coordinate2D<double> nextMinimumFrom(double start, double step, double max, Poincare::Context * context) const;
|
||||
Poincare::Coordinate2D<double> nextMaximumFrom(double start, double step, double max, Poincare::Context * context) const;
|
||||
// Roots
|
||||
Poincare::Coordinate2D<double> nextRootFrom(double start, double step, double max, Poincare::Context * context) const;
|
||||
Poincare::Coordinate2D<double> nextIntersectionFrom(double start, double step, double max, Poincare::Context * context, CartesianFunction * f) const;
|
||||
private:
|
||||
constexpr static float k_polarParamRangeSearchNumberOfPoints = 100.0f; // This is ad hoc, no special justification
|
||||
typedef Poincare::Coordinate2D<double> (*ComputePointOfInterest)(Poincare::Expression e, char * symbol, double start, double step, double max, Poincare::Context * context);
|
||||
|
||||
Reference in New Issue
Block a user