Skip to content

Commit

Permalink
Add Rect::is_zero_area, Size::is_zero_area (#370)
Browse files Browse the repository at this point in the history
These replace `Rect::is_empty` and `Size::is_empty` (which are now
deprecated) as the treatment of negative areas as not being empty can be
slightly confusing, so using a more specific name makes things more
clear.
  • Loading branch information
waywardmonkeys authored Aug 29, 2024
1 parent 9c77957 commit b5bd2aa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This release has an [MSRV][] of 1.65.
- Add `CubicBez::tangents` ([#288] by [@raphlinus])
- Add `Arc::flipped`. ([#367] by [@waywardmonkeys])
- Add `CircleSegment::inner_arc` and `CircleSegment::outer_arc` ([#368] by [@waywardmonkeys])
- Add `Rect::is_zero_area` and `Size::is_zero_area` and deprecate their `is_empty` methods. ([#370] by [@waywardmonkeys])

### Changed

Expand Down Expand Up @@ -59,6 +60,7 @@ Note: A changelog was not kept for or before this release
[#361]: https://github.com/linebender/kurbo/pull/361
[#367]: https://github.com/linebender/kurbo/pull/367
[#368]: https://github.com/linebender/kurbo/pull/368
[#370]: https://github.com/linebender/kurbo/pull/370

[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
9 changes: 8 additions & 1 deletion src/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,19 @@ impl Rect {
self.width() * self.height()
}

/// Whether this rectangle has zero area.
#[inline]
pub fn is_zero_area(&self) -> bool {
self.area() == 0.0
}

/// Whether this rectangle has zero area.
///
/// Note: a rectangle with negative area is not considered empty.
#[inline]
#[deprecated(since = "0.11.1", note = "use is_zero_area instead")]
pub fn is_empty(&self) -> bool {
self.area() == 0.0
self.is_zero_area()
}

/// The center point of the rectangle.
Expand Down
9 changes: 8 additions & 1 deletion src/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,19 @@ impl Size {
self.width * self.height
}

/// Whether this size has zero area.
#[inline]
pub fn is_zero_area(self) -> bool {
self.area() == 0.0
}

/// Whether this size has zero area.
///
/// Note: a size with negative area is not considered empty.
#[inline]
#[deprecated(since = "0.11.1", note = "use is_zero_area instead")]
pub fn is_empty(self) -> bool {
self.area() == 0.0
self.is_zero_area()
}

/// Returns a new size bounded by `min` and `max.`
Expand Down

0 comments on commit b5bd2aa

Please sign in to comment.