Source code for reli.types

"""Small value types shared across modules."""

from __future__ import annotations

import math
from dataclasses import dataclass, field
from typing import Any


def wrap_angle(angle: float) -> float:
    """Wrap an angle in radians to (-pi, pi]."""
    return math.atan2(math.sin(angle), math.cos(angle))


[docs] @dataclass(frozen=True) class Pose2D: """Planar pose in the map frame. ``yaw`` is in radians, counter-clockwise.""" x: float = 0.0 y: float = 0.0 yaw: float = 0.0 @property def yaw_deg(self) -> float: return math.degrees(wrap_angle(self.yaw)) def distance_to(self, x: float, y: float) -> float: return math.hypot(x - self.x, y - self.y)
[docs] def bearing_to(self, x: float, y: float) -> float: """Heading change (rad) needed to face (x, y).""" return wrap_angle(math.atan2(y - self.y, x - self.x) - self.yaw)
def to_dict(self) -> dict[str, float]: return {"x": round(self.x, 3), "y": round(self.y, 3), "yaw_deg": round(self.yaw_deg, 1)}
[docs] @dataclass(frozen=True) class Action: """One validated step: a catalogue name and its typed parameters.""" name: str params: dict[str, Any] = field(default_factory=dict) def get(self, key: str, default: Any = None) -> Any: value = self.params.get(key) return default if value is None else value def to_dict(self) -> dict[str, Any]: return {"action": self.name, **{k: v for k, v in self.params.items() if v is not None}}
[docs] @dataclass class Event: """Something the agent wants to tell the outside world. kind: ``response`` (text for the user), ``image`` (BGR array in ``data``), ``status`` (structured progress in ``data``) or ``plan`` (parsed plan). """ kind: str text: str = "" language: str = "en" data: Any = None turn_id: int | None = None