pub enum SegmentPointLocation {
OnVertex(u32),
OnEdge([f32; 2]),
}Expand description
Describes where a point is located on a segment.
This enum is used by point projection queries to indicate whether the projected point is at one of the endpoints or somewhere along the segment.
§Variants
- OnVertex(id): Point projects to an endpoint (0 =
a, 1 =b) - OnEdge(bary): Point projects to the interior with barycentric coordinates
§Example
use parry3d::shape::SegmentPointLocation;
// Point at first vertex
let loc = SegmentPointLocation::OnVertex(0);
assert_eq!(loc.barycentric_coordinates(), [1.0, 0.0]);
// Point at second vertex
let loc = SegmentPointLocation::OnVertex(1);
assert_eq!(loc.barycentric_coordinates(), [0.0, 1.0]);
// Point halfway along the segment
let loc = SegmentPointLocation::OnEdge([0.5, 0.5]);
assert_eq!(loc.barycentric_coordinates(), [0.5, 0.5]);Variants§
OnVertex(u32)
The point lies on a vertex (endpoint).
0= Point is atsegment.a1= Point is atsegment.b
OnEdge([f32; 2])
The point lies on the segment interior.
Contains barycentric coordinates [u, v] where:
u + v = 1.0- Point =
a * u + b * v 0.0 < u, v < 1.0(strictly between endpoints)
Implementations§
Source§impl SegmentPointLocation
impl SegmentPointLocation
Sourcepub fn barycentric_coordinates(&self) -> [f32; 2]
pub fn barycentric_coordinates(&self) -> [f32; 2]
Returns the barycentric coordinates corresponding to this location.
Barycentric coordinates [u, v] satisfy:
u + v = 1.0- Point =
a * u + b * v
§Example
use parry3d::shape::{Segment, SegmentPointLocation};
use nalgebra::Point3;
let segment = Segment::new(
Point3::origin(),
Point3::new(10.0, 0.0, 0.0)
);
// Point at endpoint a
let loc_a = SegmentPointLocation::OnVertex(0);
assert_eq!(loc_a.barycentric_coordinates(), [1.0, 0.0]);
// Point at endpoint b
let loc_b = SegmentPointLocation::OnVertex(1);
assert_eq!(loc_b.barycentric_coordinates(), [0.0, 1.0]);
// Point at 30% from a to b
let loc_mid = SegmentPointLocation::OnEdge([0.7, 0.3]);
let coords = loc_mid.barycentric_coordinates();
assert_eq!(coords[0], 0.7);
assert_eq!(coords[1], 0.3);Trait Implementations§
Source§impl Clone for SegmentPointLocation
impl Clone for SegmentPointLocation
Source§fn clone(&self) -> SegmentPointLocation
fn clone(&self) -> SegmentPointLocation
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SegmentPointLocation
impl Debug for SegmentPointLocation
Source§impl PartialEq for SegmentPointLocation
impl PartialEq for SegmentPointLocation
impl Copy for SegmentPointLocation
impl StructuralPartialEq for SegmentPointLocation
Auto Trait Implementations§
impl Freeze for SegmentPointLocation
impl RefUnwindSafe for SegmentPointLocation
impl Send for SegmentPointLocation
impl Sync for SegmentPointLocation
impl Unpin for SegmentPointLocation
impl UnwindSafe for SegmentPointLocation
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
Mutably borrows from an owned value. Read more
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>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn 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>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which 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)
Converts
&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)
Converts
&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> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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>
Converts
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>
Converts
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<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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.