Point

Struct Point 

Source
#[repr(transparent)]
pub struct Point<Repr, Space = ()>(pub Repr, _);

Tuple Fields§

§0: Repr

Implementations§

Source§

impl<R, Sp> Point<R, Sp>

Source

pub const fn new(repr: R) -> Self

Source

pub fn to<S>(self) -> Point<R, S>

Returns a point with value equal to self but in space S.

Source

pub fn to_vec(self) -> Vector<R, Sp>

Returns the vector equivalent to self.

Source§

impl<Sc: Copy, Sp, const N: usize> Point<[Sc; N], Sp>

Source

pub fn map<T>(self, f: impl FnMut(Sc) -> T) -> Point<[T; N], Sp>

Returns a vector of the same dimension as self by applying f component-wise.

§Examples
use retrofire_core::math::{pt3};

let p = pt3::<i32, ()>(1, 2, 3);
assert_eq!(p.map(|x| x as f32 + 0.5), pt3(1.5, 2.5, 3.5));
Source

pub fn zip_map<T: Copy, U>( self, other: Point<[T; N], Sp>, f: impl FnMut(Sc, T) -> U, ) -> Point<[U; N], Sp>

Returns a vector of the same dimension as self by applying f component-wise to self and other.

§Examples
use retrofire_core::math::pt3;

let a = pt3::<f32, ()>(1.0, 2.0, 3.0);
let b = pt3(4, 3, 2);
assert_eq!(a.zip_map(b, |x, exp| x.powi(exp)), pt3(1.0, 8.0, 9.0));
Source§

impl<const N: usize, B> Point<[f32; N], Real<N, B>>

Source

pub const fn origin() -> Self

Returns the canonical origin point (0, …, 0).

Source

pub fn distance(&self, other: &Self) -> f32

Returns the Euclidean distance between self and another point.

§Example
use retrofire_core::math::{Point2, pt2};

let x3: Point2 = pt2(3.0, 0.0);
let y4 = pt2(0.0, 4.0);
assert_eq!(x3.distance(&y4), 5.0);
Source

pub fn distance_sqr(&self, other: &Self) -> f32

Returns the square of the Euclidean distance between self and another point.

The squared distance is faster to compute than the distance.

§Example
use retrofire_core::math::{Point2, pt2};

let x3: Point2 = pt2(3.0, 0.0);
let y4 = pt2(0.0, 4.0);
assert_eq!(x3.distance_sqr(&y4), 5.0 * 5.0);
Source

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

Returns self clamped component-wise to the given range.

The result is a vector v such that for each valid index i, v[i] is equal to self[i].clamp(min[i], max[i]).

See also f32::clamp.

§Panics

If min[i] > max[i] for any valid index i, or if either min or max contains a NaN.

§Examples
use retrofire_core::math::{pt3, Point3};

let pt: Point3 = pt3(0.5, 1.5, -2.0);
// Clamp to the unit cube
let clamped = pt.clamp(&pt3(0.0, 0.0, 0.0), &pt3(1.0, 1.0, 1.0));
assert_eq!(clamped, pt3(0.5, 1.0, 0.0));
Source§

impl<R, B, Sc> Point<R, Real<2, B>>
where R: Index<usize, Output = Sc>, Sc: Copy,

Source

pub fn x(&self) -> Sc

Returns the x component of self.

Source

pub fn y(&self) -> Sc

Returns the y component of self.

Source§

impl Point<[f32; 2], Real<2>>

Source

pub fn to_pt3(self) -> Point3

Converts self into a Point3, with z equal to 0.

Source§

impl<R, Sc, B> Point<R, Real<3, B>>
where R: Index<usize, Output = Sc>, Sc: Copy,

Source

pub fn x(&self) -> Sc

Returns the x component of self.

Source

pub fn y(&self) -> Sc

Returns the y component of self.

Source

pub fn z(&self) -> Sc

Returns the z component of self.

Trait Implementations§

Source§

impl<R, Sp> Add<<Point<R, Sp> as Affine>::Diff> for Point<R, Sp>
where Self: Affine,

Source§

type Output = Point<R, Sp>

The resulting type after applying the + operator.
Source§

fn add(self, other: <Self as Affine>::Diff) -> Self

Performs the + operation. Read more
Source§

impl<R, Sp> AddAssign<<Point<R, Sp> as Affine>::Diff> for Point<R, Sp>
where Self: Affine,

Source§

fn add_assign(&mut self, other: <Self as Affine>::Diff)

Performs the += operation. Read more
Source§

impl<ScSelf, ScDiff, Sp, const N: usize> Affine for Point<[ScSelf; N], Sp>
where ScSelf: Affine<Diff = ScDiff> + Copy, ScDiff: Linear<Scalar = ScDiff> + Copy,

Source§

const DIM: usize = N

The dimension of Self.
Source§

type Space = Sp

The space that Self is the element type of.
Source§

type Diff = Vector<[ScDiff; N], Sp>

The (signed) difference of two values of Self. Diff must have the same dimension as Self.
Source§

fn add(&self, other: &Self::Diff) -> Self

Adds diff to self component-wise. Read more
Source§

fn sub(&self, other: &Self) -> Self::Diff

Subtracts other from self, returning the (signed) difference. Read more
Source§

fn combine<S: Copy, const N: usize>( weights: &[S; N], points: &[Self; N], ) -> Self
where Self: Clone, Self::Diff: Linear<Scalar = S>,

Returns an affine combination of points. Read more
Source§

impl<Src, Dest> Apply<Point<[f32; 2], Real<2, Src>>> for Mat2x2<RealToReal<2, Src, Dest>>

Source§

fn apply(&self, pt: &Point2<Src>) -> Point2<Dest>

Maps a real 2-vector from basis Src to basis Dst.

Computes the matrix–point multiplication Mp where p is interpreted as a column vector:

 Mp  =  ⎛ M00 M01 ⎞ ⎛ v0 ⎞  =  ⎛ v0' ⎞
        ⎝ M10 M11 ⎠ ⎝ v1 ⎠     ⎝ v1' ⎠
Source§

type Output = Point<[f32; 2], Real<2, Dest>>

The transform codomain type.
Source§

impl<Src, Dest> Apply<Point<[f32; 2], Real<2, Src>>> for Mat3x3<RealToReal<2, Src, Dest>>

Source§

fn apply(&self, p: &Point2<Src>) -> Point2<Dest>

Maps a real 2-point from basis Src to basis Dst.

Computes the affine matrix–point multiplication 𝝡p where p is interpreted as a column vector with an implicit p2 component with value 1:

        ⎛ M00 ·  ·  ⎞ ⎛ p0 ⎞     ⎛ p0' ⎞
 Mp  =  ⎜  ·  ·  ·  ⎟ ⎜ p1 ⎟  =  ⎜ p1' ⎟
        ⎝  ·  · M22 ⎠ ⎝  1 ⎠     ⎝  1  ⎠
Source§

type Output = Point<[f32; 2], Real<2, Dest>>

The transform codomain type.
Source§

impl<Src, Dest> Apply<Point<[f32; 3], Real<3, Src>>> for Mat3x3<RealToReal<3, Src, Dest>>

Source§

fn apply(&self, p: &Point3<Src>) -> Point3<Dest>

Maps a real 3-point from basis Src to basis Dst.

Computes the linear matrix–point multiplication Mp where p is interpreted as a column vector:

        ⎛ M00 ·  ·  ⎞ ⎛ p0 ⎞     ⎛ p0' ⎞
 Mp  =  ⎜  ·  ·  ·  ⎟ ⎜ p1 ⎟  =  ⎜ p1' ⎟
        ⎝  ·  · M22 ⎠ ⎝ p2 ⎠     ⎝ p2' ⎠
Source§

type Output = Point<[f32; 3], Real<3, Dest>>

The transform codomain type.
Source§

impl<Src> Apply<Point<[f32; 3], Real<3, Src>>> for Mat4x4<RealToProj<Src>>

Source§

fn apply(&self, p: &Point3<Src>) -> ProjVec3

Maps the real 3-point p from basis B to the projective 3-space.

Computes the matrix–point multiplication Mp where p is interpreted as a column vector with an implicit p3 component with value 1:

        ⎛ M00  ·  · ⎞ ⎛ p0 ⎞     ⎛ p0' ⎞
 Mp  =  ⎜    ·      ⎟ ⎜ p1 ⎟  =  ⎜ p1' ⎟
        ⎜      ·    ⎟ ⎜ p2 ⎟     ⎜ p2' ⎟
        ⎝ ·  ·  M33 ⎠ ⎝  1 ⎠     ⎝ p3' ⎠
Source§

type Output = Vector<[f32; 4], Proj3>

The transform codomain type.
Source§

impl<Src, Dst> Apply<Point<[f32; 3], Real<3, Src>>> for Mat4x4<RealToReal<3, Src, Dst>>

Source§

fn apply(&self, p: &Point3<Src>) -> Point3<Dst>

Maps a real 3-point from basis Src to basis Dst.

Computes the affine matrix–point multiplication 𝝡p where p is interpreted as a column vector with an implicit p3 component with value 1:

        ⎛ M00 ·  ·  ·  ⎞ ⎛ p0 ⎞     ⎛ p0' ⎞
 Mp  =  ⎜  ·  ·  ·  ·  ⎟ ⎜ p1 ⎟  =  ⎜ p1' ⎟
        ⎜  ·  ·  ·  ·  ⎟ ⎜ p2 ⎟     ⎜ p2' ⎟
        ⎝  ·  ·  · M33 ⎠ ⎝  1 ⎠     ⎝  1  ⎠
Source§

type Output = Point<[f32; 3], Real<3, Dst>>

The transform codomain type.
Source§

impl<Sc: ApproxEq, Sp, const N: usize> ApproxEq<Point<[Sc; N], Sp>, Sc> for Point<[Sc; N], Sp>

Source§

fn approx_eq_eps(&self, other: &Self, eps: &Sc) -> bool

Returns whether self and other are approximately equal, using the relative epsilon rel_eps.
Source§

fn relative_epsilon() -> Sc

Returns the default relative epsilon of type E.
Source§

fn approx_eq(&self, other: &Other) -> bool

Returns whether self and other are approximately equal. Uses the epsilon returned by Self::relative_epsilon.
Source§

impl<R: Clone, S> Clone for Point<R, S>

Source§

fn clone(&self) -> Self

Returns a duplicate 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<R: Debug, Sp: Debug + Default> Debug for Point<R, Sp>

Source§

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

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

impl<R: Default, S> Default for Point<R, S>

Source§

fn default() -> Self

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

impl<'a, B: Default> Extend<&'a Point<[f32; 3], Real<3, B>>> for BBox<B>

Source§

fn extend<I: IntoIterator<Item = &'a Point3<B>>>(&mut self, it: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<R, Sp> From<R> for Point<R, Sp>

Source§

fn from(repr: R) -> Self

Converts to this type from the input type.
Source§

impl<'a, B: Default> FromIterator<&'a Point<[f32; 3], Real<3, B>>> for BBox<B>

Source§

fn from_iter<I: IntoIterator<Item = &'a Point3<B>>>(it: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<R: Index<usize>, Sp> Index<usize> for Point<R, Sp>

Source§

type Output = <R as Index<usize>>::Output

The returned type after indexing.
Source§

fn index(&self, i: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<R: IndexMut<usize>, Sp> IndexMut<usize> for Point<R, Sp>

Source§

fn index_mut(&mut self, i: usize) -> &mut R::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<R: PartialEq, S> PartialEq for Point<R, S>

Source§

fn eq(&self, other: &Self) -> 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<R, Sp> Sub<<Point<R, Sp> as Affine>::Diff> for Point<R, Sp>
where Self: Affine,

Source§

type Output = Point<R, Sp>

The resulting type after applying the - operator.
Source§

fn sub(self, other: <Self as Affine>::Diff) -> Self

Performs the - operation. Read more
Source§

impl<R, Sp> Sub for Point<R, Sp>
where Self: Affine,

Source§

type Output = <Point<R, Sp> as Affine>::Diff

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<R, Sp> SubAssign<<Point<R, Sp> as Affine>::Diff> for Point<R, Sp>
where Self: Affine,

Source§

fn sub_assign(&mut self, other: <Self as Affine>::Diff)

Performs the -= operation. Read more
Source§

impl<Sc, Sp, const N: usize> ZDiv for Point<[Sc; N], Sp>
where Sc: ZDiv + Copy,

Source§

fn z_div(self, z: f32) -> Self

Source§

impl<R: Copy, S> Copy for Point<R, S>

Source§

impl<R: Eq, S> Eq for Point<R, S>

Auto Trait Implementations§

§

impl<Repr, Space> Freeze for Point<Repr, Space>
where Repr: Freeze,

§

impl<Repr, Space> RefUnwindSafe for Point<Repr, Space>
where Repr: RefUnwindSafe, Space: RefUnwindSafe,

§

impl<Repr, Space> Send for Point<Repr, Space>
where Repr: Send, Space: Send,

§

impl<Repr, Space> Sync for Point<Repr, Space>
where Repr: Sync, Space: Sync,

§

impl<Repr, Space> Unpin for Point<Repr, Space>
where Repr: Unpin, Space: Unpin,

§

impl<Repr, Space> UnwindSafe for Point<Repr, Space>
where Repr: UnwindSafe, Space: 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<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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.