building-blocks icon indicating copy to clipboard operation
building-blocks copied to clipboard

How to migrate to bonsairobo/my-stack?

Open wlinna opened this issue 3 years ago • 2 comments

Hello,

could you give some pointers on how to migrate to the new stack?

I used building-blocks in my project some time ago, and now I'm wondering how to migrate to bonsairobo/my-stack. I'm not sure what is the best way to do that, and I'm not very familiar with some concepts, such as localize_points_array . I don't even know which crates to use.

Here are some of the structs, impls and functions I use. I mostly just use building_blocks to generate grids and iterate through them.

  • PointN (ilattice?)
  • Extent2i::from_min_and_shape, Extent3i::from_min_and_shape (ilattice)
  • Extent3i::from_min_and_max (ilattice)
  • Array2x1::fill, Array3x1::fill
  • Array::extent
  • Point3::axis_component_mut
  • Local::localize_points_array(&Point3i::MOORE_OFFSETS)
  • Array::strides_from_local_points
  • Array::for_each

Extents and Points seem to be covered by ilattice, but what about strides? It seems like I might need ndshape-rs. And do these new libraries work with WebAssembly (Never used that before, but I'm intending to) ?

I have code like this. I don't suppose there are drop-in replacements for something like this? (Note: I'm not asking you to rewrite the code for me, I'm just putting it here so that you could give me some pointers):

        let offsets = Local::localize_points_array(&Point3i::MOORE_OFFSETS);
        let mut neighbor_strides = [Stride(0); Point3i::MOORE_OFFSETS.len()];
        self.array.strides_from_local_points(&offsets, &mut neighbor_strides);

        let mut make_surfaces = Vec::new();

        let iter_ext = Extent3i::from_min_and_max(Point3i::fill(1), arr_ext.max() - Point3i::fill(1));

        self.array.for_each(&iter_ext, |stride: Stride, value| {
            if value != NON_EMPTY {
                return;
            }

            for offset in neighbor_strides.iter() {
                let adjacent_value = self.array.get(stride + *offset);
                if adjacent_value == OUTSIDE {
                    make_surfaces.push(stride);
                    return;
                }
            }
        });

        for stride in make_surfaces {
            let val = self.array.get_mut(stride);
            *val = SURFACE;
        }

Thanks

wlinna avatar Oct 08 '22 11:10 wlinna

Hello, @wlinna ,

The most noticeable absence from the new crates is an actual multi-dimensional array. I decided having a highly generic array like ArrayN was actually detrimental to the API. So instead, the new crates just ask for 1D slices, and ndshape handles all of the linearizing of multidimensional coordinates.

Extents and Points seem to be covered by ilattice, but what about strides?

Strides are covered by ndshape. You just need to use the Shape trait to linearize your coordinates into strides.

And do these new libraries work with WebAssembly (Never used that before, but I'm intending to) ?

Yea there's nothing preventing this.

RE: Your code snippet. This should be possible with just ndshape and ilattice. You can fill your own 1D array. I don't think I kept MOORE_OFFSETs but you can just copy that constant. ilattice has an Extent type with a few for_each methods.

bonsairobo avatar Oct 08 '22 18:10 bonsairobo

Okay, thanks for the quick reply. I'll try to migrate

wlinna avatar Oct 09 '22 06:10 wlinna