Skip to content

Commit

Permalink
CircleSegment: Add inner_arc and outer_arc
Browse files Browse the repository at this point in the history
  • Loading branch information
waywardmonkeys committed Aug 22, 2024
1 parent 2ea831a commit 6e36b16
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
54 changes: 34 additions & 20 deletions src/circle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -301,33 +333,15 @@ 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,
self.inner_radius,
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]
Expand Down

0 comments on commit 6e36b16

Please sign in to comment.