Skip to main content

Ray3

Struct Ray3 

Source
pub struct Ray3 { /* private fields */ }
Expand description

A 3D ray that holds an origin and direction both as 3D vectors

Implementations§

Source§

impl Ray3

Constructors

Source

pub fn new(origin: Vector3, direction: Vector3) -> Self

Creates a new 3D ray

  • origin: The origin of the ray
  • direction: The direction the ray is pointing at

Returns: Returns a new 3D ray

§Examples
let ray = Ray3::new(Vector3::one(), Vector3::forward());
assert_eq!(Vector3::one(), ray.origin());
assert_eq!(Vector3::forward(), ray.direction());
Source§

impl Ray3

Properties

Source

pub fn origin(&self) -> Vector3

Gets the origin of the ray as a 3D vector

Returns: Returns the origin of the ray

§Examples
let ray = Ray3::new(Vector3::one(), Vector3::forward());
assert_eq!(Vector3::one(), ray.origin());
Source

pub fn set_origin(&mut self, value: Vector3)

Sets the origin of the ray

  • value: The value to set the origin to
§Examples
let mut ray = Ray3::new(Vector3::one(), Vector3::forward());
ray.set_origin(Vector3::forward());
assert_eq!(Vector3::forward(), ray.origin());
Source

pub fn direction(&self) -> Vector3

Gets the direction of the ray as a 3D vector

Returns: Returns the direction of the ray

§Examples
let ray = Ray3::new(Vector3::one(), Vector3::forward());
assert_eq!(Vector3::forward(), ray.direction());
Source

pub fn set_direction(&mut self, value: Vector3)

Sets the direction of the ray

  • value: The value to set the direction to
§Examples
let mut ray = Ray3::new(Vector3::one(), Vector3::forward());
 
ray.set_direction(Vector3::one());
assert_eq!(Vector3::one(), ray.direction());
Source§

impl Ray3

Public Methods

Source

pub fn get_point(self, distance: f32) -> Vector3

Gets the point on the ray from the given distance

  • distance: The distance from the ray to get the point from

Returns: Returns a 3D point from the given distance from the ray

§Examples
let ray = Ray3::new(Vector3::one(), Vector3::forward());
let point = ray.get_point(4.3);
assert_eq!(Vector3::new(1.0, 1.0, 5.3), point);
Source

pub fn closest_point(self, point: Vector3) -> Vector3

Gets the closest point on the ray from the given point

  • point: The point to get the closest point from

Returns: Returns the closest point from the given point

§Examples
let ray = Ray3::new(Vector3::one(), Vector3::forward());
let point = ray.closest_point(Vector3::down());
assert_eq!(Vector3::new(1.0, 1.0, 0.0), point);
Source

pub fn distance(self, point: Vector3) -> f32

Gets the distance between the point and the ray’s line

  • point: The point to check the distance from

Returns: Returns the distance between the point and the ray’s line

§Examples
let ray = Ray3::new(Vector3::forward(), Vector3::forward());
let distance = ray.distance(Vector3::down());
assert_eq!(1.0, distance);
let ray = Ray3::new(Vector3::one(), Vector3::forward());
let distance = ray.distance(Vector3::down());
assert_eq!(2.236068, distance);

Trait Implementations§

Source§

impl Clone for Ray3

Source§

fn clone(&self) -> Ray3

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Ray3

Source§

impl Debug for Ray3

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div<Ray3> for f32

Source§

type Output = Ray3

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Ray3) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Ray3> for i32

Source§

type Output = Ray3

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Ray3) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<f32> for Ray3

Source§

type Output = Ray3

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f32) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<i32> for Ray3

Source§

type Output = Ray3

The resulting type after applying the / operator.
Source§

fn div(self, rhs: i32) -> Self::Output

Performs the / operation. Read more
Source§

impl DivAssign<f32> for Ray3

Source§

fn div_assign(&mut self, rhs: f32)

Performs the /= operation. Read more
Source§

impl DivAssign<i32> for Ray3

Source§

fn div_assign(&mut self, rhs: i32)

Performs the /= operation. Read more
Source§

impl Eq for Ray3

Source§

impl From<Ray2> for Ray3

Source§

fn from(value: Ray2) -> Self

Converts to this type from the input type.
Source§

impl From<Ray3> for Ray2

Source§

fn from(value: Ray3) -> Self

Converts to this type from the input type.
Source§

impl Mul<Ray3> for f32

Source§

type Output = Ray3

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Ray3) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Ray3> for i32

Source§

type Output = Ray3

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Ray3) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<f32> for Ray3

Source§

type Output = Ray3

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f32) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<i32> for Ray3

Source§

type Output = Ray3

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: i32) -> Self::Output

Performs the * operation. Read more
Source§

impl MulAssign<f32> for Ray3

Source§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
Source§

impl MulAssign<i32> for Ray3

Source§

fn mul_assign(&mut self, rhs: i32)

Performs the *= operation. Read more
Source§

impl Neg for Ray3

Source§

type Output = Ray3

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl PartialEq for Ray3

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Send for Ray3

Source§

impl Sync for Ray3

Auto Trait Implementations§

§

impl Freeze for Ray3

§

impl RefUnwindSafe for Ray3

§

impl Unpin for Ray3

§

impl UnsafeUnpin for Ray3

§

impl UnwindSafe for Ray3

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.