Add Box::IsEmpty()

This commit is contained in:
ArthurSonzogni 2024-04-11 23:07:09 +02:00
parent 3d6c48e800
commit 0279bed8c4
No known key found for this signature in database
GPG Key ID: 41D98248C074CD6C
4 changed files with 9 additions and 6 deletions

View File

@ -29,6 +29,9 @@ current (development)
reflecting the current scroll position. Proposed by @ibrahimnasson in
[issue 752](https://github.com/ArthurSonzogni/FTXUI/issues/752)
### Screen
- Feature: Add `Box::IsEmpty()`.
### Build
- Support for cmake's "unity/jumbo" builds. Fixed by @ClausKlein.

View File

@ -15,7 +15,7 @@ struct Box {
static auto Intersection(Box a, Box b) -> Box;
static auto Union(Box a, Box b) -> Box;
bool Contain(int x, int y) const;
int Area() const noexcept;
bool IsEmpty();
bool operator==(const Box& other) const;
bool operator!=(const Box& other) const;
};

View File

@ -850,8 +850,9 @@ void Canvas::DrawImage(int x,
y = 0;
}
if (crop.Area() == 0)
if (crop.IsEmpty()) {
return;
}
const auto xend = x + crop.x_max - crop.x_min;
const auto yend = y + crop.y_max - crop.y_min;

View File

@ -39,11 +39,10 @@ bool Box::Contain(int x, int y) const {
y_max >= y;
}
/// @return the are of the box
/// @return whether the box is empty.
/// @ingroup screen
int Box::Area() const noexcept {
const auto area = (x_max - x_min) * (y_max - y_min);
return area < 0 ? 0 : area;
bool Box::IsEmpty() {
return x_min > x_max || y_min > y_max;
}
/// @return whether |other| is the same as |this|