1use crate::{Num, Vec2, impl_approx, impl_bytemuck, impl_casts};
2use serde::{Deserialize, Serialize};
3
4pub type RayF = Ray<f32>;
5
6#[repr(C)]
8#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
9pub struct Ray<T> {
10 pub origin: Vec2<T>,
11 pub direction: Vec2<T>,
12}
13
14impl_bytemuck!(Ray);
15
16impl_approx!(
17 NAME = Ray
18 FIELDS = (origin, direction)
19);
20
21impl_casts!(
22 NAME = Ray
23 FIELDS = (origin, direction)
24);
25
26#[inline]
28pub const fn ray<T>(origin: Vec2<T>, direction: Vec2<T>) -> Ray<T> {
29 Ray { origin, direction }
30}
31
32impl<T> Ray<T> {
33 #[inline]
35 pub const fn new(origin: Vec2<T>, direction: Vec2<T>) -> Self {
36 ray(origin, direction)
37 }
38}
39
40impl<T: Num> Ray<T> {
41 #[inline]
43 pub fn point(&self, dist: T) -> Vec2<T> {
44 self.origin + self.direction * dist
45 }
46}