#include "UnitTests.hpp"
#include <PlayRho/Dynamics/Joints/PulleyJointConf.hpp>
#include <PlayRho/Dynamics/StepConf.hpp>
#include <PlayRho/Dynamics/World.hpp>
#include <PlayRho/Dynamics/WorldJoint.hpp>
#include <PlayRho/Dynamics/WorldBody.hpp>
#include <PlayRho/Dynamics/Joints/Joint.hpp>
#include <PlayRho/Dynamics/Contacts/ConstraintSolverConf.hpp>
#include <PlayRho/Dynamics/Contacts/BodyConstraint.hpp>
#include <stdexcept>
{
EXPECT_EQ(def.
mass, 0_kg);
}
{
const auto gndA =
Length2{-5_m, -4.2_m};
const auto gndB =
Length2{+2.3_m, +3.1_m};
const auto locA =
Length2{-1.1_m, +0.2_m};
const auto locB =
Length2{-1.4_m, +2.9_m};
const auto lenA = 2.2_m;
const auto lenB = 0.24_m;
EXPECT_EQ(
PulleyJointConf(bA, bB, gndA, gndB, locA, locB).localAnchorA, locA);
EXPECT_EQ(
PulleyJointConf(bA, bB, gndA, gndB, locA, locB).localAnchorB, locB);
EXPECT_EQ(
PulleyJointConf(bA, bB, gndA, gndB, locA, locB, lenA, lenB).lengthA, lenA);
EXPECT_EQ(
PulleyJointConf(bA, bB, gndA, gndB, locA, locB, lenA, lenB).lengthB, lenB);
}
{
const auto posA =
Length2{+1_m, +1_m};
const auto posB =
Length2{-1_m, -1_m};
const auto gA =
Length2{2.2_m, 3.0_m};
const auto gB =
Length2{-1.0_m, 1_m};
const auto aA =
Length2{+10_m, 10_m};
const auto aB =
Length2{-10_m, 10_m};
EXPECT_EQ(conf.bodyA, bA);
EXPECT_EQ(conf.bodyB, bB);
EXPECT_EQ(conf.groundAnchorA, gA);
EXPECT_EQ(conf.groundAnchorB, gB);
EXPECT_EQ(conf.localAnchorA, aA - posA);
EXPECT_EQ(conf.localAnchorB, aB - posB);
EXPECT_NEAR(
static_cast<double>(
Real(conf.lengthA / 1_m)), 10.4805, 0.0001);
EXPECT_NEAR(
static_cast<double>(
Real(conf.lengthB / 1_m)), 12.7279, 0.0001);
}
{
const auto gndA =
Length2{-5_m, -4.2_m};
const auto gndB =
Length2{+2.3_m, +3.1_m};
const auto locA =
Length2{-1.1_m, +0.2_m};
const auto locB =
Length2{-1.4_m, +2.9_m};
const auto lenA = 2.2_m;
const auto lenB = 0.24_m;
EXPECT_EQ(conf.bodyA, bA);
EXPECT_EQ(conf.bodyB, bB);
EXPECT_EQ(conf.groundAnchorA, gndA);
EXPECT_EQ(conf.groundAnchorB, gndB);
EXPECT_EQ(conf.localAnchorA, locA);
EXPECT_EQ(conf.localAnchorB, locB);
EXPECT_EQ(conf.lengthA, lenA);
EXPECT_EQ(conf.lengthB, lenB);
}
{
const auto value =
Real(31);
}
{
case 4:
break;
case 8:
break;
case 16:
break;
default:
FAIL();
break;
}
}
TEST(PulleyJoint, Construction)
{
EXPECT_EQ(
GetType(joint), GetTypeID<PulleyJointConf>());
#if 0
#endif
}
TEST(PulleyJoint, GetAnchorAandB)
{
const auto loc0 =
Length2{+1_m, -3_m};
jd.bodyB = b1;
jd.localAnchorA =
Length2(4_m, 5_m);
jd.localAnchorB =
Length2(6_m, 7_m);
#if 0
EXPECT_EQ(joint.GetAnchorA(world), loc0 + jd.localAnchorA);
EXPECT_EQ(joint.GetAnchorB(world), loc1 + jd.localAnchorB);
#endif
}
{
const auto newOrigin =
Length2{1_m, 1_m};
}
TEST(PulleyJoint, GetCurrentLength)
{
const auto loc0 =
Length2{+1_m, -3_m};
jd.bodyB = b1;
jd.localAnchorA =
Length2(4_m, 5_m);
jd.localAnchorB =
Length2(6_m, 7_m);
const auto lenA =
const auto lenB =
}
{
std::vector<BodyConstraint> bodies;
}
{
std::vector<BodyConstraint> bodies;
ASSERT_EQ(bodies.size(), 2u);
const auto copy = jd;
ASSERT_EQ(jd.bodyA,
BodyID(0u));
ASSERT_EQ(jd.bodyB,
BodyID(1u));
ASSERT_EQ(jd.mass, 0_kg);
ASSERT_EQ(jd.impulse, 0_Ns);
EXPECT_EQ(jd.bodyA, copy.bodyA);
EXPECT_EQ(jd.bodyB, copy.bodyB);
EXPECT_EQ(jd.collideConnected, copy.collideConnected);
EXPECT_EQ(jd.mass, copy.mass);
EXPECT_EQ(jd.impulse, copy.impulse);
EXPECT_NE(jd.uA, copy.uA);
EXPECT_NE(jd.uB, copy.uB);
EXPECT_NE(jd.rA, copy.rA);
EXPECT_NE(jd.rB, copy.rB);
EXPECT_EQ(jd.rA,
Length2(-1_m, 0_m));
EXPECT_EQ(jd.rB,
Length2(+1_m, 0_m));
}
{
std::vector<BodyConstraint> bodies;
stepConf.dtRatio =
Real(3);
stepConf.doWarmStart = true;
const auto originalImpulse = 2_Ns;
jd.impulse = originalImpulse;
EXPECT_EQ(jd.impulse, originalImpulse * stepConf.dtRatio);
}
{
std::vector<BodyConstraint> bodies;
stepConf.dtRatio =
Real(3);
stepConf.doWarmStart = false;
const auto originalImpulse = 2_Ns;
jd.impulse = originalImpulse;
EXPECT_EQ(jd.impulse, 0_Ns);
}
{
std::vector<BodyConstraint> bodies;
bodies.push_back(
bodies.push_back(
stepConf.dtRatio =
Real(1);
stepConf.doWarmStart = false;
ASSERT_EQ(jd.mass, 0_kg);
EXPECT_EQ(jd.mass, 2_kg);
}
{
std::vector<BodyConstraint> bodies;
}
{
std::vector<BodyConstraint> bodies;
jd.groundAnchorA = posA.linear +
Length2{0_m, 8_m};
jd.groundAnchorB = posB.linear +
Length2{0_m, 8_m};
auto solved = false;
EXPECT_FALSE(solved);
EXPECT_TRUE(solved);
}
{
{
EXPECT_TRUE(conf == conf);
}
{
EXPECT_TRUE(conf == conf);
}
{
EXPECT_TRUE(conf == conf);
}
}
{
{
EXPECT_FALSE(conf != conf);
}
}
{
EXPECT_STREQ(
GetName(GetTypeID<PulleyJointConf>()),
"d2::PulleyJointConf");
}