1
0
forked from HQU-gxy/CVTH3PE

feat: Add beartype for runtime type checking and update dependencies

- Add beartype dependency to pyproject.toml and uv.lock
- Replace typeguard with beartype in type checking
- Create camera module with type-safe camera parameter definitions
- Migrate utility function to use beartype and JAX numpy
This commit is contained in:
2025-03-06 18:35:43 +08:00
parent 245c4b502d
commit 3ce5b564bf
5 changed files with 77 additions and 12 deletions

View File

@ -1,23 +1,21 @@
from typing import Any
import numpy as np
from jaxtyping import Float, Num, jaxtyped
from typeguard import typechecked
from app._typing import NDArray
from jaxtyping import Num, jaxtyped
from beartype import beartype
from jax import numpy as jnp, Array
@jaxtyped(typechecker=typechecked)
@jaxtyped(typechecker=beartype)
def calculate_perpendicular_distance(
point: Num[NDArray, "2"],
line: Num[NDArray, "2 2"],
) -> np.floating[Any]:
point: Num[Array, "2"],
line: Num[Array, "2 2"],
) -> jnp.floating[Any]:
"""
Calculate the perpendicular distance between a point and a line.
"""
line_start, line_end = line
distance = np.linalg.norm(
np.cross(line_end - line_start, line_start - point)
) / np.linalg.norm(line_end - line_start)
distance = jnp.linalg.norm(
jnp.cross(line_end - line_start, line_start - point)
) / jnp.linalg.norm(line_end - line_start)
return distance