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, Group, Plan, plan}; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 3 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 4 | /// Plans with each block moving rigidly, for moves whose unit is a whole |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 5 | /// container such as reordering viewed tags. Blocks must partition the |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 6 | /// windows, and every window must keep its place inside its block. |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 7 | pub fn plan_blocks(from: &[Rect], to: &[Rect], blocks: &[Vec<usize>], cfg: &Config) -> Plan { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 8 | let bounds = |l: &[Rect]| -> Vec<Rect> { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 9 | blocks |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 10 | .iter() |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 11 | .map(|b| Rect::bounding(b.iter().map(|&i| &l[i]))) |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 12 | .collect() |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 13 | }; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 14 | let (bf, bt) = (bounds(from), bounds(to)); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 15 | let bp = plan(&bf, &bt, cfg); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 16 | let last = bp.keyframes.len() - 1; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 17 | let keyframes = bp |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 18 | .keyframes |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 19 | .iter() |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 20 | .enumerate() |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 21 | .map(|(k, key)| match k { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 22 | 0 => from.to_vec(), |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 23 | k if k == last => to.to_vec(), |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 24 | _ => { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 25 | let mut frame = from.to_vec(); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 26 | for (b, members) in blocks.iter().enumerate() { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 27 | for &i in members { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 28 | frame[i] = reframe(&from[i], &bf[b], &key[b]); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 29 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 30 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 31 | frame |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 32 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 33 | }) |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 34 | .collect(); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 35 | let groups = bp |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 36 | .groups |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 37 | .into_iter() |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 38 | .map(|g| Group { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 39 | members: g |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 40 | .members |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 41 | .iter() |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 42 | .flat_map(|&b| blocks[b].iter().copied()) |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 43 | .collect(), |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 44 | ..g |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 45 | }) |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 46 | .collect(); |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 47 | Plan { keyframes, groups } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 48 | } |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 49 | |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 50 | fn reframe(r: &Rect, from: &Rect, to: &Rect) -> Rect { |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 51 | let scale = |v: f64, len: f64| if len > 0.0 { v / len } else { 0.0 }; |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 52 | Rect::new( |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 53 | to.x + scale(r.x - from.x, from.w) * to.w, |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 54 | to.y + scale(r.y - from.y, from.h) * to.h, |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 55 | scale(r.w, from.w) * to.w, |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 56 | scale(r.h, from.h) * to.h, |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 57 | ) |
b563d2da1c80 | atagen | 2026-10-16 08:25 UTC | 58 | } |