Files
Mini-Nav/mini-nav/scenegraph/roomnode.py

31 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from dataclasses import dataclass
import numpy as np
@dataclass
class RoomNode:
room_id: str # 例如: "room_A"
# 范围:不用复杂的 Polygon用一个中心点+半径,或者简单的 3D BBox 足够了
center: np.ndarray # [x, y, z]
bbox_extent: np.ndarray # [dx, dy, dz] 用于快速判断一个点在不在房间里
def __post_init__(self):
self.center = np.asarray(self.center, dtype=np.float32)
self.bbox_extent = np.asarray(self.bbox_extent, dtype=np.float32)
if self.center.shape != (3,):
raise ValueError(f"center must have shape (3,), got {self.center.shape}")
if self.bbox_extent.shape != (3,):
raise ValueError(f"bbox_extent must have shape (3,), got {self.bbox_extent.shape}")
if not np.all(np.isfinite(self.center)):
raise ValueError("center must contain only finite values")
if not np.all(np.isfinite(self.bbox_extent)):
raise ValueError("bbox_extent must contain only finite values")
if np.any(self.bbox_extent < 0):
raise ValueError("bbox_extent must be non-negative")