@@ -42,15 +42,24 @@ namespace geode
4242 }
4343 const auto min_cell_length =
4444 std::pow ( numerator / max_nb_cells, 1 . / dimension );
45- const auto cell_length =
46- std::max ( min_cell_length, target_cell_length );
45+ const auto target_is_ok = target_cell_length < min_cell_length;
46+ auto cell_length = std::max ( min_cell_length, target_cell_length );
4747 std::array< index_t , dimension > cell_numbers;
4848 std::array< double , dimension > cell_lengths;
4949 for ( const auto d : LRange{ dimension } )
5050 {
51- cell_numbers[d] = std::max ( static_cast < index_t >( 1 ),
52- static_cast < index_t >(
53- std::floor ( diagonal.value ( d ) / cell_length ) ) );
51+ if ( target_is_ok )
52+ {
53+ cell_numbers[d] = std::max ( static_cast < index_t >( 1 ),
54+ static_cast < index_t >(
55+ std::ceil ( diagonal.value ( d ) / cell_length ) ) );
56+ }
57+ else
58+ {
59+ cell_numbers[d] = std::max ( static_cast < index_t >( 1 ),
60+ static_cast < index_t >(
61+ std::floor ( diagonal.value ( d ) / cell_length ) ) );
62+ }
5463 cell_lengths[d] = diagonal.value ( d ) / cell_numbers[d];
5564 }
5665 return { bbox.min (), std::move ( cell_numbers ),
0 commit comments