vec-x-rs
任意の固定長の配列を扱うためのライブラリです。
配列を管理するための構造体VecXを提供し、数値演算や代入演算をサポートしています。
A library for handling arbitrary fixed-length arrays.
It provides the structure VecX to manage arrays and supports numeric and assignment operations.
また、一意な配列にインデックスを持たせて管理する方法も提供します。
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]);
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]));
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.)