-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscale.cpp
More file actions
34 lines (28 loc) · 884 Bytes
/
Copy pathscale.cpp
File metadata and controls
34 lines (28 loc) · 884 Bytes
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
#include "scale.h"
using namespace std;
Scale::Scale(const vector<QRgb> &pointsToInitScale):
scalePoints(pointsToInitScale)
{
minValue = 0.0;
maxValue = 1.0;
// Step in numberic form between two points with known colors
step = (maxValue - minValue)/double(scalePoints.size());
}
QRgb Scale::getColor(double value)
{
if(value<=minValue) return scalePoints.front();
if(value>=maxValue) return scalePoints.back();
double tmp= (value-minValue)/step;
size_t leftIndex = size_t(tmp);
return scalePoints[leftIndex%scalePoints.size()];
}
void Scale::setMinValue(double newMinValue)
{
minValue = newMinValue;
step = (maxValue - minValue)/double(scalePoints.size());
}
void Scale::setMaxValue(double newMaxValue)
{
maxValue = newMaxValue;
step = (maxValue - minValue)/double(scalePoints.size());
}