pub struct VecX<T, const N: usize> {
pub data: [T; N],
}Expand description
A structure representing a fixed-length array of arbitrary elements and arbitrary length. Since it was created primarily to represent mathematical vectors and colors, it supports four arithmetic operations.
任意の要素、任意の長さの固定長配列を表す構造体です。 主に数学的なベクトルや色を表すために作成したため、四則演算をサポートしています。
use vec_x::{VecX};
let vec1 = VecX::new([1, 2, 3]);
let vec2 = VecX::new([4, 5, 6]);
// Add
assert_eq!(vec1 + vec2, VecX::new([5, 7, 9]));
// Sub
assert_eq!(vec1 - vec2, VecX::new([-3, -3, -3]));
// Mul
assert_eq!(vec1 * vec2, VecX::new([4, 10, 18]));
// Div
assert_eq!(vec1 / vec2, VecX::new([0, 0, 0]));
// Rem
assert_eq!(vec1 % vec2, VecX::new([1, 2, 3]));
// AddAssign
let mut vec = VecX::new([1, 2, 3]);
vec += VecX::new([4, 5, 6]);
assert_eq!(vec, VecX::new([5, 7, 9]));
// SubAssign
let mut vec = VecX::new([1, 2, 3]);
vec -= VecX::new([4, 5, 6]);
assert_eq!(vec, VecX::new([-3, -3, -3]));
// MulAssign
let mut vec = VecX::new([1, 2, 3]);
vec *= VecX::new([4, 5, 6]);
assert_eq!(vec, VecX::new([4, 10, 18]));
// DivAssign
let mut vec = VecX::new([1, 2, 3]);
vec /= VecX::new([4, 5, 6]);
assert_eq!(vec, VecX::new([0, 0, 0]));
// RemAssign
let mut vec = VecX::new([1, 2, 3]);
vec %= VecX::new([4, 5, 6]);
assert_eq!(vec, VecX::new([1, 2, 3]));Non-numeric elements can also be array elements.
数値以外を配列要素にすることもできます。
use vec_x::{VecX};
let vec1 = VecX::new(["a", "b", "c"]);ⓘ
use vec_x::{VecX};
let vec1 = VecX::new(["a", "b", "c"]);
let vec2 = VecX::new(["d", "e", "f"]);
vec1 + vec2; // compile error!Using type aliases, as shown below, improves code readability.
以下のように型エイリアスを使用することで、コードの可読性が向上します。
use vec_x::{VecX};
type XYZ = VecX<f64, 3>;
type RGBA = VecX<u8, 4>;
struct Point {
position: XYZ,
color: RGBA,
}
let point = Point {
position: XYZ::new([1.0, 2.0, 3.0]),
color: RGBA::new([255, 0, 0, 255]),
};Fields§
§data: [T; N]Implementations§
Trait Implementations§
source§impl<T: Num + AddAssign, const N: usize> AddAssign for VecX<T, N>
impl<T: Num + AddAssign, const N: usize> AddAssign for VecX<T, N>
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+= operation. Read moresource§impl<T: Num + DivAssign, const N: usize> DivAssign for VecX<T, N>
impl<T: Num + DivAssign, const N: usize> DivAssign for VecX<T, N>
source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
Performs the
/= operation. Read moresource§impl<T: Num + MulAssign, const N: usize> MulAssign for VecX<T, N>
impl<T: Num + MulAssign, const N: usize> MulAssign for VecX<T, N>
source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
Performs the
*= operation. Read moresource§impl<T: PartialEq, const N: usize> PartialEq for VecX<T, N>
impl<T: PartialEq, const N: usize> PartialEq for VecX<T, N>
source§impl<T: Num + RemAssign, const N: usize> RemAssign for VecX<T, N>
impl<T: Num + RemAssign, const N: usize> RemAssign for VecX<T, N>
source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
Performs the
%= operation. Read moresource§impl<T: Num + SubAssign, const N: usize> SubAssign for VecX<T, N>
impl<T: Num + SubAssign, const N: usize> SubAssign for VecX<T, N>
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the
-= operation. Read moreimpl<T: Copy, const N: usize> Copy for VecX<T, N>
impl<T: Eq, const N: usize> Eq for VecX<T, N>
impl<T, const N: usize> StructuralPartialEq for VecX<T, N>
Auto Trait Implementations§
impl<T, const N: usize> Freeze for VecX<T, N>where
T: Freeze,
impl<T, const N: usize> RefUnwindSafe for VecX<T, N>where
T: RefUnwindSafe,
impl<T, const N: usize> Send for VecX<T, N>where
T: Send,
impl<T, const N: usize> Sync for VecX<T, N>where
T: Sync,
impl<T, const N: usize> Unpin for VecX<T, N>where
T: Unpin,
impl<T, const N: usize> UnwindSafe for VecX<T, N>where
T: 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
Mutably borrows from an owned value. Read more
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.