Struct pix_engine::shape::Point
source · [−]#[repr(transparent)]pub struct Point<T, const N: usize>(_);Expand description
A Point in N-dimensional space.
Please see the module-level documentation for examples.
Implementations
Constructs a Point from [T; N] coordinates.
Examples
let p = Point::new([1]);
assert_eq!(p.as_array(), [1]);
let p = Point::new([1, 2]);
assert_eq!(p.as_array(), [1, 2]);
let p = Point::new([1, -2, 1]);
assert_eq!(p.as_array(), [1, -2, 1]);Returns Point coordinates as [T; N].
Example
let p = point!(2, 1, 3);
assert_eq!(p.as_array(), [2, 1, 3]);Returns Point coordinates as a byte slice &[T; N].
Example
let p = point!(2, 1, 3);
assert_eq!(p.as_bytes(), &[2, 1, 3]);Returns Point coordinates as a mutable byte slice &mut [T; N].
Example
let mut p = point!(2, 1, 3);
for v in p.as_bytes_mut() {
*v *= 2;
}
assert_eq!(p.as_bytes(), &[4, 2, 6]);Offsets a Point by shifting coordinates by given amount.
Examples
let mut p = point!(2, 3, 1);
p.offset([2, -4]);
assert_eq!(p.as_array(), [4, -1, 1]);Offsets the y-coordinate of the point by a given amount.
Panics
If Vector has less than 2 dimensions.
Offsets the z-coordinate of the point by a given amount.
Panics
If Vector has less than 3 dimensions.
Constructs a Point by multiplying it by the given scale factor.
Examples
let mut p = point!(2, 3);
p.scale(2);
assert_eq!(p.as_array(), [4, 6]);Returns the Euclidean distance between two Points.
Example
let p1 = point!(1.0, 0.0, 0.0);
let p2 = point!(0.0, 1.0, 0.0);
let dist = p1.dist(p2);
let abs_difference: f64 = (dist - std::f64::consts::SQRT_2).abs();
assert!(abs_difference <= 1e-4);Constructs a Point by linear interpolating between two Points by a given amount
between 0.0 and 1.0.
Example
let p1 = point!(1.0, 1.0, 0.0);
let p2 = point!(3.0, 3.0, 0.0);
let p3 = p1.lerp(p2, 0.5);
assert_eq!(p3.as_array(), [2.0, 2.0, 0.0]);Converts Point < T, N > to Point < U, N >.
Returns Point < T, N > with the nearest integers to the numbers. Round half-way cases away from 0.0.
Returns Point < T, N > with the largest integers less than or equal to the numbers.
Trait Implementations
Performs the += operation. Read more
Performs the += operation. Read more
Performs the += operation. Read more
impl<'de, T, const N: usize> Deserialize<'de> for Point<T, N> where
T: Serialize + DeserializeOwned,
impl<'de, T, const N: usize> Deserialize<'de> for Point<T, N> where
T: Serialize + DeserializeOwned,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Performs the /= operation. Read more
Creates a value from an iterator. Read more
Creates a value from an iterator. Read more
Creates a value from an iterator. Read more
Creates a value from an iterator. Read more
Performs the *= operation. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
Performs the -= operation. Read more
Performs the -= operation. Read more
Performs the -= operation. Read more
Auto Trait Implementations
impl<T, const N: usize> RefUnwindSafe for Point<T, N> where
T: RefUnwindSafe,
impl<T, const N: usize> UnwindSafe for Point<T, N> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more