#include "UnitTests.hpp"
#include <cstring>
TEST(WheelJointConf, DefaultConstruction)
{
WheelJointConf def{};
EXPECT_EQ(def.collideConnected, false);
EXPECT_EQ(def.localAnchorA, (
Length2{}));
EXPECT_EQ(def.localAnchorB, (
Length2{}));
EXPECT_FALSE(def.enableMotor);
EXPECT_EQ(def.maxMotorTorque,
Torque(0));
EXPECT_EQ(def.motorSpeed, 0_rpm);
EXPECT_EQ(def.frequency, 2_Hz);
}
TEST(WheelJointConf, Traits)
{
EXPECT_FALSE((IsIterableV<WheelJointConf>));
EXPECT_FALSE((IsAddableV<WheelJointConf>));
EXPECT_FALSE((IsAddableV<WheelJointConf, WheelJointConf>));
}
TEST(WheelJointConf, Construction)
{
WheelJointConf def;
Joint joint{def};
EXPECT_EQ(
GetType(joint), GetTypeID<WheelJointConf>());
}
{
World world;
auto jd = WheelJointConf{};
jd.bodyA = b0;
jd.bodyB = b1;
jd.localAnchorA =
Length2(4_m, 5_m);
jd.localAnchorB =
Length2(6_m, 7_m);
auto joint = Joint{jd};
}
TEST(WheelJointConf, MotorSpeed)
{
World world;
auto jd = WheelJointConf{};
jd.bodyA = b0;
jd.bodyB = b1;
jd.localAnchorA =
Length2(4_m, 5_m);
jd.localAnchorB =
Length2(6_m, 7_m);
const auto newValue = 5_rad / 1_s;
auto joint = Joint{jd};
}
TEST(WheelJointConf, MaxMotorTorque)
{
World world;
auto jd = WheelJointConf{};
jd.bodyA = b0;
jd.bodyB = b1;
jd.localAnchorA =
Length2(4_m, 5_m);
jd.localAnchorB =
Length2(6_m, 7_m);
const auto newValue = 5_Nm;
auto joint = Joint{jd};
}
TEST(WheelJointConf, GetAnchorAandB)
{
World world;
const auto loc0 =
Length2{+1_m, -3_m};
const auto b0 =
CreateBody(world, BodyConf{}.UseLocation(loc0));
const auto b1 =
CreateBody(world, BodyConf{}.UseLocation(loc1));
auto jd = WheelJointConf{};
jd.bodyA = b0;
jd.bodyB = b1;
jd.localAnchorA =
Length2(4_m, 5_m);
jd.localAnchorB =
Length2(6_m, 7_m);
EXPECT_EQ(
GetAnchorA(world, joint), loc0 + jd.localAnchorA);
EXPECT_EQ(
GetAnchorB(world, joint), loc1 + jd.localAnchorB);
}
{
World world;
const auto loc0 =
Length2{+1_m, -3_m};
const auto loc1 =
Length2{+1_m, +3_m};
const auto b0 =
CreateBody(world, BodyConf{}.UseLocation(loc0));
const auto b1 =
CreateBody(world, BodyConf{}.UseLocation(loc1));
auto jd = WheelJointConf{};
jd.bodyA = b0;
jd.bodyB = b1;
jd.localAnchorA =
Length2(-1_m, 5_m);
jd.localAnchorB =
Length2(+1_m, 5_m);
}
TEST(WheelJointConf, GetWheelJointConfThrows)
{
}
{
WheelJointConf def;
Joint joint{def};
ASSERT_EQ(
GetType(joint), GetTypeID<WheelJointConf>());
EXPECT_EQ(cdef.collideConnected, false);
EXPECT_EQ(cdef.localAnchorA, (
Length2{}));
EXPECT_EQ(cdef.localAnchorB, (
Length2{}));
EXPECT_FALSE(cdef.enableMotor);
EXPECT_EQ(cdef.maxMotorTorque,
Torque(0));
EXPECT_EQ(cdef.motorSpeed, 0_rpm);
EXPECT_EQ(cdef.frequency, 2_Hz);
EXPECT_EQ(cdef.dampingRatio,
Real(0.7f));
}
TEST(WheelJointConf, WithDynamicCircles)
{
auto world = World{};
const auto p1 =
Length2{-1_m, 0_m};
const auto p2 =
Length2{+1_m, 0_m};
const auto shapeId =
CreateShape(world, DiskShapeConf{}.UseRadius(2_m).UseDensity(10_kgpm2));
const auto anchor =
Length2(2_m, 1_m);
auto stepConf = StepConf{};
stepConf.doWarmStart = true;
0.1);
stepConf.doWarmStart = false;
0.1);
}
{
auto world = World{};
auto conf = WheelJointConf{bodyA, bodyB};
EXPECT_EQ(angularVelocity, 0_rpm);
}
{
auto copy = WheelJointConf{};
std::memcpy(©, &jd, sizeof(WheelJointConf));
EXPECT_TRUE(std::memcmp(&jd, ©, sizeof(WheelJointConf)) == 0);
}
TEST(WheelJointConf, EqualsOperator)
{
EXPECT_TRUE(WheelJointConf() == WheelJointConf());
{
auto conf = WheelJointConf{};
conf.localAnchorA =
Length2{1.2_m, -3_m};
EXPECT_TRUE(conf == conf);
EXPECT_FALSE(WheelJointConf() == conf);
}
{
auto conf = WheelJointConf{};
conf.localAnchorB =
Length2{1.2_m, -3_m};
EXPECT_TRUE(conf == conf);
EXPECT_FALSE(WheelJointConf() == conf);
}
{
auto conf = WheelJointConf{};
conf.motorSpeed = 0.12_rpm;
EXPECT_TRUE(conf == conf);
EXPECT_FALSE(WheelJointConf() == conf);
}
}
TEST(WheelJointConf, NotEqualsOperator)
{
EXPECT_FALSE(WheelJointConf() != WheelJointConf());
{
auto conf = WheelJointConf{};
conf.frequency = 13_Hz;
EXPECT_FALSE(conf != conf);
EXPECT_TRUE(WheelJointConf() != conf);
}
}
{
EXPECT_STREQ(
GetName(GetTypeID<WheelJointConf>()),
"d2::WheelJointConf");
}
{
auto conf = WheelJointConf{};
std::vector<BodyConstraint> bodies;
EXPECT_NO_THROW(
InitVelocity(conf, Span<BodyConstraint>(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 = WheelJointConf{};
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 = WheelJointConf{};
std::vector<BodyConstraint> bodies;
auto result = false;
EXPECT_NO_THROW(result =
SolvePosition(conf, bodies, ConstraintSolverConf{}));
EXPECT_TRUE(result);
EXPECT_THROW(
SolvePosition(conf, bodies, ConstraintSolverConf{}), std::out_of_range);
const auto posA = Position{
Length2{-5_m, 0_m}, 0_deg};
EXPECT_NO_THROW(result =
SolvePosition(conf, bodies, ConstraintSolverConf{}));
}
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 Joint class and closely related code.
Declarations of the StepConf class, and free functions associated with it.
Definition of the WheelJointConf class and closely related code.
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.
static constexpr UnitVec GetRight() noexcept
Gets the right-ward oriented unit vector.
Definition: UnitVec.hpp:122
detail::torque Torque
Torque quantity.
Definition: Units.hpp:341
detail::angular_momentum AngularMomentum
Angular momentum quantity.
Definition: Units.hpp:390
detail::moment_of_inertia RotInertia
Rotational inertia quantity.
Definition: Units.hpp:360
detail::length Length
Length quantity.
Definition: Units.hpp:244
detail::angular_velocity AngularVelocity
Angular velocity quantity.
Definition: Units.hpp:311
detail::inverse_moment_of_inertia InvRotInertia
Inverse rotational inertia quantity.
Definition: Units.hpp:368
constexpr auto RadianPerSecond
Radian per second unit of angular velocity.
Definition: Units.hpp:468
constexpr auto Meter
Meter unit of Length.
Definition: Units.hpp:423
constexpr auto NewtonMeter
Newton meter unit of torque.
Definition: Units.hpp:492
WheelJointConf GetWheelJointConf(const Joint &joint)
Gets the definition data for the given joint.
Definition: WheelJointConf.cpp:88
bool SolveVelocity(DistanceJointConf &object, const Span< BodyConstraint > &bodies, const StepConf &step)
Solves velocity constraint.
Definition: DistanceJointConf.cpp:169
bool IsMotorEnabled(const Joint &object)
Gets the specified joint's motor property value if it supports one.
Definition: Joint.cpp:563
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
constexpr UnitVec GetRevPerpendicular(const UnitVec &vector) noexcept
Gets a vector counter-clockwise (reverse-clockwise) perpendicular to the given vector.
Definition: UnitVec.hpp:437
Angle GetAngle(const Body &body) noexcept
Gets the body's angle.
Definition: Body.cpp:280
AngularVelocity GetAngularVelocity(const Body &body) noexcept
Gets the angular velocity.
Definition: Body.hpp:1322
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
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
Torque GetMotorTorque(const Joint &joint, Frequency inv_dt)
Gets the current motor torque for the given joint given the inverse time step.
Definition: Joint.hpp:672
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
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 SetMaxMotorTorque(Joint &object, Torque value)
Sets the given joint's max motor torque if its type supports that.
Definition: Joint.cpp:366
void SetMotorSpeed(Joint &object, AngularVelocity value)
Sets the given joint's motor speed if its type supports that.
Definition: Joint.cpp:272
Length GetJointTranslation(const World &world, JointID id)
Gets the current joint translation.
Definition: WorldJoint.cpp:192
UnitVec GetLocalYAxisA(const Joint &object)
Gets the given joint's local Y axis A if its type supports that.
Definition: Joint.cpp:245
UnitVec GetLocalXAxisA(const Joint &object)
Gets the given joint's local X axis A if its type supports that.
Definition: Joint.cpp:233
Torque GetMaxMotorTorque(const Joint &object)
Gets the given joint's max motor torque if its type supports that.
Definition: Joint.cpp:354
Length2 GetAnchorB(const World &world, JointID id)
Definition: WorldJoint.cpp:179
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 GetAnchorA(const World &world, JointID id)
Definition: WorldJoint.cpp:171
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
void EnableMotor(Joint &object, bool value)
Enables the specified joint's motor property if it supports one.
Definition: Joint.cpp:578
constexpr void SetFrequency(DistanceJointConf &object, NonNegative< Frequency > value) noexcept
Free function for setting the frequency value of the given configuration.
Definition: DistanceJointConf.hpp:236
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
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
constexpr auto StripUnit(const T &value) -> std::enable_if_t< IsArithmeticV< T > &&!detail::is_detected_v< detail::get_member_type, T >, T >
Strips the units off of the given value.
Definition: Units.hpp:926
static constexpr auto DefaultDampingRatio
Default damping ratio.
Definition: WheelJointConf.hpp:79
static constexpr auto DefaultFrequency
Default frequency.
Definition: WheelJointConf.hpp:76