-
Notifications
You must be signed in to change notification settings - Fork 9
/
number_axis.cpp
57 lines (45 loc) · 1.2 KB
/
number_axis.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
#include "number_axis.h"
NumberAxis::NumberAxis(QString label, NumberRange range, float min, float max) {
begin = range.minimum; end = range.maximum;
this->minimum = min; this->maximum = max;
this->label = label;
}
NumberAxis::NumberAxis(QString label, float begin, float end, float min, float max) {
this->begin = begin; this->end = end;
this->minimum = min; this->maximum = max;
this->label = label;
}
float NumberAxis::numToCoord(float x) const {
float level = (x - begin) / (end - begin);
float coord = (1.0f - level) * (maximum - minimum) + minimum;
return coord;
}
float NumberAxis::coordToNum(float x) const {
float level = (x - minimum) / (maximum - minimum);
float num = (1.0f - level) * (end - begin) + begin;
return num;
}
float NumberAxis::getMinCoord() const {
return minimum;
}
float NumberAxis::getMaxCoord() const {
return maximum;
}
float NumberAxis::getCenterCoord() const {
return (getMinCoord() + getMaxCoord()) / 2;
}
float NumberAxis::getMinNum() const {
return begin;
}
float NumberAxis::getMaxNum() const {
return end;
}
void NumberAxis::setMinNum(float x) {
begin = x;
}
void NumberAxis::setMaxNum(float x) {
end = x;
}
QString NumberAxis::getLabel() const {
return label;
}