MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / interpolatedColorAt

Method interpolatedColorAt

src/openms_gui/source/VISUAL/MultiGradient.cpp:99–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97 }
98
99 QColor MultiGradient::interpolatedColorAt(double position) const
100 {
101 if (position <= 0.0)
102 {
103 return pos_col_.begin()->second;
104 }
105
106 if (position >= 100.0)
107 {
108 return (--(pos_col_.end()))->second;
109 }
110
111 //linear
112 if (interpolation_mode_ == IM_LINEAR)
113 {
114 map<double, QColor>::const_iterator it1 = pos_col_.lower_bound(position);
115
116 if (std::abs(it1->first - position) < numeric_limits<double>::epsilon()) // compare double
117 {
118 return it1->second;
119 }
120 else
121 {
122 map<double, QColor>::const_iterator it0 = it1;
123 --it0;
124 double factor = (position - it0->first) / (it1->first - it0->first);
125 return QColor(Int(factor * it1->second.red() + (1 - factor) * it0->second.red() + 0.001)
126 , Int(factor * it1->second.green() + (1 - factor) * it0->second.green() + 0.001)
127 , Int(factor * it1->second.blue() + (1 - factor) * it0->second.blue() + 0.001));
128 }
129 }
130 //stairs
131 else
132 {
133 map<double, QColor>::const_iterator it = pos_col_.upper_bound(position);
134 --it;
135 return it->second;
136 }
137 }
138
139 QColor MultiGradient::interpolatedColorAt(double position, double min, double max) const
140 {

Callers 3

paintEventMethod · 0.80
main_Method · 0.80

Calls 3

QColorClass · 0.85
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected