From fa8faf216d1ae9693332c49fecbc078e01b31293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=82=BC=ED=98=84?= Date: Mon, 2 Nov 2026 13:49:34 +0900 Subject: [PATCH] M8: a whole ellipse starting anywhere stays whole through a .fig file (#1851) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A .fig file (and the REST JSON) holds an ellipse's start and end angles as 32-bit floats, and FigCraft writes them that way too. For a whole turn that starts anywhere but zero, end - start comes out a hair short of 2π as often as not (start 0.3: 6.283185184), which reads as an arc: the ellipse came back as a pie slice whose centred stroke draws a line from the centre to the edge. On import, a sweep within the angles' precision of a turn is now a turn. Co-authored-by: Claude Opus 5.5 --- crates/format/src/fig/export_tests.rs | 19 +++++++++++++++++++ crates/format/src/rest.rs | 7 ++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/crates/format/src/fig/export_tests.rs b/crates/format/src/fig/export_tests.rs index 5b4bcb991..b1b31262a 100644 --- a/crates/format/src/fig/export_tests.rs +++ b/crates/format/src/fig/export_tests.rs @@ -1592,3 +1592,22 @@ fn a_name_used_with_two_types_in_a_set_writes_both_definitions() { } } } + +/// A whole ellipse that starts anywhere round comes back whole: the file holds its start and end +/// angles as 32-bit floats, and their difference falls a hair short of a turn as often as not. +#[test] +fn a_whole_ellipse_starting_anywhere_comes_back_whole() { + let tau = std::f64::consts::TAU; + for start in [0.3, 2.0, -std::f64::consts::FRAC_PI_2, std::f64::consts::PI, 100.25] { + for sweep in [tau, -tau] { + let mut doc = Document::new("whole"); + let page = doc.first_page().unwrap(); + doc.create(page, NodeKind::Ellipse { start, sweep, inner: 0.0 }, "Ellipse", 0.0, 0.0, 100.0, 100.0).unwrap(); + let (bytes, _) = export(&doc, None).unwrap(); + let (back, _) = import(&bytes, "x").unwrap(); + let kinds: Vec = + back.ids().filter_map(|id| back.node(id)).map(|n| n.kind.clone()).filter(|k| matches!(k, NodeKind::Ellipse { .. })).collect(); + assert!(matches!(kinds.as_slice(), [NodeKind::Ellipse { sweep: s, .. }] if *s == sweep), "start {start}, sweep {sweep}: {kinds:?}"); + } + } +} diff --git a/crates/format/src/rest.rs b/crates/format/src/rest.rs index 26ab3586a..4604b73a6 100644 --- a/crates/format/src/rest.rs +++ b/crates/format/src/rest.rs @@ -629,7 +629,12 @@ impl<'a> Ctx<'a> { let start = arc("startingAngle").unwrap_or(0.0).clamp(-1e3, 1e3); let end = arc("endingAngle").map_or(start + std::f64::consts::TAU, |e| e.clamp(-1e3, 1e3)); let tau = std::f64::consts::TAU; - NodeKind::Ellipse { start, sweep: (end - start).clamp(-tau, tau), inner: arc("innerRadius").unwrap_or(0.0).clamp(0.0, 1.0) } + // The angles are 32-bit floats: a whole turn from anywhere but zero comes out a + // hair short of 2π as often as not. Within their precision of a turn, it is one. + let precision = (start.abs() + end.abs() + tau) * f64::from(f32::EPSILON); + let sweep = end - start; + let sweep = if sweep.abs() >= tau - precision { tau.copysign(sweep) } else { sweep }; + NodeKind::Ellipse { start, sweep: sweep.clamp(-tau, tau), inner: arc("innerRadius").unwrap_or(0.0).clamp(0.0, 1.0) } } // Point counts aren't part of the documented JSON: the outline is exact when present. "REGULAR_POLYGON" | "STAR" if point_count().is_none() && has_geometry => NodeKind::Vector { network: VectorNetwork::default() },