2020-02-25 06:16:14 +00:00
|
|
|
exception RangeWrong(string);
|
|
|
|
|
2020-02-21 13:54:39 +00:00
|
|
|
let interpolate =
|
|
|
|
(xMin: float, xMax: float, yMin: float, yMax: float, xIntended: float)
|
|
|
|
: float => {
|
|
|
|
let minProportion = (xMax -. xIntended) /. (xMax -. xMin);
|
|
|
|
let maxProportion = (xIntended -. xMin) /. (xMax -. xMin);
|
|
|
|
yMin *. minProportion +. yMax *. maxProportion;
|
|
|
|
};
|
2020-02-21 14:05:42 +00:00
|
|
|
|
2020-02-21 14:13:04 +00:00
|
|
|
// @todo: To test!
|
2020-02-21 14:05:42 +00:00
|
|
|
let sum = Belt.Array.reduce(_, 0., (i, j) => i +. j);
|
|
|
|
let mean = a => sum(a) /. (Array.length(a) |> float_of_int);
|
|
|
|
let min = Belt.Array.reduce(_, 0., (i, j) => i < j ? i : j);
|
|
|
|
let max = Belt.Array.reduce(_, 0., (i, j) => i > j ? i : j);
|
2020-02-21 14:13:04 +00:00
|
|
|
let up = (a, b) => Array.make(b - a, a) |> Array.mapi((i, c) => c + i);
|
|
|
|
let down = (a, b) => Array.make(a - b, a) |> Array.mapi((i, c) => c - i);
|
2020-02-25 06:16:14 +00:00
|
|
|
let range = (min: float, max: float, n: int): array(float) => {
|
|
|
|
switch (n) {
|
|
|
|
| 0 => [||]
|
|
|
|
| 1 => [|min|]
|
|
|
|
| 2 => [|min, max|]
|
|
|
|
| _ when min == max => Belt.Array.make(n, min)
|
|
|
|
| _ when n < 0 => raise(RangeWrong("n is less then zero"))
|
|
|
|
| _ when min > max => raise(RangeWrong("Min values is less then max"))
|
|
|
|
| _ =>
|
|
|
|
let diff = max -. min;
|
|
|
|
Belt.Array.makeBy(n, i => float_of_int(i) *. diff);
|
|
|
|
};
|
|
|
|
};
|