Skip to content

Commit c81716a

Browse files
committed
Add convenient min()/max() functions to box class
1 parent d2392b2 commit c81716a

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

src/geom-box.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ class box_t
4747
constexpr double width() const noexcept { return m_max_x - m_min_x; }
4848
constexpr double height() const noexcept { return m_max_y - m_min_y; }
4949

50+
constexpr point_t min() const noexcept { return {m_min_x, m_min_y}; }
51+
constexpr point_t max() const noexcept { return {m_max_x, m_max_y}; }
52+
5053
constexpr friend bool operator==(box_t const &a, box_t const &b)
5154
{
5255
return a.min_x() == b.min_x() && a.min_y() == b.min_y() &&

tests/test-geom-box.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ TEST_CASE("Extend box_t with points", "[NoDB]")
3434

3535
REQUIRE(box.width() == Approx(2.0));
3636
REQUIRE(box.height() == Approx(4.0));
37+
38+
REQUIRE(box.min() == geom::point_t{1.0, -2.0});
39+
REQUIRE(box.max() == geom::point_t{3.0, 2.0});
3740
}
3841

3942
TEST_CASE("Extend box_t with linestring", "[NoDB]")

0 commit comments

Comments
 (0)