|
@@ -28,12 +28,10 @@ namespace math { namespace dim2 {
|
|
|
return !(lhs == rhs);
|
|
return !(lhs == rhs);
|
|
|
}
|
|
}
|
|
|
bool operator==(quad const & lhs, quad const & rhs) {
|
|
bool operator==(quad const & lhs, quad const & rhs) {
|
|
|
- return lhs.ll == rhs.ll && lhs.lr == rhs.lr && lhs.ul == rhs.ul
|
|
|
|
|
- && lhs.ur == rhs.ur;
|
|
|
|
|
- }
|
|
|
|
|
- bool operator!=(quad const & lhs, quad const & rhs) {
|
|
|
|
|
- return !(lhs == rhs);
|
|
|
|
|
|
|
+ return lhs.ll == rhs.ll && lhs.lr == rhs.lr && lhs.ul == rhs.ul &&
|
|
|
|
|
+ lhs.ur == rhs.ur;
|
|
|
}
|
|
}
|
|
|
|
|
+ bool operator!=(quad const & lhs, quad const & rhs) { return !(lhs == rhs); }
|
|
|
}}
|
|
}}
|
|
|
|
|
|
|
|
inline Json::Value to_json(std::string const & str) {
|
|
inline Json::Value to_json(std::string const & str) {
|
|
@@ -45,7 +43,7 @@ inline Json::Value to_json(std::string const & str) {
|
|
|
TEST(CollidableTest, ConstructsUsingGraphics) {
|
|
TEST(CollidableTest, ConstructsUsingGraphics) {
|
|
|
math::dim2::rectangle bounds{make_vector(0.f, 0.f), make_vector(1.f, 1.f)};
|
|
math::dim2::rectangle bounds{make_vector(0.f, 0.f), make_vector(1.f, 1.f)};
|
|
|
graphics::object obj{bounds, bounds, cast<graphics::material>(1), bounds};
|
|
graphics::object obj{bounds, bounds, cast<graphics::material>(1), bounds};
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
collidable collide{obj};
|
|
collidable collide{obj};
|
|
|
EXPECT_THAT(collide.render_info().location, Eq(obj.location));
|
|
EXPECT_THAT(collide.render_info().location, Eq(obj.location));
|
|
|
}
|
|
}
|
|
@@ -60,16 +58,15 @@ std::string const data = R"(
|
|
|
TEST(EntityTest, ConstructsFromJson) {
|
|
TEST(EntityTest, ConstructsFromJson) {
|
|
|
math::dim2::rectangle bounds{make_vector(0.f, 0.f), make_vector(1.f, 1.f)};
|
|
math::dim2::rectangle bounds{make_vector(0.f, 0.f), make_vector(1.f, 1.f)};
|
|
|
graphics::object obj{bounds, bounds, cast<graphics::material>(1), bounds};
|
|
graphics::object obj{bounds, bounds, cast<graphics::material>(1), bounds};
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
entity ent{to_json(data), obj};
|
|
entity ent{to_json(data), obj};
|
|
|
EXPECT_THAT(ent.render_info().location, Eq(obj.location));
|
|
EXPECT_THAT(ent.render_info().location, Eq(obj.location));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
TEST(EntityTest, SizeParamAltersLocation) {
|
|
TEST(EntityTest, SizeParamAltersLocation) {
|
|
|
math::dim2::rectangle bounds{make_vector(0.f, 0.f), make_vector(1.f, 1.f)};
|
|
math::dim2::rectangle bounds{make_vector(0.f, 0.f), make_vector(1.f, 1.f)};
|
|
|
graphics::object obj{bounds, bounds, cast<graphics::material>(1), bounds};
|
|
graphics::object obj{bounds, bounds, cast<graphics::material>(1), bounds};
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
Json::Value json = to_json(data);
|
|
Json::Value json = to_json(data);
|
|
|
json["size"] = 2.f;
|
|
json["size"] = 2.f;
|
|
|
entity ent{json, obj};
|
|
entity ent{json, obj};
|
|
@@ -81,10 +78,10 @@ TEST(EntityTest, SizeParamAltersLocation) {
|
|
|
TEST(EntityTest, MoveWillAdjustPointsAndBounds) {
|
|
TEST(EntityTest, MoveWillAdjustPointsAndBounds) {
|
|
|
math::dim2::rectangle bounds{make_vector(0.f, 0.f), make_vector(1.f, 1.f)};
|
|
math::dim2::rectangle bounds{make_vector(0.f, 0.f), make_vector(1.f, 1.f)};
|
|
|
graphics::object obj{bounds, bounds, cast<graphics::material>(1), bounds};
|
|
graphics::object obj{bounds, bounds, cast<graphics::material>(1), bounds};
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
entity ent{to_json(data), obj};
|
|
entity ent{to_json(data), obj};
|
|
|
ent.update(1.f);
|
|
ent.update(1.f);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
math::dim2::rectangle expected{make_vector(1.f, 2.f), make_vector(1.f, 1.f)};
|
|
math::dim2::rectangle expected{make_vector(1.f, 2.f), make_vector(1.f, 1.f)};
|
|
|
EXPECT_THAT(ent.render_info().location, Eq(expected));
|
|
EXPECT_THAT(ent.render_info().location, Eq(expected));
|
|
|
EXPECT_THAT(ent.render_info().points, Eq(math::dim2::quad(expected)));
|
|
EXPECT_THAT(ent.render_info().points, Eq(math::dim2::quad(expected)));
|
|
@@ -93,10 +90,10 @@ TEST(EntityTest, MoveWillAdjustPointsAndBounds) {
|
|
|
TEST(EntityTest, MoveIsAFunctionOfVelocity) {
|
|
TEST(EntityTest, MoveIsAFunctionOfVelocity) {
|
|
|
math::dim2::rectangle bounds{make_vector(0.f, 0.f), make_vector(1.f, 1.f)};
|
|
math::dim2::rectangle bounds{make_vector(0.f, 0.f), make_vector(1.f, 1.f)};
|
|
|
graphics::object obj{bounds, bounds, cast<graphics::material>(1), bounds};
|
|
graphics::object obj{bounds, bounds, cast<graphics::material>(1), bounds};
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
entity ent{to_json(data), obj};
|
|
entity ent{to_json(data), obj};
|
|
|
ent.update(0.5f);
|
|
ent.update(0.5f);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
math::dim2::rectangle expected{make_vector(0.5f, 1.f), make_vector(1.f, 1.f)};
|
|
math::dim2::rectangle expected{make_vector(0.5f, 1.f), make_vector(1.f, 1.f)};
|
|
|
EXPECT_THAT(ent.render_info().location, Eq(expected));
|
|
EXPECT_THAT(ent.render_info().location, Eq(expected));
|
|
|
EXPECT_THAT(ent.render_info().points, Eq(math::dim2::quad(expected)));
|
|
EXPECT_THAT(ent.render_info().points, Eq(math::dim2::quad(expected)));
|