pub struct IndexedVecXs<T, const N: usize>{
pub values: IndexSet<VecX<T, N>, FxBuildHasher>,
pub indices: Vec<usize>,
}
Expand description
A structure representing a set of indexed VecX
.
It is indexed for unique VecX
and can efficiently handle sets of VecX in some use cases.
インデックスが付けられたVecX
の集合を表す構造体です。
一意のVecX
に対してインデックスを持ち、ユースケースによってはVecXの集合を効率的に扱えます。
For example, when considering a set of VecX
representing a vertex army in 3D space, this is useful when there are multiple vertices with the same coordinates.
This method of data management is often employed in 3D data formats.
例えば、3D空間上の頂点軍を表すVecX
の集合を考えた際、同じ座標を持つ頂点が複数存在する場合に有効です。
このデータの管理方法は、しばしば3Dデータのフォーマットに採用されています。
use vec_x::{VecX, IndexedVecXs};
let colors: Vec<VecX<u8, 3>> = [
[255, 0, 0],
[0, 255, 0],
[255, 0, 0],
[255, 0, 0],
[0, 0, 255],
[0, 255, 0],
].into_iter().map(|p| VecX::new(p)).collect::<Vec<_>>();
let indexed_colors = IndexedVecXs::from_vec(colors);
let IndexedVecXs { values, indices } = indexed_colors;
// インデックスされた要素の数は元データの一意な要素の数と一致する
assert_eq!(values.len(), 3);
// 元データでの出現順にインデックスが付けられている
assert_eq!(values[0], VecX::new([255, 0, 0]));
assert_eq!(values[1], VecX::new([0, 255, 0]));
assert_eq!(values[2], VecX::new([0, 0, 255]));
// indicesの要素数は元データの要素数と一致する
assert_eq!(indices.len(), 6);
// 同じ要素は同じインデックスを持つ
assert_eq!(indices, vec![0, 1, 0, 0, 2, 1]);
Also, IndexedVecXs
implements Index
traits, allowing access to elements using indexes.
また、IndexedVecXs
はIndex
トレイトを実装しており、インデックスを使用して要素にアクセスできます。
use vec_x::{VecX, IndexedVecXs};
let colors: Vec<VecX<u8, 3>> = [
[255, 0, 0],
[0, 255, 0],
].into_iter().map(|p| VecX::new(p)).collect::<Vec<_>>();
let indexed_colors = IndexedVecXs::from_vec(colors);
assert_eq!(indexed_colors[0], VecX::new([255, 0, 0]));
assert_eq!(indexed_colors[1], VecX::new([0, 255, 0]));
Elements of VecX
must implement PartialEq
,Eq
,Hash
.
This is because we use HashSet internally.
The Rust standard floating-point types do not implement Eq
,Hash
(due to NaN having multiple binary representations), so you cannot use f32
or f64
.
VecX
の要素はPartialEq
,Eq
,Hash
を実装している必要があります。
これは内部でHashSetを使用しているためです。
Rust標準の浮動小数点数型はEq
,Hash
を実装していない(NaNが複数のバイナリ表現を持つことに起因する)ため、f32
やf64
を使用することはできません。
If you want to handle floating point numbers, consider using ordered-float crates.
もし浮動小数点数を扱いたい場合、ordered-floatクレートを使用することを検討してください。
use vec_x::{VecX, IndexedVecXs};
let points: Vec<VecX<f64, 3>> = [
[0., 0., 0.],
[1., 0., 0.],
].into_iter().map(|p| VecX::new(p)).collect::<Vec<_>>();
let indexed_colors = IndexedVecXs::from_vec(points); // compile error
Fields§
§values: IndexSet<VecX<T, N>, FxBuildHasher>
unique set of `VecX
一意なVecX
の集合
indices: Vec<usize>
Index referring to values
.
values
を参照するインデックス
Implementations§
Source§impl<T, const N: usize> IndexedVecXs<T, N>
impl<T, const N: usize> IndexedVecXs<T, N>
Sourcepub fn new(
values: IndexSet<VecX<T, N>, FxBuildHasher>,
indices: Vec<usize>,
) -> Self
pub fn new( values: IndexSet<VecX<T, N>, FxBuildHasher>, indices: Vec<usize>, ) -> Self
This is not normally used. Use from_vec
to generate IndexedVecXs
from Vec<VecX<T, N>>
.
これは通常使用されません。Vec<VecX<T, N>>
からIndexedVecXs
を生成するためにはfrom_vec
を使用してください。
Sourcepub fn iter(&self) -> Vec<&VecX<T, N>>
pub fn iter(&self) -> Vec<&VecX<T, N>>
Returns an iterable structure IndexedVecXIter
.
Internally, each time the iterator is consumed, it searches for the corresponding VecX
from the values
for the index in the indices
.
イテレーション可能な構造体IndexedVecXIter
を返します。
内部的には、イテレータが消費されるたびにvalues
からindices
中のインデックスに対応するVecX
を検索しています。
Sourcepub fn from_vec(vec: Vec<VecX<T, N>>) -> Self
pub fn from_vec(vec: Vec<VecX<T, N>>) -> Self
Generate IndexedVecXs
from Vec<VecX<T, N>>
.
Vec<VecX<T, N>>
からIndexedVecXs
を生成します。
Sourcepub fn to_ref_vec(&self) -> Vec<&VecX<T, N>>
pub fn to_ref_vec(&self) -> Vec<&VecX<T, N>>
Generate Vec<&VecX<T, N>> from IndexedVecXs
.
IndexedVecXs
からVec<&VecX<T, N>>を生成します。