From 5b4fc6ff84e640e769b8e1fc66432ba2d3c72484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 1 Oct 2020 13:38:33 +0200 Subject: [PATCH] [apps/shared] CurveView: implement CurveView::pixelLength(Axis) --- apps/shared/curve_view.cpp | 7 +++++-- apps/shared/curve_view.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/shared/curve_view.cpp b/apps/shared/curve_view.cpp index 6e4c0f272..1890d2455 100644 --- a/apps/shared/curve_view.cpp +++ b/apps/shared/curve_view.cpp @@ -112,6 +112,10 @@ float CurveView::pixelHeight() const { return (m_curveViewRange->yMax() - m_curveViewRange->yMin()) / (m_frame.height() - 1); } +float CurveView::pixelLength(Axis axis) const { + return axis == Axis::Horizontal ? pixelWidth() : pixelHeight(); +} + float CurveView::pixelToFloat(Axis axis, KDCoordinate p) const { return (axis == Axis::Horizontal) ? m_curveViewRange->xMin() + p * pixelWidth() : @@ -140,8 +144,7 @@ float CurveView::floatToPixel(Axis axis, float f) const { } float CurveView::floatLengthToPixelLength(Axis axis, float f) const { - float pixelLength = axis == Axis::Horizontal ? pixelWidth() : pixelHeight(); - float dist = f / pixelLength; + float dist = f / pixelLength(axis); return clippedFloat(dist); } diff --git a/apps/shared/curve_view.h b/apps/shared/curve_view.h index 481429489..cc882b8f7 100644 --- a/apps/shared/curve_view.h +++ b/apps/shared/curve_view.h @@ -41,6 +41,7 @@ public: void setForceOkDisplay(bool force) { m_forceOkDisplay = force; } float pixelWidth() const; float pixelHeight() const; + float pixelLength(Axis axis) const; protected: CurveViewRange * curveViewRange() const { return m_curveViewRange; } void setCurveViewRange(CurveViewRange * curveViewRange);