vox_geometry_rust/
bcc_lattice_point_generator.rs1use crate::point_generator3::PointGenerator3;
10use crate::vector3::Vector3D;
11use crate::bounding_box3::BoundingBox3D;
12use std::sync::{RwLock, Arc};
13
14pub struct BccLatticePointGenerator {}
21
22impl PointGenerator3 for BccLatticePointGenerator {
23 fn for_each_point<Callback>(&self, bounding_box: &BoundingBox3D, spacing: f64, callback: &mut Callback)
31 where Callback: FnMut(&Vector3D) -> bool {
32 let half_spacing = spacing / 2.0;
33 let box_width = bounding_box.width();
34 let box_height = bounding_box.height();
35 let box_depth = bounding_box.depth();
36
37 let mut position = Vector3D::new_default();
38 let mut has_offset = false;
39 let mut should_quit = false;
40 let mut k = 0;
41 while k as f64 * half_spacing <= box_depth && !should_quit {
42 position.z = k as f64 * half_spacing + bounding_box.lower_corner.z;
43
44 let offset = match has_offset {
45 true => half_spacing,
46 false => 0.0
47 };
48
49 let mut j = 0;
50 while j as f64 * spacing + offset <= box_height && !should_quit {
51 position.y = j as f64 * spacing + offset + bounding_box.lower_corner.y;
52
53 let mut i = 0;
54 while i as f64 * spacing + offset <= box_width {
55 position.x = i as f64 * spacing + offset + bounding_box.lower_corner.x;
56 if !callback(&position) {
57 should_quit = true;
58 break;
59 }
60 i += 1;
61 }
62 j += 1;
63 }
64 has_offset = !has_offset;
65 k += 1;
66 }
67 }
68}
69
70pub type BccLatticePointGeneratorPtr = Arc<RwLock<BccLatticePointGenerator>>;