MCPcopy Create free account
hub / github.com/KDAB/KDChart / nextFunctionValue

Method nextFunctionValue

examples/Plotter/BigDataset/Model.cpp:109–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107}
108
109qreal Model::nextFunctionValue()
110{
111 qreal fx = 0.0;
112
113 switch (m_function) {
114 case SineFunction:
115 fx = sin(m_x);
116 break;
117 case TriangleFunction: {
118 qreal x = fmod(m_x + 0.5 * M_PI, 2 * M_PI); // make it look like sine, only less round
119 if (x < M_PI) {
120 fx = -1.0 + x * (2.0 / M_PI);
121 } else {
122 fx = 3.0 - x * (2.0 / M_PI);
123 }
124 break;
125 }
126 case SquareFunction: {
127 qreal x = fmod(m_x, 2 * M_PI);
128 fx = x < M_PI ? 1 : -1;
129 break;
130 }
131 case NoiseFunction:
132 fx = -1.0 + qreal(QRandomGenerator::global()->generate()) * 2.0 / qreal(RAND_MAX);
133 break;
134 case SineOneDivFunction: {
135 // we want this repeating and we want negative arguments, too.
136 qreal x = fmod(m_x + 10, 20) - 10;
137 if (qAbs(x) < 1e-6) {
138 break;
139 }
140 fx = sin(1.0 / x);
141 break;
142 }
143 case OneDivSineFunction: {
144 qreal s = sin(m_x);
145 fx = qAbs(s) > 1e-6 ? 1.0 / s : 0.0;
146 break;
147 }
148 default:
149 Q_ASSERT(false);
150 }
151
152 m_x += s_stepWidth;
153 return fx;
154}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected