use crate::data::{CellArray, Points, PolyData, DataSet};
pub fn outline(input: &PolyData) -> PolyData {
let bb = input.bounds();
let (xmin, xmax) = (bb.x_min, bb.x_max);
let (ymin, ymax) = (bb.y_min, bb.y_max);
let (zmin, zmax) = (bb.z_min, bb.z_max);
let mut points = Points::<f64>::new();
points.push([xmin, ymin, zmin]); points.push([xmax, ymin, zmin]); points.push([xmax, ymax, zmin]); points.push([xmin, ymax, zmin]); points.push([xmin, ymin, zmax]); points.push([xmax, ymin, zmax]); points.push([xmax, ymax, zmax]); points.push([xmin, ymax, zmax]);
let mut lines = CellArray::new();
let edges: [[i64; 2]; 12] = [
[0, 1], [1, 2], [2, 3], [3, 0], [4, 5], [5, 6], [6, 7], [7, 4], [0, 4], [1, 5], [2, 6], [3, 7], ];
for e in &edges {
lines.push_cell(e);
}
let mut pd = PolyData::new();
pd.points = points;
pd.lines = lines;
pd
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn outline_cube() {
let mut pd = PolyData::new();
pd.points.push([0.0, 0.0, 0.0]);
pd.points.push([1.0, 0.0, 0.0]);
pd.points.push([1.0, 1.0, 0.0]);
pd.points.push([0.0, 1.0, 1.0]);
pd.polys.push_cell(&[0, 1, 2, 3]);
let result = outline(&pd);
assert_eq!(result.points.len(), 8);
assert_eq!(result.lines.num_cells(), 12);
}
#[test]
fn outline_flat() {
let mut pd = PolyData::new();
pd.points.push([0.0, 0.0, 0.0]);
pd.points.push([1.0, 0.0, 0.0]);
pd.points.push([0.0, 1.0, 0.0]);
pd.polys.push_cell(&[0, 1, 2]);
let result = outline(&pd);
assert_eq!(result.points.len(), 8);
assert_eq!(result.lines.num_cells(), 12);
for i in 0..8 {
assert!((result.points.get(i)[2]).abs() < 1e-10);
}
}
}