Skip to content

Commit

Permalink
Add Arc::flipped (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
waywardmonkeys committed Aug 22, 2024
1 parent 987b6ff commit c8e9cd2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions src/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -206,3 +222,24 @@ impl Mul<Arc> 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());
}
}

0 comments on commit c8e9cd2

Please sign in to comment.