Skip to content

Commit fff4ea6

Browse files
committed
Add +1 to clear logic
A cleared float should be placed in a segment *after* the last placed float on the cleared side(s) Signed-off-by: Nico Burns <[email protected]>
1 parent 90e269e commit fff4ea6

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/compute/float.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,17 +270,17 @@ impl FloatContext {
270270
Clear::Left => {
271271
let float_dir_start = self.last_placed_floats[slot].start;
272272
let left_end = self.last_placed_floats[0].end;
273-
float_dir_start.max(left_end)
273+
float_dir_start.max(left_end + 1)
274274
}
275275
Clear::Right => {
276276
let float_dir_start = self.last_placed_floats[slot].start;
277277
let right_end = self.last_placed_floats[1].end;
278-
float_dir_start.max(right_end)
278+
float_dir_start.max(right_end + 1)
279279
}
280280
Clear::Both => {
281281
let left_end = self.last_placed_floats[0].end;
282282
let right_end = self.last_placed_floats[1].end;
283-
left_end.max(right_end)
283+
left_end.max(right_end) + 1
284284
}
285285
Clear::None => {
286286
// float_dir_start
@@ -290,7 +290,10 @@ impl FloatContext {
290290

291291
// Ensure that float is placed in a segment at or below "min_y"
292292
// (ensuring that it is placed at or below min_y within it's segment happens below)
293-
let start_idx = self.segments[hwm..].iter().position(|segment| segment.y.end > min_y).map(|idx| idx + hwm);
293+
let start_idx = self
294+
.segments
295+
.get(hwm..)
296+
.and_then(|segments| segments.iter().position(|segment| segment.y.end > min_y).map(|idx| idx + hwm));
294297

295298
let mut start_idx = start_idx.unwrap_or(self.segments.len());
296299
let mut start_y = min_y;
@@ -472,21 +475,24 @@ impl FloatContext {
472475
let hwm = match clear {
473476
Clear::Left => {
474477
let left_end = self.last_placed_floats[0].end;
475-
at_least.max(left_end)
478+
at_least.max(left_end + 1)
476479
}
477480
Clear::Right => {
478481
let right_end = self.last_placed_floats[1].end;
479-
at_least.max(right_end)
482+
at_least.max(right_end + 1)
480483
}
481484
Clear::Both => {
482485
let left_end = self.last_placed_floats[0].end;
483486
let right_end = self.last_placed_floats[1].end;
484-
at_least.max(left_end).max(right_end)
487+
at_least.max(left_end).max(right_end) + 1
485488
}
486489
Clear::None => at_least,
487490
};
488491

489-
let start_idx = self.segments[hwm..].iter().position(|segment| segment.y.end > min_y).map(|idx| idx + hwm);
492+
let start_idx = self
493+
.segments
494+
.get(hwm..)
495+
.and_then(|segments| segments.iter().position(|segment| segment.y.end > min_y).map(|idx| idx + hwm));
490496
let start_idx = start_idx.unwrap_or(self.segments.len());
491497
let segment = self.segments.get(start_idx);
492498
match segment {

0 commit comments

Comments
 (0)