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: TImplementations§
Source§impl<T: Scalar, const N: usize, S: Space> HcPoint<T, N, S>
impl<T: Scalar, const N: usize, S: Space> HcPoint<T, N, S>
Sourcepub fn new(coords: impl Into<[T; N]>, weight: T) -> Self
pub fn new(coords: impl Into<[T; N]>, weight: T) -> Self
Creates a new point with the given coordinates and weight.
Sourcepub fn to_point(self) -> Point<T, N, S>
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));Trait Implementations§
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>
See HcMatrix::transform.
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>
See HcMatrix::transform.
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>
See Matrix::transform.
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>
See Matrix::transform.
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.
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.
impl<T: Scalar, const N: usize, S: Space> Copy for HcPoint<T, N, S>
impl<T: Scalar + Eq, const N: usize, S: Space> Eq for HcPoint<T, N, S>
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>where
T: RefUnwindSafe,
S: RefUnwindSafe,
impl<T, const N: usize, S> Send for HcPoint<T, N, S>
impl<T, const N: usize, S> Sync for HcPoint<T, N, S>
impl<T, const N: usize, S> Unpin for HcPoint<T, N, S>
impl<T, const N: usize, S> UnwindSafe for HcPoint<T, N, S>where
T: UnwindSafe,
S: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§type Bits = T
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
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self.