MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/splashsurf / from_aabb

Method from_aabb

splashsurf_lib/src/uniform_grid.rs:175–201  ·  view source on GitHub ↗

Construct a new grid enclosing the given AABB The grid will at least contain the AABB but may be larger depending on the cell size.

(aabb: &Aabb3d<R>, cell_size: R)

Source from the content-addressed store, hash-verified

173 ///
174 /// The grid will at least contain the AABB but may be larger depending on the cell size.
175 pub fn from_aabb(aabb: &Aabb3d<R>, cell_size: R) -> Result<Self, GridConstructionError<I, R>> {
176 if !(cell_size > R::zero()) {
177 return Err(GridConstructionError::InvalidCellSize(cell_size));
178 }
179
180 if aabb.is_degenerate() {
181 return Err(GridConstructionError::DegenerateAabb);
182 }
183
184 if !aabb.is_consistent() {
185 return Err(GridConstructionError::InconsistentAabb);
186 }
187
188 // Align the min coordinate of the AABB to the cube grid to get consistent results between frames
189 let aligned_min = aabb
190 .min()
191 .unscale(cell_size)
192 .map(|x| x.floor())
193 .scale(cell_size);
194 let aabb = Aabb3d::new(aligned_min, *aabb.max());
195
196 let n_cells_real = aabb.extents() / cell_size;
197 let n_cells_per_dim = Self::checked_n_cells_per_dim(&n_cells_real)
198 .ok_or(GridConstructionError::IndexTypeTooSmallCellsPerDim)?;
199
200 Self::new(aabb.min(), &n_cells_per_dim, cell_size)
201 }
202
203 /// Constructs a new grid extending in positive cartesian axes direction from the min coordinate by the specified number of cubes of the given size
204 pub fn new(

Callers

nothing calls this directly

Calls 6

is_degenerateMethod · 0.80
is_consistentMethod · 0.80
scaleMethod · 0.80
extentsMethod · 0.80
minMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected