#include "UnitTests.hpp"
#include <stdexcept>
#include <type_traits>
TEST(TargetJointConf, Traits)
{
EXPECT_TRUE(std::is_default_constructible_v<TargetJointConf>);
EXPECT_TRUE(std::is_nothrow_default_constructible_v<TargetJointConf>);
EXPECT_TRUE(std::is_copy_constructible_v<TargetJointConf>);
EXPECT_TRUE(std::is_copy_assignable_v<TargetJointConf>);
#ifndef PLAYRHO_USE_BOOST_UNITS
EXPECT_TRUE(std::is_nothrow_copy_constructible_v<TargetJointConf>);
EXPECT_TRUE(std::is_nothrow_copy_assignable_v<TargetJointConf>);
#endif
}
TEST(TargetJointConf, DefaultConstruction)
{
}
TEST(TargetJointConf, UseTarget)
{
const auto value =
Length2(19_m, -9_m);
EXPECT_NE(TargetJointConf{}.target, value);
EXPECT_EQ(TargetJointConf{}.UseTarget(value).target, value);
}
TEST(TargetJointConf, UseMaxForce)
{
const auto value =
Force(19_N);
EXPECT_NE(TargetJointConf{}.maxForce, value);
EXPECT_EQ(TargetJointConf{}.UseMaxForce(value).maxForce, value);
}
TEST(TargetJointConf, UseFrequency)
{
const auto value = 19_Hz;
EXPECT_NE(TargetJointConf{}.frequency, value);
EXPECT_EQ(TargetJointConf{}.UseFrequency(value).
frequency, value);
}
TEST(TargetJointConf, UseDampingRatio)
{
const auto value =
Real(0.4);
EXPECT_NE(TargetJointConf{}.dampingRatio, value);
EXPECT_EQ(TargetJointConf{}.UseDampingRatio(value).dampingRatio, value);
}
TEST(TargetJoint, DefaultInitialized)
{
const auto def = TargetJointConf{};
auto joint = Joint{def};
}
{
auto world = World{};
auto def = TargetJointConf{};
def.bodyA = bA;
def.bodyB = bB;
def.localAnchorB =
Length2(-1.4_m, -2_m);
def.maxForce = 3_N;
def.frequency = 67_Hz;
def.dampingRatio =
Real(0.8);
const auto joint = Joint{def};
}
{
auto world = World{};
auto def = TargetJointConf{};
def.bodyA = bA;
def.bodyB = bB;
def.localAnchorB =
Length2(-1.4_m, -2_m);
def.maxForce = 3_N;
def.frequency = 67_Hz;
def.dampingRatio =
Real(0.8);
const auto joint = Joint{def};
}
{
auto world = World{};
auto def = TargetJointConf{};
def.bodyA = bA;
def.bodyB = bB;
def.target =
Length2(-1.4_m, -2_m);
auto joint = Joint{def};
const auto newOrigin =
Length2{1_m, 1_m};
EXPECT_EQ(
GetTarget(joint), def.target - newOrigin);
}
TEST(TargetJointConf, GetTargetJointConfThrows)
{
}
TEST(TargetJointConf, GetTargetJointDefFreeFunction)
{
World world;
auto def = TargetJointConf{};
def.bodyA = bA;
def.bodyB = bB;
def.target =
Length2(-1.4_m, -2_m);
def.localAnchorB =
Length2(+2.0_m, -1_m);
def.maxForce = 3_N;
def.frequency = 67_Hz;
def.dampingRatio =
Real(0.8);
const auto joint = Joint{def};
EXPECT_EQ(def.bodyA, got.bodyA);
EXPECT_EQ(def.bodyB, got.bodyB);
EXPECT_EQ(def.target, got.target);
EXPECT_EQ(def.localAnchorB, got.localAnchorB);
EXPECT_EQ(def.maxForce, got.maxForce);
EXPECT_EQ(def.frequency, got.frequency);
EXPECT_EQ(def.dampingRatio, got.dampingRatio);
}
{
auto def = TargetJointConf{};
EXPECT_EQ(
mass[0][0], 0_kg);
EXPECT_EQ(
mass[0][1], 0_kg);
EXPECT_EQ(
mass[1][0], 0_kg);
EXPECT_EQ(
mass[1][1], 0_kg);
}
TEST(TargetJointConf, InitVelocityUpdatesGamma)
{
auto position = Position{};
std::vector<BodyConstraint> bodies;
bodies.push_back(BodyConstraint{invMass, invRotI, localCenter, position,
velocity});
auto step = StepConf{};
auto conf = ConstraintSolverConf{};
auto def = TargetJointConf{};
def.frequency = 0_Hz;
def.gamma =
Real(5) / 1_kg;
EXPECT_EQ(def.gamma,
Real(0) / 1_kg);
def.frequency = 1_Hz;
def.gamma =
Real(5) / 1_kg;
EXPECT_EQ(def.gamma,
Real(0) / 1_kg);
}
{
auto conf = TargetJointConf{};
std::vector<BodyConstraint> bodies;
EXPECT_NO_THROW(
InitVelocity(conf, bodies, StepConf{}, ConstraintSolverConf{}));
EXPECT_THROW(
InitVelocity(conf, bodies, StepConf{}, ConstraintSolverConf{}), std::out_of_range);
const auto posA = Position{
Length2{-5_m, 0_m}, 0_deg};
EXPECT_NO_THROW(
InitVelocity(conf, bodies, StepConf{}, ConstraintSolverConf{}));
}
{
auto conf = TargetJointConf{};
std::vector<BodyConstraint> bodies;
auto result = false;
EXPECT_NO_THROW(result =
SolveVelocity(conf, bodies, StepConf{}));
EXPECT_EQ(result, true);
EXPECT_THROW(
SolveVelocity(conf, bodies, StepConf{}), std::out_of_range);
const auto posA = Position{
Length2{-5_m, 0_m}, 0_deg};
EXPECT_NO_THROW(result =
SolveVelocity(conf, bodies, StepConf{}));
}
{
auto conf = TargetJointConf{};
std::vector<BodyConstraint> bodies;
auto result = false;
EXPECT_NO_THROW(result =
SolvePosition(conf, bodies, ConstraintSolverConf{}));
EXPECT_TRUE(result);
}
TEST(TargetJointConf, EqualsOperator)
{
EXPECT_TRUE(TargetJointConf() == TargetJointConf());
{
auto conf = TargetJointConf{};
conf.target =
Length2{1.2_m, -3_m};
EXPECT_TRUE(conf == conf);
EXPECT_FALSE(TargetJointConf() == conf);
}
{
auto conf = TargetJointConf{};
conf.localAnchorB =
Length2{1.2_m, -3_m};
EXPECT_TRUE(conf == conf);
EXPECT_FALSE(TargetJointConf() == conf);
}
{
auto conf = TargetJointConf{};
conf.maxForce = 12_N;
EXPECT_TRUE(conf == conf);
EXPECT_FALSE(TargetJointConf() == conf);
}
}
TEST(TargetJointConf, NotEqualsOperator)
{
EXPECT_FALSE(TargetJointConf() != TargetJointConf());
{
auto conf = TargetJointConf{};
conf.frequency = 13_Hz;
EXPECT_FALSE(conf != conf);
EXPECT_TRUE(TargetJointConf() != conf);
}
}
{
EXPECT_STREQ(
GetName(GetTypeID<TargetJointConf>()),
"d2::TargetJointConf");
}
TEST(TargetJointConf, SetFrequencyFreeFunction)
{
auto def = TargetJointConf{};
const auto frequencyA = 67_Hz;
const auto frequencyB = 2_Hz;
def.frequency = frequencyA;
auto joint = Joint(def);
}
Definition of the BodyConstraint class and closely related code.
Definition of the ConstraintSolverConf class and closely related code.
Definition of the Joint class and closely related code.
Declarations of the StepConf class, and free functions associated with it.
Definition of the TargetJointConf class and closely related code.
Declarations of free functions of World for bodies identified by BodyID.
Definitions of the World class and closely related code.
detail::angular_momentum AngularMomentum
Angular momentum quantity.
Definition: Units.hpp:390
detail::inverse_moment_of_inertia InvRotInertia
Inverse rotational inertia quantity.
Definition: Units.hpp:368
detail::inverse_mass InvMass
Inverse mass quantity.
Definition: Units.hpp:277
detail::force Force
Force quantity.
Definition: Units.hpp:330
bool SolveVelocity(DistanceJointConf &object, const Span< BodyConstraint > &bodies, const StepConf &step)
Solves velocity constraint.
Definition: DistanceJointConf.cpp:169
Mass22 GetEffectiveMassMatrix(const TargetJointConf &object, const BodyConstraint &body) noexcept
Gets the effective mass matrix for the given configuration and body information.
Definition: TargetJointConf.cpp:53
constexpr Momentum2 GetLinearReaction(const DistanceJointConf &object) noexcept
Gets the current linear reaction for the given configuration.
Definition: DistanceJointConf.hpp:175
Length2 GetLocalAnchorB(const GearJointConf &conf)
Gets the local anchor B property of the given joint.
Definition: GearJointConf.cpp:510
Frequency GetFrequency(const Joint &object)
Gets the frequency of the joint if it has this property.
Definition: Joint.cpp:410
BodyID CreateBody(AabbTreeWorld &world, Body body=Body{})
Creates a rigid body that's a copy of the given one.
Definition: AabbTreeWorld.cpp:1019
BodyID GetBodyB(const Joint &object) noexcept
Gets the second body attached to this joint.
Definition: Joint.hpp:295
Length2 GetTarget(const Joint &object)
Gets the given joint's target property if it has one.
Definition: Joint.cpp:462
void ShiftOrigin(AabbTreeWorld &world, const Length2 &newOrigin)
Shifts the world origin.
Definition: AabbTreeWorld.cpp:2221
bool SolvePosition(const DistanceJointConf &object, const Span< BodyConstraint > &bodies, const ConstraintSolverConf &conf)
Solves the position constraint.
Definition: DistanceJointConf.cpp:203
Real GetDampingRatio(const Joint &object)
Gets the given joint's damping ratio property if it has one.
Definition: Joint.cpp:392
BodyID GetBodyA(const Joint &object) noexcept
Gets the first body attached to this joint.
Definition: Joint.hpp:290
TargetJointConf GetTargetJointConf(const Joint &joint)
Gets the definition data for the given joint.
Definition: TargetJointConf.cpp:48
constexpr auto GetMaxForce(const FrictionJointConf &object) noexcept
Free function for getting the max force value of the given configuration.
Definition: FrictionJointConf.hpp:213
Length2 GetAnchorB(const World &world, JointID id)
Definition: WorldJoint.cpp:179
bool GetCollideConnected(const Joint &object) noexcept
Gets collide connected.
Definition: Joint.hpp:300
constexpr void SetFrequency(DistanceJointConf &object, NonNegative< Frequency > value) noexcept
Free function for setting the frequency value of the given configuration.
Definition: DistanceJointConf.hpp:236
constexpr AngularMomentum GetAngularReaction(const DistanceJointConf &) noexcept
Gets the current angular reaction for the given configuration.
Definition: DistanceJointConf.hpp:182
void InitVelocity(DistanceJointConf &object, const Span< BodyConstraint > &bodies, const StepConf &step, const ConstraintSolverConf &conf)
Initializes velocity constraint data based on the given solver data.
Definition: DistanceJointConf.cpp:81
const char * GetName(Manifold::Type type) noexcept
Gets a unique name for the given manifold type.
Definition: Manifold.cpp:633
Real velocity
Velocity quantity type.
Definition: Units.hpp:157
Real frequency
Frequency quantity type.
Definition: Units.hpp:155
Real mass
Mass quantity type.
Definition: Units.hpp:159
Definition: ArrayList.hpp:43
Vector2< Momentum > Momentum2
2-element vector of Momentum quantities.
Definition: Vector2.hpp:76
float Real
Real-number type.
Definition: Real.hpp:69
Matrix22< Mass > Mass22
2 by 2 matrix of Mass elements.
Definition: Matrix.hpp:209
constexpr auto InvalidBodyID
Invalid body ID value.
Definition: BodyID.hpp:50
Vector2< Length > Length2
2-element vector of Length quantities.
Definition: Vector2.hpp:51
detail::IndexingNamedType< BodyCounter, struct BodyIdentifier > BodyID
Body identifier.
Definition: BodyID.hpp:44
static constexpr auto DefaultFrequency
Default frequency.
Definition: TargetJointConf.hpp:63
static constexpr auto DefaultDampingRatio
Default damping ratio.
Definition: TargetJointConf.hpp:66