| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- //
- // 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"
- namespace math { namespace vector {
- std::ostream & operator<<(std::ostream & os, math::vec2 const & p) {
- return os << '[' << p[0] << ',' << p[1] << ']';
- }
- } }
- namespace math { namespace dim2 {
- std::ostream & operator<<(std::ostream & os, line const & l) {
- return os << '[' << l.first << ',' << l.second << ']';
- }
- } }
- struct FromOriginTest : testing::TestWithParam<math::dim2::line> {};
- TEST_P(FromOriginTest, IntersectsAtOrigin) {
- math::dim2::line l1 = { GetParam().first, {{0, 0}} };
- math::dim2::line l2 = { {{0, 0}}, GetParam().second };
-
- EXPECT_THAT(math::lines::intersection(l1, l2),
- testing::Eq(math::dim2::point{{0, 0}}));
- }
- std::vector<math::dim2::line> const point_pairs{
- {{{1, 1}}, {{0, 0}}},
- {{{1, 1}}, {{1, 0}}},
- {{{1, 1}}, {{0, 1}}},
- {{{1, 1}}, {{1, 1}}},
- {{{1, 1}}, {{2, 1}}},
- {{{2, 3}}, {{1, 2}}},
- {{{1, 1}}, {{-1, 0}}},
- {{{1, 1}}, {{ 0, -1}}},
- {{{1, 1}}, {{-1, -1}}},
- };
- INSTANTIATE_TEST_CASE_P(LineIntersection, FromOriginTest,
- testing::ValuesIn(point_pairs));
|