| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- //
- // shape_test.cxx
- // math
- //
- // Created by Sam Jaffe on 5/4/19.
- // Copyright © 2019 Sam Jaffe. All rights reserved.
- //
- #include <gmock/gmock.h>
- #include "game/math/shape.hpp"
- #include "test_printers.h"
- using namespace math::dim2;
- using namespace testing;
- struct FromOriginTest : TestWithParam<line> {};
- TEST_P(FromOriginTest, IntersectsAtOrigin) {
- line l1 = { GetParam().first, {{0, 0}} };
- line l2 = { {{0, 0}}, GetParam().second };
-
- EXPECT_THAT(math::lines::intersection(l1, l2),
- Eq(point{{0, 0}}));
- }
- std::vector<line> const point_pairs{
- {{{1, 1}}, {{0, 0}}}, // 0 length
- {{{1, 1}}, {{1, 0}}}, // -45deg
- {{{1, 1}}, {{0, 1}}}, // +45deg
- {{{1, 1}}, {{1, 1}}}, // +0deg
- {{{1, 1}}, {{2, 1}}}, // -18deg (approx)
- {{{1, 1}}, {{1, 2}}}, // +18deg (approx)
- {{{2, 3}}, {{1, 2}}}, //
- {{{1, 1}}, {{-1, 0}}}, // +135deg
- {{{1, 1}}, {{ 0, -1}}}, // -135deg
- {{{1, 1}}, {{-1, -1}}}, // +180deg
- {{{1, 1}}, {{ 1, -1}}}, // +90deg
- {{{1, 1}}, {{-1, 1}}}, // -90deg
- };
- INSTANTIATE_TEST_CASE_P(LineIntersection, FromOriginTest,
- ValuesIn(point_pairs));
- struct XUnitTest : TestWithParam<point> {};
- TEST_P(XUnitTest, OrthoOnIntersection) {
- line const ln{{{0, 0}}, {{1, 0}}};
- point const pt = GetParam();
- line const expected{pt, {{pt[0], 0}}};
- EXPECT_THAT(math::lines::orthogonal(ln, pt),
- Eq(expected));
- }
- std::vector<point> x_orthos{
- {{0, 1}}, {{1, 1}}, {{1, 0}}, {{-1, 0}}, {{0, -1}}, {{-1, -1}},
- {{0, 2}}, {{2, 2}}, {{2, 0}}, {{-2, 0}}, {{0, -2}}, {{-2, -2}},
- {{2, 1}}, {{1, 2}}, {{-2, 1}}, {{-1, 2}}, {{1, -2}}, {{2, -1}}
- };
- INSTANTIATE_TEST_CASE_P(LineOrthogonal, XUnitTest, ValuesIn(x_orthos));
- struct DiagonalTest : TestWithParam<std::pair<point, float>> {};
- TEST_P(DiagonalTest, OrthoOnIntersection) {
- line const ln{{{0, 0}}, {{1, 1}}};
- point const pt = GetParam().first;
- line const expected{pt, {{GetParam().second, GetParam().second}}};
- EXPECT_THAT(math::lines::orthogonal(ln, pt),
- Eq(expected));
- }
- std::vector<std::pair<point, float>> diag_orthos{
- {{{0, 1}}, 0.5f}, {{{1, 1}}, 1.f}, {{{1, 0}}, 0.5f},
- {{{-1, 0}}, -0.5f}, {{{0, -1}}, -0.5f}, {{{-1, -1}}, -1.f},
- {{{0, 2}}, 1.f}, {{{2, 2}}, 2.f}, {{{2, 0}}, 1.f},
- {{{-2, 0}}, -1.f}, {{{0, -2}}, -1.f}, {{{-2, -2}}, -2.f},
- {{{2, 1}}, 1.5f}, {{{1, 2}}, 1.5f}, {{{-2, 1}}, -0.5f},
- {{{-1, 2}}, 0.5f}, {{{1, -2}}, -0.5f}, {{{2, -1}}, 0.5f}
- };
- INSTANTIATE_TEST_CASE_P(LineOrthogonal, DiagonalTest,
- ValuesIn(diag_orthos));
|