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 {