From a945c02edf4e52bd0f021bafa200617a126b70da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Wed, 28 Aug 2019 17:22:56 +0200 Subject: [PATCH] [poincare/Coordinate2D] Rename members x1 and x2 --- .../graph/calculation_graph_controller.cpp | 8 ++++---- apps/graph/graph/graph_controller_helper.cpp | 2 +- .../graph/intersection_graph_controller.cpp | 4 ++-- apps/shared/cartesian_function.cpp | 9 ++++++--- apps/shared/cartesian_function.h | 12 ++++++++---- apps/shared/function.h | 4 ++-- .../function_go_to_parameter_controller.cpp | 4 ++-- apps/shared/function_graph_controller.cpp | 18 +++++++++--------- .../interactive_curve_view_controller.cpp | 2 +- apps/shared/sum_graph_controller.cpp | 3 +-- apps/shared/values_controller.cpp | 6 +++--- poincare/include/poincare/coordinate_2D.h | 15 +++++++-------- 12 files changed, 46 insertions(+), 41 deletions(-) diff --git a/apps/graph/graph/calculation_graph_controller.cpp b/apps/graph/graph/calculation_graph_controller.cpp index d4a3c9811..03142f9ba 100644 --- a/apps/graph/graph/calculation_graph_controller.cpp +++ b/apps/graph/graph/calculation_graph_controller.cpp @@ -20,14 +20,14 @@ CalculationGraphController::CalculationGraphController(Responder * parentRespond void CalculationGraphController::viewWillAppear() { assert(!m_record.isNull()); Coordinate2D pointOfInterest = computeNewPointOfInteresetFromAbscissa(m_graphRange->xMin(), 1); - if (std::isnan(pointOfInterest.x())) { + if (std::isnan(pointOfInterest.x1())) { m_isActive = false; m_graphView->setCursorView(nullptr); m_graphView->setBannerView(&m_defaultBannerView); } else { m_isActive = true; assert(App::app()->functionStore()->modelForRecord(m_record)->plotType() == Shared::CartesianFunction::PlotType::Cartesian); - m_cursor->moveTo(pointOfInterest.x(), pointOfInterest.x(), pointOfInterest.y()); + m_cursor->moveTo(pointOfInterest.x1(), pointOfInterest.x1(), pointOfInterest.x2()); m_graphRange->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio); m_bannerView->setNumberOfSubviews(Shared::XYBannerView::k_numberOfSubviews); reloadBannerView(); @@ -71,11 +71,11 @@ bool CalculationGraphController::handleEnter() { bool CalculationGraphController::moveCursorHorizontally(int direction) { Coordinate2D newPointOfInterest = computeNewPointOfInteresetFromAbscissa(m_cursor->x(), direction); - if (std::isnan(newPointOfInterest.x())) { + if (std::isnan(newPointOfInterest.x1())) { return false; } assert(App::app()->functionStore()->modelForRecord(m_record)->plotType() == Shared::CartesianFunction::PlotType::Cartesian); - m_cursor->moveTo(newPointOfInterest.x(), newPointOfInterest.x(), newPointOfInterest.y()); + m_cursor->moveTo(newPointOfInterest.x1(), newPointOfInterest.x1(), newPointOfInterest.x2()); return true; } diff --git a/apps/graph/graph/graph_controller_helper.cpp b/apps/graph/graph/graph_controller_helper.cpp index 466643dca..32cb93ac5 100644 --- a/apps/graph/graph/graph_controller_helper.cpp +++ b/apps/graph/graph/graph_controller_helper.cpp @@ -25,7 +25,7 @@ bool GraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCurso } Coordinate2D xy = function->evaluateXYAtParameter(t, App::app()->localContext()); - cursor->moveTo(t, xy.x(), xy.y()); + cursor->moveTo(t, xy.x1(), xy.x2()); return true; } diff --git a/apps/graph/graph/intersection_graph_controller.cpp b/apps/graph/graph/intersection_graph_controller.cpp index 50e14ecf0..abf46f87e 100644 --- a/apps/graph/graph/intersection_graph_controller.cpp +++ b/apps/graph/graph/intersection_graph_controller.cpp @@ -51,9 +51,9 @@ Poincare::Coordinate2D IntersectionGraphController::computeNewPointOfInt if (record != m_record) { Poincare::Expression e = functionStore()->modelForRecord(record)->expressionReduced(context); Poincare::Coordinate2D intersection = Shared::PoincareHelpers::NextIntersection(functionStore()->modelForRecord(m_record)->expressionReduced(context), unknownX, start, step, max, context, e); - if ((std::isnan(result.x()) || std::fabs(intersection.x()-start) < std::fabs(result.x()-start)) && !std::isnan(intersection.x())) { + if ((std::isnan(result.x1()) || std::fabs(intersection.x1()-start) < std::fabs(result.x1()-start)) && !std::isnan(intersection.x1())) { m_intersectedRecord = record; - result = (std::isnan(result.x()) || std::fabs(intersection.x()-start) < std::fabs(result.x()-start)) ? intersection : result; + result = (std::isnan(result.x1()) || std::fabs(intersection.x1()-start) < std::fabs(result.x1()-start)) ? intersection : result; } } } diff --git a/apps/shared/cartesian_function.cpp b/apps/shared/cartesian_function.cpp index 41d89554b..e8e0643c5 100644 --- a/apps/shared/cartesian_function.cpp +++ b/apps/shared/cartesian_function.cpp @@ -112,14 +112,17 @@ void CartesianFunction::setPlotType(PlotType plotType) { return recordData()->setPlotType(plotType); } -Coordinate2D CartesianFunction::evaluateXYAtParameter(double t, Poincare::Context * context) const { - Coordinate2D x1x2 = evaluate2DAtParameter(t, context); +template +Poincare::Coordinate2D CartesianFunction::privateEvaluateXYAtParameter(T t, Poincare::Context * context) const { + Coordinate2D x1x2 = templatedApproximateAtParameter(t, context); PlotType type = plotType(); if (type == PlotType::Cartesian || type == PlotType::Parametric) { return x1x2; } assert(type == PlotType::Polar); - return Coordinate2D(x1x2.y() * std::cos(x1x2.x()*3.14/180.0), x1x2.y() * std::sin(x1x2.x()*3.14/180.0)); //TODO LEA RUBEN + T factor = (T)1.0; + // TODO LEA RUBEN + return Coordinate2D(x1x2.x2() * std::cos(x1x2.x1()*factor), x1x2.x2() * std::sin(x1x2.x1()*factor)); } bool CartesianFunction::displayDerivative() const { diff --git a/apps/shared/cartesian_function.h b/apps/shared/cartesian_function.h index ea5a33ec4..2565dcd6c 100644 --- a/apps/shared/cartesian_function.h +++ b/apps/shared/cartesian_function.h @@ -26,13 +26,16 @@ public: void setPlotType(PlotType plotType); // Evaluation - Poincare::Coordinate2D evaluateXYAtParameter(double t, Poincare::Context * context) const; - Poincare::Coordinate2D evaluate2DAtParameter(float t, Poincare::Context * context) const override { + Poincare::Coordinate2D evaluate2DAtParameter(double t, Poincare::Context * context) const { return templatedApproximateAtParameter(t, context); } - Poincare::Coordinate2D evaluate2DAtParameter(double t, Poincare::Context * context) const override { - return templatedApproximateAtParameter(t, context); + Poincare::Coordinate2D evaluateXYAtParameter(float t, Poincare::Context * context) const override { + return privateEvaluateXYAtParameter(t, context); } + Poincare::Coordinate2D evaluateXYAtParameter(double t, Poincare::Context * context) const override { + return privateEvaluateXYAtParameter(t, context); + } + // Derivative bool displayDerivative() const; void setDisplayDerivative(bool display); @@ -44,6 +47,7 @@ public: void setTMin(double tMin); void setTMax(double tMax); private: + template Poincare::Coordinate2D privateEvaluateXYAtParameter(T t, Poincare::Context * context) const; /* CartesianFunctionRecordDataBuffer is the layout of the data buffer of Record * representing a CartesianFunction. See comment on * Shared::Function::FunctionRecordDataBuffer about packing. */ diff --git a/apps/shared/function.h b/apps/shared/function.h index 0f5f2e325..11e0adfec 100644 --- a/apps/shared/function.h +++ b/apps/shared/function.h @@ -41,8 +41,8 @@ public: int nameWithArgument(char * buffer, size_t bufferSize); // Evaluation - virtual Poincare::Coordinate2D evaluate2DAtParameter(float t, Poincare::Context * context) const = 0; - virtual Poincare::Coordinate2D evaluate2DAtParameter(double t, Poincare::Context * context) const = 0; + virtual Poincare::Coordinate2D evaluateXYAtParameter(float t, Poincare::Context * context) const = 0; + virtual Poincare::Coordinate2D evaluateXYAtParameter(double t, Poincare::Context * context) const = 0; protected: /* FunctionRecordDataBuffer is the layout of the data buffer of Record * representing a Function. We want to avoid padding which would: diff --git a/apps/shared/function_go_to_parameter_controller.cpp b/apps/shared/function_go_to_parameter_controller.cpp index c3f05559b..afbbaed8e 100644 --- a/apps/shared/function_go_to_parameter_controller.cpp +++ b/apps/shared/function_go_to_parameter_controller.cpp @@ -24,8 +24,8 @@ bool FunctionGoToParameterController::setParameterAtIndex(int parameterIndex, do assert(parameterIndex == 0); FunctionApp * myApp = FunctionApp::app(); ExpiringPointer function = myApp->functionStore()->modelForRecord(m_record); - Poincare::Coordinate2D xy = function->evaluate2DAtParameter(f, myApp->localContext()); - m_cursor->moveTo(f, xy.x(), xy.y()); + Poincare::Coordinate2D xy = function->evaluateXYAtParameter(f, myApp->localContext()); + m_cursor->moveTo(f, xy.x1(), xy.x2()); m_graphRange->centerAxisAround(CurveViewRange::Axis::X, m_cursor->x()); m_graphRange->centerAxisAround(CurveViewRange::Axis::Y, m_cursor->y()); /* The range might have evolved to center around the cursor but we don't want diff --git a/apps/shared/function_graph_controller.cpp b/apps/shared/function_graph_controller.cpp index 133547a95..90f3e9bb5 100644 --- a/apps/shared/function_graph_controller.cpp +++ b/apps/shared/function_graph_controller.cpp @@ -107,10 +107,10 @@ InteractiveCurveViewRangeDelegate::Range FunctionGraphController::computeYRange( const int balancedBound = std::floor((tMax-tMin)/2/step); for (int j = -balancedBound; j <= balancedBound ; j++) { float t = (tMin+tMax)/2 + step * j; - Coordinate2D xy = f->evaluate2DAtParameter(t, context); - float x = xy.x(); + Coordinate2D xy = f->evaluateXYAtParameter(t, context); + float x = xy.x1(); if (!std::isnan(x) && !std::isinf(x) && x >= xMin && x <= xMax) { - float y = xy.y(); + float y = xy.x2(); if (!std::isnan(y) && !std::isinf(y)) { min = minFloat(min, y); max = maxFloat(max, y); @@ -139,13 +139,13 @@ void FunctionGraphController::initCursorParameters() { Coordinate2D xy; do { ExpiringPointer firstFunction = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(functionIndex++)); - xy = firstFunction->evaluate2DAtParameter(t, context); - } while ((std::isnan(xy.y()) || std::isinf(xy.y())) && functionIndex < functionStore()->numberOfActiveFunctions()); - m_cursor->moveTo(t, xy.x(), xy.y()); - functionIndex = (std::isnan(xy.y()) || std::isinf(xy.y())) ? 0 : functionIndex - 1; + xy = firstFunction->evaluateXYAtParameter(t, context); + } while ((std::isnan(xy.x2()) || std::isinf(xy.x2())) && functionIndex < functionStore()->numberOfActiveFunctions()); + m_cursor->moveTo(t, xy.x1(), xy.x2()); + functionIndex = (std::isnan(xy.x2()) || std::isinf(xy.x2())) ? 0 : functionIndex - 1; selectFunctionWithCursor(functionIndex); if (interactiveCurveViewRange()->yAuto()) { - interactiveCurveViewRange()->panToMakePointVisible(xy.x(), xy.y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio); + interactiveCurveViewRange()->panToMakePointVisible(xy.x1(), xy.x2(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio); } } @@ -181,7 +181,7 @@ bool FunctionGraphController::closestCurveIndexIsSuitable(int newIndex, int curr } Coordinate2D FunctionGraphController::xyValues(int curveIndex, double t, Poincare::Context * context) const { - return functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(curveIndex))->evaluate2DAtParameter(t, context); + return functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(curveIndex))->evaluateXYAtParameter(t, context); } int FunctionGraphController::numberOfCurves() const { diff --git a/apps/shared/interactive_curve_view_controller.cpp b/apps/shared/interactive_curve_view_controller.cpp index 72f781fa3..b6abb5671 100644 --- a/apps/shared/interactive_curve_view_controller.cpp +++ b/apps/shared/interactive_curve_view_controller.cpp @@ -187,7 +187,7 @@ bool InteractiveCurveViewController::textFieldDidFinishEditing(TextField * textF return false; } Coordinate2D xy = xyValues(selectedCurveIndex(), floatBody, textFieldDelegateApp()->localContext()); - m_cursor->moveTo(floatBody, xy.x(), xy.y()); + m_cursor->moveTo(floatBody, xy.x1(), xy.x2()); interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio); reloadBannerView(); curveView()->reload(); diff --git a/apps/shared/sum_graph_controller.cpp b/apps/shared/sum_graph_controller.cpp index e4e3551bb..cebbbee19 100644 --- a/apps/shared/sum_graph_controller.cpp +++ b/apps/shared/sum_graph_controller.cpp @@ -66,8 +66,7 @@ bool SumGraphController::moveCursorHorizontallyToPosition(double x) { assert(!m_record.isNull()); ExpiringPointer function = myApp->functionStore()->modelForRecord(m_record); - Coordinate2D xy = function->evaluate2DAtParameter(x, myApp->localContext()); //TODO LEA assertion that x = t? - double y = xy.y(); + double y = function->evaluateXYAtParameter(x, myApp->localContext()).x2(); //TODO LEA assertion that x = t? m_cursor->moveTo(x, x, y); if (m_step == Step::SecondParameter) { m_graphView->setAreaHighlight(m_startSum, m_cursor->x()); diff --git a/apps/shared/values_controller.cpp b/apps/shared/values_controller.cpp index 304e3ba47..d9721c8f5 100644 --- a/apps/shared/values_controller.cpp +++ b/apps/shared/values_controller.cpp @@ -328,9 +328,9 @@ int ValuesController::maxNumberOfElements() const { double ValuesController::evaluationOfAbscissaAtColumn(double abscissa, int columnIndex) { ExpiringPointer function = functionStore()->modelForRecord(recordAtColumn(columnIndex)); //TODO LEA RUBEN Careful with merge - //TODO LEA RUBEN change with evaluationOfParameterAtColumn? - Poincare::Coordinate2D xy = function->evaluate2DAtParameter(abscissa, textFieldDelegateApp()->localContext()); - return xy.y(); + //TODO LEA RUBEN change with evaluationOfParameterAtColumn? evaluate2DAtParameter ? + Poincare::Coordinate2D xy = function->evaluateXYAtParameter(abscissa, textFieldDelegateApp()->localContext()); + return xy.x2(); } void ValuesController::updateNumberOfColumns() { diff --git a/poincare/include/poincare/coordinate_2D.h b/poincare/include/poincare/coordinate_2D.h index 0a9489f44..078a30116 100644 --- a/poincare/include/poincare/coordinate_2D.h +++ b/poincare/include/poincare/coordinate_2D.h @@ -5,18 +5,17 @@ namespace Poincare { -// TODO LEA RUBEN x1 and x2 instead of x y template class Coordinate2D final { public: - Coordinate2D(T x = NAN, T y = NAN) : m_x(x), m_y(y) {} - T x() const { return m_x; } - T y() const { return m_y; } - void setX(T x) { m_x = x; } - void setY(T y) { m_y = y; } + Coordinate2D(T x1 = NAN, T x2 = NAN) : m_x1(x1), m_x2(x2) {} + T x1() const { return m_x1; } + T x2() const { return m_x2; } + void setX1(T x1) { m_x1 = x1; } + void setX2(T x2) { m_x2 = x2; } private: - T m_x; - T m_y; + T m_x1; + T m_x2; }; }