Refactor routing internals and archive retry benchmarks

This commit is contained in:
Jan Petykiewicz 2026-11-26 19:58:46 -08:00
commit ea5cfe7f31

View file

@ -63,3 +63,20 @@ ROT2_270 = numpy.array(((0, 1), (-1, 0)), dtype=numpy.int32)
def rotation_matrix2(rotation_deg: int | float) -> NDArray[numpy.int32]:
quadrant = (_normalize_angle(rotation_deg) // 90) % 4
return (ROT2_0, ROT2_90, ROT2_180, ROT2_270)[quadrant]
def rotate_cardinal(x: float, y: float, heading: int) -> tuple[float, float]:
"""Rotate by a multiple of 90 degrees without snapping the point."""
angle = heading % 360
if angle == 0:
return x, y
if angle == 90:
return -y, x
if angle == 180:
return -x, -y
return y, -x
def port_local_coordinates(origin: Port, x: float, y: float) -> tuple[float, float]:
"""Project a point into the forward and leftward axes of a port."""
return rotate_cardinal(x - origin.x, y - origin.y, -int(origin.r))