Passed
Pull Request — master (#6)
by Erik
52s
created

pypen.utils.math   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 22
dl 0
loc 34
rs 10
c 0
b 0
f 0

5 Functions

Rating   Name   Duplication   Size   Complexity  
A clamp() 0 2 1
A mix() 0 2 1
A random() 0 2 1
A lerp() 0 3 1
A lerp_unclamped() 0 2 1
1
from math import sin, cos, tan
2
from math import asin, acos, atan
3
from math import sinh, cosh, tanh
4
from math import asinh, acosh, atanh
5
from math import atan2
6
7
from math import sqrt
8
9
from math import pi as PI
10
from math import tau as TAU
11
from math import e as E
12
13
from random import random as py_random
14
15
def random(x=1):
16
    return py_random() * x
17
18
19
def clamp(value, min, max):
20
    return (value <= min)*min + (value >= max)*max + value*(value > min and value < max)
21
22
23
def lerp_unclamped(start, end, t):
24
    return start + t*(end-start)
25
26
27
def lerp(start, end, t):
28
    value = lerp_unclamped(start, end, t)
29
    return clamp(value, start, end)
30
31
32
def mix(a, b, t):
33
    return lerp(a, b, t)
34