b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 1 | use crate::geom::Rect; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 2 | use crate::plan::{Config, Plan, Strategy, Style, plan, plan_canonical}; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 3 | use crate::{plan_blocks, validate}; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 4 | use proptest::prelude::*; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 5 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 6 | const G: f64 = 10.0; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 7 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 8 | fn region() -> Rect { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 9 | Rect::new(G, G, 1180.0, 680.0) |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 10 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 11 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 12 | fn split(rect: Rect, ratios: &[f64], horizontal: bool) -> Vec<Rect> { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 13 | let total: f64 = ratios.iter().sum(); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 14 | let len = if horizontal { rect.w } else { rect.h }; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 15 | let avail = len - G * (ratios.len() - 1) as f64; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 16 | let mut pos = if horizontal { rect.x } else { rect.y }; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 17 | ratios |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 18 | .iter() |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 19 | .map(|r| { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 20 | let size = avail * r / total; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 21 | let out = if horizontal { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 22 | Rect::new(pos, rect.y, size, rect.h) |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 23 | } else { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 24 | Rect::new(rect.x, pos, rect.w, size) |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 25 | }; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 26 | pos += size + G; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 27 | out |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 28 | }) |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 29 | .collect() |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 30 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 31 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 32 | fn cols(rect: Rect, n: usize) -> Vec<Rect> { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 33 | split(rect, &vec![1.0; n], true) |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 34 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 35 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 36 | fn rows(rect: Rect, n: usize) -> Vec<Rect> { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 37 | split(rect, &vec![1.0; n], false) |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 38 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 39 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 40 | fn cfg(style: Style) -> Config { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 41 | Config { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 42 | style, |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 43 | ..Config::default() |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 44 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 45 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 46 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 47 | fn assert_clean(p: &Plan, c: &Config) { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 48 | let v = validate(p, c); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 49 | assert!(v.is_empty(), "violations {v:?} in {p:?}"); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 50 | assert!(p.phases() <= 4, "{} phases", p.phases()); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 51 | assert!( |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 52 | p.groups.iter().all(|g| g.strategy != Strategy::Pinch), |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 53 | "fell back to pinch: {p:?}" |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 54 | ); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 55 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 56 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 57 | fn strategy(p: &Plan) -> Strategy { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 58 | p.groups |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 59 | .iter() |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 60 | .map(|g| g.strategy) |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 61 | .find(|s| *s != Strategy::Unchanged) |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 62 | .unwrap_or(Strategy::Unchanged) |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 63 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 64 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 65 | #[test] |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 66 | fn full_reversal_needs_one_lane_per_window() { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 67 | let c = cfg(Style::Orthogonal); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 68 | let a = cols(region(), 4); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 69 | let b: Vec<Rect> = (0..4).map(|i| a[3 - i]).collect(); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 70 | let p = plan(&a, &b, &c); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 71 | assert_clean(&p, &c); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 72 | assert_eq!(strategy(&p), Strategy::Lanes { lanes: 4 }); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 73 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 74 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 75 | #[test] |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 76 | fn growing_both_axes_depends_on_style() { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 77 | let grid = |wide: bool| { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 78 | let r = if wide { [7.0, 3.0] } else { [1.0, 1.0] }; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 79 | let rs = split(region(), &r, false); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 80 | let mut out = split(rs[0], &r, true); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 81 | out.extend(split(rs[1], &[1.0, 1.0], true)); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 82 | out |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 83 | }; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 84 | let o = cfg(Style::Orthogonal); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 85 | let d = cfg(Style::Direct); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 86 | let po = plan(&grid(false), &grid(true), &o); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 87 | let pd = plan(&grid(false), &grid(true), &d); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 88 | assert_clean(&po, &o); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 89 | assert_clean(&pd, &d); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 90 | assert_eq!((po.phases(), pd.phases()), (2, 1)); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 91 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 92 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 93 | #[test] |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 94 | fn insert_and_split_rewinds() { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 95 | let c = cfg(Style::Orthogonal); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 96 | let layout = |on: bool| { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 97 | let n = if on { 4 } else { 3 }; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 98 | let ratios: Vec<f64> = (0..n) |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 99 | .map(|i| if i == 0 && on { 2.0 } else { 1.0 }) |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 100 | .collect(); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 101 | let cs = split(region(), &ratios, true); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 102 | let (a, mut b, c3) = (cs[0], cs[1], cs[n - 1]); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 103 | let d = if on { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 104 | cs[2] |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 105 | } else { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 106 | Rect::new((b.right() + c3.x) / 2.0, b.y, 0.0, b.h) |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 107 | }; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 108 | let e = if on { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 109 | let s = rows(b, 2); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 110 | b = s[0]; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 111 | s[1] |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 112 | } else { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 113 | Rect::new(b.x, b.bottom(), b.w, 0.0) |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 114 | }; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 115 | vec![a, b, c3, d, e] |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 116 | }; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 117 | let on = plan(&layout(false), &layout(true), &c); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 118 | let off = plan(&layout(true), &layout(false), &c); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 119 | assert_clean(&on, &c); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 120 | assert_clean(&off, &c); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 121 | assert!(on.groups.iter().all(|g| !g.opens_hole)); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 122 | let mut rewound = off.keyframes.clone(); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 123 | rewound.reverse(); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 124 | assert_eq!(on.keyframes, rewound); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 125 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 126 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 127 | #[test] |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 128 | fn tag_rows_swap_rigidly_with_two_lanes() { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 129 | let c = cfg(Style::Orthogonal); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 130 | let layout = |first_top: bool| { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 131 | let rs = rows(region(), 2); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 132 | let (t1, t2) = if first_top { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 133 | (rs[0], rs[1]) |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 134 | } else { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 135 | (rs[1], rs[0]) |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 136 | }; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 137 | let mut out = cols(t1, 3); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 138 | out.extend(cols(t2, 2)); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 139 | out |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 140 | }; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 141 | let blocks = vec![vec![0, 1, 2], vec![3, 4]]; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 142 | let p = plan_blocks(&layout(true), &layout(false), &blocks, &c); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 143 | assert_clean(&p, &c); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 144 | assert_eq!(strategy(&p), Strategy::Lanes { lanes: 2 }); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 145 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 146 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 147 | #[test] |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 148 | fn simultaneous_reversals_on_both_axes_use_the_grid() { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 149 | let c = cfg(Style::Orthogonal); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 150 | let halves = cols(region(), 2); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 151 | let (l, r) = (rows(halves[0], 2), rows(halves[1], 2)); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 152 | let from = vec![l[0], r[1], r[0], l[1]]; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 153 | let left3 = rows(halves[0], 3); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 154 | let to = vec![left3[0], left3[1], left3[2], halves[1]]; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 155 | let p = plan(&from, &to, &c); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 156 | assert_clean(&p, &c); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 157 | assert!(matches!(strategy(&p), Strategy::Grid { .. })); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 158 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 159 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 160 | struct Rng(u64); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 161 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 162 | impl Rng { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 163 | fn next(&mut self) -> u64 { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 164 | self.0 ^= self.0 << 13; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 165 | self.0 ^= self.0 >> 7; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 166 | self.0 ^= self.0 << 17; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 167 | self.0 |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 168 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 169 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 170 | fn below(&mut self, n: usize) -> usize { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 171 | (self.next() % n as u64) as usize |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 172 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 173 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 174 | fn unit(&mut self) -> f64 { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 175 | (self.next() >> 11) as f64 / (1u64 << 53) as f64 |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 176 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 177 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 178 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 179 | fn random_layout(rng: &mut Rng, n: usize) -> Vec<Rect> { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 180 | let mut ids: Vec<usize> = (0..n).collect(); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 181 | for i in (1..n).rev() { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 182 | ids.swap(i, rng.below(i + 1)); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 183 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 184 | let mut out = vec![Rect::default(); n]; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 185 | let horizontal = rng.below(2) == 0; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 186 | build(rng, &ids, region(), horizontal, &mut out); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 187 | out |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 188 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 189 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 190 | fn build(rng: &mut Rng, ids: &[usize], rect: Rect, horizontal: bool, out: &mut [Rect]) { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 191 | if let [only] = ids { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 192 | out[*only] = rect; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 193 | return; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 194 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 195 | let k = ids.len().min(2 + rng.below(2)); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 196 | let mut cuts = Vec::with_capacity(k); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 197 | let mut rest = ids; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 198 | for i in 0..k { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 199 | let take = if i == k - 1 { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 200 | rest.len() |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 201 | } else { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 202 | 1 + rng.below(rest.len() - (k - 1 - i)) |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 203 | }; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 204 | let (head, tail) = rest.split_at(take); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 205 | cuts.push(head); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 206 | rest = tail; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 207 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 208 | let ratios: Vec<f64> = cuts.iter().map(|_| 0.5 + rng.unit()).collect(); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 209 | for (part, ids) in split(rect, &ratios, horizontal).into_iter().zip(cuts) { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 210 | build(rng, ids, part, !horizontal, out); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 211 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 212 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 213 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 214 | proptest! { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 215 | #![proptest_config(ProptestConfig::with_cases(512))] |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 216 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 217 | #[test] |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 218 | fn random_transitions_plan_cleanly(seed in 1u64.., n in 2usize..9, direct: bool) { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 219 | let mut rng = Rng(seed); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 220 | let c = cfg(if direct { Style::Direct } else { Style::Orthogonal }); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 221 | let (a, b) = (random_layout(&mut rng, n), random_layout(&mut rng, n)); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 222 | let p = plan(&a, &b, &c); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 223 | assert_clean(&p, &c); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 224 | prop_assert_eq!(&p.keyframes[0], &a); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 225 | prop_assert_eq!(p.keyframes.last().unwrap(), &b); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 226 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 227 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 228 | #[test] |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 229 | fn planning_back_rewinds(seed in 1u64.., n in 2usize..9) { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 230 | let mut rng = Rng(seed); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 231 | let c = cfg(Style::Orthogonal); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 232 | let (a, b) = (random_layout(&mut rng, n), random_layout(&mut rng, n)); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 233 | let mut back = plan_canonical(&b, &a, &c).keys; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 234 | back.reverse(); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 235 | prop_assert_eq!(plan_canonical(&a, &b, &c).keys, back); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 236 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 237 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 238 | #[test] |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 239 | fn closing_while_spawning_never_pinches(seed in 1u64.., n in 2usize..9, edge in 0usize..3, direct: bool) { |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 240 | let mut rng = Rng(seed); |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 241 | let c = cfg(if direct { Style::Direct } else { Style::Orthogonal }); |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 242 | let a = random_layout(&mut rng, n); |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 243 | let v = rng.below(n); |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 244 | let at = [a[v].x - G / 2.0, a[v].center_x(), a[v].right() + G / 2.0][edge]; |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 245 | let line = Rect::new(at, a[v].y, 0.0, a[v].h); |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 246 | let mut from = a.clone(); |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 247 | from.push(line); |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 248 | let mut to = a.clone(); |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 249 | to[v] = Rect::new(a[v].center_x(), a[v].y, 0.0, a[v].h); |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 250 | to.push(a[v]); |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 251 | let p = plan(&from, &to, &c); |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 252 | prop_assert!(validate(&p, &c).is_empty(), "{:?}", p); |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 253 | prop_assert!(p.groups.iter().all(|g| g.strategy != Strategy::Pinch), "{:?}", p); |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 254 | } |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 255 | |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 256 | #[test] |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 257 | fn interrupts_replan_cleanly(seed in 1u64.., n in 2usize..9, at in 0.0f64..1.0, s in 0.0f64..1.0) { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 258 | let mut rng = Rng(seed); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 259 | let c = cfg(Style::Orthogonal); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 260 | let (a, b, d) = (random_layout(&mut rng, n), random_layout(&mut rng, n), random_layout(&mut rng, n)); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 261 | let first = plan(&a, &b, &c); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 262 | if first.phases() == 0 { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 263 | return Ok(()); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 264 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 265 | let phase = ((at * first.phases() as f64) as usize).min(first.phases() - 1); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 266 | let mid = first.sample(phase, s); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 267 | let second = plan(&mid, &d, &c); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 268 | assert_clean(&second, &c); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 269 | prop_assert_eq!(&second.keyframes[0], &mid); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 270 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 271 | } |
1a10e81ae5c1 | atagen | 2026-10-17 13:31 UTC | 272 | |
1a10e81ae5c1 | atagen | 2026-10-17 13:31 UTC | 273 | /// A hidden window is a zero-size seed. One sitting inside a visible window |
1a10e81ae5c1 | atagen | 2026-10-17 13:31 UTC | 274 | /// used to join its group and make every strategy fail, so the plan pinched. |
1a10e81ae5c1 | atagen | 2026-10-17 13:31 UTC | 275 | #[test] |
1a10e81ae5c1 | atagen | 2026-10-17 13:31 UTC | 276 | fn hidden_seeds_stay_out_of_the_plan() { |
1a10e81ae5c1 | atagen | 2026-10-17 13:31 UTC | 277 | let c = cfg(Style::Orthogonal); |
1a10e81ae5c1 | atagen | 2026-10-17 13:31 UTC | 278 | let a = cols(region(), 2); |
1a10e81ae5c1 | atagen | 2026-10-17 13:31 UTC | 279 | let seed = |r: Rect| Rect::new(r.center_x(), r.center_y(), 0.0, 0.0); |
1a10e81ae5c1 | atagen | 2026-10-17 13:31 UTC | 280 | let from = vec![a[0], a[1], seed(a[0])]; |
1a10e81ae5c1 | atagen | 2026-10-17 13:31 UTC | 281 | let to = vec![a[1], a[0], seed(a[1])]; |
1a10e81ae5c1 | atagen | 2026-10-17 13:31 UTC | 282 | let p = plan(&from, &to, &c); |
1a10e81ae5c1 | atagen | 2026-10-17 13:31 UTC | 283 | assert_clean(&p, &c); |
1a10e81ae5c1 | atagen | 2026-10-17 13:31 UTC | 284 | assert!(p.groups.iter().all(|g| !g.members.contains(&2))); |
1a10e81ae5c1 | atagen | 2026-10-17 13:31 UTC | 285 | assert!(p.keyframes.iter().all(|k| k[2] == to[2])); |
1a10e81ae5c1 | atagen | 2026-10-17 13:31 UTC | 286 | } |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 287 | |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 288 | /// A window closes in the slot where another opens. The ghost shrinks to a |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 289 | /// seed inside its own full rect while the newcomer grows from a seed on the |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 290 | /// same line, so no single set of phases keeps them apart and every strategy |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 291 | /// used to fail until the plan pinched the whole output. |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 292 | #[test] |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 293 | fn closing_and_spawning_in_one_slot_plan_in_stages() { |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 294 | let c = cfg(Style::Orthogonal); |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 295 | let t = cols(region(), 3); |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 296 | let seed = Rect::new(600.0, 10.0, 0.0, 680.0); |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 297 | let from = vec![t[0], t[1], t[2], seed]; |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 298 | let to = vec![t[0], seed, t[2], t[1]]; |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 299 | let p = plan(&from, &to, &c); |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 300 | assert!(validate(&p, &c).is_empty(), "{p:?}"); |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 301 | assert!(p.groups.iter().all(|g| g.strategy != Strategy::Pinch)); |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 302 | assert_eq!(p.phases(), 2); |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 303 | assert_eq!(p.keyframes[1], vec![t[0], seed, t[2], seed]); |
ab9ba6872885 | atagen | 2026-10-19 10:38 UTC | 304 | } |