HcPoint

Struct HcPoint 

Source
pub struct HcPoint<T: Scalar, const N: usize, S: Space = WorldSpace> {
    pub weight: T,
    /* private fields */
}
Expand description

A location in N-dimensional space represented by homogeneous coordinates (with N + 1 values).

Any given point can not only be represented in the familiar cartesian coordinates, but also in so called homogeneous coordinates. In fact, it has infinitely many representations in homogeneous coordinates! To represent a point in N-dimensional space, homogeneous coordinates store N+1 values: N normal coordinates and a weight. The cartesian coordinates (x, y, z) and the homogeneous coordinates (W·x, W·y, W·z; W) (for any W != 0) all represent the same point in 3D space! E.g., (1, 2, 3), (1, 2, 3; 1) and (2, 4, 6; 2) represent the same point.

Homogeneous coordinates are used to represent affine and projective transformations of N-dimensional points as (N+1)x(N+1) matrix. You usually only ever encounter them in that context.

The most important functions of this type is to convert from and to Point via the From impls or Self::to_point.

use lina::{HcPoint, point2};

let mut hc = HcPoint::from(point2(7.0, 5.0));
assert_eq!(hc.x, 7.0);
assert_eq!(hc.y, 5.0);
assert_eq!(hc.weight, 1.0);

hc.weight = 2.0;
assert_eq!(hc.to_point(), point2(3.5, 2.5));

Fields§

§weight: T

Implementations§

Source§

impl<T: Scalar, const N: usize, S: Space> HcPoint<T, N, S>

Source

pub fn origin() -> Self

Returns a representation of the origin in N-dimensional space.

Source

pub fn new(coords: impl Into<[T; N]>, weight: T) -> Self

Creates a new point with the given coordinates and weight.

Source

pub fn to_point(self) -> Point<T, N, S>

Converts this homogeneous coordinates point into a cartesian coordinate point (by dividing all components by the weight).

use lina::{HcPoint, point3};

let hc = HcPoint::new([1.0, 2.0, 3.0], 2.0);
assert_eq!(hc.to_point(), point3(0.5, 1.0, 1.5));
Source

pub const fn in_space<Target: Space>(self) -> HcPoint<T, N, Target>

Reinterprets this points as being in the space Target instead of S. Before calling this, make sure this operation makes semantic sense and don’t just use it to get rid of compiler errors.

Source

pub fn to_f32(self) -> HcPoint<f32, N, S>
where T: NumCast,

Casts self to using f32 as scalar.

Source

pub fn to_f64(self) -> HcPoint<f64, N, S>
where T: NumCast,

Casts self to using f64 as scalar.

Source

pub fn as_bytes(&self) -> &[u8]

Returns a byte slice of this point representing the full raw data (components + weight). Useful to pass to graphics APIs.

Source§

impl<T: Scalar, S: Space> HcPoint<T, 2, S>

Source

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

Converts this to an array of size N+1 with all the stored values (components + weight). This is equivalent to using the corresponding From<Self> for [T; N + 1] impl.

Trait Implementations§

Source§

impl<T: Scalar, S: Space> AsMut<[T; 3]> for HcPoint<T, 2, S>

Source§

fn as_mut(&mut self) -> &mut [T; 3]

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

impl<T: Scalar, S: Space> AsRef<[T; 3]> for HcPoint<T, 2, S>

Source§

fn as_ref(&self) -> &[T; 3]

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

impl<T: Scalar, const N: usize, S: Space> Clone for HcPoint<T, N, 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<T: Scalar, const N: usize, S: Space> Debug for HcPoint<T, N, S>

Source§

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

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

impl<T: Scalar, S: Space> Deref for HcPoint<T, 2, S>

Source§

type Target = View2<T>

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<T: Scalar, S: Space> Deref for HcPoint<T, 3, S>

Source§

type Target = View3<T>

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<T: Scalar, S: Space> DerefMut for HcPoint<T, 2, S>

Source§

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

Mutably dereferences the value.
Source§

impl<T: Scalar, S: Space> DerefMut for HcPoint<T, 3, S>

Source§

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

Mutably dereferences the value.
Source§

impl<T: Scalar, S: Space> From<[T; 3]> for HcPoint<T, 2, S>

Source§

fn from(src: [T; 3]) -> Self

Converts to this type from the input type.
Source§

impl<T: Scalar, S: Space> From<HcPoint<T, 2, S>> for [T; 3]

Source§

fn from(src: HcPoint<T, 2, S>) -> Self

Converts to this type from the input type.
Source§

impl<T: Scalar, const N: usize, S: Space> From<HcPoint<T, N, S>> for Point<T, N, S>

Source§

fn from(src: HcPoint<T, N, S>) -> Self

Converts to this type from the input type.
Source§

impl<T: Scalar, const N: usize, S: Space> From<Point<T, N, S>> for HcPoint<T, N, S>

Source§

fn from(src: Point<T, N, S>) -> Self

Converts to this type from the input type.
Source§

impl<T: Scalar + Hash, const N: usize, S: Space> Hash for HcPoint<T, N, S>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: Scalar, const N: usize, S: Space> Index<usize> for HcPoint<T, N, S>

Source§

type Output = T

The returned type after indexing.
Source§

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

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

impl<T: Scalar, const N: usize, S: Space> IndexMut<usize> for HcPoint<T, N, S>

Source§

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

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

impl<T: Scalar, const C: usize, const R: usize, Src: Space, Dst: Space> Mul<HcPoint<T, C, Src>> for &HcMatrix<T, C, R, Src, Dst>

Source§

type Output = HcPoint<T, R, Dst>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: HcPoint<T, C, Src>) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: Scalar, const C: usize, const R: usize, Src: Space, Dst: Space> Mul<HcPoint<T, C, Src>> for &Matrix<T, C, R, Src, Dst>

Source§

type Output = HcPoint<T, R, Dst>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: HcPoint<T, C, Src>) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: Scalar, const N: usize, S: Space> PartialEq for HcPoint<T, N, 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<T: Scalar + Zeroable, const N: usize, S: Space> Zeroable for HcPoint<T, N, S>

Due to the T: Zeroable bound, all our fields are zeroable. weight trivially is, coords is as [T; N] implements Zeroable as well. And PhantomData is zero sized, so implements it as well. Further, due to repr(C), this type has no padding bytes.

Source§

fn zeroed() -> Self

Source§

impl<T: Scalar, const N: usize, S: Space> Copy for HcPoint<T, N, S>

Source§

impl<T: Scalar + Eq, const N: usize, S: Space> Eq for HcPoint<T, N, S>

Source§

impl<T: Scalar + Pod, const N: usize, S: Space> Pod for HcPoint<T, N, S>

This type, with the T: Pod bounds, satisfies all properties required by Pod. All bit patterns are allowed, no padding bytes, trivially inhabiteda nad repr(C).

Auto Trait Implementations§

§

impl<T, const N: usize, S> Freeze for HcPoint<T, N, S>
where T: Freeze,

§

impl<T, const N: usize, S> RefUnwindSafe for HcPoint<T, N, S>

§

impl<T, const N: usize, S> Send for HcPoint<T, N, S>
where T: Send, S: Send,

§

impl<T, const N: usize, S> Sync for HcPoint<T, N, S>
where T: Sync, S: Sync,

§

impl<T, const N: usize, S> Unpin for HcPoint<T, N, S>
where T: Unpin, S: Unpin,

§

impl<T, const N: usize, S> UnwindSafe for HcPoint<T, N, S>
where T: UnwindSafe, S: 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> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
Source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.
Source§

impl<T> AnyBitPattern for T
where T: Pod,

Source§

impl<T> NoUninit for T
where T: Pod,