From 468cbde5e10d8d7acfe7f4d807b56835fdfc9abe Mon Sep 17 00:00:00 2001 From: Hakan Date: Tue, 12 May 2026 09:41:41 +0300 Subject: [PATCH] fix(hatch): improve angle handling for circular arcs in tessellation --- src/scene/mod.rs | 12 +++++++++--- src/scene/tessellate.rs | 10 +++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/scene/mod.rs b/src/scene/mod.rs index 724055e99..d41fc6f85 100644 --- a/src/scene/mod.rs +++ b/src/scene/mod.rs @@ -2016,14 +2016,20 @@ impl Scene { boundary.push(to_xy(line.end.x, line.end.y)); } BoundaryEdge::CircularArc(arc) => { + const TAU: f64 = std::f64::consts::TAU; let cx = arc.center.x; let cy = arc.center.y; let r = arc.radius; let sa = arc.start_angle; let ea = arc.end_angle; - let end = if ea >= sa { ea } else { ea + std::f64::consts::TAU }; - let span = end - sa; - let segs = ((span / std::f64::consts::TAU) * 32.0).ceil().max(4.0) as u32; + let ccw = arc.counter_clockwise; + let (sa, ea) = if ccw { + (sa, ea) + } else { + (TAU - sa, TAU - ea) + }; + let span = ea - sa; + let segs = ((span / TAU) * 32.0).ceil().max(4.0) as u32; for i in 0..=segs { let t = sa + span * (i as f64 / segs as f64); boundary.push(to_xy( diff --git a/src/scene/tessellate.rs b/src/scene/tessellate.rs index 8f8eb8920..b275912a5 100644 --- a/src/scene/tessellate.rs +++ b/src/scene/tessellate.rs @@ -766,9 +766,13 @@ fn legacy_geometry(entity: &EntityType, world_offset: [f64; 3]) -> Geometry { acadrust::entities::BoundaryEdge::CircularArc(arc) => { let sa = arc.start_angle; let ea = arc.end_angle; - let ccw_end = if ea >= sa { ea } else { ea + TAU }; - let (start_a, end_a) = (sa, ccw_end); - let span = end_a - start_a; + let ccw = arc.counter_clockwise; + let (sa, ea) = if ccw { + (sa, ea) + } else { + (TAU - sa, TAU - ea) + }; + let span = ea - sa; let segs = ((span / TAU) * 32.0) .ceil() .max(4.0) as u32;