diff --git a/apps/app/e2e/fixtures/interior-probe.json b/apps/app/e2e/fixtures/interior-probe.json
index 47124597..cde34864 100644
--- a/apps/app/e2e/fixtures/interior-probe.json
+++ b/apps/app/e2e/fixtures/interior-probe.json
@@ -34,7 +34,7 @@
"widest": {
"x": 43.0,
"y": 50.0,
- "r": 2.998
+ "r": 2.993
},
"svg": ""
},
@@ -167,6 +167,15 @@
],
"widest": null,
"svg": ""
+ },
+ {
+ "name": "arc-endpoints-equal-in-f32",
+ "accepted": false,
+ "codes": [
+ "annotation.geometry.too_small"
+ ],
+ "widest": null,
+ "svg": ""
}
],
"equine": [
diff --git a/crates/core/src/anatomy/path.rs b/crates/core/src/anatomy/path.rs
index bd3ba598..76d41446 100644
--- a/crates/core/src/anatomy/path.rs
+++ b/crates/core/src/anatomy/path.rs
@@ -75,9 +75,12 @@ pub const MAX_CURVE_CHORDS: usize = 64;
/// The smallest arc radius read, zero aside: `2⁻²⁰`, the reciprocal of the largest coordinate,
/// so the radii scaled up to reach the endpoint (at most `2⁸²` squared) stay finite in `f32`.
pub const MIN_ARC_RADIUS: f64 = 1.0 / 1_048_576.0;
-/// The relative `f32` error of a browser's arc arithmetic, added to an arc's chord deviation
-/// times its scaled radius: a bound, not a measure (the centre may lie far outside the frame).
-const ARC_F32_DRIFT: f64 = 1.0 / 8_388_608.0;
+/// One `f32` ulp, relative (`2⁻²³`): browsers store path points in `f32` and compute arcs in it.
+const F32_ULP: f64 = 1.0 / 8_388_608.0;
+/// The relative error of a browser's arc arithmetic (about five chained `f32` operations),
+/// added to an arc's deviation times its scaled radius: an estimate, the centre lying perhaps
+/// far outside the frame.
+const ARC_F32_DRIFT: f64 = 4.0 * F32_ULP;
/// A fill outline: its subpaths as polylines (each closed by the fill), the largest distance
/// between a chord and the curve it stands for, and whether more than the asked number of
@@ -285,6 +288,7 @@ impl<'a> Cursor<'a> {
}
}
+#[derive(Clone, Copy)]
struct Arc {
rx: f64,
ry: f64,
@@ -523,7 +527,9 @@ impl Pen {
if tiny(arc.rx) || tiny(arc.ry) {
return None;
}
- if arc.to == self.at {
+ // Browsers compare the endpoints as stored, in `f32`: equal there, no arc is drawn.
+ let stored = |(x, y): (f64, f64)| (x as f32, y as f32);
+ if stored(arc.to) == stored(self.at) {
return Some(());
}
if arc.rx == 0.0 || arc.ry == 0.0 {
@@ -539,16 +545,62 @@ impl Pen {
// Over the sweep as `t` goes from 0 to 1 the second derivative stays within the larger
// radius times the sweep squared.
let radius = ellipse.rx.max(ellipse.ry);
+ let spread = self.f32_spread(arc, &ellipse);
let count = self.chords(
radius * ellipse.sweep * ellipse.sweep,
- radius * ARC_F32_DRIFT,
+ radius * ARC_F32_DRIFT + spread,
);
self.trace(count, |t| ellipse.at(ellipse.start + ellipse.sweep * t));
self.line(arc.to);
Some(())
}
+
+ /// How far the arc a browser draws may run from this one: the same arc with an endpoint or
+ /// a radius moved by one `f32` ulp, compared at the same parameters (an ill-conditioned arc,
+ /// a flat ellipse along its chord, moves a lot). Each variant's extremes join the bounds.
+ fn f32_spread(&mut self, arc: &Arc, ellipse: &Ellipse) -> f64 {
+ let from = self.at;
+ let ulp = [from.0, from.1, arc.to.0, arc.to.1]
+ .iter()
+ .fold(1.0_f64, |m, v| m.max(v.abs()))
+ * F32_ULP;
+ let moved = |dx: f64, dy: f64, grow: (f64, f64)| Arc {
+ rx: arc.rx * grow.0,
+ ry: arc.ry * grow.1,
+ to: (arc.to.0 + dx, arc.to.1 + dy),
+ ..*arc
+ };
+ let (more, same) = (1.0 + F32_ULP, 1.0);
+ let variants = [
+ moved(ulp, 0.0, (same, same)),
+ moved(-ulp, 0.0, (same, same)),
+ moved(0.0, ulp, (same, same)),
+ moved(0.0, -ulp, (same, same)),
+ moved(0.0, 0.0, (more, same)),
+ moved(0.0, 0.0, (same, more)),
+ ];
+ let mut spread = 0.0_f64;
+ for variant in &variants {
+ let other = Ellipse::through(from, variant);
+ for angle in other.extreme_angles() {
+ if other.sweeps(angle) {
+ self.add(other.at(angle));
+ }
+ }
+ for i in 0..=SPREAD_SAMPLES {
+ let t = f64::from(i) / f64::from(SPREAD_SAMPLES);
+ let here = ellipse.at(ellipse.start + ellipse.sweep * t);
+ let there = other.at(other.start + other.sweep * t);
+ spread = spread.max(distance((here.0 - there.0, here.1 - there.1)));
+ }
+ }
+ spread
+ }
}
+/// The parameters an arc and its `f32` variants are compared at.
+const SPREAD_SAMPLES: u32 = 32;
+
/// `a − 2b + c`, the curve's second difference over three control points.
fn second_difference(a: (f64, f64), b: (f64, f64), c: (f64, f64)) -> (f64, f64) {
(a.0 - 2.0 * b.0 + c.0, a.1 - 2.0 * b.1 + c.1)
@@ -813,8 +865,8 @@ mod tests {
}
/// Every point of the curve lies within the declared deviation of its chords, and the
- /// deviation within the tolerance asked unless the curve took `MAX_CURVE_CHORDS` (an arc
- /// whose radii the endpoints scale up).
+ /// deviation within the tolerance asked (an arc's `f32` spread aside, well under 1e-3 here)
+ /// unless the curve took `MAX_CURVE_CHORDS` (an arc whose radii the endpoints scale up).
#[test]
fn outline_chords_stay_within_the_deviation() {
let mut rng = Lcg(13);
@@ -876,7 +928,7 @@ mod tests {
let line = &outline.subpaths[0];
let capped = line.len() == MAX_CURVE_CHORDS + 1;
assert!(
- outline.deviation <= tolerance || capped,
+ outline.deviation <= tolerance + 1e-3 || capped,
"case {case} {d}: {}",
outline.deviation
);
@@ -936,6 +988,40 @@ mod tests {
assert!(small.deviation <= 0.05 + 1e-6, "{}", small.deviation);
}
+ /// Endpoints a browser stores as one `f32` point draw no arc, as in the browser.
+ #[test]
+ fn an_arc_between_endpoints_equal_in_f32_draws_nothing() {
+ let outline = path_outline("M40 50A20 20 0 1 1 40.000001 50Z", 0.05, 4096).unwrap();
+ assert!(outline.subpaths.iter().all(|s| s.len() <= 2), "{outline:?}");
+ let bounds = path_bounds("M40 50A20 20 0 1 1 40.000001 50Z").unwrap();
+ assert!(bounds.max_y - bounds.min_y < 1e-3, "{bounds:?}");
+ assert!(path_bounds("M40 50A20 20 0 1 1 40.01 50Z").unwrap().min_y < 20.0);
+ }
+
+ /// A flat ellipse along its chord moves far for one `f32` ulp of its endpoint (the browser
+ /// rounds it there): the spread joins the deviation and the variants' extremes the bounds.
+ /// A semicircle keeps a spread small against its size.
+ #[test]
+ fn an_ill_conditioned_arc_carries_its_f32_spread() {
+ let d = "M40.000003 72.000003A35 0.00000095367431640625 45 0 1 90 122L90 150L40 150Z";
+ let outline = path_outline(d, 0.05, 4096).unwrap();
+ assert!(outline.deviation > 0.5, "{}", outline.deviation);
+ assert!(
+ path_bounds(d).unwrap().max_x > 100.0,
+ "the needle is inside the bounds"
+ );
+ let large = path_outline(
+ "M0 1000a1000 1000 0 1 0 2000 0a1000 1000 0 1 0 -2000 0Z",
+ 0.05,
+ 4096,
+ )
+ .unwrap();
+ // Two semicircles of radius 1 000: the endpoints sit on a diameter, where the centre
+ // moves as the square root of an endpoint's ulp (0.84 units, 0.12 px on the equine
+ // scale): under a thousandth of the radius.
+ assert!(large.deviation < 1.0, "{}", large.deviation);
+ }
+
#[test]
fn the_outline_stops_at_its_vertex_cap() {
let d = format!("M0 0{}", "l1 1".repeat(9));
@@ -951,7 +1037,12 @@ mod tests {
assert_eq!(read("M1,2,3,4"), Some((1.0, 2.0, 3.0, 4.0)));
assert_eq!(read("M.5.5L1-1"), Some((0.5, -1.0, 1.0, 0.5)));
assert_eq!(read("M0 0h5v-2H1V9z"), Some((0.0, -2.0, 5.0, 9.0)));
- assert_eq!(read("M0 0a1 1 0 1010 0"), Some((0.0, 0.0, 10.0, 5.0)));
+ // An arc's bounds hold its `f32` variants too: a few ulps around the exact half circle.
+ let arc = read("M0 0a1 1 0 1010 0").unwrap();
+ let exact = [0.0, 0.0, 10.0, 5.0];
+ for (got, want) in [arc.0, arc.1, arc.2, arc.3].iter().zip(exact) {
+ assert!((got - want).abs() < 1e-5, "{arc:?}");
+ }
assert_eq!(read("M0 0 1e1 1E-1"), Some((0.0, 0.0, 10.0, 0.1)));
assert_eq!(read(" M0 0 Z m1 1 l1 1 "), Some((0.0, 0.0, 2.0, 2.0)));
for broken in [
diff --git a/crates/core/tests/interior_probe.rs b/crates/core/tests/interior_probe.rs
index 7dcdb96f..d78a17a7 100644
--- a/crates/core/tests/interior_probe.rs
+++ b/crates/core/tests/interior_probe.rs
@@ -21,6 +21,7 @@ use serde_json::{Value, json};
const FIXTURE: &str = "apps/app/e2e/fixtures/interior-probe.json";
const THIN: &str = "annotation.geometry.interior_too_small";
const UNREADABLE: &str = "annotation.geometry.out_of_frame";
+const TOO_SMALL: &str = "annotation.geometry.too_small";
const PHONE: &str = "0 0 286 310";
/// The widest disc of a shape, measured to a thousandth of a unit: centre and radius; none for
@@ -195,6 +196,12 @@ fn cases() -> Vec {
path("M40 50A1e-49 1e-49 0 0 1 90 50Z"),
plain,
),
+ // Endpoints one `f32` point: browsers draw no arc, `f64` would draw a full circle.
+ case(
+ "arc-endpoints-equal-in-f32",
+ path("M40 50A20 20 0 1 1 40.000001 50Z"),
+ plain,
+ ),
]
}
@@ -221,7 +228,9 @@ fn equine() -> Vec {
fn the_interior_probe_is_current() {
let cases = cases();
for c in &cases {
- let refused = c["codes"] == json!([THIN]) || c["codes"] == json!([UNREADABLE]);
+ let refused = [THIN, UNREADABLE, TOO_SMALL]
+ .iter()
+ .any(|code| c["codes"] == json!([code]));
assert!(c["accepted"] == json!(true) || refused, "{}", c["name"]);
}
let probe = json!({
diff --git a/docs/development/RUST.md b/docs/development/RUST.md
index 9f46b418..e3106cd1 100644
--- a/docs/development/RUST.md
+++ b/docs/development/RUST.md
@@ -4382,12 +4382,12 @@ validated equine; below, a tap target smaller than the points'.
| `path` unit tests | 300 random cubics, quadratics and arcs: every curve point within the recorded deviation of its chords, the deviation within 0.05 unless capped (arcs whose radii the endpoints scale up); closepath restarts at the subpath start; vertex cap |
Browsers (`apps/app/e2e/ui/interior-clicks.spec.ts`, the six click projects: Chromium 1280, 375 and 320 touch, Firefox
-1280, WebKit 1280 and 375 touch; 96 passed, and `canvas-clicks.spec.ts` 99 unchanged). The probe
-(`e2e/fixtures/interior-probe.json`, written and drift-checked by `tests/interior_probe.rs`) gives 15 shapes in the
+1280, WebKit 1280 and 375 touch; 102 passed, and `canvas-clicks.spec.ts` 99 unchanged). The probe
+(`e2e/fixtures/interior-probe.json`, written and drift-checked by `tests/interior_probe.rs`) gives 16 shapes in the
preview's 286 × 310 box (one unit per CSS px) with the core's verdict and widest disc. For each, the browser's own fill
(`pointer-events="fill"`, stroke out) is sampled every 0.25 px and its widest disc taken by an exact distance transform:
-the core never claims more than the browser fills (at most 0.5 px under it); the 9 refused fill no 4 px disc in any
-engine (the ninth, an arc radius of `1e-49`, fills nothing at all); the 6 accepted take a real click or tap at the core's centre and the hit test at 32 points of 90 % of its radius,
+the core never claims more than the browser fills (at most 0.5 px under it); the 10 refused fill no 4 px disc in any
+engine (an arc radius of `1e-49` and an arc between endpoints one `f32` point apart fill nothing at all); the 6 accepted take a real click or tap at the core's centre and the hit test at 32 points of 90 % of its radius,
fill only and as shipped. A drawing root `fill-rule="evenodd"` leaves the pentagram filled at its centre (isolation).
Then the equine shapes in the canvas: the core's disc hit test-clear (samples under a point's disc aside, at most a
quarter), and a real press where the fill lies farthest from every disc records the zone.
@@ -4416,10 +4416,23 @@ reader). Informational: verdict and preview may differ by a libm ulp between nat
threshold; the verdict has no production caller yet (V1-2.3). Verifier ECARTS(3), all documentation: this section's
pointer from §12.13, the × 1.235 assertion, the audit tools committed.
-Mutations (`.claude/audits/2026-11-01-v1-2-2-mutations-interior.py`): 26 killed, 2 equivalent: Z22 (the floor prune
+Second security review, on `03be75b`: PASS, the radius MEDIUM closed, two siblings of the same `f32` class, fixed. Browsers
+store path points in `f32`: an arc whose endpoints are one `f32` point (`A20 20 0 1 1 40.000001 50` from `40 50`) draws
+nothing there, while `f64` drew a full circle; the core now compares the endpoints as stored and draws no arc either
+(`an_arc_between_endpoints_equal_in_f32_draws_nothing`, probe `arc-endpoints-equal-in-f32`). An ill-conditioned arc (a
+flat ellipse along its chord) moves far for one ulp of an endpoint: the core draws the same arc with an endpoint or a
+radius moved by one `f32` ulp (six variants), adds the largest distance between them at 33 parameters to the deviation,
+and adds the variants' extremes to the bounds (`an_ill_conditioned_arc_carries_its_f32_spread`: the reported needle,
+18 units past the chord, inside the bounds; a semicircle of radius 1 000 keeps 0.84 units, its centre moving as the square
+root of an ulp, as in the browsers). An estimate of the browser's input rounding, compared point to point; the arc
+arithmetic drift raised to `4 × 2⁻²³` of the radius. Bounds of every arc grow by a few ulps (an arc flush with the frame's
+edge counts them). LOW kept, pre-existing, outside the diff: relative commands accumulate in the browser's `f32` current
+point; the worst aligned case (4 096 segments at the 256-span offset limit) drifts 6 % of the span, contrived.
+
+Mutations (`.claude/audits/2026-11-01-v1-2-2-mutations-interior.py`): 29 killed, 2 equivalent: Z22 (the floor prune
removed; a cell that cannot reach the floor never holds an accepted disc) and Z25 (a path without an outline accepted;
-unreachable). S1, S8 and F16 of the previous scripts, whose anchors moved, re-anchored and killed. Module 579 357 B gzip -9
-(native build; +5 124 B, budget 600 000, margin 20 643 B).
+unreachable). S1, S8 and F16 of the previous scripts, whose anchors moved, re-anchored and killed. Module 580 438 B gzip -9
+(native build; +6 205 B, budget 600 000, margin 19 562 B).
Ignored cargo tests: the three are one test, `pdf_serialize::l_report_with_real_rasters_costs_what_it_costs`, counted
once per cargo run whose features build `pdf_serialize` (workspace, `cli`, `ts,pdf-read,pdf-write`). A timing print for
diff --git a/docs/development/V1-2_ANATOMICAL_SHEETS.md b/docs/development/V1-2_ANATOMICAL_SHEETS.md
index 3d279b29..208de6e5 100644
--- a/docs/development/V1-2_ANATOMICAL_SHEETS.md
+++ b/docs/development/V1-2_ANATOMICAL_SHEETS.md
@@ -1048,7 +1048,7 @@ Four stages, each a superset of the previous:
| Every reachable drawing present, size and sha256 equal to its row, read without removal, in the stored form of §9.2 | yes | | | `verification.integrity.*` |
| Every annotation entirely inside the frame of its view, edges included: the view's `view_box`, else the `viewBox` of the drawing it draws, read as a browser reads it (four numbers, positive width and height) and usable within the range rules browsers draw faithfully (owner brief 2026-11-01: edges within 2²⁰, spans from 1 unit, aspect at most 100, farthest edge at most 256 smaller spans); curves and arcs measured on their shape; path data a browser would not read whole refused; a view drawn on a clean drawing without either has no frame. Measured on the views whose drawing reads clean; the document is never rewritten (owner brief 2026-10-30, RUST.md §12.11) | yes | | | `verification.validation.out_of_frame` (issues `annotation.geometry.out_of_frame`, `view.frame.unknown`) |
| Every annotation in frame shows at least 4 CSS px on the smallest preview, the editor at 320 × 568 (main view box 286 × 310, detail view box 254 × 191, `xMidYMid meet`): a point's visible disc (`2 × max(2, r − 12)`), a trigger circle's diameter, a polygon's or a path's smaller side (curves and arcs on their shape). Same views, same frame; the document is never rewritten (owner brief 2026-11-01, RUST.md §12.13) | yes | | | `verification.validation.marker_too_small` (issue `annotation.geometry.too_small`) |
-| Every polygon or path annotation in frame fills a disc of 4 CSS px on the same preview: under the `nonzero` rule the layer fills with, its stroke left out, a centre inside the fill at least the radius from every edge (closing edges included), curves and arcs cut into chords whose deviation is taken off; measured within `interior::MAX_OUTLINE_VERTICES` 4 096 vertices and one budget of `2²⁵` edge distances per sheet, refused past them; refused in doubt (owner brief « fermeture du dernier MEDIUM » 2026-11-01, RUST.md §12.14) | yes | | | `verification.validation.marker_interior_too_small` (issue `annotation.geometry.interior_too_small`) |
+| Every polygon or path annotation in frame fills a disc of 4 CSS px on the same preview: under the `nonzero` rule the layer fills with, its stroke left out, a centre inside the fill at least the radius from every edge (closing edges included), curves and arcs cut into chords whose deviation is taken off; arcs modelled as browsers store them (`f32` endpoints, a radius other than zero at least `2⁻²⁰`, the spread of one `f32` ulp added); measured within `interior::MAX_OUTLINE_VERTICES` 4 096 vertices and one budget of `2²⁵` edge distances per sheet, refused past them; refused in doubt (owner brief « fermeture du dernier MEDIUM » 2026-11-01, RUST.md §12.14) | yes | | | `verification.validation.marker_interior_too_small` (issue `annotation.geometry.interior_too_small`) |
| Fingerprint computed | yes | | | `verification.integrity.fingerprint` |
| Verdict passed, on the current revision | | yes | yes | `verdict.missing`, `verdict.failed`, `verdict.stale` |
| No `to_confirm` element (D2) | | yes | yes | `publish.to_confirm.open` |