[poincare/Coordinate2D] Rename members x1 and x2

This commit is contained in:
Léa Saviot
2019-08-28 17:22:56 +02:00
parent c71ef7ff79
commit a945c02edf
12 changed files with 46 additions and 41 deletions

View File

@@ -20,14 +20,14 @@ CalculationGraphController::CalculationGraphController(Responder * parentRespond
void CalculationGraphController::viewWillAppear() {
assert(!m_record.isNull());
Coordinate2D<double> 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<double> 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;
}

View File

@@ -25,7 +25,7 @@ bool GraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCurso
}
Coordinate2D<double> xy = function->evaluateXYAtParameter(t, App::app()->localContext());
cursor->moveTo(t, xy.x(), xy.y());
cursor->moveTo(t, xy.x1(), xy.x2());
return true;
}

View File

@@ -51,9 +51,9 @@ Poincare::Coordinate2D<double> IntersectionGraphController::computeNewPointOfInt
if (record != m_record) {
Poincare::Expression e = functionStore()->modelForRecord(record)->expressionReduced(context);
Poincare::Coordinate2D<double> 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;
}
}
}

View File

@@ -112,14 +112,17 @@ void CartesianFunction::setPlotType(PlotType plotType) {
return recordData()->setPlotType(plotType);
}
Coordinate2D<double> CartesianFunction::evaluateXYAtParameter(double t, Poincare::Context * context) const {
Coordinate2D<double> x1x2 = evaluate2DAtParameter(t, context);
template <typename T>
Poincare::Coordinate2D<T> CartesianFunction::privateEvaluateXYAtParameter(T t, Poincare::Context * context) const {
Coordinate2D<T> x1x2 = templatedApproximateAtParameter(t, context);
PlotType type = plotType();
if (type == PlotType::Cartesian || type == PlotType::Parametric) {
return x1x2;
}
assert(type == PlotType::Polar);
return Coordinate2D<double>(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<T>(x1x2.x2() * std::cos(x1x2.x1()*factor), x1x2.x2() * std::sin(x1x2.x1()*factor));
}
bool CartesianFunction::displayDerivative() const {

View File

@@ -26,13 +26,16 @@ public:
void setPlotType(PlotType plotType);
// Evaluation
Poincare::Coordinate2D<double> evaluateXYAtParameter(double t, Poincare::Context * context) const;
Poincare::Coordinate2D<float> evaluate2DAtParameter(float t, Poincare::Context * context) const override {
Poincare::Coordinate2D<double> evaluate2DAtParameter(double t, Poincare::Context * context) const {
return templatedApproximateAtParameter(t, context);
}
Poincare::Coordinate2D<double> evaluate2DAtParameter(double t, Poincare::Context * context) const override {
return templatedApproximateAtParameter(t, context);
Poincare::Coordinate2D<float> evaluateXYAtParameter(float t, Poincare::Context * context) const override {
return privateEvaluateXYAtParameter<float>(t, context);
}
Poincare::Coordinate2D<double> evaluateXYAtParameter(double t, Poincare::Context * context) const override {
return privateEvaluateXYAtParameter<double>(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 <typename T> Poincare::Coordinate2D<T> 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. */

View File

@@ -41,8 +41,8 @@ public:
int nameWithArgument(char * buffer, size_t bufferSize);
// Evaluation
virtual Poincare::Coordinate2D<float> evaluate2DAtParameter(float t, Poincare::Context * context) const = 0;
virtual Poincare::Coordinate2D<double> evaluate2DAtParameter(double t, Poincare::Context * context) const = 0;
virtual Poincare::Coordinate2D<float> evaluateXYAtParameter(float t, Poincare::Context * context) const = 0;
virtual Poincare::Coordinate2D<double> 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:

View File

@@ -24,8 +24,8 @@ bool FunctionGoToParameterController::setParameterAtIndex(int parameterIndex, do
assert(parameterIndex == 0);
FunctionApp * myApp = FunctionApp::app();
ExpiringPointer<Function> function = myApp->functionStore()->modelForRecord(m_record);
Poincare::Coordinate2D<double> xy = function->evaluate2DAtParameter(f, myApp->localContext());
m_cursor->moveTo(f, xy.x(), xy.y());
Poincare::Coordinate2D<double> 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

View File

@@ -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<float> xy = f->evaluate2DAtParameter(t, context);
float x = xy.x();
Coordinate2D<float> 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<double> xy;
do {
ExpiringPointer<Function> 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<double> 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 {

View File

@@ -187,7 +187,7 @@ bool InteractiveCurveViewController::textFieldDidFinishEditing(TextField * textF
return false;
}
Coordinate2D<double> 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();

View File

@@ -66,8 +66,7 @@ bool SumGraphController::moveCursorHorizontallyToPosition(double x) {
assert(!m_record.isNull());
ExpiringPointer<Function> function = myApp->functionStore()->modelForRecord(m_record);
Coordinate2D<double> 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());

View File

@@ -328,9 +328,9 @@ int ValuesController::maxNumberOfElements() const {
double ValuesController::evaluationOfAbscissaAtColumn(double abscissa, int columnIndex) {
ExpiringPointer<Function> function = functionStore()->modelForRecord(recordAtColumn(columnIndex));
//TODO LEA RUBEN Careful with merge
//TODO LEA RUBEN change with evaluationOfParameterAtColumn?
Poincare::Coordinate2D<double> xy = function->evaluate2DAtParameter(abscissa, textFieldDelegateApp()->localContext());
return xy.y();
//TODO LEA RUBEN change with evaluationOfParameterAtColumn? evaluate2DAtParameter ?
Poincare::Coordinate2D<double> xy = function->evaluateXYAtParameter(abscissa, textFieldDelegateApp()->localContext());
return xy.x2();
}
void ValuesController::updateNumberOfColumns() {

View File

@@ -5,18 +5,17 @@
namespace Poincare {
// TODO LEA RUBEN x1 and x2 instead of x y
template <typename T>
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;
};
}