alloy::geometry

Struct Point3

source
pub struct Point3(/* private fields */);
Expand description

A point in 3D space.

This type is used to disambiguate geometric uses of “points” representing explicit points in space from “vectors” representing displacements or directions.

Points can implicitly deref into Vec3 to allow for easily using points in places where vectors are expected.

Implementations§

source§

impl Point3

source

pub const ORIGIN: Point3 = _

The origin point

source

pub const fn new(x: f32, y: f32, z: f32) -> Self

Create a new point

source

pub const fn from_vec3(v: &Vec3) -> Self

Create a new point from a vector

§Parameters
  • v - The vector to create the point from
source

pub const fn from_vec4(v: &Vec4) -> Self

Create a new point from a 4-component vector

This discards the w coordinate.

§Parameters
  • v - The vector to create the point from
source

pub const fn to_vector3(&self) -> Vector3

Convert the point to a vector

source§

impl Point3

source

pub const fn as_vec3(&self) -> &Vec3

Get the x-coordinate of the point

source

pub fn as_mut_vec3(&mut self) -> &mut Vec3

Get the x-coordinate of the point

source§

impl Point3

source

pub fn min(&self, other: &Point3) -> Point3

Get the minimum values between two points

§Parameters
  • other - The other point to compare against
source

pub fn max(&self, other: &Point3) -> Point3

Get the maximum values between two points

§Parameters
  • other - The other point to compare against
source

pub fn distance_to(&self, other: &Point3) -> f32

Get the distance between two points

§Parameters
  • other - The other point to get the distance to
source

pub fn square_distance_to(&self, other: &Point3) -> f32

Get the square distance between two points

§Parameters
  • other - The other point to get the square distance to

Methods from Deref<Target = Vec3>§

source

pub fn as_slice(&self) -> &[f32]

Returns this Vec3 as a slice of f32.

source

pub fn as_mut_slice(&mut self) -> &mut [f32]

Returns this Vec3 as a mutable slice of f32.

source

pub fn as_ptr(&self) -> *const f32

Returns this vector as a ptr of f32.

source

pub fn as_mut_ptr(&mut self) -> *mut f32

Returns this vector as a mutable ptr of f32.

source

pub fn iter(&self) -> impl Iterator<Item = &f32>

Returns an iterator over the vector.

source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut f32>

Returns a mutable iterator over the vector.

source

pub fn x(&self) -> f32

Returns the X-coordinate of this 3-component vector.

source

pub fn y(&self) -> f32

Returns the Y-coordinate of this 3-component vector.

source

pub fn z(&self) -> f32

Returns the Z-coordinate of this 3-component vector.

source

pub fn xy(&self) -> &Vec2

Returns the xy coordinates of this vector as a Vec3.

source

pub fn yz(&self) -> &Vec2

Returns the yz coordinates of this vector as a Vec3.

source

pub fn x_mut(&mut self) -> &mut f32

Returns a mutable reference to the X-coordinate of this 3-component vector.

source

pub fn y_mut(&mut self) -> &mut f32

Returns a mutable reference to the Y-coordinate of this 3-component vector.

source

pub fn z_mut(&mut self) -> &mut f32

Returns a mutable reference to the Z-coordinate of this 3-component vector.

source

pub fn xy_mut(&mut self) -> &mut Vec2

Returns a mutable reference to the xy coordinates of this vector.

source

pub fn yz_mut(&mut self) -> &mut Vec2

Returns a mutable reference to the yz coordinates of this vector.

source

pub fn set_x(&mut self, x: f32)

Sets the x-component

§Parameters
  • x - the X-component
source

pub fn set_y(&mut self, y: f32)

Sets the y-component

§Parameters
  • y - the Y-component
source

pub fn set_z(&mut self, z: f32)

Sets the z-component

§Parameters
  • z - the Z-component
source

pub fn set_xy(&mut self, xy: &Vec2)

Sets the X and Y components of this vector

§Parameters
  • xy - the X and Y components o
source

pub fn set_yz(&mut self, xy: &Vec2)

Sets the Y and Z components of this vector

§Parameters
  • yz - the Y and Z components of the Vec3
source

pub fn set(&mut self, other: &Vec3)

Sets all the components of this vector the values from other.

§Parameters
  • other - the other Vec3 to set.
source

pub fn square_magnitude(&self) -> f32

Computes the square magnitude of this two-component vector.

source

pub fn magnitude(&self) -> f32

Computes the magnitude of this vector.

Where possible, consider using Vec3::square_magnitude as this will avoid the need to compute the square-root.

source

pub fn is_normalized(&self) -> bool

Queries whether this vector is normalized (e.g. has a magnitude of 1).

source

pub fn normalize(&mut self)

Normalizes this vector.

source

pub fn normalized(&self) -> Vector3

Returns normalized vector.

source

pub fn rotate_x<A: Angle>(&mut self, angle: A)

Rotates this vector around the X axis by angle A.

§Parameters
  • angle - the angle to rotate
source

pub fn rotate_y<A: Angle>(&mut self, angle: A)

Rotates this vector around the Y axis by angle A.

§Parameters
  • angle - the angle to rotate
source

pub fn rotate_z<A: Angle>(&mut self, angle: A)

Rotates this vector around the Y axis by angle A.

§Parameters
  • angle - the angle to rotate
source

pub fn is_finite(&self) -> bool

Returns whether all components of this Vec are finite.

§Example

Basic use:


let finite = Vector3::UNIT_X;
let not_finite = Vector3::new(f32::INFINITY, 3.0, 0.0);

assert!(finite.is_finite());
assert!(!not_finite.is_finite());
source

pub fn is_infinite(&self) -> bool

Returns whether any component of this vec are infinite.

This is the inverse operation of is_finite.

§Example

Basic use:


let finite = Vector3::UNIT_X;
let not_finite = Vector3::new(f32::INFINITY, 3.0, 0.0);

assert!(!finite.is_infinite());
assert!(not_finite.is_infinite());
source

pub fn is_nan(&self) -> bool

Returns whether any component of this vec are nan.

source

pub fn abs(&self) -> Vector3

Computes the absolute value of self

source

pub fn min(&self, rhs: &Vec3) -> Vector3

Computes the minimum of each vector.

§Parameters
  • lhs - the left vector
  • rhs - the right vector
source

pub fn max(&self, rhs: &Vec3) -> Vector3

Computes the maximum of each vector.

§Parameters
  • lhs - the left vector
  • rhs - the right vector

Trait Implementations§

source§

impl Add<&Point3> for &Vec3

source§

type Output = Point3

The resulting type after applying the + operator.
source§

fn add(self, rhs: &Point3) -> Self::Output

Performs the + operation. Read more
source§

impl Add<&Vec3> for Point3

source§

type Output = Point3

The resulting type after applying the + operator.
source§

fn add(self, rhs: &Vec3) -> Self::Output

Performs the + operation. Read more
source§

impl Add<Point3> for &Vec3

source§

type Output = Point3

The resulting type after applying the + operator.
source§

fn add(self, rhs: Point3) -> Self::Output

Performs the + operation. Read more
source§

impl Add for Point3

source§

type Output = Point3

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
source§

impl AsMut<Vec3> for Point3

source§

fn as_mut(&mut self) -> &mut Vec3

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsRef<Vec3> for Point3

source§

fn as_ref(&self) -> &Vec3

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for Point3

source§

fn clone(&self) -> Point3

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Point3

source§

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

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

impl Default for Point3

source§

fn default() -> Point3

Returns the “default value” for a type. Read more
source§

impl Deref for Point3

source§

type Target = Vec3

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for Point3

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl Div<f32> for &Point3

source§

type Output = Point3

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl Div<f32> for Point3

source§

type Output = Point3

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl Encloses<Point3> for AABB

source§

fn encloses(&self, point: &Point3) -> bool

Determines if this object encloses another object. Read more
source§

impl Encloses<Point3> for Plane

source§

fn encloses(&self, point: &Point3) -> bool

Determines if this object encloses another object. Read more
source§

impl Encloses<Point3> for Sphere

source§

fn encloses(&self, point: &Point3) -> bool

Determines if this object encloses another object. Read more
source§

impl From<&Vec3> for Point3

source§

fn from(v: &Vec3) -> Self

Converts to this type from the input type.
source§

impl From<Point3> for Vector3

source§

fn from(p: Point3) -> Self

Converts to this type from the input type.
source§

impl From<Vector3> for Point3

source§

fn from(v: Vector3) -> Self

Converts to this type from the input type.
source§

impl Mul<&Point3> for f32

source§

type Output = Point3

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<Point3> for f32

source§

type Output = Point3

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<f32> for &Point3

source§

type Output = Point3

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<f32> for Point3

source§

type Output = Point3

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl PartialEq for Point3

source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 PartialOrd for Point3

source§

fn partial_cmp(&self, other: &Point3) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Sub<&Vec3> for &Point3

source§

type Output = Point3

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &Vec3) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<&Vec3> for Point3

source§

type Output = Point3

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &Vec3) -> Self::Output

Performs the - operation. Read more
source§

impl Sub for &Point3

source§

type Output = Vector3

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
source§

impl Sub for Point3

source§

type Output = Vector3

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
source§

impl Copy for Point3

source§

impl StructuralPartialEq for Point3

Auto Trait Implementations§

§

impl Freeze for Point3

§

impl RefUnwindSafe for Point3

§

impl Send for Point3

§

impl Sync for Point3

§

impl Unpin for Point3

§

impl UnwindSafe for Point3

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.