forked from organicmaps/organicmaps
added test for m2::Rect
This commit is contained in:
parent
e770654659
commit
f005db8585
3 changed files with 30 additions and 0 deletions
|
@ -33,3 +33,4 @@ SOURCES += \
|
|||
tree_test.cpp \
|
||||
polygon_test.cpp \
|
||||
region_test.cpp \
|
||||
rect_test.cpp
|
||||
|
|
23
geometry/geometry_tests/rect_test.cpp
Normal file
23
geometry/geometry_tests/rect_test.cpp
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include "../../base/SRC_FIRST.hpp"
|
||||
#include "../../testing/testing.hpp"
|
||||
#include "../rect2d.hpp"
|
||||
|
||||
UNIT_TEST(Rect_Intersect)
|
||||
{
|
||||
m2::RectD r(0, 0, 100, 100);
|
||||
m2::RectD r1(10, 10, 20, 20);
|
||||
|
||||
TEST(r1.IsIntersect(r), ());
|
||||
TEST(r.IsIntersect(r1), ());
|
||||
|
||||
m2::RectD r2(-100, -100, -50, -50);
|
||||
|
||||
TEST(!r2.IsIntersect(r), ());
|
||||
TEST(!r.IsIntersect(r2), ());
|
||||
|
||||
m2::RectD r3(-10, -10, 10, 10);
|
||||
|
||||
TEST(r3.IsIntersect(r), ());
|
||||
TEST(r.IsIntersect(r3), ());
|
||||
}
|
||||
|
|
@ -126,6 +126,12 @@ namespace m2
|
|||
return !(m_minX > pt.x || pt.x > m_maxX || m_minY > pt.y || pt.y > m_maxY);
|
||||
}
|
||||
|
||||
bool IsRectInside(Rect<T> const & rect) const
|
||||
{
|
||||
return (IsPointInside(Point<T>(rect.minX(), rect.minY()))
|
||||
&& IsPointInside(Point<T>(rect.maxX(), rect.maxY())));
|
||||
}
|
||||
|
||||
Point<T> Center() const { return Point<T>((m_minX + m_maxX) / 2.0, (m_minY + m_maxY) / 2.0); }
|
||||
T SizeX() const { return (m_maxX - m_minX); }
|
||||
T SizeY() const { return (m_maxY - m_minY); }
|
||||
|
|
Loading…
Add table
Reference in a new issue