Skip to content

Commit

Permalink
Fix infinite loop due to float precision in grid layout maximise trac…
Browse files Browse the repository at this point in the history
…ks step (#792)

Signed-off-by: Nico Burns <[email protected]>
  • Loading branch information
nicoburns committed Feb 20, 2025
1 parent d1daa37 commit 8fa1cef
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/compute/grid/track_sizing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ fn distribute_space_up_to_limits(
) -> f32 {
/// Define a small constant to avoid infinite loops due to rounding errors. Rather than stopping distributing
/// extra space when it gets to exactly zero, we will stop when it falls below this amount
const THRESHOLD: f32 = 0.000001;
const THRESHOLD: f32 = 0.01;

let mut space_to_distribute = space_to_distribute;
while space_to_distribute > THRESHOLD {
Expand Down Expand Up @@ -1364,7 +1364,7 @@ fn distribute_space_up_to_limits(

for track in tracks.iter_mut().filter(|track| track_is_affected(track)) {
let increase = iteration_item_incurred_increase * track_distribution_proportion(track);
if increase > 0.0 && track_affected_property(track) + increase <= track_limit(track) {
if increase > 0.0 && track_affected_property(track) + increase <= track_limit(track) + THRESHOLD {
track.item_incurred_increase += increase;
space_to_distribute -= increase;
}
Expand Down

0 comments on commit 8fa1cef

Please sign in to comment.