Skip to main content

lib_jsl_geometry/
dim_1.rs

1//! One-dimensional line- and path-oriented geometry traits.
2
3use lib_jsl_core::ErrorsJSL;
4/// Concrete one-dimensional line implementation.
5pub mod line1d;
6/// Concrete one-dimensional mirror plane implementation.
7pub mod plane1d;
8/// Concrete one-dimensional coordinate-vector implementation.
9pub mod coordinate_vector1d;
10/// Concrete one-dimensional unit vector implementation.
11pub mod unit_vector1d;
12
13use crate::common::{
14    GeometricPrimitive, GeometryMeasure, HasVertices, IsUnitVector, PointId,
15};
16use crate::zero_d::IsPoint;
17pub use line1d::Line1D;
18pub use plane1d::Plane1D;
19pub use coordinate_vector1d::CoordinateVector1D;
20pub use unit_vector1d::UnitVector1D;
21
22/// A line primitive that resolves its endpoints through point identifiers.
23pub trait IsLine<'a, T: IsPoint>:
24    GeometricPrimitive + HasVertices<'a, Vertex = T>
25{
26    /// Returns the point-table id of the first endpoint.
27    fn head_id(&self) -> PointId;
28    /// Sets the point-table id of the first endpoint.
29    fn set_head_id(&mut self, point_id: PointId) -> Result<(), ErrorsJSL>;
30    /// Returns the point-table id of the second endpoint.
31    fn tail_id(&self) -> PointId;
32    /// Sets the point-table id of the second endpoint.
33    fn set_tail_id(&mut self, point_id: PointId) -> Result<(), ErrorsJSL>;
34
35    /// Resolves and returns the first endpoint from the point table.
36    fn head(&self) -> Option<T> {
37        self.get_vertex(&self.head_id())
38    }
39
40    /// Resolves and returns the second endpoint from the point table.
41    fn tail(&self) -> Option<T> {
42        self.get_vertex(&self.tail_id())
43    }
44
45    /// Returns the Euclidean length of the line.
46    fn length(&self) -> GeometryMeasure;
47    /// Returns the midpoint of the line, if it can be derived from the point table.
48    fn midpoint(&self) -> Option<T>;
49    /// Returns the line direction as a unit vector.
50    fn direction(&self) -> impl IsUnitVector;
51}
52
53/// A connected sequence of line segments backed by a point table.
54pub trait IsPolyline<'a, T: IsPoint>:
55    GeometricPrimitive + HasVertices<'a, Vertex = T>
56{
57    /// Returns the number of segments in the polyline.
58    fn segment_count(&self) -> usize;
59    /// Returns the total path length.
60    fn length(&self) -> GeometryMeasure;
61}
62
63/// A ray primitive with an origin and a unit direction.
64pub trait IsRay<T: IsPoint>: GeometricPrimitive {
65    /// Unit-vector direction type used by the ray.
66    type Direction: IsUnitVector;
67
68    /// Returns the ray origin.
69    fn origin(&self) -> T;
70    /// Returns a mutable reference to the ray origin.
71    fn origin_mut(&mut self) -> &mut T;
72    /// Returns the ray direction.
73    fn direction(&self) -> Self::Direction;
74    /// Returns a mutable reference to the ray direction.
75    fn direction_mut(&mut self) -> &mut Self::Direction;
76}
77
78/// Marker trait for finite line segments.
79pub trait IsSegment<'a, T: IsPoint>: IsLine<'a, T> {}