vec-x-rs
固定長の配列を管理するための構造体VecX
を提供し、VecX
同士やスカラー値との数値演算や代入演算をサポートします。
Provides a structure VecX
to manage fixed-length arrays, supporting numeric operations and assignment operations
between VecX
and scalar values.
その他、要素の一括キャストなど、便利なメソッドも提供します。
Other useful methods, such as batch casting of elements, are also provided.
また、一意な配列にインデックスを持たせて管理する方法も提供します。
It also provides a way to manage unique arrays with indices.
使い方 (Usage)
use vec_x::{VecX, IndexedVecXs};
fn main() {
let vec: VecX<i32, 3> = VecX::new([1, 2, 3]);
let vec: VecX<i32, 3> = VecX::from([1, 2, 3]);
let vec: VecX<i32, 3> = VecX::from([1; 3]);
let vec: VecX<i32, 3> = VecX::from(1);
type XYZ = VecX<f64, 3>;
type RGBA = VecX<u8, 4>;
let point = XYZ::new([1., 2., 3.]);
let red = RGBA::new([255, 0, 0, 255]);
let vec = VecX::new([1, 2, 3]);
assert_eq!(vec[0], 1);
assert_eq!(vec[1], 2);
assert_eq!(vec[2], 3);
let a = VecX::new([1, 2, 3]);
let b = VecX::new([4, 5, 6]);
assert_eq!(a + b, VecX::new([5, 7, 9]));
let a = VecX::new([1, 2, 3]);
assert_eq!(a + 1, VecX::new([2, 3, 4]));
let mut a = VecX::new([1, 2, 3]);
a += VecX::new([4, 5, 6]);
assert_eq!(a, VecX::new([5, 7, 9]));
let mut a = VecX::new([1, 2, 3]);
a += 1;
assert_eq!(a, VecX::new([2, 3, 4]));
let vec1 = VecX::new([1, 2, 3]);
let vec2 = VecX::new([1, 2, 3]);
assert_eq!(vec1, vec2);
assert!(vec1 <= vec2);
assert!(vec1 >= vec2);
let vec1 = VecX::new([1, 2, 3]);
let vec2 = VecX::new([4, 5, 6]);
assert!(vec1 < vec2);
let vec1 = VecX::new([1, 2, 3]);
let vec2 = VecX::new([1, 2, 2]);
assert_ne!(vec1, vec2);
assert!(vec1 > vec2);
let vec = VecX::new([1, 2, 3]);
let vec_f64: VecX<f64, 3> = vec.as_();
type RGB = VecX<u8, 3>;
let unique_colors = vec![
RGB::new([255, 0, 0]),
RGB::new([0, 255, 0]),
RGB::new([0, 0, 255]),
];
let colors = vec![
unique_colors[0], unique_colors[1], unique_colors[1], unique_colors[0], unique_colors[2], unique_colors[2], ];
let indexed_colors = IndexedVecXs::from_vec(colors);
let IndexedVecXs { values, indices } = indexed_colors;
assert_eq!(values[0], unique_colors[0]);
assert_eq!(values[1], unique_colors[1]);
assert_eq!(values[2], unique_colors[2]);
assert_eq!(indices, vec![0, 1, 1, 0, 2, 2]);
}
ライセンス (License)
Licensed under either of
at your option.
(The English in the README and comments in the source code were translated by DeepL.)