Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

check: a card that shares one word with a line isn't held to it as a caption (#102, #89 item 3)

Mattias Hjemgaarde90d70f0dc6e
diff --git a/apps/check/src/tests.rs b/apps/check/src/tests.rs
index 644cd892..38a594c5 100644
--- a/apps/check/src/tests.rs
+++ b/apps/check/src/tests.rs
@@ -332,3 +332,22 @@ fn safe_area_tests_the_letters_not_the_box() {
assert!(left.contains("at the left") && left.contains("its letters 0,160 140x40"), "{left}");
assert!(safe_area(Value::Null).contains("its box 0,160 640x40"));
}
+
+#[test]
+fn a_card_sharing_one_word_with_another_line_isnt_held_to_it() {
+ let run = |text: &str, from: f64| Run { text: text.into(), from, to: from + 2.0, box_: [0.0; 4], boxes: vec![], color: String::new(), size: 48.0 };
+ let said = |ws: &[(&str, f64)]| ws.iter().map(|(t, s)| Word { text: (*t).into(), start: *s, end: *s }).collect::<Vec<Word>>();
+ let words = said(&[("at", 37.9), ("wirestock", 38.2), ("i", 38.9), ("worked", 39.0), ("on", 39.2), ("a", 39.3), ("sora", 39.5), ("campaign", 40.2)]);
+ let (mut issues, mut passed) = (vec![], vec![]);
+ // one word of three shared with the line, said 1.35 s before: not a caption of it (the film's false P1)
+ cues(&[run("Wirestock × OpenAI Sora", 39.55)], &words, &mut issues, &mut passed);
+ // one word of four, "campaign": the same
+ cues(&[run("Classroom of Tomorrow campaign", 39.55)], &words, &mut issues, &mut passed);
+ assert!(issues.is_empty(), "{:?}", issues.iter().map(|i| &i.says).collect::<Vec<_>>());
+ // a one-word card is held only to the word said right by it: "wirestock" 1.35 s earlier is another moment
+ cues(&[run("Wirestock", 39.55)], &words, &mut issues, &mut passed);
+ assert!(issues.is_empty(), "{:?}", issues.iter().map(|i| &i.says).collect::<Vec<_>>());
+ // a real caption late by 0.4 s is still found
+ cues(&[run("a Sora campaign", 39.7)], &words, &mut issues, &mut passed);
+ assert_eq!(issues.len(), 1, "{:?}", issues.iter().map(|i| &i.says).collect::<Vec<_>>());
+}
diff --git a/apps/check/src/text.rs b/apps/check/src/text.rs
index e7ec9d10..a1644120 100644
--- a/apps/check/src/text.rs
+++ b/apps/check/src/text.rs
@@ -248,12 +248,21 @@ pub(crate) fn cues(runs: &[Run], words: &[Word], issues: &mut Vec<Issue>, passed
for r in runs {
let shown: Vec<String> = r.text.split_whitespace().map(norm).filter(|t| !t.is_empty()).collect();
let Some((k, i)) = shown.iter().enumerate().filter(|(_, t)| t.len() >= 3 && !SMALL.contains(&t.as_str())).find_map(|(k, t)| {
- words.iter().enumerate().filter(|(_, w)| norm(&w.text) == *t && (w.start - r.from).abs() <= 2.0).min_by(|(_, a), (_, b)| (a.start - r.from).abs().total_cmp(&(b.start - r.from).abs())).map(|(i, _)| (k, i))
+ // a one-word card matches only a word said right by it: the same word said 2 s earlier is another moment
+ let near = if shown.len() == 1 { 0.75 } else { 2.0 };
+ words.iter().enumerate().filter(|(_, w)| norm(&w.text) == *t && (w.start - r.from).abs() <= near).min_by(|(_, a), (_, b)| (a.start - r.from).abs().total_cmp(&(b.start - r.from).abs())).map(|(i, _)| (k, i))
}) else {
continue;
};
// back over the words the text shows before it, while the voice says them in the same order just before
let back = (1..=k.min(i)).take_while(|&n| norm(&words[i - n].text) == shown[k - n]).last().unwrap_or(0);
+ // a caption says what the voice says: at least half its words, in order, around the anchor. A card that only
+ // shares one word with another line ("Wirestock x OpenAI Sora" against "At Wirestock, I worked on...") isn't
+ // a caption of it, and holding it to that word's time was a false P1
+ let fwd = (1..).take_while(|&n| k + n < shown.len() && i + n < words.len() && norm(&words[i + n].text) == shown[k + n]).last().unwrap_or(0);
+ if (back + 1 + fwd) * 2 < shown.len() {
+ continue;
+ }
let w = &words[i - back];
let tok = norm(&w.text);
checked += 1;