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.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
raea check: the safe-area rule tests a text's letters, not its box, and a missing taste file is a note (#89, items 1 and 4)
shinyobjectz6f88437dc182
diff --git a/apps/check/src/lib.rs b/apps/check/src/lib.rsindex 4ffee128..0c7dae14 100644--- a/apps/check/src/lib.rs+++ b/apps/check/src/lib.rs@@ -143,8 +143,7 @@ fn measured(args: &[String], taste: Vec<Taste>) -> R<(String, Vec<Issue>, Vec<Streturn Err(format!("no file at {video}\n{USAGE}"));}let probe = Probe::of(&video)?;- let mut issues = Vec::new();- let mut passed = Vec::new();+ let (mut issues, mut passed) = (Vec::new(), Vec::new());let manifest: Option<Value> = match flag(args, "--manifest") {Some(m) => Some(serde_json::from_str(&std::fs::read_to_string(m).map_err(|e| format!("{m}: {e}"))?).map_err(|e| format!("{m}: {e}"))?),None => None,@@ -180,23 +179,13 @@ fn measured(args: &[String], taste: Vec<Taste>) -> R<(String, Vec<Issue>, Vec<St/// `fps`), with `more` (a render's own), worst first then by time.fn findings_of(mut issues: Vec<Issue>, more: Vec<Finding>, fps: f64) -> Vec<Finding> {issues.sort_by(|a, b| a.p.cmp(&b.p).then(a.at.unwrap_or(0.0).total_cmp(&b.at.unwrap_or(0.0))));- finding::ranked(- issues- .iter()- .map(|i| {- let f = Finding::new(i.rule, Level::of_rank(i.p), &i.says, "raea check");- // an issue at a second is about the frame it falls on- match i.at {- Some(t) => {- let fr = (t * fps).round() as i64;- f.frames(fr, fr + 1)- }- None => f,- }- })- .chain(more)- .collect(),- )+ let mut found = Vec::new();+ for i in &issues {+ // an issue at a second is about the frame it falls on+ let (f, fr) = (Finding::new(i.rule, Level::of_rank(i.p), &i.says, "raea check"), (i.at.unwrap_or(0.0) * fps).round() as i64);+ found.push(if i.at.is_some() { f.frames(fr, fr + 1) } else { f });+ }+ finding::ranked(found.into_iter().chain(more).collect())}/// The findings (`findings_of`), written to -o as JSON when asked, and the report's text with the count last. True@@ -244,10 +233,8 @@ fn last_packet_end(video: &str) -> Option<f64> {impl Probe {fn of(video: &str) -> R<Probe> {- let out = Command::new("ffprobe")- .args(["-v", "error", "-show_entries", "stream=codec_type,width,height,r_frame_rate,duration,start_time:format=duration,start_time", "-of", "json", video])- .output()- .map_err(|e| format!("ffprobe: {e}"))?;+ let entries = "stream=codec_type,width,height,r_frame_rate,duration,start_time:format=duration,start_time";+ let out = Command::new("ffprobe").args(["-v", "error", "-show_entries", entries, "-of", "json", video]).output().map_err(|e| format!("ffprobe: {e}"))?;let v: Value = serde_json::from_slice(&out.stdout).map_err(|e| format!("ffprobe: {e}"))?;let streams = v["streams"].as_array().cloned().unwrap_or_default();let vid = streams.iter().find(|s| s["codec_type"] == "video").ok_or("no video stream")?;@@ -258,12 +245,7 @@ impl Probe {Some(length) => seconds(&vid["start_time"]).unwrap_or(origin) - origin + length,None => last_packet_end(video).map_or(duration, |end| end - origin),};- Ok(Probe {- w: vid["width"].as_f64().unwrap_or(1920.0),- h: vid["height"].as_f64().unwrap_or(1080.0),- duration,- picture,- audio: streams.iter().any(|s| s["codec_type"] == "audio"),- })+ let audio = streams.iter().any(|s| s["codec_type"] == "audio");+ Ok(Probe { w: vid["width"].as_f64().unwrap_or(1920.0), h: vid["height"].as_f64().unwrap_or(1080.0), duration, picture, audio })}}diff --git a/apps/check/src/tests.rs b/apps/check/src/tests.rsindex 496c69bc..75999dd6 100644--- a/apps/check/src/tests.rs+++ b/apps/check/src/tests.rs@@ -413,3 +413,19 @@ fn a_colour_crossing_the_saturation_line_is_not_a_red_flash() {let found = flash_samples(180, 60.0, |f, _, _, _| if f * 5 * 2 / 60 % 2 == 0 { [100, 49, 0] } else { [100, 50, 0] });assert_eq!(found, None);}++/// A centred line in a left: 0; right: 0 box isn't in the left zone: its letters are tested where the render recorded+/// them (#89); a left-aligned one is, the finding naming the edge, and a manifest without ink is tested by the box.+#[test]+fn safe_area_tests_the_letters_not_the_box() {+ let safe_area = |ink: Value| {+ let m = json!({"fps": 1.0, "frames": [{"frame": 0, "text": [{"text": "centred", "box": [0, 160, 640, 40], "ink": ink}]}]});+ let (mut issues, mut passed) = (vec![], vec![]);+ text_rules(&text_runs(&m), None, 640.0, 360.0, None, None, &mut issues, &mut passed);+ issues.into_iter().filter(|i| i.rule == "safe-area").map(|i| i.says).collect::<String>()+ };+ assert_eq!(safe_area(json!([250, 160, 140, 40])), "");+ let left = safe_area(json!([0, 160, 140, 40]));+ 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"));+}diff --git a/apps/check/src/text.rs b/apps/check/src/text.rsindex 966cc156..e7ec9d10 100644--- a/apps/check/src/text.rs+++ b/apps/check/src/text.rs@@ -8,7 +8,8 @@ pub(crate) struct Run {pub(crate) from: f64,pub(crate) to: f64,pub(crate) box_: [f64; 4],- /// its box on every frame it shows its whole text: a text the camera carries (a sign on a panning street) moves+ /// where its letters are on every frame it shows its whole text (the manifest's `ink`, else its box: a centred line in+ /// a full-width box is nowhere near x = 0, #89): a text the camera carries (a sign on a panning street) moves/// through the frame's edges and zones, which only counts against it when no frame shows it clearpub(crate) boxes: Vec<[f64; 4]>,pub(crate) color: String,@@ -61,7 +62,8 @@ pub(crate) fn text_runs(manifest: &Value) -> Vec<Run> {let mut next = Vec::new();for x in shown {let text = x["text"].as_str().unwrap_or("").trim().to_string();- let b = x["box"].as_array().map(|b| [0, 1, 2, 3].map(|i| b.get(i).and_then(Value::as_f64).unwrap_or(0.0))).unwrap_or([0.0; 4]);+ let quad = |k: &str| x[k].as_array().map(|b| [0, 1, 2, 3].map(|i| b.get(i).and_then(Value::as_f64).unwrap_or(0.0)));+ let (b, ink) = (quad("box").unwrap_or([0.0; 4]), quad("ink"));let k = key(&text);let found = open.iter().position(|r| {let rk = key(&r.text);@@ -77,7 +79,7 @@ pub(crate) fn text_runs(manifest: &Value) -> Vec<Run> {if text.len() >= r.text.len() {r.text = text;r.box_ = b;- r.boxes.push(b);+ r.boxes.push(ink.unwrap_or(b));}r.to = t + 1.0 / fps;r.color = x["color"].as_str().unwrap_or("rgb(255, 255, 255)").to_string();@@ -169,7 +171,9 @@ pub(crate) fn text_rules(runs: &[Run], heard: Option<&[Word]>, w: f64, h: f64, sissues.push(Issue { rule: "clipped", p: 0, at: Some(r.from), says: format!("{q} runs off the frame (box {x:.0},{y:.0} {bw:.0}x{bh:.0} in {w:.0}x{h:.0}); fit it or break the line") });} else if r.boxes.iter().all(zoned) {unsafe_ += 1;- issues.push(Issue { rule: "safe-area", p: 1, at: Some(r.from), says: format!("{q} sits in the app's UI zone (keep {zt:.0} px top, {zb:.0} bottom, {zl:.0} left, {zr:.0} right clear)") });+ let [ix, iy, iw, ih] = *r.boxes.last().unwrap_or(&r.box_);+ let edge = if iy < zt { format!("the top (keep {zt:.0} px clear)") } else if iy + ih > h - zb { format!("the bottom (keep {zb:.0} px clear)") } else if ix < zl { format!("the left (keep {zl:.0} px clear)") } else { format!("the right (keep {zr:.0} px clear)") };+ issues.push(Issue { rule: "safe-area", p: 1, at: Some(r.from), says: format!("{q} sits in the app's UI zone at {edge}: its {} {ix:.0},{iy:.0} {iw:.0}x{ih:.0} in {w:.0}x{h:.0}", if r.boxes.last() == Some(&r.box_) { "box" } else { "letters" }) });}let words = r.text.split_whitespace().count() as f64;let need = (0.3 * words).max(1.0);diff --git a/apps/direction/src/check.rs b/apps/direction/src/check.rsindex 508c1457..7d15b822 100644--- a/apps/direction/src/check.rs+++ b/apps/direction/src/check.rs@@ -35,10 +35,17 @@ pub fn taste_dir() -> Option<PathBuf> {std::env::var_os("RAEA_TASTE").map(PathBuf::from).or_else(|| std::env::var_os("HOME").map(|h| PathBuf::from(h).join(".raea/taste")))}-/// The .ts files `--taste` names: the file, or every .ts in the folder.+/// The .ts files `--taste` names: the file, or every .ts in the folder. A file named under the person's taste folder+/// that isn't there yet is a note, not a refusal: the skill prescribes --taste on that folder's own taste file, and a+/// machine with none yet should still check (#89); any other missing path is left to the reader to refuse.pub fn taste_files(args: &[String]) -> Vec<PathBuf> {let Some(t) = flag(args, "--taste").map(PathBuf::from) else { return vec![] };if t.extension().is_some_and(|x| x == "ts") {+ let home = taste_dir().map(std::path::absolute).and_then(Result::ok);+ if !t.is_file() && t.parent().map(std::path::absolute).and_then(Result::ok) == home {+ eprintln!("note: no taste yet ({} isn't there); checking without it", t.display());+ return vec![];+ }return vec![t];}let mut v: Vec<PathBuf> = std::fs::read_dir(&t).into_iter().flatten().filter_map(|e| e.ok().map(|e| e.path())).filter(|f| f.extension().is_some_and(|x| x == "ts")).collect();diff --git a/engine/page/src/motion/manifest.rs b/engine/page/src/motion/manifest.rsindex d71ff0f8..a4a45453 100644--- a/engine/page/src/motion/manifest.rs+++ b/engine/page/src/motion/manifest.rs@@ -136,6 +136,22 @@ impl BlitzPage {}let mut t = json!({"text": words, "box": [r(b.x), r(b.y), r(w), r(h)], "opacity": (alpha(owner) * 100.0).round() / 100.0,"color": color, "size": font.font_size.computed_size().px() as f64, "weight": font.font_weight.value() as f64, "align": align});+ // where the letters are across the lines (each line's offset is its alignment's), as a box of its own: a+ // centred line in a full-width box is tested by this, not the box (raea check's safe-area rule, #89)+ if let Some(l) = node.element_data().and_then(|e| e.inline_layout_data.as_ref()) {+ let (fl, scale) = (node.final_layout(), doc.viewport().scale() as f64);+ let fx = b.width / (fl.size.width as f64).max(1e-6);+ let (mut x0, mut x1) = (f64::MAX, f64::MIN);+ for line in l.layout.lines() {+ let m = line.metrics();+ x0 = x0.min(m.offset as f64);+ x1 = x1.max((m.offset + m.advance) as f64);+ }+ if x1 > x0 {+ let left = b.x + ((fl.border.left + fl.padding.left) as f64 + x0 / scale) * fx;+ t["ink"] = json!([r(left), r(b.y), r((x1 - x0) / scale * fx), r(h)]);+ }+ }// its first named face and how many lines it was set on (docs/direction.feature DR1's Text)if let Some(f) = font.font_family.families.iter().find_map(|f| match f { style::values::computed::font::SingleFontFamily::FamilyName(n) => Some(n.name.to_string()), _ => None }) {t["family"] = json!(f);