1use std::ops::{Add, Mul};
2
3use crate::{Real, Vector3};
4
5#[derive(Debug, Clone)]
7pub struct Ray3<T> {
8 pub origin: Vector3<T>,
9 pub direction: Vector3<T>,
10}
11impl<T> Ray3<T> {
12 #[inline(always)]
13 pub fn from_origin_to(origin: Vector3<T>, to: Vector3<T>) -> Self
14 where
15 T: Copy + Real,
16 {
17 Self {
18 origin,
19 direction: (to - origin).normalize(),
20 }
21 }
22
23 #[inline(always)]
24 pub fn point(&self, t: T) -> Vector3<T>
25 where
26 T: Copy + Mul<T, Output = T> + Add<T, Output = T>,
27 {
28 self.origin + self.direction * t
29 }
30}