| 1 |
/*************************************************************************** |
| 2 |
* Copyright (C) 2005-2019 by the FIFE team * |
| 3 |
* http://www.fifengine.net * |
| 4 |
* This file is part of FIFE. * |
| 5 |
* * |
| 6 |
* FIFE is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Lesser General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2.1 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 14 |
* Lesser General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Lesser General Public * |
| 17 |
* License along with this library; if not, write to the * |
| 18 |
* Free Software Foundation, Inc., * |
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
| 20 |
***************************************************************************/ |
| 21 |
|
| 22 |
// Standard C++ library includes |
| 23 |
#include <ctime> |
| 24 |
#include <vector> |
| 25 |
|
| 26 |
// Platform specific includes |
| 27 |
#include "fife_unittest.h" |
| 28 |
|
| 29 |
// 3rd party library includes |
| 30 |
|
| 31 |
// FIFE includes |
| 32 |
// These includes are split up in two parts, separated by one empty line |
| 33 |
// First block: files included from the FIFE root src directory |
| 34 |
// Second block: files included from the same folder |
| 35 |
#include "util/structures/rect.h" |
| 36 |
|
| 37 |
using namespace FIFE; |
| 38 |
|
| 39 |
TEST(rectangle_interesection) |
| 40 |
{ |
| 41 |
Rect a(0,0,10,10); |
| 42 |
|
| 43 |
std::vector<Rect> do_intersect; |
| 44 |
#define ADD_RECT(x,y,w,h) do_intersect.push_back( Rect(x,y,w,h) ) |
| 45 |
|
| 46 |
ADD_RECT(5,5,10,10); |
| 47 |
ADD_RECT(-5,5,10,10); |
| 48 |
ADD_RECT(-5,-5,10,10); |
| 49 |
ADD_RECT(5,-5,10,10); |
| 50 |
|
| 51 |
ADD_RECT(-5,5,20,1); |
| 52 |
ADD_RECT(-5,5,10,1); |
| 53 |
|
| 54 |
ADD_RECT(5,-5,1,20); |
| 55 |
ADD_RECT(5,-5,1,10); |
| 56 |
|
| 57 |
ADD_RECT(5,5,3,3); |
| 58 |
|
| 59 |
ADD_RECT(-5,-5,30,30); |
| 60 |
|
| 61 |
for(size_t i=0; i<do_intersect.size(); ++i) { |
| 62 |
CHECK(a.intersects(do_intersect[i])); |
| 63 |
CHECK(do_intersect[i].intersects(a)); |
| 64 |
} |
| 65 |
|
| 66 |
std::vector<Rect> dont_intersect; |
| 67 |
|
| 68 |
#undef ADD_RECT |
| 69 |
#define ADD_RECT(x,y,w,h) dont_intersect.push_back( Rect(x,y,w,h) ) |
| 70 |
|
| 71 |
ADD_RECT(-5,-5,4,4); |
| 72 |
ADD_RECT(-5,-5,40,4); |
| 73 |
ADD_RECT(-5,-5,4,40); |
| 74 |
ADD_RECT(-5,-5,4,4); |
| 75 |
|
| 76 |
ADD_RECT(15,15,4,4); |
| 77 |
ADD_RECT(15,15,40,4); |
| 78 |
ADD_RECT(15,15,4,40); |
| 79 |
|
| 80 |
for(size_t i=0; i<dont_intersect.size(); ++i) { |
| 81 |
CHECK(!a.intersects(dont_intersect[i])); |
| 82 |
CHECK(!dont_intersect[i].intersects(a)); |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
int main() { |
| 88 |
return UnitTest::RunAllTests(); |
| 89 |
} |