from typing import Any import numpy as np from jaxtyping import Float, Num, jaxtyped from typeguard import typechecked from app._typing import NDArray @jaxtyped(typechecker=typechecked) def calculate_perpendicular_distance( point: Num[NDArray, "2"], line: Num[NDArray, "2 2"], ) -> np.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) return distance