//! The marks, read by rule: lines, scratch-outs, checks, dots. No model.usesuper::*;usecrate::ink::testing::{arc, checks, circle, line, shape, written, zigzag_letters, Hand, SYNTHETIC_SHAPES};usecrate::ink::{shipped, Point, Reading, CHECK};fn knobs() -> &'staticcrate::ink::Knobs { &shipped().knobs}fn p(x: f64, y: f64) -> Point {Point::new(x, y)}/// RULE: any straight line but an upright one is handed back as a line, never a letter, never a clear: a level one (the page swipe's), a slant, and a thumb's swipe that arcs 70° of a circle; an upright one is the model's.#[test]fn a_line_is_a_line_unless_upright() {let level = line(p(320.0, 300.0), p(60.0, 310.0)); assert_eq!(mark(&level, None, knobs()), Some(Reading::Line { from: level[0], to: level[level.len() - 1] }));let slant = line(p(40.0, 400.0), p(260.0, 180.0)); assert_eq!(mark(&slant, None, knobs()), Some(Reading::Line { from: slant[0], to: slant[slant.len() - 1] }));let thumb = arc(p(200.0, 520.0), 220.0, 305.0, 235.0); assert_eq!(mark(&thumb, None, knobs()), Some(Reading::Line { from: thumb[0], to: thumb[thumb.len() - 1] }), "a thumb's arcing swipe"); assert_eq!(mark(&line(p(200.0, 120.0), p(210.0, 220.0)), None, knobs()), None, "a stroke down is the model's"); assert_eq!(mark(&line(p(200.0, 320.0), p(195.0, 200.0)), None, knobs()), None, "a stroke up is the model's");}/// RULE: a tall upright line alone is no letter (most likely a letter's first stem, or a drag): past `vertical_short` of the page it is a line; a short one is the model's.#[test]fn a_tall_upright_line_is_a_line() {let page = 450.0;let tall = line(p(100.0, 100.0), p(102.0, 100.0 + page * 0.7)); assert_eq!(mark(&tall, Some(page), knobs()), Some(Reading::Line { from: p(100.0, 100.0), to: p(102.0, 100.0 + page * 0.7) })); assert_eq!(mark(&line(p(100.0, 100.0), p(102.0, 100.0 + page * 0.4)), Some(page), knobs()), None);}/// RULE (design, 3 Nov 2026): a short level stroke to the left — the backspace — is a line, never a dash or an l: from its shortest readable length to just under `swipe_at_once`, straight, a little aslant or with a hook.#[test]fn a_short_left_stroke_is_a_line() {for length in [knobs().shortest + 2.0, 60.0, 100.0, knobs().swipe_at_once - 1.0] {letmut hooked = line(p(300.0, 300.0), p(300.0 - length, 300.0)); hooked.extend([p(300.0 - length - 3.0, 304.0), p(300.0 - length - 4.0, 308.0)]);for (name, stroke) in [ ("straight", line(p(300.0, 300.0), p(300.0 - length, 300.0))), ("aslant", line(p(300.0, 300.0), p(300.0 - length, 300.0 + length * 0.2))), ("hooked", hooked), ] { assert!(matches!(mark(&stroke, None, knobs()), Some(Reading::Line { .. })), "a {name} left stroke of {length} reads {:?}", mark(&stroke, None, knobs())); } }}/// RULE: a scratch-out — back and forth three or more times — clears, however tall or flat and from either end; a flat one turning back twice is nothing.#[test]fn a_scratch_out_clears() {let flat = vec![vec![0.0, 45.0], vec![100.0, 50.0], vec![3.0, 55.0], vec![98.0, 52.0], vec![5.0, 58.0]];let tall = vec![vec![0.0, 0.0], vec![100.0, 30.0], vec![0.0, 50.0], vec![100.0, 70.0], vec![0.0, 100.0]];let busy = vec![vec![0.0, 40.0], vec![100.0, 45.0], vec![0.0, 50.0], vec![100.0, 55.0], vec![0.0, 60.0], vec![100.0, 65.0], vec![0.0, 70.0]];for (name, zigzag) in [("flat", flat), ("tall", tall), ("busy", busy)] {for backwards in [false, true] {letmut shape = zigzag.clone();if backwards { shape.reverse(); }let stroke = written(&shape, Hand::at(160.0, 200.0, 300.0).wobble(1.0, 2)); assert_eq!(mark(&stroke, None, knobs()), Some(Reading::Clear), "{name} backwards {backwards}"); } }let once = written(&[vec![0.0, 40.0], vec![100.0, 50.0], vec![0.0, 60.0]], Hand::at(160.0, 200.0, 300.0)); assert_ne!(mark(&once, None, knobs()), Some(Reading::Clear), "one turn back is no scratch-out");let twice = written(&[vec![0.0, 40.0], vec![100.0, 50.0], vec![0.0, 60.0], vec![100.0, 70.0]], Hand::at(160.0, 200.0, 300.0)); assert_eq!(mark(&twice, None, knobs()), Some(Reading::Nothing), "a flat zigzag turning back twice is a scratch-out begun, never a z");let b = written(&shape("b"), Hand::at(90.0, 150.0, 200.0)); assert_ne!(mark(&b, None, knobs()), Some(Reading::Clear), "a B is no scratch-out");}/// RULE (owner, 3 Nov 2026: scratch-out "worked once and didn't work other times … sometimes it's getting confused into B or N"): a scratch-out clears read along its own axis — level, at 20° and 45° either way, tight and wide, turning back 3, 5 or 7 times, begun from the left or the right.#[test]fn a_thumbs_scratch_out_clears_at_any_angle() {let scratches: [(&str, f64, f64, i64, f64, bool); 10] = [ ("level", 160.0, 30.0, 3, 0.0, true), ("level from the right", 160.0, 30.0, 3, 0.0, false), ("20°", 140.0, 30.0, 3, 20.0, true), ("-20° five times", 140.0, 40.0, 5, -20.0, false), ("45°", 120.0, 30.0, 3, 45.0, false), ("-45° five times", 120.0, 40.0, 5, -45.0, true), ("tight", 44.0, 12.0, 4, 0.0, true), ("tight 20° five times", 40.0, 14.0, 5, 20.0, false), ("wide five times", 220.0, 50.0, 5, 5.0, true), ("tight seven times", 36.0, 16.0, 7, -10.0, true), ];for (name, width, drift, reversals, angle, from_left) in scratches {let zigzag: Vec<Vec<f64>> = (0..=(reversals + 1)) .map(|end| {let left = (end % 2 == 0) == from_left; vec![if left { 0.0 } else { 100.0 }, 50.0 + (end as f64 / (reversals + 1) as f64 - 0.5) * drift * 100.0 / width] }) .collect();let stroke = written(&zigzag, Hand::at(width, 200.0, 300.0).turned(angle).wobble(1.0, 3)); assert_eq!(mark(&stroke, None, knobs()), Some(Reading::Clear), "{name}: {:?}", turns(&stroke)); assert!(turns(&stroke).reversals >= reversals, "{name}"); }}/// RULE: the letters a zigzag looks like — W, M, w, m, z, N and B, each in one stroke at a natural size — are never a scratch-out: they go to the letter model.#[test]fn zigzag_letters_are_the_models() {for (name, shape, size) in zigzag_letters() {let stroke = written(&shape, Hand::at(size, 200.0, 300.0).wobble(1.0, 5)); assert_eq!(mark(&stroke, None, knobs()), None, "{name} is the model's: {:?}", turns(&stroke)); }}/// RULE: a dot and a tap's slide are nothing; so is no point at all.#[test]fn taps_and_dots_are_nothing() { assert_eq!(mark(&[p(100.0, 100.0), p(104.0, 103.0), p(106.0, 101.0)], None, knobs()), Some(Reading::Nothing), "a tap's slide"); assert_eq!(mark(&circle(p(150.0, 150.0), 5.0), None, knobs()), Some(Reading::Nothing), "a dot"); assert_eq!(mark(&[], None, knobs()), Some(Reading::Nothing)); assert!(dot(&[p(1.0, 1.0)], knobs()));}/// RULE (owner, 3 Nov 2026: "marking a todo as done is just having a check mark"): a check — a short leg down to a corner and a longer leg up and on, at least `check_ratio` times the first — is the mark `check`, read before the model: at any size past a dot (24 pt to 320 pt), tilted up to 20° either way, with a finger's wobble.#[test]fn a_check_is_a_mark() {letmut missed = Vec::new();for (name, shape) in checks() {for size in [24.0, 40.0, 90.0, 200.0, 320.0] {for degrees in [-20.0, -10.0, 0.0, 10.0, 20.0] {for seed in0..3u64 {let stroke = written(&shape, Hand::at(size, 200.0, 400.0).turned(degrees).wobble(1.0, seed));if mark(&stroke, None, knobs()) != Some(Reading::Mark(CHECK.into())) { missed.push(format!("{name} {size}pt {degrees}° #{seed}")); } } } } } assert!(missed.is_empty(), "checks not read as one: {missed:?}");}/// RULE: what a check is not — a v (its legs alike), a u, a u with its tail, a y and a J in one stroke, an L, a straight line up, a check written mirrored, on its side or upside down, and one smaller than a dot — never reads as a check, written at any size, tilted or not; nor does any synthetic letter or digit shape.#[test]fn what_is_no_check() {let v = |points: &[[f64; 2]]| points.iter().map(|p| p.to_vec()).collect::<Vec<_>>();let shapes = vec![ ("v", v(&[[0., 0.], [50., 100.], [100., 0.]])), ("v short first", v(&[[15., 40.], [45., 100.], [100., 0.]])), ("u", v(&[[0., 0.], [0., 70.], [15., 95.], [50., 100.], [85., 95.], [100., 70.], [100., 0.]])), ("u with its tail", v(&[[0., 0.], [0., 75.], [20., 98.], [60., 98.], [90., 75.], [95., 0.], [95., 95.], [100., 100.]])), ("y", v(&[[0., 0.], [20., 40.], [45., 45.], [60., 0.], [60., 40.], [50., 90.], [30., 100.], [15., 90.]])), ("J", v(&[[70., 0.], [70., 80.], [55., 100.], [25., 100.], [10., 80.]])), ("L", v(&[[0., 0.], [0., 100.], [60., 100.]])), ("line up", v(&[[0., 100.], [100., 0.]])), ("mirrored", v(&[[100., 60.], [75., 85.], [0., 0.]])), ("on its side", v(&[[60., 0.], [85., 25.], [0., 100.]])), ("upside down", v(&[[0., 40.], [25., 15.], [100., 100.]])), ];letmut read = Vec::new();for (name, shape) in &shapes {for size in [45.0, 90.0, 220.0] {for degrees in [-15.0, 0.0, 15.0] {if check(&written(shape, Hand::at(size, 200.0, 400.0).turned(degrees).wobble(1.0, 4)), knobs()) { read.push(format!("{name} {size}pt {degrees}°")); } } } } assert!(read.is_empty(), "read as a check: {read:?}"); assert!(!check(&written(&checks()[0].1, Hand::at(14.0, 200.0, 400.0)), knobs()), "a tick smaller than a dot is the i's or the j's");letmut synthetic = Vec::new();for letter in &SYNTHETIC_SHAPES.letters {for (variant, stroke) in letter.strokes.iter().enumerate() {for size in [45.0, 90.0, 220.0] {for degrees in [-15.0, 0.0, 15.0] {if check(&written(stroke, Hand::at(size, 200.0, 400.0).turned(degrees).wobble(1.5, 1)), knobs()) { synthetic.push(format!("{}#{variant} {size}pt {degrees}°", letter.letter)); } } } } } assert!(synthetic.is_empty(), "synthetic letters read as a check: {synthetic:?}");}/// RULE: one letter's strokes overlap across or nearly touch (`group_overlap`, `group_touch`); two letters side by side do not; near is within a box's longer side.#[test]fn across_and_near() {let stem = bounds(&[p(0.0, 0.0), p(0.0, 100.0)]);let bar = bounds(&[p(0.0, 50.0), p(60.0, 50.0)]); assert!(across(&stem, &bar, knobs()), "a bar from the stem");let beside = bounds(&[p(80.0, 0.0), p(140.0, 100.0)]); assert!(!across(&bar, &beside, knobs()), "the next letter, beside"); assert!(near(&stem, &beside, knobs())); assert!(!near(&bounds(&[p(0.0, 0.0), p(10.0, 10.0)]), &bounds(&[p(100.0, 100.0), p(110.0, 110.0)]), knobs()));}/// A stroke through `points` written in `seconds`.fn flicked(points: &[Point], seconds: f64) -> Option<Reading> { flick(points, seconds, knobs())}/// RULE (the hands-on passes, 21 Nov 2026): a quick flick across a deck is a swipe however it hooks, read as the line from its first point to its last and never handed to the model (which read such a hook as an f and narrowed the shelf to nothing); the same stroke at a finger's writing pace, an upright flick and one that loops back are not flicks.#[test]fn a_quick_flick_is_a_swipe_however_it_hooks() {let hooked = [p(300.0, 400.0), p(260.0, 401.0), p(210.0, 400.0), p(160.0, 395.0), p(150.0, 370.0), p(155.0, 355.0)]; assert_eq!(mark(&hooked, None, knobs()), None, "by its shape alone the hook is the model's"); assert_eq!(flicked(&hooked, 0.1), Some(Reading::Line { from: hooked[0], to: hooked[5] })); assert_eq!(flicked(&hooked, length(&hooked) / 450.0), None, "at a finger's writing pace it is the model's");let upright = [p(200.0, 100.0), p(202.0, 200.0), p(215.0, 230.0)]; assert_eq!(flicked(&upright, 0.05), None, "an upright flick is a letter's stem");let looped = [p(100.0, 100.0), p(200.0, 100.0), p(200.0, 160.0), p(110.0, 150.0)]; assert_eq!(flicked(&looped, 0.05), None, "a stroke that comes back is no swipe"); assert_eq!(flicked(&[p(0.0, 0.0), p(20.0, 0.0)], 0.001), None, "too short to be anything");}/// RULE: no letter of the synthetic hand reads as a flick at a finger's pace, nor at twice it.#[test]fn no_letter_written_is_a_flick() {for (letter, shape) in SYNTHETIC_SHAPES.natural.iter() {for stroke in shape {let points: Vec<Point> = stroke.iter().map(|point| p(point[0] * 1.1, point[1] * 1.1)).collect();for pace in [450.0, 900.0] { assert_eq!(flicked(&points, length(&points) / pace), None, "{letter} at {pace} a second"); } } }}