discretize(step)

koadrobot/aritmatics/discretize(step)

If input `X` is between the threshold from start to stop. If `X` is even greater than the last threshold, the value is round to it.
discretize(step)
@/discretize(step)
If input `X` is between the threshold from start to stop. If `X` is even greater than the last threshold, the value is round to it.
Xnumber
Input Value that will be discretize.
STEPnumber
step count in bound
STARTnumber
Source range begin bound
STOPnumber
Source range end bound
discretize(step)
X
STEP
START
STOP
T
Tnumber
The rounding result. Equals to one of Tx.
To use the node in your project you should have the koadrobot/aritmatics library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

#pragma XOD dirtieness disable

struct State {
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    Number x = getValue<input_X>(ctx);
    Number start = getValue<input_START>(ctx);
    Number stop = getValue<input_STOP>(ctx);
    Number step = getValue<input_STEP>(ctx);
    Number outX = round(step * (x-start)/(stop-start));
    emitValue<output_T>(ctx, outX);
}

Tabular tests

XSTEPSTARTSTOPT
4.1100104
4.6100105
6.3105103
6.1105102