pub struct LineSegment<T, const D: usize> {
pub start: SVector<T, D>,
pub end: SVector<T, D>,
}Expand description
Line segment in any number of dimensions
Fields§
§start: SVector<T, D>One end of the line segment, the point returned when interpolating at t = 0.0
end: SVector<T, D>One end of the line segment, the point returned when interpolating at t = 1.0
Implementations§
Source§impl<T, const D: usize> LineSegment<T, D>
impl<T, const D: usize> LineSegment<T, D>
Sourcepub fn new(start: &SVector<T, D>, end: &SVector<T, D>) -> Self
pub fn new(start: &SVector<T, D>, end: &SVector<T, D>) -> Self
Create a new line segment with the given points.
Sourcepub fn is_degenerate(&self) -> bool
pub fn is_degenerate(&self) -> bool
The two end-points of the line segment are equal.
Sourcepub fn interpolate(&self, t: T) -> SVector<T, D>
pub fn interpolate(&self, t: T) -> SVector<T, D>
Create a point somewhere between start and end.
When t = 0.0, start is returned.
When t = 1.0, end is returned.
The result is (1.0 - t) * start + t * end, which may produce points off the line segment,
if t < 0.0 or t > 1.0.
Sourcepub fn interpolate_clamped(&self, t: T) -> SVector<T, D>
pub fn interpolate_clamped(&self, t: T) -> SVector<T, D>
Create a point somewhere between start and end.
This is just like LineSegment::interpolate except that t is clamped to between 0.0 and 1.0,
so points off the line segment can never be returned.
Sourcepub fn length_squared(&self) -> T
pub fn length_squared(&self) -> T
The square of the distance between start and end
Sourcepub fn nearest_t(&self, point: &SVector<T, D>) -> T
pub fn nearest_t(&self, point: &SVector<T, D>) -> T
The interpolation parameter of the point on this segment that is closest to the given point.
Sourcepub fn nearest_point(&self, point: &SVector<T, D>) -> SVector<T, D>
pub fn nearest_point(&self, point: &SVector<T, D>) -> SVector<T, D>
The point on this segment that is closest to the given point.
Sourcepub fn distance_squared(&self, point: &SVector<T, D>) -> T
pub fn distance_squared(&self, point: &SVector<T, D>) -> T
The squared distance between the given point and the nearest point on this line segment.
Source§impl<T> LineSegment<T, 2>
impl<T> LineSegment<T, 2>
Sourcepub fn collinearity(&self, point: &Vector2<T>) -> T
pub fn collinearity(&self, point: &Vector2<T>) -> T
Test whether a point is collinear with this segment.
- 0.0 means collinear. Near to 0.0 means near to collinear.
- Negative means that the point is to the counter-clockwise of
endas viewed fromstart. - Positive means that the point is to the clockwise of
endas viewed fromstart.
Sourcepub fn intersects(&self, other: &LineSegment2<T>) -> bool
pub fn intersects(&self, other: &LineSegment2<T>) -> bool
True if this segment intersects the given segment based on collinearity.
Trait Implementations§
Source§impl<T: Clone, const D: usize> Clone for LineSegment<T, D>
impl<T: Clone, const D: usize> Clone for LineSegment<T, D>
Source§fn clone(&self) -> LineSegment<T, D>
fn clone(&self) -> LineSegment<T, D>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<T, const D: usize> Freeze for LineSegment<T, D>where
T: Freeze,
impl<T, const D: usize> RefUnwindSafe for LineSegment<T, D>where
T: RefUnwindSafe,
impl<T, const D: usize> Send for LineSegment<T, D>where
T: Send,
impl<T, const D: usize> Sync for LineSegment<T, D>where
T: Sync,
impl<T, const D: usize> Unpin for LineSegment<T, D>where
T: Unpin,
impl<T, const D: usize> UnwindSafe for LineSegment<T, D>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.