File size: 680 Bytes
9e18664
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Simple utilities to be used for Rerun demos."""

from __future__ import annotations

from typing import TYPE_CHECKING, Any

if TYPE_CHECKING:
    import numpy as np


def bounce_lerp(
    a: float,
    b: float,
    t: float | np.ndarray[Any, np.dtype[Any]],
) -> float | np.ndarray[Any, np.dtype[Any]]:
    """
    A linear interpolator that bounces between `a` and `b` as `t` goes above `1.0`.

    Parameters
    ----------
    a:
        Start value (t == 0).
    b:
        End value (t == 1).
    t:
        Interpolation coefficient.

    """
    tf = t % 1
    if int(t) % 2 == 0:
        return (1.0 - tf) * a + tf * b
    else:
        return tf * a + (1.0 - tf) * b