// file: crates/engines/engine-v1-common/src/pointer.rs // version: 1 /// Platform-independent normalized primary pointer state for one engine update. #[derive(Clone, Copy, Debug, PartialEq)] pub struct PointerState { active: bool, x: f32, y: f32, } impl PointerState { /// Creates an inactive pointer at the normalized origin. #[must_use] pub const fn inactive() -> Self { return Self { active: false, x: 0.0, y: 0.0 }; } /// Creates a pointer state from normalized coordinates. #[must_use] pub fn normalized(active: bool, x: f32, y: f32) -> Self { return Self { active, x: x.clamp(0.0, 1.0), y: y.clamp(0.0, 1.0) }; } /// Reports whether the pointer is currently active. #[must_use] pub const fn active(self) -> bool { return self.active; } /// Returns the normalized horizontal coordinate. #[must_use] pub const fn x(self) -> f32 { return self.x; } /// Returns the normalized vertical coordinate. #[must_use] pub const fn y(self) -> f32 { return self.y; } } impl Default for PointerState { fn default() -> Self { return Self::inactive(); } } #[cfg(test)] #[path = "../unit_tests/pointer.rs"] mod tests;