diff --git a/CHANGELOG.md b/CHANGELOG.md index 44204668..1f46aaa1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ This release has an [MSRV][] of 1.65. - Add `From (f32, f32)` for `Point`. ([#339] by [@rsheeter]) - Add `Rect::overlaps` and `Rect::contains_rect`. ([#347] by [@nils-mathieu]) - Add `CubicBez::tangents` ([#288] by [@raphlinus]) +- Add `Arc::flipped`. ([#367] by [@waywardmonkeys]) ### Changed @@ -55,6 +56,7 @@ Note: A changelog was not kept for or before this release [#354]: https://github.com/linebender/kurbo/pull/354 [#356]: https://github.com/linebender/kurbo/pull/356 [#361]: https://github.com/linebender/kurbo/pull/361 +[#367]: https://github.com/linebender/kurbo/pull/367 [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/arc.rs b/src/arc.rs index de9b4499..fd903c32 100644 --- a/src/arc.rs +++ b/src/arc.rs @@ -49,6 +49,22 @@ impl Arc { } } + /// Return a copy of this `Arc` in the opposite direction. + /// + /// The new `Arc` will sweep towards the original `Arc`s + /// start angle. + #[must_use] + #[inline] + pub fn flipped(&self) -> Arc { + Self { + center: self.center, + radii: self.radii, + start_angle: self.start_angle + self.sweep_angle, + sweep_angle: -self.sweep_angle, + x_rotation: self.x_rotation, + } + } + /// Create an iterator generating Bezier path elements. /// /// The generated elements can be appended to an existing bezier path. @@ -206,3 +222,24 @@ impl Mul for Affine { } } } + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn flipped_arc() { + let a = Arc::new((0., 0.), (1., 0.), 0., PI, 0.); + let f = a.flipped(); + + // Most fields should be unchanged: + assert_eq!(a.center, f.center); + assert_eq!(a.radii, f.radii); + assert_eq!(a.x_rotation, f.x_rotation); + + // Sweep angle should be in reverse + assert_eq!(a.sweep_angle, -f.sweep_angle); + + // Flipping it again should result in the original arc + assert_eq!(a, f.flipped()); + } +}