mirror of
https://github.com/storytold/gridcraft.git
synced 2026-12-02 02:33:55 -06:00
Fill handle: Growth Trend repeats the same number exactly
A lane that holds one number repeated went through the logarithm and back, so two cells of 1e300 filled 9.99999999999976e299. Such a lane is now copied unchanged, as a lone number already was.
This commit is contained in:
@@ -382,7 +382,7 @@ impl Pattern {
|
||||
/// The exponential curve y = b·m^x fitted to `nums` at positions 0, 1, 2… by least squares on
|
||||
/// the logarithms, as the GROWTH function fits positive numbers. Numbers below zero are fitted
|
||||
/// by their magnitudes and keep their sign. `None` when the numbers are not all above zero or
|
||||
/// all below zero. A lone number is copied unchanged.
|
||||
/// all below zero. A lone number, or the same number repeated, is copied unchanged.
|
||||
fn growth(nums: &[f64]) -> Option<Pattern> {
|
||||
let sign = if nums.iter().all(|y| *y > 0.0) {
|
||||
1.0
|
||||
@@ -391,7 +391,7 @@ impl Pattern {
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
if nums.len() == 1 {
|
||||
if nums.windows(2).all(|w| w.first() == w.last()) {
|
||||
return Some(Pattern::Copy);
|
||||
}
|
||||
let logs: Vec<f64> = nums.iter().map(|y| (y * sign).ln()).collect();
|
||||
|
||||
@@ -1118,6 +1118,10 @@ fn linear_and_growth_trend_continue_the_fitted_line_or_curve() {
|
||||
s.execute("range.setValues", json!({"range": "Y1", "values": [[big, big14], [big, big14], [big, big14]]})).unwrap();
|
||||
fill(&mut s, "Y1:Z3", "Y1:Z4", "linearTrend").unwrap();
|
||||
assert_eq!(nums(&s, &["Y4", "Z4"]), n(&[big, big14]));
|
||||
// Growth Trend repeats the same number exactly too, huge, tiny or below zero.
|
||||
s.execute("range.setValues", json!({"range": "AA1", "values": [[1e300, 1e-300, -0.3], [1e300, 1e-300, -0.3]]})).unwrap();
|
||||
fill(&mut s, "AA1:AC2", "AA1:AC4", "growthTrend").unwrap();
|
||||
assert_eq!(nums(&s, &["AA4", "AB4", "AC4"]), n(&[1e300, 1e-300, -0.3]));
|
||||
s.execute("cell.set", json!({"cell": "N1", "input": "1/15/2026"})).unwrap();
|
||||
s.execute("cell.set", json!({"cell": "N2", "input": "2/15/2026"})).unwrap();
|
||||
fill(&mut s, "N1:N2", "N1:N3", "linearTrend").unwrap();
|
||||
|
||||
Reference in New Issue
Block a user