diff --git a/apps/graph/graph/extremum_graph_controller.cpp b/apps/graph/graph/extremum_graph_controller.cpp index 999b211d9..6044d07f9 100644 --- a/apps/graph/graph/extremum_graph_controller.cpp +++ b/apps/graph/graph/extremum_graph_controller.cpp @@ -16,11 +16,7 @@ const char * MinimumGraphController::title() { } Coordinate2D 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 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); } } diff --git a/apps/shared/cartesian_function.cpp b/apps/shared/cartesian_function.cpp index bf3ebcf54..cdeea46cc 100644 --- a/apps/shared/cartesian_function.cpp +++ b/apps/shared/cartesian_function.cpp @@ -274,6 +274,14 @@ Coordinate2D CartesianFunction::templatedApproximateAtParameter(T t, Poincare PoincareHelpers::ApproximateWithValueForSymbol(e.childAtIndex(1), unknown, t, context)); } +Coordinate2D 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 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 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(PoincareHelpers::NextRoot(e, symbol, start, step, max, context), 0.0); }); } diff --git a/apps/shared/cartesian_function.h b/apps/shared/cartesian_function.h index 2b3e36b50..94f5d9d42 100644 --- a/apps/shared/cartesian_function.h +++ b/apps/shared/cartesian_function.h @@ -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 nextIntersectionFrom(double start, double step, double max, Poincare::Context * context, CartesianFunction * f) const; + // Extremum + Poincare::Coordinate2D nextMinimumFrom(double start, double step, double max, Poincare::Context * context) const; + Poincare::Coordinate2D nextMaximumFrom(double start, double step, double max, Poincare::Context * context) const; + // Roots Poincare::Coordinate2D nextRootFrom(double start, double step, double max, Poincare::Context * context) const; + Poincare::Coordinate2D 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 (*ComputePointOfInterest)(Poincare::Expression e, char * symbol, double start, double step, double max, Poincare::Context * context);