Skip to main content

Point3

Struct Point3 

Source
pub struct Point3<T> {
    pub x: T,
    pub y: T,
    pub z: T,
}
Expand description

A point with three coordinates x, y, and z.

Fields§

§x: T

The first coordinate.

§y: T

The second coordinate.

§z: T

The third coordinate.

Implementations§

Source§

impl<T> Point3<T>

Source

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

Constructs a point from its three coordinates.

Source

pub fn from_array(array: [T; 3]) -> Self

Constructs a point from an array [x, y, z].

Source

pub fn to_array(self) -> [T; 3]

Returns the coordinates as an array [x, y, z].

Source

pub fn with_x(self, x: T) -> Self

Returns a copy of self with the x coordinate replaced.

Source

pub fn with_y(self, y: T) -> Self

Returns a copy of self with the y coordinate replaced.

Source

pub fn with_z(self, z: T) -> Self

Returns a copy of self with the z coordinate replaced.

Source

pub fn from_vector(vector: Vector3<T>) -> Self

Reinterprets a displacement from the origin as a point.

Source

pub fn to_vector(self) -> Vector3<T>

Returns the position vector of self relative to the origin.

Source

pub fn map<U, F: FnMut(T) -> U>(self, f: F) -> Point3<U>

Applies f to every coordinate, returning the resulting point.

Source

pub fn zip_map<U, R, F: FnMut(T, U) -> R>( self, rhs: Point3<U>, f: F, ) -> Point3<R>

Combines self and rhs coordinate-wise through f.

Source§

impl<T: Copy> Point3<T>

Source

pub const fn splat(value: T) -> Self

Constructs a point with all three coordinates set to value.

Source

pub fn from_slice(slice: &[T]) -> Self

Constructs a point from the first three elements of a slice.

§Panics

Panics if slice has fewer than three elements.

Source§

impl<T: Add<Output = T> + Sub<Output = T> + Copy> Point3<T>

Source

pub fn lerp<S: Scalar>(self, rhs: Self, t: S) -> Self
where T: Mul<S, Output = T>,

Linearly interpolates from self toward rhs by the factor t.

t == 0 yields self, t == 1 yields rhs.

Source§

impl<V: Scalar> Point3<V>

Source

pub const ORIGIN: Self

The origin, (0, 0, 0).

Source

pub fn distance_squared(self, rhs: Self) -> V

Returns the squared Euclidean distance between self and rhs.

Cheaper than distance and sufficient whenever only relative distances are compared.

Source

pub fn distance(self, rhs: Self) -> V

Returns the Euclidean distance between self and rhs.

Source

pub fn midpoint(self, rhs: Self) -> Self

Returns the midpoint of the segment between self and rhs.

Source

pub fn centroid(points: &[Self]) -> Self

Returns the centroid (arithmetic mean) of points, or the ORIGIN when points is empty.

Source

pub fn min(self, rhs: Self) -> Self

Returns the component-wise minimum of self and rhs.

Source

pub fn max(self, rhs: Self) -> Self

Returns the component-wise maximum of self and rhs.

Source

pub fn clamp(self, min: Self, max: Self) -> Self

Restricts every coordinate to the interval [min, max], confining the point to an axis-aligned bounding box.

§Panics

Panics if any coordinate of min exceeds the corresponding coordinate of max.

Source

pub fn floor(self) -> Self

Returns the component-wise floor (largest integer not exceeding each coordinate).

Source

pub fn ceil(self) -> Self

Returns the component-wise ceiling (smallest integer not less than each coordinate).

Source

pub fn round(self) -> Self

Returns the component-wise nearest integer, rounding halves away from zero.

Source

pub fn round_ties_even(self) -> Self

Returns the component-wise nearest integer, rounding halves to even.

Source

pub fn trunc(self) -> Self

Returns the component-wise truncation toward zero.

Source

pub fn fract(self) -> Self

Returns the component-wise fractional part, i.e. the position of self within the unit-grid cell it occupies.

Source

pub fn is_finite(self) -> bool

Returns true if every coordinate is finite.

Source

pub fn is_infinite(self) -> bool

Returns true if any coordinate is positive or negative infinity.

Source

pub fn is_nan(self) -> bool

Returns true if any coordinate is NaN.

Trait Implementations§

Source§

impl<T: Add<Output = T>> Add<Vector3<T>> for Point3<T>

Source§

fn add(self, rhs: Vector3<T>) -> Self

Translates the point by the displacement rhs.

Source§

type Output = Point3<T>

The resulting type after applying the + operator.
Source§

impl<T: AddAssign> AddAssign<Vector3<T>> for Point3<T>

Source§

fn add_assign(&mut self, rhs: Vector3<T>)

Performs the += operation. Read more
Source§

impl<T: Clone> Clone for Point3<T>

Source§

fn clone(&self) -> Self

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<T: Copy> Copy for Point3<T>

Source§

impl<T: Debug> Debug for Point3<T>

Source§

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

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

impl<T: Default> Default for Point3<T>

Source§

fn default() -> Self

Returns the origin.

Source§

impl<T> Index<usize> for Point3<T>

Source§

fn index(&self, index: usize) -> &T

Returns the coordinate at index, where 0, 1, and 2 map to x, y, and z.

§Panics

Panics if index is greater than 2.

Source§

type Output = T

The returned type after indexing.
Source§

impl<T> IndexMut<usize> for Point3<T>

Source§

fn index_mut(&mut self, index: usize) -> &mut T

Returns the coordinate at index, where 0, 1, and 2 map to x, y, and z.

§Panics

Panics if index is greater than 2.

Source§

impl<T: PartialEq> PartialEq for Point3<T>

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<T: Sub<Output = T>> Sub for Point3<T>

Source§

fn sub(self, rhs: Self) -> Vector3<T>

Returns the displacement from rhs to self.

Source§

type Output = Vector3<T>

The resulting type after applying the - operator.
Source§

impl<T: Sub<Output = T>> Sub<Vector3<T>> for Point3<T>

Source§

fn sub(self, rhs: Vector3<T>) -> Self

Translates the point by the negated displacement rhs.

Source§

type Output = Point3<T>

The resulting type after applying the - operator.
Source§

impl<T: SubAssign> SubAssign<Vector3<T>> for Point3<T>

Source§

fn sub_assign(&mut self, rhs: Vector3<T>)

Performs the -= operation. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Point3<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Point3<T>
where T: RefUnwindSafe,

§

impl<T> Send for Point3<T>
where T: Send,

§

impl<T> Sync for Point3<T>
where T: Sync,

§

impl<T> Unpin for Point3<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Point3<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Point3<T>
where T: UnwindSafe,

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> 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.