From bfbbcd6a54118f2ff3401a49cc43801d589a997c Mon Sep 17 00:00:00 2001 From: job runner Date: Wed, 7 Oct 2026 11:15:56 +0200 Subject: [PATCH] aspect-ratio-repaired: store c6_kimi_for_coding_p8a312ded.rs, train 33 of 33, held-out 7 of 7 Stage: store --- .../fixtures/aspect-ratio-repaired/NOTICE | 5 + .../c6_kimi_for_coding_p8a312ded.rs | 235 ++++++++++++++++++ 2 files changed, 240 insertions(+) create mode 100644 crates/generation/tests/fixtures/aspect-ratio-repaired/c6_kimi_for_coding_p8a312ded.rs diff --git a/crates/generation/tests/fixtures/aspect-ratio-repaired/NOTICE b/crates/generation/tests/fixtures/aspect-ratio-repaired/NOTICE index 8efb7c4e..b7d1e1b5 100644 --- a/crates/generation/tests/fixtures/aspect-ratio-repaired/NOTICE +++ b/crates/generation/tests/fixtures/aspect-ratio-repaired/NOTICE @@ -29,3 +29,8 @@ Scoring them again: cargo run --release -p generation --bin score_candidates -- --function aspect-ratio \ --sources crates/generation/tests/fixtures/aspect-ratio-repaired \ --cases corpus/aspect-ratio-wpt-ground-truth --work --out + +c6_kimi_for_coding_p8a312ded.rs: written by kimi-for-coding (seed 6) from a prompt with sha256 8a312deddee9f29376a46d8c6068ad5689ed708069037fa7e27f0cd51508afc4, +stored by the store stage of a feature job after 0 repair round(s) +(bench/repair-loop.sh, its source corpus/aspect-ratio-batch/sources/c6_kimi_for_coding.rs). Train 33 of 33, +held-out 7 of 7. diff --git a/crates/generation/tests/fixtures/aspect-ratio-repaired/c6_kimi_for_coding_p8a312ded.rs b/crates/generation/tests/fixtures/aspect-ratio-repaired/c6_kimi_for_coding_p8a312ded.rs new file mode 100644 index 00000000..d35684cf --- /dev/null +++ b/crates/generation/tests/fixtures/aspect-ratio-repaired/c6_kimi_for_coding_p8a312ded.rs @@ -0,0 +1,235 @@ +use dom::computed::LengthPercentageOrAuto; +use layout::aspect_ratio::{AspectRatioInputs, AspectRatioOutputs, AspectRatioResolver}; + +fn definite_length(value: LengthPercentageOrAuto) -> Option { + match value { + LengthPercentageOrAuto::Length(length) => Some(length), + _ => None, + } +} + +fn raw_to_content(value: f64, edge: f64, border_box_sizing: bool) -> f64 { + if border_box_sizing { + (value - edge).max(0.0) + } else { + value.max(0.0) + } +} + +fn clamp_size(size: f64, min: Option, max: Option) -> f64 { + let mut result = size.max(0.0); + if let Some(maximum) = max { + result = result.min(maximum.max(0.0)); + } + if let Some(minimum) = min { + result = result.max(minimum.max(0.0)); + } + result +} + +fn transfer_min( + origin_min: Option, + destination_preferred: Option, + destination_max: Option, + convert: impl FnOnce(f64) -> f64, +) -> Option { + origin_min.map(|origin| { + let mut transferred = convert(origin).max(0.0); + if let Some(preferred) = destination_preferred { + transferred = transferred.min(preferred.max(0.0)); + } + if let Some(maximum) = destination_max { + transferred = transferred.min(maximum.max(0.0)); + } + transferred + }) +} + +fn transfer_max( + origin_max: Option, + destination_preferred: Option, + destination_min: Option, + transferred_min: Option, + convert: impl FnOnce(f64) -> f64, +) -> Option { + origin_max.map(|origin| { + let mut transferred = convert(origin).max(0.0); + if let Some(preferred) = destination_preferred { + transferred = transferred.max(preferred.max(0.0)); + } + if let Some(minimum) = destination_min { + transferred = transferred.max(minimum.max(0.0)); + } + if let Some(minimum) = transferred_min { + transferred = transferred.max(minimum.max(0.0)); + } + transferred + }) +} + +pub fn resolve(inputs: &AspectRatioInputs) -> AspectRatioOutputs { + let ratio = inputs.ratio; + let ratio_is_effective = ratio.is_finite() && ratio > 0.0; + + if !ratio_is_effective { + let width = definite_length(inputs.width) + .map(|value| raw_to_content(value, inputs.edge_lr, inputs.border_box_sizing)) + .unwrap_or(inputs.width_from_width_function.max(0.0)); + let height = definite_length(inputs.height) + .map(|value| raw_to_content(value, inputs.edge_tb, inputs.border_box_sizing)) + .unwrap_or(inputs.content_height_from_children.max(0.0)); + + let min_width = inputs + .min_width + .map(|value| raw_to_content(value, inputs.edge_lr, inputs.border_box_sizing)); + let max_width = inputs + .max_width + .map(|value| raw_to_content(value, inputs.edge_lr, inputs.border_box_sizing)); + let min_height = inputs + .min_height + .map(|value| raw_to_content(value, inputs.edge_tb, inputs.border_box_sizing)); + let max_height = inputs + .max_height + .map(|value| raw_to_content(value, inputs.edge_tb, inputs.border_box_sizing)); + + return AspectRatioOutputs { + content_width: clamp_size(width, min_width, max_width), + content_height: clamp_size(height, min_height, max_height), + }; + } + + // CSS Sizing 4 §4.1: a bare uses the box-sizing box for ratio + // calculations, while `auto ` always uses the content box. + let ratio_uses_border_box = !inputs.auto && inputs.border_box_sizing; + + let to_ratio_base = |value: f64, edge: f64| { + if ratio_uses_border_box { + value.max(0.0) + } else if inputs.border_box_sizing { + (value - edge).max(0.0) + } else { + value.max(0.0) + } + }; + + let preferred_width = definite_length(inputs.width) + .map(|value| to_ratio_base(value, inputs.edge_lr)); + let preferred_height = definite_length(inputs.height) + .map(|value| to_ratio_base(value, inputs.edge_tb)); + + let min_width = inputs + .min_width + .map(|value| to_ratio_base(value, inputs.edge_lr)); + let max_width = inputs + .max_width + .map(|value| to_ratio_base(value, inputs.edge_lr)); + let min_height = inputs + .min_height + .map(|value| to_ratio_base(value, inputs.edge_tb)); + let max_height = inputs + .max_height + .map(|value| to_ratio_base(value, inputs.edge_tb)); + + let fill_width = if ratio_uses_border_box { + (inputs.width_from_width_function + inputs.edge_lr).max(0.0) + } else { + inputs.width_from_width_function.max(0.0) + }; + + // The preferred size in the ratio-determining axis is transferred before + // min/max constraints are applied to either axis. + let mut width = match (preferred_width, preferred_height) { + (Some(width), Some(_)) => width, + (Some(width), None) => width, + (None, Some(height)) => height * ratio, + (None, None) => fill_width, + }; + let mut height = match preferred_height { + Some(height) => height, + None => width / ratio, + }; + + // §4.4 transfers a definite constraint only into an indefinite constraint + // slot on the other axis. Definite destination constraints therefore win + // over the corresponding transferred constraint. + let mut transferred_min_width = None; + let mut effective_min_width = min_width; + if effective_min_width.is_none() { + transferred_min_width = transfer_min( + min_height, + preferred_width, + max_width, + |height| height * ratio, + ); + effective_min_width = transferred_min_width; + } + + let mut effective_max_width = max_width; + if effective_max_width.is_none() { + effective_max_width = transfer_max( + max_height, + preferred_width, + min_width, + transferred_min_width, + |height| height * ratio, + ); + } + + let mut transferred_min_height = None; + let mut effective_min_height = min_height; + if effective_min_height.is_none() { + transferred_min_height = transfer_min( + min_width, + preferred_height, + max_height, + |width| width / ratio, + ); + effective_min_height = transferred_min_height; + } + + let mut effective_max_height = max_height; + if effective_max_height.is_none() { + effective_max_height = transfer_max( + max_width, + preferred_height, + min_height, + transferred_min_height, + |width| width / ratio, + ); + } + + width = clamp_size(width, effective_min_width, effective_max_width); + height = clamp_size(height, effective_min_height, effective_max_height); + + // §4.3: min-height: auto supplies a content-based minimum in the block + // axis when that axis is ratio-dependent. A transferred maximum does not + // clamp this automatic minimum, but a definite max-height does. + if preferred_height.is_none() && inputs.min_height_auto && !inputs.scroll_container { + let mut content_minimum = if ratio_uses_border_box { + inputs.content_height_from_children + inputs.edge_tb + } else { + inputs.content_height_from_children + }; + content_minimum = content_minimum.max(0.0); + if let Some(definite_max_height) = max_height { + content_minimum = content_minimum.min(definite_max_height.max(0.0)); + } + height = height.max(content_minimum); + } + + let content_width = if ratio_uses_border_box { + (width - inputs.edge_lr).max(0.0) + } else { + width + }; + let content_height = if ratio_uses_border_box { + (height - inputs.edge_tb).max(0.0) + } else { + height + }; + + AspectRatioOutputs { + content_width, + content_height, + } +} \ No newline at end of file -- 2.54.0