fix(anatomy): V1-2.2 refuse markers too small on the phone preview

Owner decision 2026-11-01: the scale bypass (viewBox blown up, drawing
scaled back) is closed by the visible size, 4 CSS px on the editor at
320 x 568 (equine junctions 4.97 px), verdict marker_too_small. A frame
is usable only where browsers draw it faithfully: edges within 2^20,
span from 1 unit, aspect 100, offset 256 spans; measured in 3 engines.
This commit is contained in:
bchanot committed 2026-11-01 01:28:48 +01:00
1 parent 9c606aa567
commit 96b99784b5
17 files changed
+944 -37

No files matched your search

+115 -11
View File
@@ -8,8 +8,16 @@
//! visible in the canvas and in the PDF raster, whatever their aspect. Transforms inside the
//! drawing move the drawing only; the reader removes the root's own `transform`. So an
//! annotation is in frame when every point of its shape is inside the frame, edges included.
//!
//! Owner brief 2026-11-01 (the scale bypass): a frame moved far or blown up, its drawing scaled
//! back, kept the horse and shrank every marker to a speck while staying in frame. Two rules
//! close it. The frame is usable only inside the range browsers draw faithfully: they hold
//! coordinates and the view transform in `f32` (24-bit mantissa), so a coordinate's error is
//! about `|v| × 2⁻²⁴` and, measured against the frame, grows with the ratio of the frame's
//! farthest edge to its span. And each annotation must show at least `MIN_VISIBLE_PX` on the
//! smallest preview the product supports, measured on the shape the layer paints.
use super::layer::find_view;
use super::layer::{find_view, twin_radius};
use super::path::{Bounds, number_list, path_bounds};
use super::svg::Element;
use crate::domain::sheet::{AnatomicalSheetDocument, Annotation, Geometry, SheetView};
@@ -28,11 +36,44 @@ pub struct Frame {
/// below a device pixel.
const EDGE_TOLERANCE: f64 = 1e-9;
/// The largest magnitude of a frame edge: `2²⁰`, where an `f32` still holds a sixteenth of a
/// unit (the equine drawing spans 2 073.4).
pub const MAX_FRAME_MAGNITUDE: f64 = 1_048_576.0;
/// The smallest span: one unit. Measured 2026-11-01 (a disc a quarter of the frame, 286 px box,
/// painted pixels): WebKit 27.2 paints nothing from a span of `2⁻⁷`, Chromium 156 drifts at
/// `2⁻¹⁴` and paints nothing at `2⁻²⁰`, all three exact at `2⁻⁵`; one unit keeps a factor 32.
/// Below it the layer's fixed sizes (the disc floor of 4 units, strokes of 1.5 and 2) exceed
/// the frame anyway.
pub const MIN_FRAME_SPAN: f64 = 1.0;
/// The largest ratio of the frame's farthest edge to its smaller span: `2⁸`. A coordinate's
/// `f32` error is then at most `2⁻¹⁶` of the span, 0.15 px on a frame shown 10 000 px wide
/// (equine main view 1.27, head view 1.47).
pub const MAX_FRAME_OFFSET_RATIO: f64 = 256.0;
/// The largest ratio of the longer span to the shorter: beyond it the frame shows as a line on
/// the phone preview (2.9 px tall at 286 px wide; equine 1.27 and 1.32).
pub const MAX_FRAME_ASPECT: f64 = 100.0;
/// The smallest preview the markers must show on (owner decision 2026-11-01): the editor at
/// 320 × 568 CSS px, measured in Chromium. The main view's canvas box is 286 px wide and grows
/// to 310 px tall; a detail view sits in the dialog's 4:3 box, 254 × 191.
pub const MAIN_PREVIEW_PX: (f64, f64) = (286.0, 310.0);
pub const DETAIL_PREVIEW_PX: (f64, f64) = (254.0, 191.0);
/// The smallest visible size of an annotation on that preview (owner decision 2026-11-01): a
/// point's visible disc, a filled shape's smaller side. The equine junctions show 4.97 px.
pub const MIN_VISIBLE_PX: f64 = 4.0;
impl Frame {
fn from_numbers(min_x: f64, min_y: f64, width: f64, height: f64) -> Option<Self> {
let usable = [min_x, min_y, width, height].iter().all(|n| n.is_finite())
&& width > 0.0
&& height > 0.0;
let finite = [min_x, min_y, width, height].iter().all(|n| n.is_finite());
let (short, long) = (width.min(height), width.max(height));
let reach = [min_x, min_y, min_x + width, min_y + height]
.iter()
.fold(0.0_f64, |m, v| m.max(v.abs()));
let usable = finite
&& short >= MIN_FRAME_SPAN
&& reach <= MAX_FRAME_MAGNITUDE
&& long <= short * MAX_FRAME_ASPECT
&& reach <= short * MAX_FRAME_OFFSET_RATIO;
usable.then_some(Self {
min_x,
min_y,
@@ -52,6 +93,16 @@ impl Frame {
)
}
/// CSS pixels per frame unit on the smallest preview (`xMidYMid meet`).
pub fn preview_scale(&self, main_view: bool) -> f64 {
let (w, h) = if main_view {
MAIN_PREVIEW_PX
} else {
DETAIL_PREVIEW_PX
};
(w / self.width).min(h / self.height)
}
fn holds(&self, bounds: &Bounds) -> bool {
let slack = EDGE_TOLERANCE * self.width.max(self.height);
bounds.min_x >= self.min_x - slack
@@ -85,6 +136,19 @@ pub enum Placement {
OutOfFrame,
/// Path data a browser would not read whole.
Unreadable,
/// In frame, but smaller than `MIN_VISIBLE_PX` on the smallest preview.
TooSmall,
}
/// The size an annotation shows, in frame units: what the layer paints. A point's (or a circle
/// zone's) visible disc is its twin's diameter (`layer::twin_radius`, the hitbox is
/// transparent); a trigger's circle, its diameter; a polygon or a path, the smaller side of
/// its bounds (curves and arcs on their shape). `bounds` are the shape's, finite.
fn visible_size(annotation: &Annotation, geometry: &Geometry, bounds: &Bounds) -> f64 {
match geometry {
Geometry::Circle(c) if annotation.trigger().is_none() => 2.0 * twin_radius(c.r),
_ => (bounds.max_x - bounds.min_x).min(bounds.max_y - bounds.min_y),
}
}
pub fn geometry_bounds(geometry: &Geometry) -> Option<Bounds> {
@@ -110,15 +174,39 @@ pub fn geometry_bounds(geometry: &Geometry) -> Option<Bounds> {
/// A bound that is not a finite number (`f64::min` and `max` would drop a NaN) is unreadable,
/// never in frame.
pub fn placement(geometry: &Geometry, frame: &Frame) -> Placement {
placement_with_bounds(geometry, frame).0
}
fn placement_with_bounds(geometry: &Geometry, frame: &Frame) -> (Placement, Option<Bounds>) {
let finite = |b: &Bounds| {
[b.min_x, b.min_y, b.max_x, b.max_y]
.iter()
.all(|n| n.is_finite())
};
match geometry_bounds(geometry).filter(finite) {
None => Placement::Unreadable,
Some(bounds) if frame.holds(&bounds) => Placement::InFrame,
Some(_) => Placement::OutOfFrame,
None => (Placement::Unreadable, None),
Some(bounds) if frame.holds(&bounds) => (Placement::InFrame, Some(bounds)),
Some(bounds) => (Placement::OutOfFrame, Some(bounds)),
}
}
/// The placement of `annotation` on its view's frame, its visible size on the smallest preview
/// included.
pub fn annotation_placement(annotation: &Annotation, frame: &Frame, main_view: bool) -> Placement {
let Some(geometry) = geometry_of(annotation) else {
return Placement::InFrame;
};
match placement_with_bounds(geometry, frame) {
(Placement::InFrame, Some(bounds)) => {
let shown =
visible_size(annotation, geometry, &bounds) * frame.preview_scale(main_view);
if shown >= MIN_VISIBLE_PX {
Placement::InFrame
} else {
Placement::TooSmall
}
}
(placement, _) => placement,
}
}
@@ -154,23 +242,23 @@ pub fn frame_faults<'a>(
faults.push(FrameFault::NoFrame { view_index });
continue;
};
faults.extend(annotation_faults(document, view.id(), &frame));
faults.extend(annotation_faults(document, view, &frame));
}
faults
}
fn annotation_faults(
document: &AnatomicalSheetDocument,
view_id: &str,
view: &SheetView,
frame: &Frame,
) -> Vec<FrameFault> {
document
.annotations
.iter()
.enumerate()
.filter(|(_, a)| a.view_id() == view_id)
.filter(|(_, a)| a.view_id() == view.id())
.filter_map(|(annotation_index, annotation)| {
let placement = placement(geometry_of(annotation)?, frame);
let placement = annotation_placement(annotation, frame, view.is_main());
(placement != Placement::InFrame).then_some(FrameFault::Annotation {
annotation_index,
placement,
@@ -185,3 +273,19 @@ fn geometry_of(annotation: &Annotation) -> Option<&Geometry> {
Annotation::DetailTrigger(a) => a.geometry.as_ref(),
}
}
#[cfg(test)]
mod tests {
use super::*;
/// Neither JSON nor the `viewBox` grammar carries a NaN, and the range rules refuse an
/// infinity; a NaN given directly is refused too (`f64::max` would drop it from the reach).
#[test]
fn a_non_finite_number_never_makes_a_frame() {
assert!(Frame::from_numbers(0.0, 0.0, 10.0, 10.0).is_some());
assert!(Frame::from_numbers(f64::NAN, 0.0, 10.0, 10.0).is_none());
assert!(Frame::from_numbers(0.0, f64::NAN, 10.0, 10.0).is_none());
assert!(Frame::from_numbers(f64::INFINITY, 0.0, 10.0, 10.0).is_none());
assert!(Frame::from_numbers(0.0, 0.0, f64::INFINITY, 10.0).is_none());
}
}
+6 -1
View File
@@ -237,7 +237,7 @@ impl Context<'_> {
let mut visible: Attrs = vec![
("cx", js_number(cx)),
("cy", js_number(cy)),
("r", js_number(2.0_f64.max(r - 12.0))),
("r", js_number(twin_radius(r))),
("fill", color.to_owned()),
("fill-opacity", self.twin_opacity.to_owned()),
("stroke", "#000".to_owned()),
@@ -256,6 +256,11 @@ impl Context<'_> {
}
}
/// The radius of a point's visible twin, drawn on its hitbox of radius `r`.
pub fn twin_radius(r: f64) -> f64 {
2.0_f64.max(r - 12.0)
}
/// A trigger without a name of its own takes the opened view's name in each language
/// (owner decision 2026-10-15; until R3 both attributes carried the French name). A language
/// left empty falls back to the other one.
+13 -7
View File
@@ -22,8 +22,12 @@ pub const GEOMETRY_MISSING: &str = "annotation.geometry.missing";
/// An annotation not entirely inside the frame of its view, or whose path data a browser would
/// not read whole (V1-2.2 owner brief 2026-10-30, `anatomy::frame`).
pub const OUT_OF_FRAME: &str = "annotation.geometry.out_of_frame";
/// A view drawn on a drawing with neither a `view_box` nor a usable drawing `viewBox`.
/// A view drawn on a drawing with neither a usable `view_box` nor a usable drawing `viewBox`
/// (`anatomy::frame`: finite, within the `f32` range rules, not a line).
pub const NO_FRAME: &str = "view.frame.unknown";
/// An annotation in frame that shows below `anatomy::frame::MIN_VISIBLE_PX` on the smallest
/// preview (owner brief 2026-11-01, the scale bypass).
pub const TOO_SMALL: &str = "annotation.geometry.too_small";
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export))]
@@ -107,7 +111,7 @@ fn frame_issue(document: &AnatomicalSheetDocument, fault: &FrameFault) -> SheetI
NO_FRAME,
format!("views[{view_index}]"),
format!(
"View \"{}\" has neither a view_box nor a usable drawing viewBox",
"View \"{}\" has neither a usable view_box nor a usable drawing viewBox",
document.views[view_index].id()
),
),
@@ -116,13 +120,15 @@ fn frame_issue(document: &AnatomicalSheetDocument, fault: &FrameFault) -> SheetI
placement,
} => {
let annotation = &document.annotations[annotation_index];
let what = if placement == Placement::Unreadable {
"has path data that cannot be read whole"
} else {
"is not entirely inside the frame"
let (code, what) = match placement {
Placement::Unreadable => (OUT_OF_FRAME, "has path data that cannot be read whole"),
Placement::TooSmall => (TOO_SMALL, "shows too small on the phone preview"),
Placement::InFrame | Placement::OutOfFrame => {
(OUT_OF_FRAME, "is not entirely inside the frame")
}
};
(
OUT_OF_FRAME,
code,
format!("annotations[{annotation_index}].geometry"),
format!(
"Annotation \"{}\" {what} of view \"{}\"",
+31 -11
View File
@@ -21,7 +21,8 @@ use ts_rs::TS;
use super::caps::CapsReport;
use super::fingerprint::{FingerprintError, document_fingerprint};
use super::report::{
NO_FRAME, OUT_OF_FRAME, SheetReport, frame_issues, referenced_asset_ids, sheet_report,
NO_FRAME, OUT_OF_FRAME, SheetReport, TOO_SMALL, frame_issues, referenced_asset_ids,
sheet_report,
};
use super::review::{Completeness, ElementChange, ReviewGroup, change_list};
use super::schema::AnatomicalSheetDocument;
@@ -54,6 +55,9 @@ pub mod codes {
/// An annotation outside the frame of its view, or a view without a frame (V1-2.2):
/// measured on the views whose drawing reads clean.
pub const OUT_OF_FRAME: &str = "verification.validation.out_of_frame";
/// An annotation in frame that shows below 4 CSS px on the smallest preview (owner brief
/// 2026-11-01): measured on the same views.
pub const MARKER_TOO_SMALL: &str = "verification.validation.marker_too_small";
pub const FINGERPRINT: &str = "verification.integrity.fingerprint";
}
@@ -275,8 +279,15 @@ fn rule_failures(report: &SheetReport) -> Vec<&'static str> {
.filter(|i| i.severity == SheetIssueSeverity::Error)
};
let mut out = Vec::new();
let rule =
|code: &str| ![super::report::GEOMETRY_MISSING, OUT_OF_FRAME, NO_FRAME].contains(&code);
let rule = |code: &str| {
![
super::report::GEOMETRY_MISSING,
OUT_OF_FRAME,
NO_FRAME,
TOO_SMALL,
]
.contains(&code)
};
if errors().any(|i| rule(&i.code)) {
out.push(codes::RULES);
}
@@ -289,14 +300,23 @@ fn rule_failures(report: &SheetReport) -> Vec<&'static str> {
out
}
/// The frame code when a frame issue was found (after the drawing faults: a view is measured
/// only on a drawing that reads clean).
fn frame_failures(report: &SheetReport) -> Option<&'static str> {
report
.issues
.iter()
.any(|i| i.code == OUT_OF_FRAME || i.code == NO_FRAME)
.then_some(codes::OUT_OF_FRAME)
/// The frame codes of the frame issues found, in code order (after the drawing faults: a view
/// is measured only on a drawing that reads clean).
fn frame_failures(report: &SheetReport) -> Vec<&'static str> {
let found = |codes: &[&str]| {
report
.issues
.iter()
.any(|i| codes.contains(&i.code.as_str()))
};
let mut out = Vec::new();
if found(&[OUT_OF_FRAME, NO_FRAME]) {
out.push(codes::OUT_OF_FRAME);
}
if found(&[TOO_SMALL]) {
out.push(codes::MARKER_TOO_SMALL);
}
out
}
struct CheckedDrawing {
+14 -5
View File
@@ -409,16 +409,25 @@ fn both_composers_frame_the_view_on_the_measured_frame() {
}
/// The edge slack follows the frame's span, never its offset: a frame far from the origin
/// keeps the same strictness (security review of the three-MEDIUM brief).
/// keeps the same strictness (security review of the three-MEDIUM brief). Since the owner
/// brief of 2026-11-01 a frame that far (`1e15`) is unusable (`f32` range rules); at the
/// largest offset still accepted (256 spans) the edge is as strict.
#[test]
fn a_frame_far_from_the_origin_is_as_strict() {
let far = |cx: f64| {
let far = |min_x: f64, cx: f64| {
with_view_box(
&with_geometry("main", circle(cx, 5.0, 1.0)),
0,
json!({ "min_x": 1e15, "min_y": 0, "width": 1000, "height": 10 }),
json!({ "min_x": min_x, "min_y": 0, "width": 10, "height": 10 }),
)
};
assert!(accepted(&far(1e15 + 500.0)));
assert!(!accepted(&far(1e15 + 5000.0)));
assert!(accepted(&far(2550.0, 2559.0)), "edge reached");
assert!(
!accepted(&far(2550.0, 2559.0 + 1e-6)),
"a millionth past the edge"
);
assert!(
!accepted(&far(1e15, 1e15 + 5.0)),
"a frame at 1e15 is not usable"
);
}
@@ -0,0 +1,362 @@
//! V1-2.2 owner brief « décisions et poursuite des corrections » (2026-11-01), the scale
//! bypass: the horse with its `viewBox` blown up and its content scaled back is the same horse,
//! every marker in frame and shrunk to a speck, accepted. Two rules of `anatomy::frame` close
//! it, one definition for the verdict and the preview: every annotation shows at least 4 CSS px
//! on the smallest preview (the editor at 320 × 568: the main view's 286 × 310 box, a detail
//! view's 254 × 191; the visible disc for a point, the smaller side for a shape), and a frame is
//! usable only within the `f32` range rules (magnitude, span, aspect, offset against the span).
//! The document is never rewritten.
#![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)]
mod common;
use common::sheet_readers::{DETAIL_ASSET, MAIN_ASSET, OPEN, document, drawing};
use faunosteo_core::anatomy::frame::{
MAX_FRAME_ASPECT, MAX_FRAME_MAGNITUDE, MAX_FRAME_OFFSET_RATIO, MIN_FRAME_SPAN, MIN_VISIBLE_PX,
};
use faunosteo_core::anatomy::svg::clean::clean_svg;
use faunosteo_core::domain::sheet::preview::{PreviewInput, PreviewSheet, PreviewStatus};
use faunosteo_core::domain::sheet::verdict::{
VerdictBinding, VerdictDrawing, VerdictInput, compute_verdict, sha256_hex,
};
use serde_json::{Value, json};
const SEED: &str = "supabase/seed/anatomical-sheets/equine/draft";
const HORSE_ID: &str = "7f767f74-3b36-51a7-8465-52dd7e2ead4a";
const TOO_SMALL: &str = "annotation.geometry.too_small";
const NO_FRAME: &str = "view.frame.unknown";
const OUT_OF_FRAME: &str = "annotation.geometry.out_of_frame";
/// The verdict's closed codes, as the SQL stores them.
const SMALL_FAILURE: &str = "verification.validation.marker_too_small";
const FRAME_FAILURE: &str = "verification.validation.out_of_frame";
/// The frame and size issues `(code, path)`, the verdict and the preview agreeing, and the
/// verdict's failures.
fn judged(
document: &str,
drawings: &[(&'static str, &str)],
) -> (Vec<(String, String)>, Vec<String>) {
let rows = drawings
.iter()
.map(|(asset_id, text)| VerdictDrawing {
asset_id,
sha256: Box::leak(sha256_hex(text.as_bytes()).into_boxed_str()),
byte_size: text.len() as u64,
bytes: Some(Box::leak(text.as_bytes().to_vec().into_boxed_slice())),
})
.collect();
let verdict = compute_verdict(&VerdictInput {
binding: VerdictBinding {
sheet_id: "s".to_owned(),
version_id: "v".to_owned(),
revision: 1,
review_id: "r".to_owned(),
},
document,
base_document: None,
drawings: rows,
});
let input = PreviewInput {
status: PreviewStatus::Draft,
document: document.to_owned(),
fingerprint: None,
};
let given = drawings
.iter()
.map(|(id, text)| drawing(id, text))
.collect();
let state = PreviewSheet::load(input, given).unwrap().state().unwrap();
let issues = |all: &[faunosteo_core::domain::sheet::SheetIssue]| -> Vec<(String, String)> {
all.iter()
.filter(|i| [TOO_SMALL, NO_FRAME, OUT_OF_FRAME].contains(&i.code.as_str()))
.map(|i| (i.code.clone(), i.path.clone()))
.collect()
};
let found = issues(&verdict.issues);
assert_eq!(
found,
issues(&state.report.issues),
"verdict and preview agree"
);
(found, verdict.failures)
}
/// The shared sheet with the given geometry on its first annotation, and drawings with the
/// given `viewBox` values.
fn shared(
view: &str,
geometry: Value,
main_box: &str,
detail_box: &str,
) -> (Vec<(String, String)>, Vec<String>) {
let mut doc: Value = serde_json::from_str(&document()).unwrap();
doc["annotations"][0]["geometry"] = geometry;
doc["annotations"][0]["view_id"] = json!(view);
let main = OPEN.replace("0 0 10 10", main_box) + "<path d=\"M0 0h1\"/></svg>";
let detail = OPEN.replace("0 0 10 10", detail_box) + "<path d=\"M0 0h1\"/></svg>";
judged(
&doc.to_string(),
&[(MAIN_ASSET, &main), (DETAIL_ASSET, &detail)],
)
}
fn on_main(geometry: Value, view_box: &str) -> (Vec<(String, String)>, Vec<String>) {
shared("main", geometry, view_box, "0 0 10 10")
}
fn circle(cx: f64, cy: f64, r: f64) -> Value {
json!({ "type": "circle", "cx": cx, "cy": cy, "r": r })
}
fn path(d: &str) -> Value {
json!({ "type": "path", "d": d })
}
fn codes(found: &(Vec<(String, String)>, Vec<String>)) -> Vec<String> {
found.0.iter().map(|(code, _)| code.clone()).collect()
}
/// The horse with its `viewBox` multiplied by `factor` and its content scaled back.
fn scaled_horse(factor: f64) -> String {
let horse = common::repo_file(&format!("{SEED}/assets/horse.svg"));
let frame = "viewBox=\"0 0 2073.4 1629.4\">";
assert_eq!(horse.matches(frame).count(), 1);
let text = horse
.replacen(
frame,
&format!(
"viewBox=\"0 0 {} {}\"><g transform=\"scale({factor})\">",
2073.4 * factor,
1629.4 * factor
),
1,
)
.replacen("</svg>", "</g></svg>", 1);
clean_svg(text.as_bytes()).stored.unwrap()
}
fn equine() -> String {
common::repo_file(&format!("{SEED}/document.json"))
}
#[test]
fn the_equine_draft_shows_every_marker_on_the_phone_preview() {
let horse = common::repo_file(&format!("{SEED}/assets/horse.svg"));
let (issues, failures) = judged(&equine(), &[(HORSE_ID, &horse)]);
assert!(issues.is_empty(), "{issues:?}");
assert!(failures.is_empty(), "{failures:?}");
// The smallest: the junctions (r 30, disc r 18) at 286 / 2073.4 px per unit.
let junction = 36.0 * 286.0 / 2073.4;
assert!((4.96..4.97).contains(&junction) && junction >= MIN_VISIBLE_PX);
}
/// The bypass: scaled ×100, every one of the 19 main-view markers is refused as too small (the
/// head view has its own `view_box`); scaled ×1 000 the frame passes `2²⁰` and is not usable.
/// The document text never changes.
#[test]
fn the_blown_up_horse_is_refused() {
let text = equine();
let (issues, failures) = judged(&text, &[(HORSE_ID, &scaled_horse(100.0))]);
assert_eq!(issues.len(), 19, "{issues:?}");
assert!(
issues.iter().all(|(code, _)| code == TOO_SMALL),
"{issues:?}"
);
assert_eq!(failures, [SMALL_FAILURE]);
let doc: Value = serde_json::from_str(&text).unwrap();
for (_, path) in &issues {
let index: usize = path
.strip_prefix("annotations[")
.and_then(|p| p.strip_suffix("].geometry"))
.unwrap()
.parse()
.unwrap();
assert_eq!(doc["annotations"][index]["view_id"], "main");
}
let (issues, failures) = judged(&text, &[(HORSE_ID, &scaled_horse(1000.0))]);
assert_eq!(issues, [(NO_FRAME.to_owned(), "views[0]".to_owned())]);
assert_eq!(failures, [FRAME_FAILURE]);
assert_eq!(text, equine(), "the document is never rewritten");
}
/// The threshold on the real sheet: the junctions fall below 4 px once the horse is scaled by
/// more than 4.966 / 4 ≈ 1.2414; the other points (disc r 22) hold until ≈ 1.517.
#[test]
fn the_equine_threshold_falls_on_the_junctions_first() {
let text = equine();
let small = |factor: f64| -> Vec<String> {
let (issues, _) = judged(&text, &[(HORSE_ID, &scaled_horse(factor))]);
let doc: Value = serde_json::from_str(&text).unwrap();
issues
.iter()
.map(|(_, path)| {
let index: usize = path[12..path.len() - 10].parse().unwrap();
doc["annotations"][index]["id"].as_str().unwrap().to_owned()
})
.collect()
};
assert!(small(1.24).is_empty());
let mut junctions = small(1.25);
junctions.sort();
assert_eq!(junctions, ["c7-t1", "l6-s1", "t18-l1"]);
assert_eq!(small(1.51).len(), 3);
assert_eq!(small(1.52).len(), 13, "every point, the zones still shown");
}
/// A point shows its visible disc, `2 × max(2, r − 12)`, never its transparent hitbox; at
/// 28.6 px per unit (a 10-unit frame on the main box) the disc floor of 4 units shows 114 px.
#[test]
fn a_point_is_measured_on_its_visible_disc() {
// A 1 000-unit frame: 0.286 px per unit. Hitbox r 20 (11.4 px across), disc r 8: 4.58 px.
assert!(codes(&on_main(circle(500.0, 500.0, 20.0), "0 0 1000 1000")).is_empty());
// Disc r 6 (r 18): 3.43 px, while the hitbox would show 10.3 px.
assert_eq!(
codes(&on_main(circle(500.0, 500.0, 18.0), "0 0 1000 1000")),
[TOO_SMALL]
);
// Under r 14 the disc stays r 2: a frame of 10 units shows it 114 px.
assert!(codes(&on_main(circle(5.0, 5.0, 1.0), "0 0 10 10")).is_empty());
}
/// A detail view is measured on the dialog's box (254 × 191), the main view on its own
/// (286 × 310): the same disc on the same 200-unit frame shows 3.82 px in a detail view,
/// 5.72 px on the main view.
#[test]
fn a_detail_view_is_measured_on_the_dialog_box() {
let disc = circle(100.0, 100.0, 1.0);
assert!(codes(&shared("main", disc.clone(), "0 0 200 200", "0 0 200 200")).is_empty());
assert_eq!(
codes(&shared("detail", disc, "0 0 200 200", "0 0 200 200")),
[TOO_SMALL]
);
}
/// Shapes show their smaller side, measured on the curve (never the control points) and the
/// arc: on a 10-unit frame (28.6 px per unit), 4 px is 0.14 unit.
#[test]
fn shapes_are_measured_on_their_curves_and_arcs() {
let main = |d: &str| codes(&on_main(path(d), "0 0 10 10"));
// A cubic whose control points rise 0.18 (5.1 px) while the curve rises 0.135 (3.9 px).
assert_eq!(main("M1 1 C1 1.18 3 1.18 3 1 Z"), [TOO_SMALL]);
assert!(
main("M1 1 C1 1.2 3 1.2 3 1 Z").is_empty(),
"rises 0.15: 4.3 px"
);
// A half ellipse of radius 0.06 (1.7 px), then 0.2 (5.7 px).
assert_eq!(main("M1 1 A1 0.06 0 0 1 3 1 Z"), [TOO_SMALL]);
assert!(main("M1 1 A1 0.2 0 0 1 3 1 Z").is_empty());
// A flat polygon has no smaller side. Declared limit: a thin shape drawn on a diagonal is
// measured on its bounds (the rule is a scale floor, never a shape review).
let line = json!({ "type": "polygon", "points": [[1, 1], [5, 1], [9, 1]] });
assert_eq!(codes(&on_main(line, "0 0 10 10")), [TOO_SMALL]);
}
/// The frame range rules, each at its limit and one step past it; past it the frame is not
/// usable (`view.frame.unknown`, the frame failure).
#[test]
fn the_frame_range_rules_hold_at_their_limits() {
let at =
|view_box: &str, cx: f64, cy: f64, r: f64| codes(&on_main(circle(cx, cy, r), view_box));
// Magnitude: the far edge at 2²⁰ (span 2¹³: the offset ratio, 128, holds on both sides).
let span = 8192.0;
let near = MAX_FRAME_MAGNITUDE - span;
let edge = format!("{near} 0 {span} {span}");
assert!(at(&edge, near + 4096.0, 4096.0, 200.0).is_empty(), "{edge}");
let past = format!("{} 0 {span} {span}", near + 1.0);
assert_eq!(at(&past, near + 4096.0, 4096.0, 200.0), [NO_FRAME]);
// Span: one unit is usable, just below it is not (browsers stop painting a frame of
// `2⁻⁷`, see `MIN_FRAME_SPAN`).
assert!(
at(
&format!("0 0 {MIN_FRAME_SPAN} {MIN_FRAME_SPAN}"),
0.5,
0.5,
0.25
)
.is_empty()
);
assert_eq!(at("0 0 0.999 0.999", 0.5, 0.5, 0.25), [NO_FRAME]);
assert_eq!(
at("0 0 0.0078125 0.0078125", 0.004, 0.004, 0.002),
[NO_FRAME]
);
// Aspect, on the main view while the annotation sits on the detail view (a frame of aspect
// 100 is at most 2.86 px tall on the phone, so nothing in it shows 4 px): 100, then 101.
let band = |w: f64| {
codes(&shared(
"detail",
circle(5.0, 5.0, 1.0),
&format!("0 0 {w} 10"),
"0 0 10 10",
))
};
assert!(band(10.0 * MAX_FRAME_ASPECT).is_empty());
assert_eq!(band(10.0 * MAX_FRAME_ASPECT + 10.0), [NO_FRAME]);
// Offset: the far edge at 256 spans, then past it.
let ratio = MAX_FRAME_OFFSET_RATIO;
assert!(
at(
&format!("{} 0 10 10", ratio * 10.0 - 10.0),
ratio * 10.0 - 5.0,
5.0,
1.0
)
.is_empty()
);
assert_eq!(
at(
&format!("{} 0 10 10", ratio * 10.0 - 9.0),
ratio * 10.0 - 4.0,
5.0,
1.0
),
[NO_FRAME]
);
// Negative offsets count the same.
assert_eq!(
at(
&format!("{} 0 10 10", -ratio * 10.0 - 1.0),
-ratio * 10.0 + 4.0,
5.0,
1.0
),
[NO_FRAME]
);
}
/// A view's own `view_box` follows the same rules as a drawing's `viewBox`.
#[test]
fn a_view_box_follows_the_same_rules() {
let mut doc: Value = serde_json::from_str(&document()).unwrap();
doc["views"][0]["view_box"] = json!({ "min_x": 1e7, "min_y": 0, "width": 10, "height": 10 });
doc["annotations"][0]["geometry"] = circle(1e7 + 5.0, 5.0, 1.0);
let main = OPEN.to_owned() + "<path d=\"M0 0h1\"/></svg>";
let (issues, failures) = judged(
&doc.to_string(),
&[(MAIN_ASSET, &main), (DETAIL_ASSET, &main)],
);
assert_eq!(issues, [(NO_FRAME.to_owned(), "views[0]".to_owned())]);
// The shared sheet fails `verification.validation.rules` on its own; the frame code joins it.
assert!(failures.iter().any(|f| f == FRAME_FAILURE), "{failures:?}");
}
/// The drawing's own transforms move the drawing only (the markers are drawn by the engine, in
/// the frame's user space): a drawing scaled down to nothing keeps its markers' size, and the
/// rule measures them alone.
#[test]
fn transforms_inside_the_drawing_never_change_the_measure() {
let mut doc: Value = serde_json::from_str(&document()).unwrap();
doc["annotations"][0]["geometry"] = circle(5.0, 5.0, 1.0);
let tiny =
OPEN.to_owned() + "<g transform=\"scale(0.000001)\"><path d=\"M0 0h10v10z\"/></g></svg>";
let main = OPEN.to_owned() + "<path d=\"M0 0h1\"/></svg>";
let (issues, failures) = judged(
&doc.to_string(),
&[(MAIN_ASSET, &tiny), (DETAIL_ASSET, &main)],
);
let measured = |f: &String| f == FRAME_FAILURE || f == SMALL_FAILURE;
assert!(
issues.is_empty() && !failures.iter().any(measured),
"{issues:?} {failures:?}"
);
}