srctree

Robin Linden parent ed3867a4 36ed0e32
geom: Add a Rect::empty helper

inlinesplit
geom/geom.h added: 13, removed: 4, total 9
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2021-2023 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2021-2024 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
@@ -81,6 +81,8 @@ struct Rect {
bool inside_vertically = p.y >= top() && p.y <= bottom();
return inside_vertically && inside_horizontally;
}
 
[[nodiscard]] constexpr bool empty() const { return width <= 0 || height <= 0; }
};
 
} // namespace geom
 
geom/geom_test.cpp added: 13, removed: 4, total 9
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2021-2023 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2021-2024 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
@@ -126,5 +126,12 @@ int main() {
expect(!r.contains({11, 10}));
});
 
etest::test("Rect::empty", [] {
expect(Rect{0, 0, 0, 0}.empty());
expect(Rect{0, 0, 1, 0}.empty());
expect(Rect{0, 0, 0, 1}.empty());
expect(!Rect{0, 0, 1, 1}.empty());
});
 
return etest::run_all_tests();
}