#include "UnitTests.hpp"
#include <playrho/d2/part/Compositor.hpp>
TEST(Compositor, ByteSize)
{
#ifdef _WIN32
EXPECT_EQ(sizeof(Compositor<GeometryIs<StaticRectangle<1, 1>>>), 5u);
EXPECT_EQ(
sizeof(Compositor<GeometryIs<StaticRectangle<1, 1, 2>>, DensityIs<StaticAreaDensity<6>>>),
5u);
EXPECT_EQ(sizeof(Compositor<GeometryIs<StaticRectangle<1, 1>>, DensityIs<StaticAreaDensity<4>>,
FrictionIs<StaticTenthsFriction<3>>>{}),
5u);
EXPECT_EQ(sizeof(Compositor<GeometryIs<StaticRectangle<1, 2>>, FrictionIs<StaticFriction<>>>),
5u);
#else
EXPECT_EQ(sizeof(Compositor<GeometryIs<StaticRectangle<1, 1>>>), 1u);
EXPECT_EQ(
sizeof(Compositor<GeometryIs<StaticRectangle<1, 1, 2>>, DensityIs<StaticAreaDensity<6>>>),
1u);
EXPECT_EQ(sizeof(Compositor<GeometryIs<StaticRectangle<1, 1>>, DensityIs<StaticAreaDensity<4>>,
FrictionIs<StaticTenthsFriction<3>>>{}),
1u);
EXPECT_EQ(sizeof(Compositor<GeometryIs<StaticRectangle<1, 2>>, FrictionIs<StaticFriction<>>>),
1u);
#endif
case 4u:
#ifdef _WIN32
EXPECT_EQ(sizeof(Compositor<GeometryIs<DynamicRectangle<1, 1>>>), 40u);
EXPECT_EQ(
sizeof(Compositor<GeometryIs<StaticRectangle<1, 1>>, DensityIs<StaticAreaDensity<4>>,
FrictionIs<DynamicFriction<4>>>{}),
12u);
EXPECT_EQ(
sizeof(
Compositor<GeometryIs<StaticRectangle<1, 1>>, DensityIs<StaticAreaDensity<4>>,
FrictionIs<StaticFriction<4>>, RestitutionIs<DynamicRestitution<>>>{}),
12u);
EXPECT_EQ(
sizeof(
Compositor<GeometryIs<StaticRectangle<1, 2>>, RestitutionIs<DynamicRestitution<>>>),
12u);
EXPECT_EQ(
sizeof(Compositor<GeometryIs<StaticRectangle<1, 2>>,
RestitutionIs<DynamicRestitution<>>, FrictionIs<DynamicFriction<>>>),
16u);
#else
EXPECT_EQ(sizeof(Compositor<GeometryIs<DynamicRectangle<1, 1>>>), 36u);
EXPECT_EQ(
sizeof(Compositor<GeometryIs<StaticRectangle<1, 1>>, DensityIs<StaticAreaDensity<4>>,
FrictionIs<DynamicFriction<4>>>{}),
4u);
EXPECT_EQ(
sizeof(
Compositor<GeometryIs<StaticRectangle<1, 1>>, DensityIs<StaticAreaDensity<4>>,
FrictionIs<StaticFriction<4>>, RestitutionIs<DynamicRestitution<>>>{}),
4u);
EXPECT_EQ(
sizeof(
Compositor<GeometryIs<StaticRectangle<1, 2>>, RestitutionIs<DynamicRestitution<>>>),
4u);
EXPECT_EQ(
sizeof(Compositor<GeometryIs<StaticRectangle<1, 2>>,
RestitutionIs<DynamicRestitution<>>, FrictionIs<DynamicFriction<>>>),
8u);
#endif
EXPECT_EQ(sizeof(Compositor<GeometryIs<DynamicRectangle<1, 1>>,
DensityIs<DynamicAreaDensity<1>>,
RestitutionIs<DynamicRestitution<>>,
FrictionIs<DynamicFriction<4>>,
SensorIs<DynamicSensor<>>,
FilterIs<DynamicFilter<>>
>),
56u);
break;
case 8u:
EXPECT_EQ(sizeof(Compositor<GeometryIs<DynamicRectangle<1, 1>>>), 72u);
EXPECT_EQ(
sizeof(Compositor<GeometryIs<StaticRectangle<1, 1>>, DensityIs<StaticAreaDensity<4>>,
FrictionIs<DynamicFriction<4>>>{}),
8u);
EXPECT_EQ(
sizeof(
Compositor<GeometryIs<StaticRectangle<1, 1>>, DensityIs<StaticAreaDensity<4>>,
FrictionIs<StaticFriction<4>>, RestitutionIs<DynamicRestitution<>>>{}),
8u);
EXPECT_EQ(
sizeof(
Compositor<GeometryIs<StaticRectangle<1, 2>>, RestitutionIs<DynamicRestitution<>>>),
8u);
EXPECT_EQ(
sizeof(Compositor<GeometryIs<StaticRectangle<1, 2>>,
RestitutionIs<DynamicRestitution<>>, FrictionIs<DynamicFriction<>>>),
16u);
break;
}
}
struct Void2 {
{
return 0u;
}
{
throw InvalidArgument("no index is valid");
}
{
throw InvalidArgument("no index is valid");
}
{
throw InvalidArgument("no index is valid");
}
};
}
{
}
TEST(Compositor, GetNormalsForDefaultCompositor)
{
ASSERT_EQ(
size(Compositor<>{}.GetNormals()), 4u);
}
{
EXPECT_EQ(
GetDimensions(Compositor<GeometryIs<DynamicRectangle<1, 1>>>{{2_m, 2_m}}),
{
auto rect = Compositor<GeometryIs<DynamicRectangle<0, 0>>>{};
const auto value =
Length2{4_m, 8_m};
}
}
{
{
auto o = Compositor<GeometryIs<StaticRectangle<1, 1>>>{};
}
{
auto o = Compositor<GeometryIs<DynamicRectangle<1, 1>>>{};
}
}
{
EXPECT_EQ(
GetOffset(Compositor<GeometryIs<StaticRectangle<1, 1>>>{}),
Length2(0_m, 0_m));
EXPECT_EQ(
GetOffset(Compositor<GeometryIs<DynamicRectangle<1, 1>>>{}),
Length2(0_m, 0_m));
EXPECT_EQ(
GetOffset(Compositor<GeometryIs<DynamicRectangle<1, 1>>>{{2_m, 2_m}}),
{
auto rect = Compositor<GeometryIs<DynamicRectangle<1, 1>>>{{4_m, 2_m}};
const auto value =
Length2{4_m, 8_m};
}
}
{
EXPECT_EQ(
GetChildCount(Compositor<GeometryIs<StaticRectangle<1, 1>>>{}), 1u);
EXPECT_EQ(
GetChildCount(Compositor<GeometryIs<DynamicRectangle<>>>{}), 1u);
EXPECT_EQ(
GetChildCount(Compositor<GeometryIs<StaticRectangle<1, 1>>, StaticAreaDensity<6>>{}),
1u);
EXPECT_EQ(
GetChildCount(Compositor<GeometryIs<DynamicRectangle<0, 0>>, StaticAreaDensity<6>>{}),
1u);
}
TEST(Compositor, GetChildDynamicRectangle)
{
auto compositor = Compositor<GeometryIs<DynamicRectangle<>>>{};
EXPECT_THROW(
GetChild(compositor, 1u), InvalidArgument);
EXPECT_NO_THROW(distanceProxy =
GetChild(compositor, 0u));
}
TEST(Compositor, GetChildDefaultCompositor)
{
const auto compositor = Compositor<>{};
EXPECT_NO_THROW(distanceProxy =
GetChild(compositor, 0u));
EXPECT_THROW(distanceProxy =
GetChild(compositor, 1u), InvalidArgument);
}
TEST(Compositor, SetVertexRadiusDefaultCompositor)
{
auto compositor = Compositor<>{};
ASSERT_NO_THROW(distanceProxy =
GetChild(compositor, 0u));
}
TEST(Compositor, SetVertexRadiusDynamicRectangle)
{
auto compositor = Compositor<GeometryIs<DynamicRectangle<>>>{};
ASSERT_NO_THROW(distanceProxy =
GetChild(compositor, 0u));
const auto amount = 2_m;
ASSERT_NO_THROW(distanceProxy =
GetChild(compositor, 0u));
EXPECT_EQ(distanceProxy.GetVertexRadius(), amount);
}
{
Compositor<GeometryIs<StaticRectangle<1, 1>>, DensityIs<StaticAreaDensity<4>>>{}),
4_kgpm2);
EXPECT_EQ(
Compositor<GeometryIs<DynamicRectangle<1, 1>>, DensityIs<StaticAreaDensity<4>>>{}),
4_kgpm2);
Compositor<GeometryIs<StaticRectangle<1, 1>>, DensityIs<StaticAreaDensity<5>>>{}),
5_kgpm2);
EXPECT_EQ(
Compositor<GeometryIs<StaticRectangle<1, 1>>, DensityIs<DynamicAreaDensity<6>>>{}),
6_kgpm2);
EXPECT_EQ(
GetDensity(Compositor<GeometryIs<StaticRectangle<1, 1>>, DensityIs<DynamicAreaDensity<6>>>{
{}, {2.4_kgpm2}}),
2.4_kgpm2);
}
{
EXPECT_EQ(
Compositor<GeometryIs<StaticRectangle<1, 1>>, FrictionIs<StaticTenthsFriction<>>>{}),
EXPECT_EQ(
Compositor<GeometryIs<StaticRectangle<1, 1>>, FrictionIs<StaticTenthsFriction<3>>>{}),
Compositor<GeometryIs<StaticRectangle<1, 1>>, FrictionIs<DynamicFriction<4>>>{}),
EXPECT_EQ(
GetFriction(Compositor<GeometryIs<StaticRectangle<1, 1>>, FrictionIs<DynamicFriction<4>>>{
}
{
EXPECT_EQ(
Compositor<GeometryIs<StaticRectangle<1, 1>>, RestitutionIs<StaticRestitution<1>>>{}),
EXPECT_EQ(
Compositor<GeometryIs<StaticRectangle<1, 1>>, RestitutionIs<DynamicRestitution<8>>>{}),
EXPECT_EQ(
Compositor<GeometryIs<StaticRectangle<1, 1>>, RestitutionIs<DynamicRestitution<8>>>{
{}, {}, {}, {
Real(1.2)}}),
}
{
{
auto rectangle = Compositor<GeometryIs<StaticRectangle<1, 1>>>{};
ASSERT_EQ(rectangle.friction,
Real(2) /
Real(10));
{
}
EXPECT_EQ(rectangle.friction,
Real(2) /
Real(10));
}
{
auto rectangle =
Compositor<GeometryIs<StaticRectangle<1, 1>>, FrictionIs<DynamicFriction<>>>{};
ASSERT_EQ(rectangle.friction,
Real(0));
EXPECT_EQ(rectangle.friction,
Real(3));
}
}
{
{
auto rectangle = Compositor<GeometryIs<StaticRectangle<1, 1>>>{};
ASSERT_EQ(rectangle.restitution,
Real(0));
EXPECT_EQ(rectangle.restitution,
Real(0));
}
{
auto rectangle =
Compositor<GeometryIs<StaticRectangle<1, 1>>, RestitutionIs<DynamicRestitution<>>>{};
ASSERT_EQ(rectangle.restitution,
Real(0));
EXPECT_EQ(rectangle.restitution,
Real(3));
}
}
TEST(Compositor, SetFrictionDefaultCompositor)
{
auto composite = Compositor<>{};
}
TEST(Compositor, SetRestitutionDefaultCompositor)
{
auto composite = Compositor<>{};
}
TEST(Compositor, SetDensityDefaultCompositor)
{
auto composite = Compositor<>{};
EXPECT_THROW(
SetDensity(composite, 1_kgpm2), InvalidArgument);
EXPECT_TRUE((std::is_same_v<decltype(
SetDensity(composite, 1_kgpm2)),
void>));
}
TEST(Compositor, SetSensorDefaultCompositor)
{
auto composite = Compositor<>{};
EXPECT_NO_THROW(
SetSensor(composite,
false));
EXPECT_THROW(
SetSensor(composite,
true), InvalidArgument);
EXPECT_TRUE((std::is_same_v<decltype(
SetSensor(composite,
true)),
void>));
}
TEST(Compositor, SetFilterDefaultCompositor)
{
auto composite = Compositor<>{};
EXPECT_THROW(
SetFilter(composite, Filter{2, 0, 1}), InvalidArgument);
}
TEST(Compositor, GetMassDataForStaticRectangle)
{
auto composite =
Compositor<GeometryIs<StaticRectangle<1, 1>>, DensityIs<StaticAreaDensity<1>>>{};
EXPECT_EQ(massData.center,
Length2(0_m, 0_m));
EXPECT_EQ(massData.mass, 1_kg);
}
TEST(Compositor, GetMassDataForDynamicRectangle)
{
auto composite =
Compositor<GeometryIs<DynamicRectangle<1, 1>>, DensityIs<StaticAreaDensity<1>>>{};
EXPECT_EQ(massData.center,
Length2(0_m, 0_m));
EXPECT_EQ(massData.mass, 1_kg);
}
TEST(Compositor, TranslateStaticRectangle)
{
auto rectangle = Compositor<GeometryIs<StaticRectangle<1, 1>>>{};
}
TEST(Compositor, ScaleStaticRectangle)
{
auto rectangle = Compositor<GeometryIs<StaticRectangle<1, 1>>>{};
}
TEST(Compositor, RotateStaticRectangle)
{
auto rectangle = Compositor<GeometryIs<StaticRectangle<1, 1>>>{};
}
TEST(Compositor, TranslateDynamicRectangle)
{
auto rectangle = Compositor<GeometryIs<DynamicRectangle<1, 1>>>{};
}
TEST(Compositor, ScaleDynamicRectangle)
{
auto rectangle = Compositor<GeometryIs<DynamicRectangle<1, 1>>>{};
}
TEST(Compositor, RotateDynamicRectangle)
{
auto rectangle = Compositor<GeometryIs<DynamicRectangle<1, 1>>>{};
}
TEST(Compositor, EqualsOperator)
{
EXPECT_TRUE(Compositor<>() == Compositor<>());
EXPECT_TRUE(Compositor<GeometryIs<DynamicRectangle<>>>() ==
Compositor<GeometryIs<DynamicRectangle<>>>());
EXPECT_FALSE((Compositor<>() == Compositor<GeometryIs<DynamicRectangle<2, 3>>>()));
EXPECT_FALSE((Compositor<>() == Compositor<GeometryIs<StaticRectangle<2, 3>>>()));
EXPECT_FALSE((Compositor<>() == Compositor<FrictionIs<StaticFriction<4>>>()));
EXPECT_FALSE(Compositor<>() == Compositor<GeometryIs<Void2>>());
}
Definition of the ShapeModel class and related code.
Definition of the Shape class and closely related code.
Distance Proxy.
Definition: DistanceProxy.hpp:64
Shape.
Definition: Shape.hpp:219
static constexpr UnitVec GetUp() noexcept
Gets the up-ward oriented unit vector.
Definition: UnitVec.hpp:128
static constexpr UnitVec GetDown() noexcept
Gets the down-ward oriented unit vector.
Definition: UnitVec.hpp:140
static constexpr UnitVec GetLeft() noexcept
Gets the left-ward oriented unit vector.
Definition: UnitVec.hpp:134
static constexpr UnitVec GetRight() noexcept
Gets the right-ward oriented unit vector.
Definition: UnitVec.hpp:122
detail::length Length
Length quantity.
Definition: Units.hpp:244
constexpr bool IsValidShapeTypeV
Boolean value for whether the specified type is a valid shape type.
Definition: ShapeModel.hpp:113
Definition: Compositor.hpp:43
auto SetDimensions(Compositor< P1, P2, P3, P4, P5, P6 > &arg, decltype(arg.GetDimensions()) value) -> decltype(arg.SetDimensions(value))
Sets the rectangle's width and height dimensions.
Definition: Compositor.hpp:652
auto SetFriction(Compositor< P1, P2, P3, P4, P5, P6 > &arg, NonNegative< Real > value) -> std::enable_if_t<!std::is_const_v< decltype(arg.friction)>, void >
Sets friction.
Definition: Compositor.hpp:959
auto GetChild(const Compositor< P1, P2, P3, P4, P5, P6 > &arg, ChildCounter index) noexcept(noexcept(arg.GetChild(index))) -> decltype(arg.GetChild(index))
Gets the "child" shape for the given shape configuration.
Definition: Compositor.hpp:696
constexpr auto GetChildCount(const Compositor< P1, P2, P3, P4, P5, P6 > &arg) noexcept -> decltype(arg.GetChildCount())
Gets the "child" count for the given shape configuration.
Definition: Compositor.hpp:685
auto SetOffset(Compositor< P1, P2, P3, P4, P5, P6 > &arg, decltype(arg.GetOffset()) value) -> decltype(arg.SetOffset(value))
Sets the rectangle's x and y offset.
Definition: Compositor.hpp:674
auto Rotate(Compositor< P1, P2, P3, P4, P5, P6 > &arg, ::playrho::d2::UnitVec value) -> std::enable_if_t< detail::HasMemberRotateV< decltype(arg)>, void >
Rotates the given compositor's vertices by the given value.
Definition: Compositor.hpp:847
constexpr auto GetFriction(const Compositor< P1, P2, P3, P4, P5, P6 > &arg) noexcept -> decltype(arg.friction)
Gets the friction of the given shape configuration.
Definition: Compositor.hpp:730
auto Scale(Compositor< P1, P2, P3, P4, P5, P6 > &arg, const Vec2 &value) -> std::enable_if_t< detail::HasMemberScaleV< decltype(arg)>, void >
Scales the given compositor's vertices by the given value.
Definition: Compositor.hpp:822
constexpr auto GetOffset(const Compositor< P1, P2, P3, P4, P5, P6 > &arg) noexcept -> decltype(arg.GetOffset())
Gets the rectangle's x and y offset.
Definition: Compositor.hpp:663
auto GetMassData(const Compositor< P1, P2, P3, P4, P5, P6 > &arg) noexcept -> decltype(arg.GetMassData(GetDensity(arg)))
Gets the mass data for the given shape configuration.
Definition: Compositor.hpp:786
auto SetVertexRadius(Compositor< P1, P2, P3, P4, P5, P6 > &arg, ChildCounter index, decltype(arg.GetVertexRadius()) value) -> decltype(arg.SetVertexRadius(index, value))
Gets the vertex radius of the given shape configuration.
Definition: Compositor.hpp:872
auto Translate(Compositor< P1, P2, P3, P4, P5, P6 > &arg, const Length2 &value) -> std::enable_if_t< detail::HasMemberTranslateV< decltype(arg)>, void >
Translates the given compositor's vertices by the given value.
Definition: Compositor.hpp:797
constexpr auto GetDensity(const Compositor< P1, P2, P3, P4, P5, P6 > &arg) noexcept -> decltype(arg.density)
Gets the density of the given shape configuration.
Definition: Compositor.hpp:708
auto SetDensity(Compositor< P1, P2, P3, P4, P5, P6 > &arg, NonNegative< AreaDensity > value) -> std::enable_if_t<!std::is_const_v< decltype(arg.density)>, void >
Density setter.
Definition: Compositor.hpp:884
auto SetRestitution(Compositor< P1, P2, P3, P4, P5, P6 > &arg, Real value) -> std::enable_if_t<!std::is_const_v< decltype(arg.restitution)>, void >
Sets restitution.
Definition: Compositor.hpp:984
auto SetSensor(Compositor< P1, P2, P3, P4, P5, P6 > &arg, bool value) -> std::enable_if_t<!std::is_const_v< decltype(arg.sensor)>, void >
Sensor setter.
Definition: Compositor.hpp:934
constexpr auto GetDimensions(const Compositor< P1, P2, P3, P4, P5, P6 > &arg) noexcept -> decltype(arg.GetDimensions())
Gets the rectangle's width and height dimensions.
Definition: Compositor.hpp:641
constexpr auto GetRestitution(const Compositor< P1, P2, P3, P4, P5, P6 > &arg) noexcept -> decltype(arg.restitution)
Gets the restitution of the given shape configuration.
Definition: Compositor.hpp:719
constexpr auto GetVertexRadius(const Compositor< P1, P2, P3, P4, P5, P6 > &arg) noexcept(noexcept(arg.GetVertexRadius())) -> decltype(arg.GetVertexRadius())
Gets the vertex radius of the given shape configuration.
Definition: Compositor.hpp:763
auto SetFilter(Compositor< P1, P2, P3, P4, P5, P6 > &arg, Filter value) -> std::enable_if_t<!std::is_const_v< decltype(arg.filter)>, void >
Filter setter.
Definition: Compositor.hpp:909
std::size_t size(const DynamicTree &tree) noexcept
Gets the "size" of the given tree.
Definition: DynamicTree.hpp:715
::playrho::detail::MassData< 2 > MassData
Mass data alias for 2-D objects.
Definition: MassData.hpp:88
Definition: ArrayList.hpp:43
std::remove_const_t< decltype(MaxChildCount)> ChildCounter
Child counter type.
Definition: Settings.hpp:57
float Real
Real-number type.
Definition: Real.hpp:69
Vector2< Length > Length2
2-element vector of Length quantities.
Definition: Vector2.hpp:51
constexpr auto DefaultLinearSlop
Default linear slop.
Definition: Settings.hpp:100
Vector2< Real > Vec2
Vector with 2 Real elements.
Definition: Vector2.hpp:47
static const auto filter
The filter of the shape.
Definition: Compositor.hpp:456
Mass data.
Definition: MassData.hpp:46