Skip to content

Commit 08ddfb3

Browse files
committed
style: update typing
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
1 parent dfe59cb commit 08ddfb3

4 files changed

Lines changed: 27 additions & 22 deletions

File tree

t4_devkit/dataclass/box.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def translate(self, x: Vector3Like) -> None:
189189
Args:
190190
x (Vector3Like): 3D translation vector in the order of (x, y, z).
191191
"""
192-
self.position += x
192+
self.position += Vector3(x)
193193

194194
if self.future is not None:
195195
self.future.translate(x)

t4_devkit/dataclass/trajectory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from attrs import define, field, validators
77

88
from t4_devkit.common.converter import to_quaternion
9-
from t4_devkit.typing import Trajectory
9+
from t4_devkit.typing import Trajectory, Vector3
1010

1111
if TYPE_CHECKING:
1212
from t4_devkit.typing import NDArrayFloat, NDArrayInt, RotationLike, Vector3Like
@@ -86,7 +86,7 @@ def translate(self, x: Vector3Like) -> None:
8686
Args:
8787
x (Vector3Like): 3D translation vector.
8888
"""
89-
self.waypoints += x
89+
self.waypoints += Vector3(x)
9090

9191
def rotate(self, q: RotationLike) -> None:
9292
"""Apply a rotation.

t4_devkit/dataclass/transform.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing_extensions import Self
99

1010
from t4_devkit.common.converter import to_quaternion
11-
from t4_devkit.typing import Matrix3x3, Matrix4x4, NDArray, Quaternion, Vector3
11+
from t4_devkit.typing import Matrix3x3, Matrix4x4, Quaternion, Vector3
1212

1313
if TYPE_CHECKING:
1414
from t4_devkit.typing import Matrix4x4Like, RotationLike, Vector3Like
@@ -292,8 +292,7 @@ def rotate(self, *args, **kwargs) -> RotateItemLike:
292292
if {"position"} == set(inputs.keys()):
293293
return np.matmul(self.rotation_matrix, inputs["position"])
294294
elif {"rotation"} == set(inputs.keys()):
295-
rotation_matrix: NDArray = inputs["rotation"].rotation_matrix
296-
return np.matmul(self.rotation_matrix, rotation_matrix)
295+
return np.matmul(self.rotation_matrix, inputs["rotation"].rotation_matrix)
297296
elif {"matrix"} == set(inputs.keys()):
298297
matrix: HomogeneousMatrix = deepcopy(inputs["matrix"])
299298
matrix.rotation = Quaternion(
@@ -413,13 +412,16 @@ def _format_transform_args(*args, **kwargs) -> dict[str, Any]:
413412
if "matrix" in kwargs:
414413
raise KeyError("Cannot specify `position` and `matrix` at the same time.")
415414
elif "rotation" in kwargs:
416-
return {"position": kwargs["position"], "rotation": kwargs["rotation"]}
415+
return {
416+
"position": Vector3(kwargs["position"]),
417+
"rotation": to_quaternion(kwargs["rotation"]),
418+
}
417419
else:
418-
return {"position": kwargs["position"]}
420+
return {"position": Vector3(kwargs["position"])}
419421
elif "rotation" in kwargs:
420422
if "matrix" in kwargs:
421423
raise KeyError("Cannot specify `rotation` and `matrix` at the same time.")
422-
return {"rotation": kwargs["rotation"]}
424+
return {"rotation": to_quaternion(kwargs["rotation"])}
423425
elif "matrix" in kwargs:
424426
return {"matrix": kwargs["matrix"]}
425427
else:
@@ -436,15 +438,15 @@ def _format_transform_args(*args, **kwargs) -> dict[str, Any]:
436438
arg0 = np.asarray(arg0)
437439
if arg0.ndim == 1:
438440
if len(arg0) == 3:
439-
return {"position": arg0}
441+
return {"position": Vector3(arg0)}
440442
elif len(arg0) == 4:
441-
return {"rotation": arg0}
443+
return {"rotation": to_quaternion(arg0)}
442444
else:
443445
raise ValueError(f"Unexpected argument shape: {arg0.shape}.")
444446
else:
445447
if not arg0.shape != (3, 3):
446448
raise ValueError(f"Unexpected argument shape: {arg0.shape}.")
447-
return {"rotation": arg0}
449+
return {"rotation": to_quaternion(arg0)}
448450
elif num_kwargs == 1:
449451
if "rotation" not in kwargs:
450452
raise KeyError("Expected two arguments: position and rotation.")
@@ -453,7 +455,7 @@ def _format_transform_args(*args, **kwargs) -> dict[str, Any]:
453455
raise ValueError(f"Too much arguments {num_args + num_kwargs}.")
454456
# >>> (position, rotation)
455457
elif num_args == 2:
456-
return {"position": args[0], "rotation": args[1]}
458+
return {"position": Vector3(args[0]), "rotation": to_quaternion(args[1])}
457459
else:
458460
raise ValueError(f"Too much arguments {num_args + num_kwargs}.")
459461

t4_devkit/viewer/geography.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
11
from __future__ import annotations
22

33
import math
4+
from typing import TYPE_CHECKING
45

56
import numpy as np
67

7-
from t4_devkit.typing import Vector3
8+
from t4_devkit.typing import Vector2, Vector3
9+
10+
if TYPE_CHECKING:
11+
from t4_devkit.typing import Vector2Like, Vector3Like
812

913
__all__ = ["calculate_geodetic_point"]
1014

1115
EARTH_RADIUS_METERS = 6.378137e6
1216
FLATTENING = 1 / 298.257223563
1317

1418

15-
def calculate_geodetic_point(position: Vector3, origin: tuple[float, float]) -> tuple[float, float]:
19+
def calculate_geodetic_point(position: Vector3Like, origin: Vector2Like) -> Vector2:
1620
"""Transform a position in a map coordinate system to a position in a geodetic coordinate system.
1721
1822
Args:
19-
position (Vector3): 3D position in a map coordinate system.
20-
origin (tuple[float, float]): Map origin position in a geodetic coordinate system,
23+
position (Vector3Like): 3D position in a map coordinate system.
24+
origin (Vector2Like): Map origin position in a geodetic coordinate system,
2125
which is (latitude, longitude).
2226
2327
Returns:
24-
tuple[float, float]: Transformed position in a geodetic coordinate system,
25-
which is (latitude, longitude).
28+
Transformed position in a geodetic coordinate system, which is (latitude, longitude).
2629
"""
27-
x, y, _ = position
30+
x, y, _ = Vector3(position)
2831
bearing = math.atan2(x, y)
2932
distance = math.hypot(x, y)
3033

31-
latitude, longitude = np.radians(origin)
34+
latitude, longitude = np.radians(Vector2(origin))
3235
angular_distance = distance / EARTH_RADIUS_METERS
3336

3437
target_latitude = math.asin(
@@ -40,4 +43,4 @@ def calculate_geodetic_point(position: Vector3, origin: tuple[float, float]) ->
4043
math.cos(angular_distance) - math.sin(latitude) * math.sin(target_latitude),
4144
)
4245

43-
return math.degrees(target_latitude), math.degrees(target_longitude)
46+
return Vector2(math.degrees(target_latitude), math.degrees(target_longitude))

0 commit comments

Comments
 (0)