diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f46aaa1..b67d8d1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ This release has an [MSRV][] of 1.65. - Add `Rect::overlaps` and `Rect::contains_rect`. ([#347] by [@nils-mathieu]) - Add `CubicBez::tangents` ([#288] by [@raphlinus]) - Add `Arc::flipped`. ([#367] by [@waywardmonkeys]) +- Add `CircleSegment::inner_arc` and `CircleSegment::outer_arc` ([#368] by [@waywardmonkeys]) ### Changed @@ -57,6 +58,7 @@ Note: A changelog was not kept for or before this release [#356]: https://github.com/linebender/kurbo/pull/356 [#361]: https://github.com/linebender/kurbo/pull/361 [#367]: https://github.com/linebender/kurbo/pull/367 +[#368]: https://github.com/linebender/kurbo/pull/368 [Unreleased]: https://github.com/linebender/kurbo/compare/v0.11.0...HEAD [0.11.0]: https://github.com/linebender/kurbo/releases/tag/v0.11.0 diff --git a/src/circle.rs b/src/circle.rs index 13b8a39a..c340a42b 100644 --- a/src/circle.rs +++ b/src/circle.rs @@ -228,6 +228,38 @@ impl CircleSegment { } } + /// Return an arc representing the outer radius. + #[must_use] + #[inline] + pub fn outer_arc(&self) -> Arc { + Arc { + center: self.center, + radii: Vec2::new(self.outer_radius, self.outer_radius), + start_angle: self.start_angle, + sweep_angle: self.sweep_angle, + x_rotation: 0.0, + } + } + + /// Return an arc representing the inner radius. + /// + /// This is [flipped] from the outer arc, so that it is in the + /// same direction as the arc that would be drawn (as the path + /// elements for this circle segment produce a closed path). + /// + /// [flipped]: Arc::flipped + #[must_use] + #[inline] + pub fn inner_arc(&self) -> Arc { + Arc { + center: self.center, + radii: Vec2::new(self.inner_radius, self.inner_radius), + start_angle: self.start_angle + self.sweep_angle, + sweep_angle: -self.sweep_angle, + x_rotation: 0.0, + } + } + /// Is this circle segment [finite]? /// /// [finite]: f64::is_finite @@ -301,16 +333,7 @@ impl Shape for CircleSegment { self.start_angle, )))) // outer arc - .chain( - Arc { - center: self.center, - radii: Vec2::new(self.outer_radius, self.outer_radius), - start_angle: self.start_angle, - sweep_angle: self.sweep_angle, - x_rotation: 0.0, - } - .append_iter(tolerance), - ) + .chain(self.outer_arc().append_iter(tolerance)) // second radius .chain(iter::once(PathEl::LineTo(point_on_circle( self.center, @@ -318,16 +341,7 @@ impl Shape for CircleSegment { self.start_angle + self.sweep_angle, )))) // inner arc - .chain( - Arc { - center: self.center, - radii: Vec2::new(self.inner_radius, self.inner_radius), - start_angle: self.start_angle + self.sweep_angle, - sweep_angle: -self.sweep_angle, - x_rotation: 0.0, - } - .append_iter(tolerance), - ) + .chain(self.inner_arc().append_iter(tolerance)) } #[inline]