-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: replace
dataclasses
to attrs
Signed-off-by: ktro2828 <[email protected]>
- Loading branch information
Showing
28 changed files
with
242 additions
and
452 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, overload | ||
|
||
import numpy as np | ||
from pyquaternion import Quaternion | ||
|
||
if TYPE_CHECKING: | ||
from t4_devkit.typing import ArrayLike, NDArray | ||
|
||
__all__ = ("as_array", "as_quaternion") | ||
|
||
|
||
@overload | ||
def as_array(value: ArrayLike) -> NDArray: | ||
"""Covert array like object to numpy array.""" | ||
... | ||
|
||
|
||
@overload | ||
def as_array(value: None) -> None: | ||
"""Do nothing if the input value is None.""" | ||
... | ||
|
||
|
||
def as_array(value: ArrayLike | None) -> NDArray | None: | ||
"""Convert input array to `NDArray`. | ||
Note that, it returns `None` if the input is `None`. | ||
Args: | ||
value (ArrayLike | None): Array or None. | ||
Returns: | ||
NDArray | None: Numpy array or None. | ||
""" | ||
return np.asarray(value) if value is not None else None | ||
|
||
|
||
def as_quaternion(value: ArrayLike | NDArray) -> Quaternion: | ||
"""Convert input rotation like array to `Quaternion`. | ||
Args: | ||
value (ArrayLike | NDArray): Rotation matrix or quaternion. | ||
Returns: | ||
Quaternion: Converted instance. | ||
""" | ||
return ( | ||
Quaternion(matrix=value) | ||
if isinstance(value, np.ndarray) and value.ndim == 2 | ||
else Quaternion(value) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.