Skip to main content

shape_core/elements/lines/line_3d/
mod.rs

1use super::*;
2
3mod constructors;
4/// A lines segment of finite length in 3D space, determined by a starting points and an ending points
5#[cfg_attr(feature = "serde", repr(C), derive(Serialize, Deserialize))]
6#[derive(Copy, Clone, PartialEq, Eq, Hash)]
7pub struct Line3D<T> {
8    /// Start points of the lines segment in 3D space.
9    pub s: Point3D<T>,
10    /// End points of the lines segment in 3D space.
11    pub e: Point3D<T>,
12}
13
14#[cfg_attr(feature = "serde", repr(C), derive(Serialize, Deserialize))]
15#[derive(Copy, Clone, PartialEq, Eq, Hash)]
16pub struct Vector3D<T> {
17    pub dx: T,
18    pub dy: T,
19    pub dz: T,
20}
21
22impl<T> Line3D<T> {
23    /// Construct new lines
24    pub fn new<P>(start: P, end: P) -> Self
25    where
26        Point3D<T>: From<P>,
27    {
28        Self { s: start.into(), e: end.into() }
29    }
30}
31
32impl<T: Real> Line3D<T> {
33    pub fn quantile_point(&self, p: usize, q: usize) -> Point3D<T> {
34        let _ = (p, q);
35        todo!()
36    }
37    /// Take the middle point of a 3D line
38    pub fn middle_point(&self) -> Point3D<T> {
39        let mx = (self.s.x + self.e.x) / two();
40        let my = (self.s.y + self.e.y) / two();
41        let mz = (self.s.z + self.e.z) / two();
42        Point3D { x: mx, y: my, z: mz }
43    }
44}