constrain

koadrobot/aritmatics/constrain

Clip number. Min..Max. (calculate min/max for min<x<max)
constrain
@/constrain
Clip number. Min..Max. (calculate min/max for min<x<max)
Xnumber
MINnumber
MAXnumber
constrain
OUT
X
MIN
MAX
OUTnumber
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 inX = getValue<input_X>(ctx);
    Number minX = getValue<input_MIN>(ctx);
    Number maxX = getValue<input_MAX>(ctx);
    Number outX = (inX > maxX) ? maxX : ((inX < minX) ? minX : inX);
    emitValue<output_OUT>(ctx, outX);
}

Tabular tests

XMINMAXOUT
50105
-5-100-5