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)
| 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( |
nothing calls this directly
no test coverage detected