diff --git a/crates/core/src/anatomy/frame.rs b/crates/core/src/anatomy/frame.rs index 8d7c6c8f..09f25085 100644 --- a/crates/core/src/anatomy/frame.rs +++ b/crates/core/src/anatomy/frame.rs @@ -24,7 +24,8 @@ pub struct Frame { pub height: f64, } -/// Rounding slack on the edges, relative to the frame's span: far below a device pixel. +/// Rounding slack on the edges, relative to the frame's span only (never to its offset): far +/// below a device pixel. const EDGE_TOLERANCE: f64 = 1e-9; impl Frame { @@ -52,8 +53,7 @@ impl Frame { } fn holds(&self, bounds: &Bounds) -> bool { - let slack = - EDGE_TOLERANCE * (self.width.max(self.height) + self.min_x.abs().max(self.min_y.abs())); + let slack = EDGE_TOLERANCE * self.width.max(self.height); bounds.min_x >= self.min_x - slack && bounds.min_y >= self.min_y - slack && bounds.max_x <= self.min_x + self.width + slack @@ -107,8 +107,15 @@ pub fn geometry_bounds(geometry: &Geometry) -> Option { } } +/// 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 { - match geometry_bounds(geometry) { + 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, diff --git a/crates/core/tests/sheet_frame.rs b/crates/core/tests/sheet_frame.rs index 03ed62f3..924f8cf2 100644 --- a/crates/core/tests/sheet_frame.rs +++ b/crates/core/tests/sheet_frame.rs @@ -407,3 +407,18 @@ fn both_composers_frame_the_view_on_the_measured_frame() { assert_eq!(composed.attr("preserveAspectRatio"), None); } } + +/// 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). +#[test] +fn a_frame_far_from_the_origin_is_as_strict() { + let far = |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 }), + ) + }; + assert!(accepted(&far(1e15 + 500.0))); + assert!(!accepted(&far(1e15 + 5000.0))); +}