#include "UnitTests.hpp"
TEST(FrictionJointConf, DefaultConstruction)
{
FrictionJointConf def{};
EXPECT_EQ(def.collideConnected, false);
EXPECT_EQ(def.localAnchorA, (
Length2{}));
EXPECT_EQ(def.localAnchorB, (
Length2{}));
EXPECT_EQ(def.maxForce, 0_N);
EXPECT_EQ(def.maxTorque, 0_Nm);
}
TEST(FrictionJointConf, InitializingConstructor)
{
const auto laA =
Length2{-1_m, 0_m};
const auto laB =
Length2{+1_m, 0_m};
const auto def = FrictionJointConf(bA, bB, laA, laB);
EXPECT_EQ(def.bodyA, bA);
EXPECT_EQ(def.bodyB, bB);
EXPECT_EQ(def.localAnchorA, laA);
EXPECT_EQ(def.localAnchorB, laB);
EXPECT_EQ(def.maxForce, NonNegative<Force>());
EXPECT_EQ(def.maxTorque, NonNegative<Torque>());
EXPECT_EQ(def.linearMass,
Mass22());
}
{
World world{};
const auto p1 =
Length2{-1_m, 0_m};
const auto p2 =
Length2{+1_m, 0_m};
const auto anchor =
Length2{0_m, 0_m};
EXPECT_EQ(def.bodyA, b1);
EXPECT_EQ(def.bodyB, b2);
}
TEST(FrictionJoint, Construction)
{
auto world = World{};
const auto joint = Joint{def};
EXPECT_EQ(
GetType(joint), GetTypeID<FrictionJointConf>());
}
TEST(FrictionJoint, GetFrictionJointConfThrows)
{
}
{
auto world = World{};
const auto joint = Joint{def};
ASSERT_EQ(
GetType(joint), GetTypeID<FrictionJointConf>());
EXPECT_EQ(cdef.bodyA, b0);
EXPECT_EQ(cdef.bodyB, b1);
EXPECT_EQ(cdef.collideConnected, false);
EXPECT_EQ(cdef.localAnchorA, (
Length2{}));
EXPECT_EQ(cdef.localAnchorB, (
Length2{}));
EXPECT_EQ(cdef.maxForce, 0_N);
EXPECT_EQ(cdef.maxTorque, 0_Nm);
}
TEST(FrictionJoint, WithDynamicCircles)
{
World world{};
const auto p1 =
Length2{-1_m, 0_m};
const auto p2 =
Length2{+1_m, 0_m};
const auto s0 =
CreateShape(world, DiskShapeConf{}.UseRadius(0.2_m));
auto jd = FrictionJointConf{};
jd.bodyA = b1;
jd.bodyB = b2;
auto stepConf = StepConf{};
stepConf.doWarmStart = true;
stepConf.doWarmStart = false;
}
{
auto def = FrictionJointConf{};
def.localAnchorA =
Length2{-2_m, +3_m};
def.localAnchorB =
Length2{+2_m, -3_m};
def.maxForce = 2_N;
def.maxTorque = 3_Nm;
def.linearMass =
Mass22{Vector2<Mass>{1_kg, 2_kg}, Vector2<Mass>{3_kg, 4_kg}};
const auto copy = def;
const auto amount =
Length2{1_m, 2_m};
EXPECT_EQ(def.bodyA, copy.bodyA);
EXPECT_EQ(def.bodyB, copy.bodyB);
EXPECT_EQ(def.collideConnected, copy.collideConnected);
EXPECT_EQ(def.localAnchorA, copy.localAnchorA);
EXPECT_EQ(def.localAnchorB, copy.localAnchorB);
EXPECT_EQ(def.maxForce, copy.maxForce);
EXPECT_EQ(def.maxTorque, copy.maxTorque);
EXPECT_EQ(def.linearImpulse, copy.linearImpulse);
EXPECT_EQ(def.angularImpulse, copy.angularImpulse);
EXPECT_EQ(def.rA, copy.rA);
EXPECT_EQ(def.rB, copy.rB);
EXPECT_EQ(def.linearMass, copy.linearMass);
EXPECT_EQ(def.angularMass, copy.angularMass);
}
TEST(FrictionJointConf, GetMotorSpeedThrows)
{
const auto joint = Joint{FrictionJointConf{}};
}
TEST(FrictionJointConf, SetMotorSpeedThrows)
{
auto joint = Joint{FrictionJointConf{}};
EXPECT_THROW(
SetMotorSpeed(joint, 1_rpm), std::invalid_argument);
}
{
auto conf = FrictionJointConf{};
EXPECT_EQ(conf.angularMass, rotInertia);
}
TEST(FrictionJointConf, EqualsOperator)
{
EXPECT_TRUE(FrictionJointConf() == FrictionJointConf());
{
auto conf = FrictionJointConf{};
conf.localAnchorA =
Length2{1.2_m, -3_m};
EXPECT_TRUE(conf == conf);
EXPECT_FALSE(FrictionJointConf() == conf);
}
{
auto conf = FrictionJointConf{};
conf.localAnchorB =
Length2{1.2_m, -3_m};
EXPECT_TRUE(conf == conf);
EXPECT_FALSE(FrictionJointConf() == conf);
}
{
auto conf = FrictionJointConf{};
conf.maxForce = 2.4_N;
EXPECT_TRUE(conf == conf);
EXPECT_FALSE(FrictionJointConf() == conf);
}
{
auto conf = FrictionJointConf{};
conf.maxTorque = 1.5_Nm;
EXPECT_TRUE(conf == conf);
EXPECT_FALSE(FrictionJointConf() == conf);
}
}
TEST(FrictionJointConf, NotEqualsOperator)
{
EXPECT_FALSE(FrictionJointConf() != FrictionJointConf());
{
auto conf = FrictionJointConf{};
EXPECT_FALSE(conf != conf);
EXPECT_TRUE(FrictionJointConf() != conf);
}
}
{
EXPECT_STREQ(
GetName(GetTypeID<FrictionJointConf>()),
"d2::FrictionJointConf");
}
{
auto conf = FrictionJointConf{};
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 = FrictionJointConf{};
std::vector<BodyConstraint> bodies;
auto result = false;
EXPECT_NO_THROW(result =
SolveVelocity(conf, bodies, StepConf{}));
EXPECT_TRUE(result);
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 = FrictionJointConf{};
std::vector<BodyConstraint> bodies;
auto result = false;
EXPECT_NO_THROW(result =
SolvePosition(conf, bodies, ConstraintSolverConf{}));
EXPECT_TRUE(result);
}
Declarations of BodyConf class & free functions associated with it.
Definition of the BodyConstraint class and closely related code.
Definition of the ConstraintSolverConf class and closely related code.
Definition of the DiskShapeConf class and closely related code.
Definition of the FrictionJointConf 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.
Declarations of free functions of World for bodies identified by BodyID.
Declarations of free functions of World for joints identified by JointID.
Declarations of free functions of World for unidentified information.
Declarations of free functions of World for shapes identified by ShapeID.
Definitions of the World class and closely related code.
detail::angular_momentum AngularMomentum
Angular momentum quantity.
Definition: Units.hpp:390
detail::moment_of_inertia RotInertia
Rotational inertia quantity.
Definition: Units.hpp:360
detail::inverse_moment_of_inertia InvRotInertia
Inverse rotational inertia quantity.
Definition: Units.hpp:368
constexpr auto SquareRadian
Square radian unit type.
Definition: Units.hpp:463
constexpr auto GetMaxTorque(const FrictionJointConf &object) noexcept
Free function for getting the max torque value of the given configuration.
Definition: FrictionJointConf.hpp:227
bool SolveVelocity(DistanceJointConf &object, const Span< BodyConstraint > &bodies, const StepConf &step)
Solves velocity constraint.
Definition: DistanceJointConf.cpp:169
constexpr auto GetY(const UnitVec &value) -> decltype(get< 1 >(value))
Gets the "Y" element of the given value - i.e. the second element.
Definition: UnitVec.hpp:499
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
Angle GetAngle(const Body &body) noexcept
Gets the body's angle.
Definition: Body.cpp:280
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
BodyType GetType(const Body &body) noexcept
Gets the type of this body.
Definition: Body.hpp:748
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
ShapeID CreateShape(AabbTreeWorld &world, Shape def)
Creates an identifiable copy of the given shape within this world.
Definition: AabbTreeWorld.cpp:1234
BodyID GetBodyA(const Joint &object) noexcept
Gets the first body attached to this joint.
Definition: Joint.hpp:290
void Attach(AabbTreeWorld &world, BodyID id, ShapeID shapeID)
Associates a validly identified shape with the validly identified body.
Definition: AabbTreeWorld.cpp:2896
Length2 GetLocation(const Body &body) noexcept
Gets the body's origin location.
Definition: Body.hpp:930
void SetMotorSpeed(Joint &object, AngularVelocity value)
Sets the given joint's motor speed if its type supports that.
Definition: Joint.cpp:272
constexpr auto GetMaxForce(const FrictionJointConf &object) noexcept
Free function for getting the max force value of the given configuration.
Definition: FrictionJointConf.hpp:213
Length2 GetLocalPoint(const Body &body, const Length2 &worldPoint) noexcept
Gets a local point relative to the body's origin given a world point.
Definition: Body.hpp:1379
RotInertia GetAngularMass(const Joint &object)
Gets the given joint's angular mass.
Definition: Joint.cpp:290
JointID CreateJoint(AabbTreeWorld &world, Joint def)
Creates a joint to constrain one or more bodies.
Definition: AabbTreeWorld.cpp:1132
Length2 GetLocalAnchorA(const GearJointConf &conf)
Gets the local anchor A property of the given joint.
Definition: GearJointConf.cpp:502
bool GetCollideConnected(const Joint &object) noexcept
Gets collide connected.
Definition: Joint.hpp:300
constexpr auto GetX(const UnitVec &value)
Gets the "X" element of the given value - i.e. the first element.
Definition: UnitVec.hpp:493
FrictionJointConf GetFrictionJointConf(const Joint &joint)
Gets the definition data for the given joint.
Definition: FrictionJointConf.cpp:65
StepStats Step(AabbTreeWorld &world, const StepConf &conf)
Steps the world simulation according to the given configuration.
Definition: AabbTreeWorld.cpp:2144
constexpr AngularMomentum GetAngularReaction(const DistanceJointConf &) noexcept
Gets the current angular reaction for the given configuration.
Definition: DistanceJointConf.hpp:182
AngularVelocity GetMotorSpeed(const Joint &object)
Gets the given joint's motor speed if its type supports that.
Definition: Joint.cpp:257
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
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
constexpr auto InvalidJointID
Invalid joint ID value.
Definition: JointID.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