[apps] Fix Orthonormal setting in graphs

It was not perfectly orthormal.
This commit is contained in:
Léa Saviot
2018-12-04 14:12:54 +01:00
parent 020e459379
commit cea413e91d
4 changed files with 30 additions and 12 deletions

View File

@@ -39,20 +39,20 @@ void CurveViewRange::normalize() {
float xMax = m_xMax;
float yMin = m_yMin;
float yMax = m_yMax;
float newXMin = clipped((xMin+xMax)/2 - 5.3f, false);
float newXMax = clipped((xMin+xMax)/2 + 5.3f, true);
float newXMin = clipped((xMin+xMax)/2 - NormalizedXHalfRange(), false);
float newXMax = clipped((xMin+xMax)/2 + NormalizedXHalfRange(), true);
if (!std::isnan(newXMin) && !std::isnan(newXMax)) {
m_xMin = newXMin;
m_xMax = newXMax;
m_xGridUnit = computeGridUnit(Axis::X, m_xMin, m_xMax);
}
if (m_xMin < 0.0f) {
m_xMin = -k_displayLeftMarginRatio*2.0f*5.3f;
m_xMax = m_xMin + 2.0f*5.3f;
m_xMin = -k_displayLeftMarginRatio*2.0f*NormalizedXHalfRange();
m_xMax = m_xMin + 2.0f*NormalizedXHalfRange();
}
m_yAuto = false;
float newYMin = clipped((yMin+yMax)/2 - 3.1f, false);
float newYMax = clipped((yMin+yMax)/2 + 3.1f, true);
float newYMin = clipped((yMin+yMax)/2 - NormalizedYHalfRange(), false);
float newYMax = clipped((yMin+yMax)/2 + NormalizedYHalfRange(), true);
if (!std::isnan(newYMin) && !std::isnan(newYMax)) {
m_yMin = newYMin;
m_yMax = newYMax;

View File

@@ -115,23 +115,23 @@ void InteractiveCurveViewRange::roundAbscissa() {
}
void InteractiveCurveViewRange::normalize() {
/* We center the ranges on the current range center, and put each axis so that
* 1cm = 2 units. */
float xMin = m_xMin;
float xMax = m_xMax;
float yMin = m_yMin;
float yMax = m_yMax;
// Set x range
float xMargin = 5.3f;
float newXMin = clipped((xMin+xMax)/2 - xMargin, false);
float newXMax = clipped((xMin+xMax)/2 + xMargin, true);
float newXMin = clipped((xMin+xMax)/2 - NormalizedXHalfRange(), false);
float newXMax = clipped((xMin+xMax)/2 + NormalizedXHalfRange(), true);
if (!std::isnan(newXMin) && !std::isnan(newXMax)) {
m_xMax = newXMax;
MemoizedCurveViewRange::setXMin(newXMin);
}
// Set y range
setYAuto(false);
float yMargin = 3.1f;
float newYMin = clipped((yMin+yMax)/2 - yMargin, false);
float newYMax = clipped((yMin+yMax)/2 + yMargin, true);
float newYMin = clipped((yMin+yMax)/2 - NormalizedYHalfRange(), false);
float newYMax = clipped((yMin+yMax)/2 + NormalizedYHalfRange(), true);
if (!std::isnan(newYMin) && !std::isnan(newYMax)) {
m_yMax = newYMax;
MemoizedCurveViewRange::setYMin(newYMin);

View File

@@ -5,6 +5,7 @@
#include "memoized_curve_view_range.h"
#include "curve_view_cursor.h"
#include "interactive_curve_view_range_delegate.h"
#include <ion/display.h>
namespace Shared {
@@ -42,6 +43,18 @@ public:
bool isCursorVisible(float topMarginRatio, float rightMarginRatio, float bottomMarginRation, float leftMarginRation);
protected:
bool m_yAuto;
/* In normalized settings, we put each axis so that 1cm = 2 units. For now,
* the screen has size 43.2mm * 57.6mm.
* We want:
* 2*NormalizedXHalfRange -> 57.6mm
* 2*1 -> 10.0mm
* So NormalizedXHalfRange = 5.76
* We want:
* 2*NormalizedYHalfRange -> 43.2mm * 170/240
* 2*1 -> 10.0mm
* So NormalizedYHalfRange = 3.06 */
constexpr static float NormalizedXHalfRange() { return 5.76f; }
constexpr static float NormalizedYHalfRange() { return 3.06f; }
static float clipped(float f, bool isMax);
InteractiveCurveViewRangeDelegate * m_delegate;
private:
@@ -53,6 +66,9 @@ private:
CurveViewCursor * m_cursor;
};
static_assert(Ion::Display::WidthInTenthOfMillimeter == 576, "Use the new screen width to compute Shared::InteractiveCurveViewRange::NormalizedXHalfRange");
static_assert(Ion::Display::HeightInTenthOfMillimeter == 432, "Use the new screen height to compute Shared::InteractiveCurveViewRange::NormalizedYHalfRange");
typedef void (InteractiveCurveViewRange::*ParameterSetterPointer)(float);
typedef float (InteractiveCurveViewRange::*ParameterGetterPointer)();
typedef void (InteractiveCurveViewRange::*RangeMethodPointer)();

View File

@@ -25,6 +25,8 @@ void waitForVBlank();
constexpr int Width = 320;
constexpr int Height = 240;
constexpr int WidthInTenthOfMillimeter = 576;
constexpr int HeightInTenthOfMillimeter = 432;
}
}