-
Notifications
You must be signed in to change notification settings - Fork 3
/
qcpl_types.cpp
59 lines (50 loc) · 1.63 KB
/
qcpl_types.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "qcpl_types.h"
#include <cmath>
namespace QCPL {
//------------------------------------------------------------------------------
// AxisLimits
//------------------------------------------------------------------------------
bool AxisLimits::isInvalid() const
{
return std::isnan(min) or std::isnan(max);
}
QString AxisLimits::str() const
{
return QString("%1 - %2").arg(min).arg(max);
}
//------------------------------------------------------------------------------
// AxisLimits
//------------------------------------------------------------------------------
bool isAxisFactorSet(const AxisFactor& factor)
{
if (std::holds_alternative<int>(factor))
return std::get<int>(factor) != 0;
if (std::holds_alternative<double>(factor))
{
auto f = std::get<double>(factor);
return f != 0.0 && f != 1.0;
}
return false;
}
QString axisFactorStr(const AxisFactor& factor)
{
if (!isAxisFactorSet(factor))
return QString();
if (std::holds_alternative<int>(factor))
{
int f = std::get<int>(factor);
switch (f) {
case 3: return QStringLiteral("×1000");
case 2: return QStringLiteral("×100");
case 1: return QStringLiteral("×10");
case -1: return QStringLiteral("×0.1");
case -2: return QStringLiteral("×0.01");
case -3: return QStringLiteral("×0.001");
}
return QString("×1e%1").arg(f);
}
if (std::holds_alternative<double>(factor))
return QString("×%1").arg(std::get<double>(factor));
return QString();
}
} // namespace QCPL