diff --git a/crates/effects/src/addons/halftone.rs b/crates/effects/src/addons/halftone.rs index 252945c768..371f664781 100644 --- a/crates/effects/src/addons/halftone.rs +++ b/crates/effects/src/addons/halftone.rs @@ -249,39 +249,23 @@ fn elliptical_quadrant(a: f64) -> Vec { fn quadrant(a: f64, b: f64, h: f64) -> Vec { use std::f64::consts::FRAC_PI_2; let at = |th: f64| Point::new(a * th.cos(), b * th.sin()); - let arc = |out: &mut Vec, t0: f64, t1: f64| { - if t1 <= t0 { - return; - } - let n = ((t1 - t0) / std::f64::consts::FRAC_PI_4).ceil().max(1.0); - let d = (t1 - t0) / n; - let k = 4.0 / 3.0 * (d / 4.0).tan(); - for i in 0..n as usize { - let (u0, u1) = (t0 + d * i as f64, t0 + d * (i as f64 + 1.0)); - let (p0, p3) = (at(u0), at(u1)); - let c1 = p0 + k * vectorcraft_geom::Vec2::new(-a * u0.sin(), b * u0.cos()); - let c2 = p3 - k * vectorcraft_geom::Vec2::new(-a * u1.sin(), b * u1.cos()); - out.push(CubicBez::new(p0, c1, c2, p3)); - } - }; - let line = |p: Point, q: Point| CubicBez::new(p, p.lerp(q, 1.0 / 3.0), p.lerp(q, 2.0 / 3.0), q); let mut out = vec![]; let r = a.hypot(b); if r <= h { - arc(&mut out, 0.0, FRAC_PI_2); + ellipse_arc(&mut out, a, b, 0.0, FRAC_PI_2); return out; } let (phi, alpha) = (b.atan2(a), (h / r).acos()); let (ts, te) = (phi - alpha, phi + alpha); let start = if ts > 0.0 { - arc(&mut out, 0.0, ts); + ellipse_arc(&mut out, a, b, 0.0, ts); at(ts) } else { Point::new(h, 0.0) }; let end = if te < FRAC_PI_2 { at(te) } else { Point::new(0.0, h) }; - out.push(line(start, end)); - arc(&mut out, te, FRAC_PI_2); + out.push(segment(start, end)); + ellipse_arc(&mut out, a, b, te, FRAC_PI_2); out }