igd-geo / pasture

Rust library for point cloud processing
Apache License 2.0
73 stars 9 forks source link

Views on trait objects #26

Closed Mortano closed 5 months ago

Mortano commented 10 months ago

Enables point and attribute views on trait objects (e.g. dyn BorrowedBuffer, dyn InterleavedBuffer etc.). This closes a gap in conjunction with the as_interleaved and as_columnar functions on the BorrowedBuffer trait, and makes code like this possible:

fn accepts_any_buffer<'a, B: BorrowedBuffer<'a>>(buffer: &'a B) {
    if let Some(interleaved) = buffer.as_interleaved() {
        for point in interleaved.view::<SimplePoint>().iter() {
            println!("{point:?}");
        }
    } else if let Some(columnar) = buffer.as_columnar() {
        for position in columnar.view_attribute::<Vector3<f64>>(&POSITION_3D).iter() {
            println!("{position}");
        }
    }
}

Also made some traits objects-safe that weren't before.