Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150// Admitted candidate `model_0` (claude-code:default, 109/109); provenance: float.provenance.jsonuse crate::float::{Clear, FloatInputs, FloatOutputs, FloatSide, PlacedFloat, Subject};
fn compute_clearance(clear: Clear, flow_top: f64, placed: &[PlacedFloat]) -> f64 { let mut max_bottom: Option<f64> = None; for f in placed { let relevant = match clear { Clear::None => false, Clear::Left => f.side == FloatSide::Left, Clear::Right => f.side == FloatSide::Right, Clear::Both => true, }; if relevant { max_bottom = Some(match max_bottom { Some(m) => m.max(f.bottom), None => f.bottom, }); } } match max_bottom { Some(b) if b > flow_top => b - flow_top, _ => 0.0, }}
fn span_at(y: f64, cb_left: f64, cb_right: f64, placed: &[PlacedFloat]) -> (f64, f64) { let mut left_edge = cb_left; let mut right_edge = cb_right; for f in placed { if f.top <= y && f.bottom > y { match f.side { FloatSide::Left => { if f.right > left_edge { left_edge = f.right; } } FloatSide::Right => { if f.left < right_edge { right_edge = f.left; } } } } } (left_edge, right_edge)}
fn candidate_ys(start_y: f64, placed: &[PlacedFloat]) -> Vec<f64> { let mut ys: Vec<f64> = vec![start_y]; for f in placed { if f.bottom > start_y { ys.push(f.bottom); } } ys.sort_by(|a, b| a.partial_cmp(b).unwrap()); ys.dedup_by(|a, b| (*a - *b).abs() < 1e-9); ys}
fn place_float( side: FloatSide, width: f64, start_y: f64, cb_left: f64, cb_right: f64, placed: &[PlacedFloat],) -> (f64, f64, f64) { let ys = candidate_ys(start_y, placed); for &y in &ys { let (le, re) = span_at(y, cb_left, cb_right, placed); if re - le >= width - 1e-9 { return match side { FloatSide::Left => (le, le + width, y), FloatSide::Right => (re - width, re, y), }; } } let y = *ys.last().unwrap(); let (le, re) = span_at(y, cb_left, cb_right, placed); match side { FloatSide::Left => (le, le + width, y), FloatSide::Right => (re - width, re, y), }}
fn place_bfc_root( width: f64, start_y: f64, cb_left: f64, cb_right: f64, placed: &[PlacedFloat],) -> (f64, f64, f64) { let ys = candidate_ys(start_y, placed); for &y in &ys { let (le, re) = span_at(y, cb_left, cb_right, placed); if re - le >= width - 1e-9 { return (y, le, re); } } let y = *ys.last().unwrap(); let (le, re) = span_at(y, cb_left, cb_right, placed); (y, le, re)}
pub fn resolve(inputs: &FloatInputs) -> FloatOutputs { match inputs.subject { Subject::Block => { let clearance = compute_clearance(inputs.clear, inputs.flow_top, &inputs.placed); FloatOutputs { left: inputs.containing_block_left, right: inputs.containing_block_right, top: inputs.flow_top + clearance, clearance, } } Subject::BfcRoot => { let clearance = compute_clearance(inputs.clear, inputs.flow_top, &inputs.placed); let start_y = (inputs.flow_top + clearance).max(inputs.containing_block_top); let (top, left, right) = place_bfc_root( inputs.margin_box_width, start_y, inputs.containing_block_left, inputs.containing_block_right, &inputs.placed, ); FloatOutputs { left, right, top, clearance } } Subject::Float(side) => { let clearance = compute_clearance(inputs.clear, inputs.flow_top, &inputs.placed); let mut start_y = (inputs.flow_top + clearance).max(inputs.containing_block_top); let max_earlier_top = inputs .placed .iter() .map(|f| f.top) .fold(None, |acc: Option<f64>, t| Some(acc.map_or(t, |a| a.max(t)))); if let Some(mt) = max_earlier_top { start_y = start_y.max(mt); } let (left, right, top) = place_float( side, inputs.margin_box_width, start_y, inputs.containing_block_left, inputs.containing_block_right, &inputs.placed, ); FloatOutputs { left, right, top, clearance } } }}