#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SelectionContentType {
GlobalIds,
PedigreeIds,
Indices,
Frustum,
Thresholds,
Blocks,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SelectionFieldType {
Point,
Cell,
}
#[derive(Debug, Clone)]
pub struct SelectionNode {
pub content_type: SelectionContentType,
pub field_type: SelectionFieldType,
pub selection_list: Vec<f64>,
pub array_name: Option<String>,
}
impl SelectionNode {
pub fn from_point_indices(indices: Vec<i64>) -> Self {
Self {
content_type: SelectionContentType::Indices,
field_type: SelectionFieldType::Point,
selection_list: indices.into_iter().map(|i| i as f64).collect(),
array_name: None,
}
}
pub fn from_cell_indices(indices: Vec<i64>) -> Self {
Self {
content_type: SelectionContentType::Indices,
field_type: SelectionFieldType::Cell,
selection_list: indices.into_iter().map(|i| i as f64).collect(),
array_name: None,
}
}
pub fn from_threshold(array_name: &str, min: f64, max: f64, field_type: SelectionFieldType) -> Self {
Self {
content_type: SelectionContentType::Thresholds,
field_type,
selection_list: vec![min, max],
array_name: Some(array_name.to_string()),
}
}
}
#[derive(Debug, Clone, Default)]
pub struct Selection {
nodes: Vec<SelectionNode>,
}
impl Selection {
pub fn new() -> Self {
Self::default()
}
pub fn add_node(&mut self, node: SelectionNode) {
self.nodes.push(node);
}
pub fn num_nodes(&self) -> usize {
self.nodes.len()
}
pub fn node(&self, idx: usize) -> Option<&SelectionNode> {
self.nodes.get(idx)
}
pub fn nodes(&self) -> &[SelectionNode] {
&self.nodes
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn point_index_selection() {
let mut sel = Selection::new();
sel.add_node(SelectionNode::from_point_indices(vec![0, 5, 10]));
assert_eq!(sel.num_nodes(), 1);
let node = sel.node(0).unwrap();
assert_eq!(node.content_type, SelectionContentType::Indices);
assert_eq!(node.field_type, SelectionFieldType::Point);
assert_eq!(node.selection_list.len(), 3);
}
#[test]
fn threshold_selection() {
let node = SelectionNode::from_threshold("temperature", 100.0, 200.0, SelectionFieldType::Cell);
assert_eq!(node.content_type, SelectionContentType::Thresholds);
assert_eq!(node.array_name.as_deref(), Some("temperature"));
assert_eq!(node.selection_list, vec![100.0, 200.0]);
}
}