vla_lang/projection.rs
1//! The projections seam: a window onto the grid, and a projection as a pure
2//! function from the model and a window to lines (`KERNEL.1`, the seam as
3//! data; `KERNEL.4`, the first implementation, [`crate::view::Grid`]). Cut
4//! out of `frazaro-core`'s `kernel.rs` with the language (`PORT.12`), since
5//! an engine's screen is a projection of the grid and must not depend on
6//! the bridges; the seams' registry, the engines trait and the host
7//! profiles stay in the core.
8
9use crate::sheet::{A1Range, Workbook};
10
11/// A window onto the model: one sheet by name, one rectangle of it.
12#[derive(Clone, Debug, PartialEq, Eq)]
13pub struct Window {
14 pub sheet: String,
15 pub range: A1Range,
16}
17
18/// A projection: a pure function from the model and a window to lines, the
19/// shape every door prints (`SD-23`). The grid is the first
20/// (`crate::view::Grid`, `KERNEL.4`), the sentence pane and the dependency
21/// cone drawn as a diagram the core's (`KERNEL.12`). An engine's plane, a
22/// byte a cell, is a projection by name beside this trait
23/// (`crate::machine::plane`, `KERNEL.22`), since its output is a raster
24/// and not lines; whether rasters get a trait of their own waits for a
25/// second one. A projection never edits the model.
26pub trait Projection {
27 /// The projection's name, as `frazaro view` selects it.
28 fn name(&self) -> &str;
29 /// The window's lines, in a fixed order, to the sink.
30 fn project(&self, model: &Workbook, window: &Window, out: &mut dyn FnMut(&str));
31}
32
33#[cfg(test)]
34mod tests {
35 use super::*;
36
37 #[test]
38 fn a_window_is_one_sheet_and_one_rectangle() {
39 let w = Window {
40 sheet: "Model".to_string(),
41 range: A1Range {
42 top: 1,
43 left: 1,
44 bottom: 20,
45 right: 6,
46 },
47 };
48 assert_eq!(w.range.cells(), 120);
49 assert_eq!(w.sheet, "Model");
50 }
51}