pub struct LineSegment<T, const D: usize> {
pub start: Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>,
pub end: Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>,
}
Expand description
Line segment in any number of dimensions
Fields§
§start: Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>
One end of the line segment, the point returned when interpolating at t = 0.0
end: Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>
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: &Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>,
end: &Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>,
) -> LineSegment<T, D>
pub fn new( start: &Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>, end: &Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>, ) -> LineSegment<T, D>
Create a new line segment with the given points.
Sourcepub fn swapped(&self) -> LineSegment<T, D>
pub fn swapped(&self) -> LineSegment<T, D>
Creates a reversed line segment by swapping start
and end
.
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,
) -> Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>
pub fn interpolate( &self, t: T, ) -> Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>
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,
) -> Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>
pub fn interpolate_clamped( &self, t: T, ) -> Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>
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 vector(&self) -> Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>
pub fn vector(&self) -> Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>
The vector from start
to end
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: &Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>,
) -> T
pub fn nearest_t( &self, point: &Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>, ) -> T
The interpolation parameter of the point on this segment that is closest to the given point.
Sourcepub fn nearest_point(
&self,
point: &Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>,
) -> Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>
pub fn nearest_point( &self, point: &Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>, ) -> Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>
The point on this segment that is closest to the given point.
Sourcepub fn distance_squared(
&self,
point: &Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>,
) -> T
pub fn distance_squared( &self, point: &Matrix<T, Const<D>, Const<1>, ArrayStorage<T, D, 1>>, ) -> 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: &Matrix<T, Const<2>, Const<1>, ArrayStorage<T, 2, 1>>,
) -> T
pub fn collinearity( &self, point: &Matrix<T, Const<2>, Const<1>, ArrayStorage<T, 2, 1>>, ) -> 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
end
as viewed fromstart
. - Positive means that the point is to the clockwise of
end
as viewed fromstart
.
Sourcepub fn intersects(&self, other: &LineSegment<T, 2>) -> bool
pub fn intersects(&self, other: &LineSegment<T, 2>) -> bool
True if this segment intersects the given segment based on collinearity.
Trait Implementations§
Source§impl<T, const D: usize> Clone for LineSegment<T, D>where
T: Clone,
impl<T, const D: usize> Clone for LineSegment<T, D>where
T: Clone,
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> AsyncTaskResult for T
impl<T> AsyncTaskResult for T
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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Any
. Could be used to downcast a trait object
to a particular type.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Any
. Could be used to downcast a trait object
to a particular type.fn into_any(self: Box<T>) -> Box<dyn Any>
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> FieldValue for Twhere
T: 'static,
impl<T> FieldValue for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> ScriptMessagePayload for T
impl<T> ScriptMessagePayload for T
Source§fn as_any_ref(&self) -> &(dyn Any + 'static)
fn as_any_ref(&self) -> &(dyn Any + 'static)
self
as &dyn Any
Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
self
as &dyn Any
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.