Struct Ray
pub struct Ray {
pub origin: Vec3,
pub direction: Vec3,
}Expand description
A half-line: an origin and a direction.
direction is expected to be normalised. Ray::new guarantees it; the
struct literal — kept public because a ray is plain data — does not.
Fields§
§origin: Vec3Origin point.
direction: Vec3Direction vector (should be normalized).
Implementations§
§impl Ray
impl Ray
pub fn inv_direction(&self) -> Vec3
pub fn inv_direction(&self) -> Vec3
The component-wise reciprocal of the direction, as the slab test wants it.
A zero component yields an infinity, which Aabb::intersect_ray
handles correctly: a ray parallel to a slab simply never leaves it.
pub fn intersect_aabb(&self, aabb: &Aabb) -> Option<f32>
pub fn intersect_aabb(&self, aabb: &Aabb) -> Option<f32>
Distance to the near face of aabb, or None if the ray misses it.
Negative when the origin is already inside or past the box. Hoist
Ray::inv_direction and call Aabb::intersect_ray directly when
testing one ray against many boxes.
pub fn intersect_plane(&self, point: Vec3, normal: Vec3) -> Option<f32>
pub fn intersect_plane(&self, point: Vec3, normal: Vec3) -> Option<f32>
Distance to the plane through point with normal normal, or None
when the ray is parallel to it or the plane lies behind the origin.
normal need not be normalised — it only appears in a ratio.
pub fn distance_to_point(&self, point: Vec3) -> f32
pub fn distance_to_point(&self, point: Vec3) -> f32
Perpendicular distance from point to the ray.
Measured from the half-line: a point behind the origin is measured from the origin itself, not from the line the ray extends backwards along.
pub fn closest_param_on_line(
&self,
origin: Vec3,
direction: Vec3,
) -> Option<f32>
pub fn closest_param_on_line( &self, origin: Vec3, direction: Vec3, ) -> Option<f32>
How far along the line origin + t * direction its closest approach to
this ray sits, or None if the two are parallel.
The classic closest-approach of two skew lines. direction must be
normalised. Note this parameterises the other line, not the ray —
which is what a caller dragging along an axis wants to know.
pub fn closest_point_on_segment(&self, a: Vec3, b: Vec3) -> Vec3
pub fn closest_point_on_segment(&self, a: Vec3, b: Vec3) -> Vec3
The point on segment a..b closest to this ray.
Falls back to the midpoint when the segment is parallel to the ray or degenerate — every point on it is then equally close, and a caller hit-testing a handle wants an answer rather than an absence.
Trait Implementations§
§impl<'__de, __Context> BorrowDecode<'__de, __Context> for Ray
impl<'__de, __Context> BorrowDecode<'__de, __Context> for Ray
§fn borrow_decode<__D>(decoder: &mut __D) -> Result<Ray, DecodeError>where
__D: BorrowDecoder<'__de, Context = __Context>,
fn borrow_decode<__D>(decoder: &mut __D) -> Result<Ray, DecodeError>where
__D: BorrowDecoder<'__de, Context = __Context>,
§impl<'de> Deserialize<'de> for Ray
impl<'de> Deserialize<'de> for Ray
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Ray, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Ray, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl Serialize for Ray
impl Serialize for Ray
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Copy for Ray
impl StructuralPartialEq for Ray
Auto Trait Implementations§
impl Freeze for Ray
impl RefUnwindSafe for Ray
impl Send for Ray
impl Sync for Ray
impl Unpin for Ray
impl UnsafeUnpin for Ray
impl UnwindSafe for Ray
Blanket Implementations§
§impl<T> AppLifecycle for Twhere
T: ?Sized,
impl<T> AppLifecycle for Twhere
T: ?Sized,
§fn on_start(&mut self, ctx: &mut dyn AppContext)
fn on_start(&mut self, ctx: &mut dyn AppContext)
update. Apps install their theme / fonts here.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,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§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>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§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.§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.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<F, T, S> SimdInto<T, S> for Fwhere
T: SimdFrom<F, S>,
S: Simd,
impl<F, T, S> SimdInto<T, S> for Fwhere
T: SimdFrom<F, S>,
S: Simd,
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§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).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.