[apps/shared] CurveView: implement CurveView::pixelLength(Axis)

This commit is contained in:
Émilie Feral
2020-10-01 13:38:33 +02:00
parent d6751e6e03
commit 5b4fc6ff84
2 changed files with 6 additions and 2 deletions

View File

@@ -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);
}

View File

@@ -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);