Repository: ManimCommunity/manim
File: manim/utils/space_ops.py (Python)

Code before:
from functools import reduce
from typing import Callable, List, Optional, Sequence, Tuple, TypeVar, Union

import numpy as np
from mapbox_earcut import triangulate_float32 as earcut

from .. import config
from ..constants import DOWN, OUT, PI, RIGHT, TAU
from ..utils.deprecation import deprecated
from ..utils.iterables import adjacent_pairs


@deprecated(since="v0.6.0", until="v0.8.0", replacement="np.linalg.norm")
def get_norm(vect):
    return np.linalg.norm(vect)


def norm_squared(v):
    return np.dot(v, v)


# Quaternions
# TODO, implement quaternion type


def quaternion_mult(*quats: Sequence[float]) -> List[Union[float, np.ndarray]]:
    """Gets the Hamilton product the quaternions provided.
    For more about the quaternion multiplication see: https://en.wikipedia.org/wiki/Quaternion

    Returns
    -------
    List[Union[float, np.ndarray]]
        Returns a list of product of two quaternions.
    """
    if config.renderer == "opengl":
        if len(quats) == 0:
            return [1, 0, 0, 0]
        result = quats[0]
        for next_quat in quats[1:]:
            w1, x1, y1, z1 = result
            w2, x2, y2, z2 = next_quat
            result = [
                w1 * w2 - x1 * x2 - y1 * y2 - z1 * z2,
                w1 * x2 + x1 * w2 + y1 * z2 - z1 * y2,
                w1 * y2 + y1 * w2 + z1 * x2 - x1 * z2,
                w1 * z2 + z1 * w2 + x1 * y2 - y1 * x2,
            ]
        return result
    else:
        q1 = quats[0]
        q2 = quats[1]

Review comment (suggestion):
this function returns `np.ndarray` and `List[float]` also `List[np.ndarray]`, the typing should be
```suggestion
def quaternion_mult(*quats: Sequence[float]) -> Union[np.ndarray, List[Union[float, np.ndarray]]]:
```

Code after:
import math
from functools import reduce
from typing import List, Optional, Sequence, Tuple, Union

import numpy as np
from mapbox_earcut import triangulate_float32 as earcut

from .. import config
from ..constants import DOWN, OUT, PI, RIGHT, TAU
from ..utils.deprecation import deprecated
from ..utils.iterables import adjacent_pairs


@deprecated(since="v0.6.0", until="v0.8.0", replacement="np.linalg.norm")
def get_norm(vect):
    return np.linalg.norm(vect)


def norm_squared(v: float) -> float:
    return np.dot(v, v)


# Quaternions
# TODO, implement quaternion type


def quaternion_mult(
    *quats: Sequence[float],
) -> Union[np.ndarray, List[Union[float, np.ndarray]]]:
    """Gets the Hamilton product of the quaternions provided.
    For more information, check `this Wikipedia page
    <https://en.wikipedia.org/wiki/Quaternion>`_.

    Returns
    -------
    Union[np.ndarray, List[Union[float, np.ndarray]]]
        Returns a list of product of two quaternions.
    """
    if config.renderer == "opengl":
        if len(quats) == 0:
            return [1, 0, 0, 0]
        result = quats[0]
        for next_quat in quats[1:]:
            w1, x1, y1, z1 = result
            w2, x2, y2, z2 = next_quat
            result = [
                w1 * w2 - x1 * x2 - y1 * y2 - z1 * z2,
                w1 * x2 + x1 * w2 + y1 * z2 - z1 * y2,
                w1 * y2 + y1 * w2 + z1 * x2 - x1 * z2,
                w1 * z2 + z1 * w2 + x1 * y2 - y1 * x2,
            ]