38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
{12, 'T', 'tera', true, 'p', 'pico', true};
{9, 'G', 'giga', true, 'n', 'nano', true};
{6, 'M', 'mega', true, 'μ', 'micro', true};
{3, 'k', 'kilo', true, 'm', 'milli', true};
{2, 'h', 'hecto', false, 'c', 'centi', true};
{1, 'da','deca', false, 'd', 'deci', false};
}
for i, s in ipairs(scales) do
local amt, smaj, pmaj, cmaj,
smin, pmin, cmin = lib.tbl.unpack(s)
if math.abs(val) > 1 then
if uncommonScales or cmaj then
local denom = 10^amt
local vd = val/denom
if prec then vd = lib.math.trim(vd, prec) end
if math.abs(val) >= (10^(amt)) then
return string.format("%s%s%s",
vd, (full and (' ' .. pmaj) or smaj), unit)
end
end
elseif math.abs(val) < 1 then
if uncommonScales or cmin then
local denom = 10^-amt
local vd = val/denom
if prec then vd = lib.math.trim(vd, prec) end
if math.abs(val) <= (10^-(amt-1)) then
return string.format("%s%s%s",
vd, (full and (' ' .. pmin) or smin), unit)
end
end
end
end
return string.format("%s%s", val, unit)
end
function fn.lerp(t, a, b) return (1-t)*a + t*b end
function fn.gradient(grad, pos)
local n = #grad
if n == 1 then return grad[1] end
local op = pos*(n-1)
local idx = math.floor(op)
|
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
>
|
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
{12, 'T', 'tera', true, 'p', 'pico', true};
{9, 'G', 'giga', true, 'n', 'nano', true};
{6, 'M', 'mega', true, 'μ', 'micro', true};
{3, 'k', 'kilo', true, 'm', 'milli', true};
{2, 'h', 'hecto', false, 'c', 'centi', true};
{1, 'da','deca', false, 'd', 'deci', false};
}
local function unitForAmt(n)
if type(unit)=='table' then
if n == 1
then return unit[1]
else return unit[2]
end
end
return unit
end
for i, s in ipairs(scales) do
local amt, smaj, pmaj, cmaj,
smin, pmin, cmin = lib.tbl.unpack(s)
if math.abs(val) > 1 then
if uncommonScales or cmaj then
local denom = 10^amt
local vd = val/denom
if prec then vd = lib.math.trim(vd, prec) end
if math.abs(val) >= (10^(amt)) then
return string.format("%s%s%s",
vd, (full and (' ' .. pmaj) or smaj), unitForAmt(vd))
end
end
elseif math.abs(val) < 1 then
if uncommonScales or cmin then
local denom = 10^-amt
local vd = val/denom
if prec then vd = lib.math.trim(vd, prec) end
if math.abs(val) <= (10^-(amt-1)) then
return string.format("%s%s%s",
vd, (full and (' ' .. pmin) or smin), unitForAmt(vd))
end
end
end
end
return string.format("%s%s", val, unitForAmt(val))
end
function fn.siUI(u,v,f,us,...) return fn.si(u,v,f,us,2,...) end
function fn.lerp(t, a, b) return (1-t)*a + t*b end
function fn.gradient(grad, pos)
local n = #grad
if n == 1 then return grad[1] end
local op = pos*(n-1)
local idx = math.floor(op)
|