-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
24 lines (21 loc) · 851 Bytes
/
Copy pathutil.py
File metadata and controls
24 lines (21 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from collections.abc import Iterable
def linear(from_, to_, progress=0):
"""Linearly interpolate between two values.
Args:
from_ (Union[float|Iterable])
to_ (Union[float|Iterable])
progress (float, optional): A float between 0 and 1. Defaults to 0.
"""
if progress > 1 or progress < 0:
raise AttributeError('progress must be a float between 0 and 1')
if isinstance(from_, int) or isinstance(from_, float):
return _linear_value(from_, to_, progress)
if len(from_) != len(to_):
raise AttributeError(f'{from_} and {to_} cannot be interpolated')
return None
d = type(from_)(from_)
for i in range(len(from_)):
d[i] = _linear_value(from_[i], to_[i], progress)
return d
def _linear_value(from_, to_, progress):
return progress * (to_ - from_) + from_