fey_math/
ray_hit.rs

1use crate::{Vec2, impl_approx, impl_bytemuck, impl_casts};
2use serde::{Deserialize, Serialize};
3
4pub type RayHitF = RayHit<f32>;
5
6/// A raycast hit on the surface of a shape.
7///
8/// Contains the `distance` along the ray the hit occurred, and the
9/// `normal` of the edge the ray intersected.
10#[repr(C)]
11#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
12pub struct RayHit<T> {
13    pub normal: Vec2<T>,
14    pub distance: T,
15}
16
17impl<T> RayHit<T> {
18    /// Create a new raycast hit.
19    #[inline]
20    pub const fn new(normal: Vec2<T>, distance: T) -> Self {
21        Self { normal, distance }
22    }
23}
24
25impl_bytemuck!(RayHit);
26
27impl_approx!(
28    NAME = RayHit
29    FIELDS = (normal, distance)
30);
31
32impl_casts!(
33    NAME = RayHit
34    FIELDS = (normal, distance)
35);