mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[apps] Tweaked panning for better cache alignement
Method InteractiveCurveViewRange::panToMakePointVisible now moves the range of a whole number of pixels when panning horizontally. This allows the cache of cartesian functions not to be invalidated. Change-Id: Idb9904fef134dd13458e1f2287b0fe5145e8aec7
This commit is contained in:
committed by
Émilie Feral
parent
5bc19af196
commit
4007f4d452
@@ -30,7 +30,7 @@ void CalculationGraphController::viewWillAppear() {
|
||||
m_isActive = true;
|
||||
assert(App::app()->functionStore()->modelForRecord(m_record)->plotType() == Shared::ContinuousFunction::PlotType::Cartesian);
|
||||
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_graphRange->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio, curveView()->pixelWidth());
|
||||
m_bannerView->setNumberOfSubviews(Shared::XYBannerView::k_numberOfSubviews);
|
||||
reloadBannerView();
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ const char * TangentGraphController::title() {
|
||||
|
||||
void TangentGraphController::viewWillAppear() {
|
||||
Shared::SimpleInteractiveCurveViewController::viewWillAppear();
|
||||
m_graphRange->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio);
|
||||
m_graphRange->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio, curveView()->pixelWidth());
|
||||
m_graphView->drawTangent(true);
|
||||
m_graphView->setOkView(nullptr);
|
||||
m_graphView->selectMainView(true);
|
||||
@@ -51,7 +51,7 @@ bool TangentGraphController::textFieldDidFinishEditing(TextField * textField, co
|
||||
assert(function->plotType() == Shared::ContinuousFunction::PlotType::Cartesian);
|
||||
double y = function->evaluate2DAtParameter(floatBody, myApp->localContext()).x2();
|
||||
m_cursor->moveTo(floatBody, floatBody, y);
|
||||
interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio);
|
||||
interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio, curveView()->pixelWidth());
|
||||
reloadBannerView();
|
||||
curveView()->reload();
|
||||
return true;
|
||||
|
||||
@@ -262,7 +262,7 @@ void GraphController::initCursorParameters() {
|
||||
double y = m_store->meanOfColumn(*m_selectedSeriesIndex, 1);
|
||||
m_cursor->moveTo(x, x, y);
|
||||
if (m_store->yAuto()) {
|
||||
m_store->panToMakePointVisible(x, y, cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio);
|
||||
m_store->panToMakePointVisible(x, y, cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio, curveView()->pixelWidth());
|
||||
}
|
||||
*m_selectedDotIndex = m_store->numberOfPairsOfSeries(*m_selectedSeriesIndex);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ bool GraphController::textFieldDidFinishEditing(TextField * textField, const cha
|
||||
floatBody = std::fmax(0, std::round(floatBody));
|
||||
double y = xyValues(selectedCurveIndex(), floatBody, myApp->localContext()).x2();
|
||||
m_cursor->moveTo(floatBody, floatBody, y);
|
||||
interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio);
|
||||
interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio, curveView()->pixelWidth());
|
||||
reloadBannerView();
|
||||
m_view.reload();
|
||||
return true;
|
||||
|
||||
@@ -146,7 +146,7 @@ void FunctionGraphController::initCursorParameters() {
|
||||
}
|
||||
m_cursor->moveTo(t, xy.x1(), xy.x2());
|
||||
if (interactiveCurveViewRange()->yAuto()) {
|
||||
interactiveCurveViewRange()->panToMakePointVisible(xy.x1(), xy.x2(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio);
|
||||
interactiveCurveViewRange()->panToMakePointVisible(xy.x1(), xy.x2(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio, curveView()->pixelWidth());
|
||||
}
|
||||
selectFunctionWithCursor(functionIndex);
|
||||
}
|
||||
|
||||
@@ -93,7 +93,8 @@ bool InteractiveCurveViewController::handleEvent(Ion::Events::Event event) {
|
||||
if (moveCursorVertically(direction)) {
|
||||
interactiveCurveViewRange()->panToMakePointVisible(
|
||||
m_cursor->x(), m_cursor->y(),
|
||||
cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio
|
||||
cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio,
|
||||
curveView()->pixelWidth()
|
||||
);
|
||||
reloadBannerView();
|
||||
curveView()->reload();
|
||||
@@ -220,7 +221,7 @@ bool InteractiveCurveViewController::textFieldDidFinishEditing(TextField * textF
|
||||
}
|
||||
Coordinate2D<double> xy = xyValues(selectedCurveIndex(), floatBody, textFieldDelegateApp()->localContext());
|
||||
m_cursor->moveTo(floatBody, xy.x1(), xy.x2());
|
||||
interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio);
|
||||
interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio, curveView()->pixelWidth());
|
||||
reloadBannerView();
|
||||
curveView()->reload();
|
||||
return true;
|
||||
|
||||
@@ -199,20 +199,23 @@ void InteractiveCurveViewRange::centerAxisAround(Axis axis, float position) {
|
||||
}
|
||||
}
|
||||
|
||||
void InteractiveCurveViewRange::panToMakePointVisible(float x, float y, float topMarginRatio, float rightMarginRatio, float bottomMarginRatio, float leftMarginRatio) {
|
||||
void InteractiveCurveViewRange::panToMakePointVisible(float x, float y, float topMarginRatio, float rightMarginRatio, float bottomMarginRatio, float leftMarginRatio, float pixelWidth) {
|
||||
if (!std::isinf(x) && !std::isnan(x)) {
|
||||
const float xRange = xMax() - xMin();
|
||||
const float leftMargin = leftMarginRatio * xRange;
|
||||
if (x < xMin() + leftMargin) {
|
||||
m_yAuto = false;
|
||||
const float newXMin = x - leftMargin;
|
||||
/* The panning increment is a whole number of pixels so that the caching
|
||||
* for cartesian functions is not invalidated. */
|
||||
const float newXMin = std::floor((x - leftMargin - xMin()) / pixelWidth) * pixelWidth + xMin();
|
||||
m_xRange.setMax(newXMin + xRange, k_lowerMaxFloat, k_upperMaxFloat);
|
||||
MemoizedCurveViewRange::protectedSetXMin(newXMin, k_lowerMaxFloat, k_upperMaxFloat);
|
||||
}
|
||||
const float rightMargin = rightMarginRatio * xRange;
|
||||
if (x > xMax() - rightMargin) {
|
||||
m_yAuto = false;
|
||||
m_xRange.setMax(x + rightMargin, k_lowerMaxFloat, k_upperMaxFloat);
|
||||
const float newXMax = std::ceil((x + rightMargin - xMax()) / pixelWidth) * pixelWidth + xMax();
|
||||
m_xRange.setMax(newXMax, k_lowerMaxFloat, k_upperMaxFloat);
|
||||
MemoizedCurveViewRange::protectedSetXMin(xMax() - xRange, k_lowerMaxFloat, k_upperMaxFloat);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
virtual void setTrigonometric();
|
||||
virtual void setDefault();
|
||||
void centerAxisAround(Axis axis, float position);
|
||||
void panToMakePointVisible(float x, float y, float topMarginRatio, float rightMarginRatio, float bottomMarginRation, float leftMarginRation);
|
||||
void panToMakePointVisible(float x, float y, float topMarginRatio, float rightMarginRatio, float bottomMarginRation, float leftMarginRation, float pixelWidth);
|
||||
protected:
|
||||
constexpr static float k_upperMaxFloat = 1E+8f;
|
||||
constexpr static float k_lowerMaxFloat = 9E+7f;
|
||||
|
||||
@@ -31,7 +31,8 @@ bool SimpleInteractiveCurveViewController::handleLeftRightEvent(Ion::Events::Eve
|
||||
if (moveCursorHorizontally(direction, Ion::Events::repetitionFactor())) {
|
||||
interactiveCurveViewRange()->panToMakePointVisible(
|
||||
m_cursor->x(), m_cursor->y(),
|
||||
cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio
|
||||
cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio,
|
||||
curveView()->pixelWidth()
|
||||
);
|
||||
reloadBannerView();
|
||||
curveView()->reload();
|
||||
|
||||
@@ -26,7 +26,7 @@ SumGraphController::SumGraphController(Responder * parentResponder, InputEventHa
|
||||
|
||||
void SumGraphController::viewWillAppear() {
|
||||
SimpleInteractiveCurveViewController::viewWillAppear();
|
||||
m_graphRange->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio);
|
||||
m_graphRange->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio, curveView()->pixelWidth());
|
||||
m_graphView->setBannerView(&m_legendView);
|
||||
m_graphView->setCursorView(&m_cursorView);
|
||||
m_graphView->setOkView(nullptr);
|
||||
@@ -77,7 +77,7 @@ bool SumGraphController::moveCursorHorizontallyToPosition(double x) {
|
||||
m_graphView->setAreaHighlight(m_startSum, m_cursor->x());
|
||||
}
|
||||
m_legendView.setEditableZone(m_cursor->x());
|
||||
m_graphRange->panToMakePointVisible(x, y, cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio);
|
||||
m_graphRange->panToMakePointVisible(x, y, cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio, curveView()->pixelWidth());
|
||||
m_graphView->reload();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user