Scale

Scale

Overview

scale provides some helpful scaling functions. Scaling refers to taking a value in some range, and then protionally refitting it to be in another range. In other words... scaling!

Tangled files

scale.h and scale.c

<<scale.h>>=
#ifndef SK_SCALE_H
#define SK_SCALE_H
#ifndef SKFLT
#define SKFLT float
#endif
<<funcdefs>>
#endif

<<scale.c>>=
#include "scale.h"
<<funcs>>

Scale

The function sk_scale takes in a value between 0 and 1, an returns a value to be in between min and max.

<<funcdefs>>=
SKFLT sk_scale(SKFLT in, SKFLT min, SKFLT max);

<<funcs>>=
SKFLT sk_scale(SKFLT in, SKFLT min, SKFLT max)
{

    return in * (max - min) + min;
}

Biscale

The function sk_biscale takes a value between -1 and 1 and returns a value between min and max.

<<funcdefs>>=
SKFLT sk_biscale(SKFLT in, SKFLT min, SKFLT max);

<<funcs>>=
SKFLT sk_biscale(SKFLT in, SKFLT min, SKFLT max)
{
    return min + (in + 1.0) * 0.5 * (max - min);
}