chemrust_nasl/geometry/primitives/
line.rs1use nalgebra::{Point3, UnitVector3};
2
3#[derive(Debug, Clone, Copy)]
4pub struct Line {
5 origin: Point3<f64>,
6 direction: UnitVector3<f64>,
7}
8
9impl Line {
10 pub fn new(origin: Point3<f64>, direction: UnitVector3<f64>) -> Self {
11 Self { origin, direction }
12 }
13
14 pub fn origin(&self) -> Point3<f64> {
15 self.origin
16 }
17 pub fn direction(&self) -> UnitVector3<f64> {
18 self.direction
19 }
20 pub fn point(&self, t: f64) -> Point3<f64> {
21 self.origin + self.direction().scale(t)
22 }
23
24 pub fn point_to_line_distance(&self, point: &Point3<f64>) -> f64 {
25 let l = point - self.origin();
26 let angle = l.angle(&self.direction());
27 l.norm() * angle.sin()
28 }
29}