From b5a82554a9945d4922386df77715032dfb8075fa Mon Sep 17 00:00:00 2001 From: nihilist-narwhal <240798405+nihilist-narwhal@users.noreply.github.com> Date: Sat, 10 Oct 2026 05:48:36 -0500 Subject: [PATCH] Fill Series: a falling growth series stops at its stop value A growth series with a step below 1 stopped at once when given a stop value, since the stop was only checked for rising series. It now bounds the series in the direction it runs. --- crates/engine/src/fill.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/fill.rs b/crates/engine/src/fill.rs index 8a40961..03f0808 100644 --- a/crates/engine/src/fill.rs +++ b/crates/engine/src/fill.rs @@ -373,6 +373,7 @@ pub fn series(cx: &mut Ctx, sheet: usize, r: RangeRef, rows: bool, kind: &str, s let style = sh.style_id(first_cell); let mut v = start; for i in 1..len { + let prev = v; v = match kind { "growth" => v * step, "date" => { @@ -396,8 +397,9 @@ pub fn series(cx: &mut Ctx, sheet: usize, r: RangeRef, rows: bool, kind: &str, s } _ => v + step, }; + // The stop value bounds the series in the direction it runs (a growth by 0.5 falls). if let Some(s) = stop - && ((step >= 0.0 && v > s) || (step < 0.0 && v < s)) + && ((v >= prev && v > s) || (v < prev && v < s)) { break; } @@ -635,4 +637,16 @@ mod tests { ["Product 1", "On backorder", "Product 2", "On backorder", "Product 3", "On backorder"] ); } + + #[test] + fn falling_growth_series_stops_at_its_stop_value() { + let mut s = crate::Session::new(); + s.new_workbook(); + s.execute("cell.set", serde_json::json!({"cell": "A1", "input": "5"})).unwrap(); + s.execute("edit.fillSeries", serde_json::json!({"range": "A1:A6", "type": "growth", "step": 0.5, "stop": 1})).unwrap(); + let d = s.doc().unwrap(); + let sh = d.wb.active().unwrap(); + let growth: Vec = (1..6).map(|r| crate::display::cell_text(&d.wb, sh, CellRef::new(r, 0))).collect(); + assert_eq!(growth, ["2.5", "1.25", "", "", ""]); + } }