use arc_motion::{CubicBezier, is_reduced_motion, motion_now};
use arc_tokens::{ActiveArcTheme as _, CubicBezierSpec, hex};
use gpui_kit::{
App, Bounds, Corners, Edges, ElementId, Hsla, IntoElement, ParentElement, Pixels, RenderOnce,
Role, SharedString, Styled, TestSupportExt as _, Window, base::StyledExt as _, canvas, div,
point, prelude::*, px, quad, size,
};
use std::cell::RefCell;
use std::rc::Rc;
const EASE_IN_OUT: CubicBezierSpec = CubicBezierSpec::new(0.77, 0.0, 0.175, 1.0);
const EASE_OUT: CubicBezierSpec = CubicBezierSpec::new(0.23, 1.0, 0.32, 1.0);
const EASE_IN_OUT_SOLVER: CubicBezier = CubicBezier::from_spec(EASE_IN_OUT);
const EASE_OUT_SOLVER: CubicBezier = CubicBezier::from_spec(EASE_OUT);
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct LatticeLit(pub f32);
impl LatticeLit {
pub const DEFAULT: LatticeLit = LatticeLit(0.62);
pub fn fractions(self) -> (f32, f32, f32) {
let lit = self.0.clamp(0.05, 1.0);
let (r, p) = match lit {
v if (v - 0.62).abs() < 0.005 => (18.0, 42.0),
v if (v - 0.45).abs() < 0.005 => (13.0, 31.0),
v if (v - 0.35).abs() < 0.005 => (10.0, 24.0),
v if (v - 0.25).abs() < 0.005 => (7.0, 17.0),
v => (v * 18.0 / 0.62, v * 42.0 / 0.62),
};
(r / 100.0, p / 100.0, lit)
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum LatticePattern {
Arrow,
Dots,
Ripple,
Spiral,
Orbit,
Snake,
Sweep,
Spin,
Rain,
Pulse,
}
impl LatticePattern {
fn resolve(self, grid: usize) -> ResolvedPattern {
let n = grid * grid;
let (raw, loop_steps, scale, lit) = match (self, grid) {
(Self::Arrow, 3) => (
&[1, 2, 3, 0, 1, 2, 1, 2, 3][..],
7.2,
1.0,
LatticeLit::DEFAULT,
),
(Self::Dots, 3) => (
&[0, 1, 2, 0, 1, 2, 0, 1, 2][..],
3.0,
2.4,
LatticeLit::DEFAULT,
),
(Self::Ripple, 3) => (
&[2, 1, 2, 1, 0, 1, 2, 1, 2][..],
4.8,
1.5,
LatticeLit::DEFAULT,
),
(Self::Spiral, 3) => (&[0, 1, 2, 7, 8, 3, 6, 5, 4][..], 9.0, 1.2, LatticeLit(0.35)),
(Self::Orbit, 3) => (
&[0, 1, 2, 7, USIZE_HOLE, 3, 6, 5, 4][..],
8.0,
1.2,
LatticeLit::DEFAULT,
),
(Self::Orbit, _) => (
&[
0, 1, 2, 3, 11, USIZE_HOLE, USIZE_HOLE, 4, 10, USIZE_HOLE, USIZE_HOLE, 5, 9, 8,
7, 6,
][..],
6.0,
1.2,
LatticeLit(0.45),
),
(Self::Snake, 3) => (&[0, 1, 2, 5, 4, 3, 6, 7, 8][..], 9.0, 1.0, LatticeLit(0.35)),
(Self::Snake, _) => (
&[0, 1, 2, 3, 7, 6, 5, 4, 8, 9, 10, 11, 15, 14, 13, 12][..],
16.0,
1.0,
LatticeLit(0.25),
),
(Self::Sweep, 4) => (
&[0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6][..],
5.0,
1.0,
LatticeLit(0.45),
),
(Self::Spin, 4) => (
&[0, 0, 1, 1, 0, 0, 1, 1, 3, 3, 2, 2, 3, 3, 2, 2][..],
4.0,
1.6,
LatticeLit(0.35),
),
(Self::Rain, 4) => (
&[0, 2, 1, 3, 1, 3, 2, 4, 2, 4, 3, 5, 3, 5, 4, 6][..],
4.0,
1.2,
LatticeLit(0.35),
),
(Self::Pulse, 4) => (
&[2, 1, 1, 2, 1, 0, 0, 1, 1, 0, 0, 1, 2, 1, 1, 2][..],
2.4,
2.5,
LatticeLit(0.45),
),
(_, _) => (
&[0, 1, 2, 7, USIZE_HOLE, 3, 6, 5, 4][..],
8.0,
1.2,
LatticeLit::DEFAULT,
),
};
let mut cells = Vec::with_capacity(n);
for i in 0..n {
let v = raw.get(i).copied().unwrap_or(USIZE_HOLE);
cells.push(if v == USIZE_HOLE {
None
} else {
Some(v as f32)
});
}
ResolvedPattern {
cells,
loop_steps,
scale,
lit,
}
}
}
const USIZE_HOLE: usize = usize::MAX;
pub struct ResolvedPattern {
pub cells: Vec<Option<f32>>,
pub loop_steps: f32,
pub scale: f32,
pub lit: LatticeLit,
}
#[derive(Clone, Debug, PartialEq)]
pub struct LatticeCells {
pub cells: Vec<Option<f32>>,
pub loop_steps: Option<f32>,
pub scale: Option<f32>,
pub lit: Option<LatticeLit>,
}
impl LatticeCells {
pub fn resolve(self, grid: usize) -> ResolvedPattern {
let n = grid * grid;
let cells: Vec<Option<f32>> = (0..n)
.map(|i| self.cells.get(i).copied().unwrap_or(None))
.collect();
let max = cells.iter().flatten().fold(0.0f32, |a, v| a.max(*v));
ResolvedPattern {
cells,
loop_steps: self.loop_steps.unwrap_or(max + 4.2),
scale: self.scale.unwrap_or(1.0),
lit: self.lit.unwrap_or(LatticeLit::DEFAULT),
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum LatticeWave {
Named(LatticePattern),
Custom(LatticeCells),
}
impl LatticeWave {
fn resolve(self, grid: usize) -> ResolvedPattern {
match self {
Self::Named(p) => p.resolve(grid),
Self::Custom(c) => c.resolve(grid),
}
}
}
impl From<LatticePattern> for LatticeWave {
fn from(p: LatticePattern) -> Self {
Self::Named(p)
}
}
impl From<LatticeCells> for LatticeWave {
fn from(c: LatticeCells) -> Self {
Self::Custom(c)
}
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum LatticeStatus {
#[default]
Working,
Done,
Error,
}
#[derive(Clone)]
struct LatticeState {
anchor: f64,
frozen_ds: u32,
last_status: LatticeStatus,
}
pub fn lattice_cell_opacity(phase: f32, cycle: f32, lit: LatticeLit, idle: f32) -> f32 {
if cycle <= 0.0 {
return idle;
}
let (rise, peak_end, settle) = lit.fractions();
let rise = rise * cycle;
let peak_end = peak_end * cycle;
let settle = settle * cycle;
let p = if phase <= 0.0 { 0.0 } else { phase };
if p < rise {
let t = p / rise.max(1e-6);
idle + (1.0 - idle) * EASE_IN_OUT_SOLVER.sample(t)
} else if p < peak_end {
1.0
} else if p < settle {
let t = (p - peak_end) / (settle - peak_end).max(1e-6);
1.0 - (1.0 - idle) * EASE_IN_OUT_SOLVER.sample(t)
} else {
idle
}
}
pub fn lattice_format_ds(ds: u32) -> String {
if ds < 600 {
format!("{:.1}s", ds as f32 / 10.0)
} else {
format!("{}m {:.1}s", ds / 600, (ds % 600) as f32 / 10.0)
}
}
pub fn lattice_spoken_ds(ds: u32) -> String {
if ds < 600 {
format!("{:.1} seconds", ds as f32 / 10.0)
} else {
format!(
"{} minutes {:.1} seconds",
ds / 600,
(ds % 600) as f32 / 10.0
)
}
}
pub fn lattice_mark_cells(grid: usize, status: LatticeStatus) -> &'static [usize] {
match (grid, status) {
(3, LatticeStatus::Done) => &[2, 3, 5, 7],
(3, _) => &[0, 2, 4, 6, 8],
(_, LatticeStatus::Done) => &[7, 8, 10, 13],
(_, _) => &[0, 3, 5, 6, 9, 10, 12, 15],
}
}
#[derive(IntoElement)]
pub struct LatticeLoader {
id: ElementId,
label: SharedString,
done_label: SharedString,
error_label: SharedString,
status: LatticeStatus,
wave: LatticeWave,
grid: usize,
shape_round: bool,
color: Option<Hsla>,
done_color: Hsla,
error_color: Hsla,
cell_size: f32,
gap: f32,
font_size: f32,
step_ms: f32,
idle_opacity: f32,
glow: bool,
glow_color: Option<Hsla>,
show_timer: bool,
elapsed_secs: Option<f64>,
}
impl LatticeLoader {
pub fn new(id: impl Into<ElementId>) -> Self {
Self {
id: id.into(),
label: "Thinking".into(),
done_label: "Done in".into(),
error_label: "Failed after".into(),
status: LatticeStatus::Working,
wave: LatticeWave::Named(LatticePattern::Orbit),
grid: 3,
shape_round: true,
color: None,
done_color: hex(0x22c55e, 1.0),
error_color: hex(0xef4444, 1.0),
cell_size: 6.0,
gap: 2.0,
font_size: 14.0,
step_ms: 90.0,
idle_opacity: 0.15,
glow: false,
glow_color: None,
show_timer: true,
elapsed_secs: None,
}
}
pub fn label(mut self, v: impl Into<SharedString>) -> Self {
self.label = v.into();
self
}
pub fn done_label(mut self, v: impl Into<SharedString>) -> Self {
self.done_label = v.into();
self
}
pub fn error_label(mut self, v: impl Into<SharedString>) -> Self {
self.error_label = v.into();
self
}
pub fn status(mut self, v: LatticeStatus) -> Self {
self.status = v;
self
}
pub fn wave(mut self, v: impl Into<LatticeWave>) -> Self {
self.wave = v.into();
self
}
pub fn grid(mut self, v: usize) -> Self {
self.grid = if v == 4 { 4 } else { 3 };
self
}
pub fn shape_round(mut self, v: bool) -> Self {
self.shape_round = v;
self
}
pub fn color(mut self, v: Hsla) -> Self {
self.color = Some(v);
self
}
pub fn done_color(mut self, v: Hsla) -> Self {
self.done_color = v;
self
}
pub fn error_color(mut self, v: Hsla) -> Self {
self.error_color = v;
self
}
pub fn cell_size(mut self, v: f32) -> Self {
self.cell_size = v.max(1.0);
self
}
pub fn gap(mut self, v: f32) -> Self {
self.gap = v.max(0.0);
self
}
pub fn font_size(mut self, v: f32) -> Self {
self.font_size = v.max(6.0);
self
}
pub fn step_ms(mut self, v: f32) -> Self {
self.step_ms = v.max(1.0);
self
}
pub fn idle_opacity(mut self, v: f32) -> Self {
self.idle_opacity = v.clamp(0.0, 1.0);
self
}
pub fn glow(mut self, v: bool) -> Self {
self.glow = v;
self
}
pub fn glow_color(mut self, v: Hsla) -> Self {
self.glow_color = Some(v);
self
}
pub fn show_timer(mut self, v: bool) -> Self {
self.show_timer = v;
self
}
pub fn elapsed_secs(mut self, v: f64) -> Self {
self.elapsed_secs = Some(v);
self
}
}
impl RenderOnce for LatticeLoader {
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let theme = cx.arc_theme();
let colors = theme.colors;
let reduced = is_reduced_motion(cx);
let now = motion_now(cx);
let grid = if self.grid == 4 { 4 } else { 3 };
let n = grid;
let pat = self.wave.clone().resolve(grid);
let d = (self.step_ms * pat.scale).max(1.0) / 1000.0; let cycle = (pat.loop_steps * d).max(0.05); let lit = LatticeLit(pat.lit.0.clamp(0.05, 1.0));
let ink = self.color.unwrap_or(colors.foreground);
let mark_color = match self.status {
LatticeStatus::Error => self.error_color,
_ => self.done_color,
};
let glow_ink = self.glow_color.unwrap_or(ink);
let glow_mark = self.glow_color.unwrap_or(mark_color);
let state_cell = window
.use_keyed_state(
ElementId::NamedChild(self.id.clone().into(), "lattice-state".into()),
cx,
|_, _| {
Rc::new(RefCell::new(LatticeState {
anchor: now,
frozen_ds: 0,
last_status: LatticeStatus::Working,
}))
},
)
.read(cx)
.clone();
let ds = {
let mut st = state_cell.borrow_mut();
if st.last_status != self.status {
match self.status {
LatticeStatus::Working => {
st.anchor = now;
st.frozen_ds = 0;
}
_ => {
let live = ((now - st.anchor).max(0.0) * 10.0) as u32;
st.frozen_ds = live;
}
}
st.last_status = self.status;
}
match (self.status, self.elapsed_secs) {
(_, Some(e)) => (e.max(0.0) * 10.0) as u32,
(LatticeStatus::Working, None) => ((now - st.anchor).max(0.0) * 10.0) as u32,
(_, None) => st.frozen_ds,
}
};
let timer_text = lattice_format_ds(ds);
let working = self.status == LatticeStatus::Working;
let needs_anim_frame = working && self.elapsed_secs.is_none();
let wave_progress = if working {
(now % cycle as f64) as f32
} else {
0.0
};
let layer_progress = if working { 0.0f32 } else { 1.0f32 };
let grid_px_w = n as f32 * self.cell_size + (n.saturating_sub(1)) as f32 * self.gap;
let grid_px_h = grid_px_w;
let cells: Vec<(usize, Option<f32>)> =
pat.cells.iter().enumerate().map(|(i, v)| (i, *v)).collect();
let mark_set: Vec<usize> = lattice_mark_cells(grid, self.status).to_vec();
let status = self.status;
let lattice_canvas = canvas(
move |bounds, _, _| bounds,
move |bounds: Bounds<Pixels>, _, window, _| {
let cell = self.cell_size.max(1.0);
let gap = self.gap.max(0.0);
let radius = if self.shape_round {
cell * 0.5
} else {
(cell * 0.25).max(1.0)
};
let mark_alpha = layer_progress;
let run_alpha = 1.0 - layer_progress;
let origin_x = f32::from(bounds.origin.x);
let origin_y = f32::from(bounds.origin.y);
if run_alpha > 0.001 {
for (i, unit) in &cells {
let Some(unit) = unit else { continue };
let col = (*i % n) as f32;
let row = (*i / n) as f32;
let x = origin_x + col * (cell + gap);
let y = origin_y + row * (cell + gap);
let delay = unit * d;
let phase = if reduced {
(now % 1.4) as f32 / 1.4 * cycle
} else {
(wave_progress - delay).rem_euclid(cycle)
};
let mut alpha = lattice_cell_opacity(phase, cycle, lit, self.idle_opacity);
if reduced {
alpha *= 0.7;
}
let mut c = ink;
c.a *= alpha * run_alpha;
window.paint_quad(quad(
Bounds::new(point(px(x), px(y)), size(px(cell), px(cell))),
Corners::all(px(radius)),
c,
Edges::all(px(0.0)),
Hsla::default(),
gpui_kit::BorderStyle::default(),
));
if self.glow && alpha > 0.05 {
let halo = cell * 1.2;
for k in 1..=3usize {
let spread = halo * (k as f32) / 3.0;
let mut hc = glow_ink;
hc.a *= alpha * run_alpha * 0.10 / k as f32;
let b = Bounds::new(
point(px(x - spread + cell * 0.5), px(y - spread + cell * 0.5)),
size(px(cell + spread * 2.0), px(cell + spread * 2.0)),
);
window.paint_quad(quad(
b,
Corners::all(px((cell + spread * 2.0) * 0.5)),
hc,
Edges::all(px(0.0)),
Hsla::default(),
gpui_kit::BorderStyle::default(),
));
}
}
}
for (i, unit) in &cells {
if unit.is_some() {
continue;
}
let col = (*i % n) as f32;
let row = (*i / n) as f32;
let mut c = ink;
c.a *= self.idle_opacity * 0.47 * run_alpha;
window.paint_quad(quad(
Bounds::new(
point(
px(origin_x + col * (cell + gap)),
px(origin_y + row * (cell + gap)),
),
size(px(cell), px(cell)),
),
Corners::all(px(radius)),
c,
Edges::all(px(0.0)),
Hsla::default(),
gpui_kit::BorderStyle::default(),
));
}
}
if mark_alpha > 0.001 {
let scale = 0.9 + 0.1 * ease_out_sample(mark_alpha);
let cx_pt = origin_x + grid_px_w * 0.5;
let cy_pt = origin_y + grid_px_h * 0.5;
for i in &mark_set {
let col = (*i % n) as f32;
let row = (*i / n) as f32;
let base_x = origin_x + col * (cell + gap);
let base_y = origin_y + row * (cell + gap);
let cx_cell = base_x + cell * 0.5;
let cy_cell = base_y + cell * 0.5;
let sx = cx_pt + (cx_cell - cx_pt) * scale;
let sy = cy_pt + (cy_cell - cy_pt) * scale;
let s = cell * scale;
let mut c = mark_color;
c.a *= mark_alpha;
window.paint_quad(quad(
Bounds::new(
point(px(sx - s * 0.5), px(sy - s * 0.5)),
size(px(s), px(s)),
),
Corners::all(px(if self.shape_round {
s * 0.5
} else {
(s * 0.25).max(1.0)
})),
c,
Edges::all(px(0.0)),
Hsla::default(),
gpui_kit::BorderStyle::default(),
));
if self.glow {
let halo = cell * 1.2;
for k in 1..=2usize {
let spread = halo * (k as f32) / 2.0;
let mut hc = glow_mark;
hc.a *= mark_alpha * 0.12 / k as f32;
window.paint_quad(quad(
Bounds::new(
point(
px(sx - s * 0.5 - spread + s * 0.5),
px(sy - s * 0.5 - spread + s * 0.5),
),
size(px(s + spread * 2.0), px(s + spread * 2.0)),
),
Corners::all(px((s + spread * 2.0) * 0.5)),
hc,
Edges::all(px(0.0)),
Hsla::default(),
gpui_kit::BorderStyle::default(),
));
}
}
}
}
},
)
.w(px(grid_px_w))
.h(px(grid_px_h));
let active = status;
let text_items = [
(LatticeStatus::Working, self.label.clone()),
(LatticeStatus::Done, self.done_label.clone()),
(LatticeStatus::Error, self.error_label.clone()),
];
let active_label = text_items
.iter()
.find(|(s, _)| *s == active)
.map(|(_, t)| t.clone())
.unwrap_or_else(|| self.label.clone());
let timer_el = if self.show_timer {
Some(
div()
.text_size(px(self.font_size * 0.875))
.text_color(ink.opacity(0.6))
.child(SharedString::from(timer_text)),
)
} else {
None
};
let announce = if working {
format!("{}, in progress", self.label)
} else if status == LatticeStatus::Done {
format!(
"{}{}",
self.done_label,
if self.show_timer {
format!(" {}", lattice_spoken_ds(ds))
} else {
String::new()
}
)
} else {
format!(
"{}{}",
self.error_label,
if self.show_timer {
format!(" {}", lattice_spoken_ds(ds))
} else {
String::new()
}
)
};
if needs_anim_frame {
window.request_animation_frame();
}
div()
.id(self.id.clone())
.test_support()
.role(Role::Status)
.aria_label(SharedString::from(announce))
.flex_none()
.flex()
.items_center()
.gap(px(self.font_size * 0.625))
.child(lattice_canvas)
.child(
div()
.text_size(px(self.font_size))
.font_medium()
.text_color(ink)
.child(active_label),
)
.children(timer_el)
}
}
fn ease_out_sample(t: f32) -> f32 {
EASE_OUT_SOLVER.sample(t)
}
#[cfg(test)]
mod tests {
use super::*;
fn close(a: f32, b: f32) -> bool {
(a - b).abs() < 1e-3
}
#[test]
fn lattice_keyframes_track_source_curve_shape() {
let lit = LatticeLit(0.62);
let idle = 0.15;
let (rise, peak_end, settle) = lit.fractions();
assert!(close(lattice_cell_opacity(0.0, 1.0, lit, idle), idle));
let mid = lattice_cell_opacity(rise * 0.5, 1.0, lit, idle);
assert!(mid > idle && mid < 1.0, "mid={mid}");
assert!(close(
lattice_cell_opacity((rise + peak_end) * 0.5, 1.0, lit, idle),
1.0
));
let tail = lattice_cell_opacity((peak_end + settle) * 0.5, 1.0, lit, idle);
assert!(tail < 1.0 && tail > idle, "tail={tail}");
assert!(close(lattice_cell_opacity(settle, 1.0, lit, idle), idle));
assert!(close(
lattice_cell_opacity(settle + 0.1, 1.0, lit, idle),
idle
));
}
#[test]
fn lattice_lit_variants_compress_the_wave() {
let lit = LatticeLit(0.35);
let idle = 0.15;
let (rise, peak_end, settle) = lit.fractions();
assert!(close(
lattice_cell_opacity((rise + peak_end) * 0.5, 1.0, lit, idle),
1.0
));
assert!(close(lattice_cell_opacity(settle, 1.0, lit, idle), idle));
let (r45, p45, s45) = LatticeLit(0.45).fractions();
assert!(close(r45, 0.13) && close(p45, 0.31) && close(s45, 0.45));
let (r25, p25, s25) = LatticeLit(0.25).fractions();
assert!(close(r25, 0.07) && close(p25, 0.17) && close(s25, 0.25));
assert!(close(
lattice_cell_opacity(2.0 * 0.62, 2.0, LatticeLit(0.62), idle),
idle
));
}
#[test]
fn lattice_timer_formats_like_source() {
assert_eq!(lattice_format_ds(0), "0.0s");
assert_eq!(lattice_format_ds(41), "4.1s");
assert_eq!(lattice_format_ds(599), "59.9s");
assert_eq!(lattice_format_ds(600), "1m 0.0s");
assert_eq!(lattice_format_ds(641), "1m 4.1s");
assert_eq!(lattice_spoken_ds(41), "4.1 seconds");
assert_eq!(lattice_spoken_ds(641), "1 minutes 4.1 seconds");
}
#[test]
fn lattice_marks_match_source_cells() {
assert_eq!(lattice_mark_cells(3, LatticeStatus::Done), &[2, 3, 5, 7]);
assert_eq!(
lattice_mark_cells(3, LatticeStatus::Error),
&[0, 2, 4, 6, 8]
);
assert_eq!(lattice_mark_cells(4, LatticeStatus::Done), &[7, 8, 10, 13]);
assert_eq!(
lattice_mark_cells(4, LatticeStatus::Error),
&[0, 3, 5, 6, 9, 10, 12, 15]
);
}
#[test]
fn lattice_patterns_resolve_with_holes_and_cycles() {
let o3 = LatticePattern::Orbit.resolve(3);
assert_eq!(o3.cells[4], None);
assert_eq!(o3.cells.len(), 9);
assert!(close(o3.loop_steps, 8.0));
assert!(close(o3.scale, 1.2));
assert!(close(o3.lit.0, 0.62));
let o4 = LatticePattern::Orbit.resolve(4);
assert_eq!(o4.cells[5], None);
assert_eq!(o4.cells[6], None);
assert!(close(o4.lit.0, 0.45));
let s4 = LatticePattern::Snake.resolve(4);
assert!(close(s4.lit.0, 0.25));
assert!(close(s4.loop_steps, 16.0));
let p4 = LatticePattern::Pulse.resolve(4);
assert!(close(p4.scale, 2.5));
let sp = LatticePattern::Spin.resolve(4);
assert_eq!(sp.cells[0], Some(0.0));
assert_eq!(sp.cells[1], Some(0.0));
assert_eq!(sp.cells[2], Some(1.0));
}
#[test]
fn lattice_custom_cells_follow_source_defaults() {
let c = LatticeCells {
cells: vec![Some(0.0), None, Some(3.0)],
loop_steps: None,
scale: None,
lit: None,
};
let r = c.resolve(2);
assert_eq!(r.cells.len(), 4); assert_eq!(r.cells[1], None);
assert_eq!(r.cells[3], None);
assert!(close(r.loop_steps, 7.2)); assert!(close(r.scale, 1.0));
assert!(close(r.lit.0, 0.62));
let c2 = LatticeCells {
cells: vec![Some(1.0)],
loop_steps: Some(5.0),
scale: Some(2.0),
lit: Some(LatticeLit(0.4)),
};
let r2 = c2.resolve(3);
assert!(close(r2.loop_steps, 5.0));
assert!(close(r2.scale, 2.0));
assert!(close(r2.lit.0, 0.4));
}
#[test]
fn lattice_cycle_and_delay_follow_step_scale() {
let p = LatticePattern::Dots.resolve(3);
assert!(close(p.loop_steps, 3.0));
assert!(close(p.scale, 2.4));
let step_ms = 90.0;
let d = step_ms * p.scale / 1000.0;
let cycle = p.loop_steps * d;
assert!(close(cycle, 3.0 * 90.0 * 2.4 / 1000.0));
}
}