You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

box.cpp 1.4 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <lol/main.h>
  14. #include "lol/unit.h"
  15. namespace lol
  16. {
  17. LOLUNIT_FIXTURE(BoxTest)
  18. {
  19. void SetUp() {}
  20. void TearDown() {}
  21. LOLUNIT_TEST(Box2DIsect)
  22. {
  23. box2 b1(vec2(0.f, 0.f), vec2(10.f, 10.f));
  24. box2 b2(vec2(5.f, 8.f), vec2(8.f, 12.f));
  25. box2 b3(vec2(5.f, 11.f), vec2(8.f, 13.f));
  26. LOLUNIT_ASSERT_EQUAL(true, TestAABBVsAABB(b1, b2));
  27. LOLUNIT_ASSERT_EQUAL(false, TestAABBVsAABB(b1, b3));
  28. box2 b4(vec2(96.f, 33.f), vec2(144.f, 129.f));
  29. box2 b5(vec2(264.f, 91.f), vec2(244.f, 71.f));
  30. LOLUNIT_ASSERT_EQUAL(false, TestAABBVsAABB(b4, b5));
  31. }
  32. LOLUNIT_TEST(Box2DMove)
  33. {
  34. box2 b1(vec2(0.f, 0.f), vec2(1.f, 1.f));
  35. box2 b2(vec2(2.f, 2.f), vec2(3.f, 3.f));
  36. b1 += vec2(0.6f, 0.6f);
  37. LOLUNIT_ASSERT_EQUAL(false, TestAABBVsAABB(b1, b2));
  38. b1 += vec2(0.6f, 0.6f);
  39. LOLUNIT_ASSERT_EQUAL(true, TestAABBVsAABB(b1, b2));
  40. b1 -= vec2(0.0f, 0.6f);
  41. LOLUNIT_ASSERT_EQUAL(false, TestAABBVsAABB(b1, b2));
  42. }
  43. };
  44. } /* namespace lol */