scale(number)

koadrobot/aritmatics/scale(number)

Sacle value (map) with check min<max.
scale(number)
@/scale(number)
Sacle value (map) with check min<max.
Xnumber
Value to map
Sstartnumber
Source range lower bound
Sstopnumber
Source range upper bound
Tstartnumber
Target range lower bound
Tstopnumber
Tartger range upper bound
scale(number)
OUT
X
Sstart
Sstop
Tstart
Tstop
OUTnumber
Mapped value
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 Sstart = getValue<input_Sstart>(ctx);
    Number Sstop = getValue<input_Sstop>(ctx);
    Number Tstart = getValue<input_Tstart>(ctx);
    Number Tstop = getValue<input_Tstop>(ctx);
    Number outX = Tstart + ((x-Sstart) / (Sstop-Sstart)) * (Tstop-Tstart);
    emitValue<output_OUT>(ctx, outX);
}

Tabular tests

XSstartSstopTstartTstopOUT
20100102
21000108
20101008
21001002
20-10010-2
2-10001012
20-1010012
2-100100-2
-2010010-2
-210001012
-201010012
-2100100-2
-20-100102
-2-1000108
-20-101008
-2-1001002
20100-10-2
21000-10-8
2010-100-8
2100-100-2
20-100-102
2-1000-10-12
20-10-100-12
2-100-1002
-20100-102
-21000-10-12
-2010-100-12
-2100-1002
-20-10-100-8
-2-100-100-2
-20-100-10-2
-2-1000-10-8