From 7e6694990075448df8aa30ccff6db6c8d6ef7a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 3 Jan 2017 14:56:51 +0100 Subject: [PATCH] [apps/regression] Add methods in data model to set the cursor position at a specific abscissa/ordinate Change-Id: I95cde32b36405f57e3e6ccfa37e6e0cda70da59a --- apps/regression/data.cpp | 18 ++++++++++++++++++ apps/regression/data.h | 3 +++ 2 files changed, 21 insertions(+) diff --git a/apps/regression/data.cpp b/apps/regression/data.cpp index e12a6b41d..7110f805e 100644 --- a/apps/regression/data.cpp +++ b/apps/regression/data.cpp @@ -107,6 +107,20 @@ int Data::selectedDotIndex() { return m_selectedDotIndex; } +void Data::setCursorPositionAtAbscissa(float abscissa) { + m_xCursorPosition = abscissa; + centerAxisAround(CurveViewWindow::Axis::X, m_xCursorPosition); + m_yCursorPosition = yValueForXValue(m_xCursorPosition); + centerAxisAround(CurveViewWindow::Axis::Y, m_yCursorPosition); +} + +void Data::setCursorPositionAtOrdinate(float ordinate) { + m_yCursorPosition = ordinate; + centerAxisAround(CurveViewWindow::Axis::Y, m_yCursorPosition); + m_xCursorPosition = xValueForYValue(m_yCursorPosition); + centerAxisAround(CurveViewWindow::Axis::X, m_xCursorPosition); +} + /* Window */ void Data::setDefault() { @@ -197,6 +211,10 @@ float Data::yValueForXValue(float x) { return slope()*x+yIntercept(); } +float Data::xValueForYValue(float y) { + return (y - yIntercept())/slope(); +} + float Data::correlationCoefficient() { return covariance()/(xStandardDeviation()*yStandardDeviation()); } diff --git a/apps/regression/data.h b/apps/regression/data.h index f8b4731d4..abf4546cd 100644 --- a/apps/regression/data.h +++ b/apps/regression/data.h @@ -27,6 +27,8 @@ public: /* The selectedDotIndex is -1 when no dot is selected, m_numberOfPairs when * the mean dot is selected and the dot index otherwise */ int selectedDotIndex(); + void setCursorPositionAtAbscissa(float abscissa); + void setCursorPositionAtOrdinate(float ordinate); // Window void setDefault(); @@ -47,6 +49,7 @@ public: float slope(); float yIntercept(); float yValueForXValue(float x); + float xValueForYValue(float y); float correlationCoefficient(); float squaredCorrelationCoefficient();