PlayRho
1.1.0
An Interactive Real-Time-Oriented C++ Physics Engine & Library
|
|
This is the googletest
based unit testing file for the interfaces to playrho::d2::DistanceJointConf
.
#include "UnitTests.hpp"
#include <PlayRho/Dynamics/Joints/DistanceJointConf.hpp>
#include <PlayRho/Dynamics/Joints/Joint.hpp>
#include <PlayRho/Dynamics/World.hpp>
#include <PlayRho/Dynamics/WorldJoint.hpp>
#include <PlayRho/Dynamics/WorldBody.hpp>
#include <PlayRho/Dynamics/WorldMisc.hpp>
#include <PlayRho/Dynamics/WorldFixture.hpp>
#include <PlayRho/Dynamics/StepConf.hpp>
#include <PlayRho/Dynamics/BodyConf.hpp>
#include <PlayRho/Collision/Shapes/DiskShapeConf.hpp>
#include <stdexcept>
{
case 4:
break;
case 8:
break;
case 16:
break;
default:
FAIL();
break;
}
}
{
EXPECT_EQ(def.collideConnected, false);
EXPECT_EQ(def.localAnchorA, (
Length2{}));
EXPECT_EQ(def.localAnchorB, (
Length2{}));
EXPECT_EQ(def.length, 1_m);
EXPECT_EQ(def.frequency, 0_Hz);
EXPECT_EQ(def.dampingRatio,
Real(0));
}
{
const auto value =
Length(31_m);
}
{
const auto value = 19_Hz;
}
{
const auto value =
Real(0.4);
}
{
EXPECT_THROW(TypeCast<int>(joint), std::bad_cast);
EXPECT_NO_THROW(TypeCast<DistanceJointConf>(joint));
}
TEST(DistanceJoint, Construction)
{
EXPECT_EQ(
GetType(world, joint), GetTypeID<DistanceJointConf>());
EXPECT_EQ(
GetBodyA(world, joint), def.bodyA);
EXPECT_EQ(
GetBodyB(world, joint), def.bodyB);
EXPECT_EQ(
GetLength(world, joint), def.length);
}
{
const auto newOrigin =
Length2{1_m, 1_m};
}
TEST(DistanceJoint, InZeroGravBodiesMoveOutToLength)
{
const auto location1 =
Length2{-1_m, 0_m};
const auto body1 =
const auto location2 =
Length2{+1_m, 0_m};
const auto body2 =
jointdef.bodyB = body2;
jointdef.collideConnected = false;
jointdef.length = 5_m;
jointdef.frequency = 0_Hz;
jointdef.dampingRatio = 0;
auto distanceMet = 0u;
for (auto i = 0u; !distanceMet || i < distanceMet + 100; ++i) {
const auto newDistance =
if (distanceMet) {
}
else {
EXPECT_GE(newDistance, oldDistance);
}
if (!distanceMet && (
abs(newDistance - jointdef.length) < 0.01_m)) {
distanceMet = i;
}
oldDistance = newDistance;
}
}
TEST(DistanceJoint, InZeroGravBodiesMoveInToLength)
{
const auto location1 =
Length2{-10_m, 10_m};
const auto body1 =
const auto location2 =
Length2{+10_m, -10_m};
const auto body2 =
jointdef.bodyB = body2;
jointdef.collideConnected = false;
jointdef.length = 5_m;
jointdef.frequency = 60_Hz;
jointdef.dampingRatio = 0;
auto distanceMet = 0u;
for (auto i = 0u; !distanceMet || i < distanceMet + 1000; ++i) {
const auto newDistance =
if (!distanceMet && (newDistance - oldDistance) >= 0_m) {
distanceMet = i;
}
if (distanceMet) {
}
else {
EXPECT_LE(newDistance, oldDistance);
}
oldDistance = newDistance;
}
EXPECT_NEAR(
double(
Real{oldDistance /
Meter}),
double(
Real{jointdef.length /
Meter}), 0.1);
}
{
def.bodyB = bB;
def.collideConnected = false;
def.localAnchorA =
Length2(21_m, -2_m);
def.localAnchorB =
Length2(13_m, 12_m);
def.length = 5_m;
def.frequency = 67_Hz;
def.dampingRatio =
Real(0.8);
EXPECT_EQ(def.bodyA, got.bodyA);
EXPECT_EQ(def.bodyB, got.bodyB);
EXPECT_EQ(def.localAnchorA, got.localAnchorA);
EXPECT_EQ(def.localAnchorB, got.localAnchorB);
EXPECT_EQ(def.length, got.length);
EXPECT_EQ(def.frequency, got.frequency);
EXPECT_EQ(def.dampingRatio, got.dampingRatio);
}
{
def.bodyB = bB;
def.collideConnected = false;
def.localAnchorA =
Length2(21_m, -2_m);
def.localAnchorB =
Length2(13_m, 12_m);
def.length = 5_m;
def.frequency = 67_Hz;
def.dampingRatio =
Real(0.8);
}
{
}
{
EXPECT_THROW(
SetMotorSpeed(joint, 1_rpm), std::invalid_argument);
}
{
def.localAnchorA =
Length2(21_m, -2_m);
def.localAnchorB =
Length2(13_m, 12_m);
def.length = 5_m;
def.frequency = 67_Hz;
def.dampingRatio =
Real(0.8);
}
{
{
EXPECT_TRUE(conf == conf);
}
{
EXPECT_TRUE(conf == conf);
}
{
EXPECT_TRUE(conf == conf);
}
{
EXPECT_TRUE(conf == conf);
}
}
{
{
EXPECT_FALSE(conf != conf);
}
}
{
EXPECT_STREQ(
GetName(GetTypeID<DistanceJointConf>()),
"d2::DistanceJointConf");
}
constexpr auto & UseDampingRatio(Real v) noexcept
Uses the given damping ratio.
Definition: DistanceJointConf.hpp:83
@ Static
Static body type.
constexpr auto RadianPerSquareSecond
Radian per square second unit of angular acceleration.
Definition: Units.hpp:394
constexpr auto MeterPerSquareSecond
Meter per square second unit of linear acceleration.
Definition: Units.hpp:345
BodyID CreateBody(World &world, const BodyConf &def)
Creates a rigid body with the given configuration.
Definition: WorldBody.cpp:58
Real dampingRatio
Damping ratio.
Definition: DistanceJointConf.hpp:109
constexpr BodyConf & UseType(BodyType t) noexcept
Use the given type.
Definition: BodyConf.hpp:166
PLAYRHO_QUANTITY(boost::units::si::length) Length
Length quantity.
Definition: Units.hpp:158
Length2 localAnchorA
Local anchor point relative to body A's origin.
Definition: DistanceJointConf.hpp:91
Name space for 2-dimensionally related PlayRho names.
Definition: AABB.cpp:34
BodyID bodyA
1st attached body.
Definition: JointConf.hpp:36
constexpr auto InvalidJointID
Invalid joint ID value.
Definition: JointID.hpp:33
auto GetMagnitude(T value)
Gets the magnitude of the given value.
Definition: Math.hpp:329
constexpr void SetFrequency(DistanceJointConf &object, NonNegative< Frequency > value) noexcept
Free function for setting the frequency value of the given configuration.
Definition: DistanceJointConf.hpp:205
const char * GetName(Manifold::Type type) noexcept
Gets a unique name for the given manifold type.
Definition: Manifold.cpp:788
constexpr ConcreteConf & UseDensity(NonNegative< AreaDensity > value) noexcept
Uses the given density.
Definition: ShapeConf.hpp:111
Name space for all PlayRho related names.
Definition: AABB.cpp:33
Length2 localAnchorB
Local anchor point relative to body B's origin.
Definition: DistanceJointConf.hpp:95
const Joint & GetJoint(const WorldImpl &world, JointID id)
Gets the identified joint's value.
Definition: WorldImplJoint.cpp:57
Length2 GetLocalAnchorA(const Joint &object)
Get the anchor point on body-A in local coordinates.
Definition: Joint.cpp:62
constexpr auto & UseLength(Length v) noexcept
Uses the given length.
Definition: DistanceJointConf.hpp:69
Definition of an independent and simulatable "world".
Definition: World.hpp:129
constexpr auto InvalidFixtureID
Invalid fixture ID value.
Definition: FixtureID.hpp:33
constexpr auto & UseFrequency(NonNegative< Frequency > v) noexcept
Uses the given frequency.
Definition: DistanceJointConf.hpp:76
LinearVelocity bias
Bias. 4-bytes (with 4-byte Real).
Definition: DistanceJointConf.hpp:121
constexpr bool ShiftOrigin(DistanceJointConf &, Length2) noexcept
Shifts the origin notion of the given configuration.
Definition: DistanceJointConf.hpp:177
BodyID GetBodyB(const Contact &contact) noexcept
Gets the body B ID of the given contact.
Definition: Contact.hpp:588
bool GetCollideConnected(const Joint &object) noexcept
Gets collide connected.
Definition: Joint.hpp:293
DistanceJointConf GetDistanceJointConf(const Joint &joint) noexcept
Gets the definition data for the given joint.
Definition: DistanceJointConf.cpp:68
BodyID GetBodyA(const Contact &contact) noexcept
Gets the body A ID of the given contact.
Definition: Contact.hpp:581
Angle GetReferenceAngle(const Joint &object)
Gets the reference angle of the joint if it has one.
Definition: Joint.cpp:215
constexpr auto Meter
Meter unit of Length.
Definition: Units.hpp:337
std::add_pointer_t< std::add_const_t< T > > TypeCast(const Shape *value) noexcept
Converts the given shape into its current configuration value.
Definition: Shape.hpp:610
JointID CreateJoint(WorldImpl &world, const Joint &def)
Creates a new joint.
Definition: WorldImplJoint.cpp:47
Length2 GetLocalAnchorB(const Joint &object)
Get the anchor point on body-B in local coordinates.
Definition: Joint.cpp:96
constexpr Fixed< BT, FB > abs(Fixed< BT, FB > arg)
Computes the absolute value.
Definition: FixedMath.hpp:48
constexpr auto InvalidBodyID
Invalid body ID value.
Definition: BodyID.hpp:33
PLAYRHO_QUANTITY(boost::units::si::angular_momentum) AngularMomentum
Angular momentum quantity.
Definition: Units.hpp:304
Step configuration.
Definition: StepConf.hpp:42
AngularVelocity GetMotorSpeed(const Joint &object)
Gets the given joint's motor speed if its type supports that.
Definition: Joint.cpp:254
Frequency GetFrequency(const Joint &object)
Gets the frequency of the joint if it has this property.
Definition: Joint.cpp:407
NonNegative< Frequency > frequency
Mass-spring-damper frequency.
Definition: DistanceJointConf.hpp:104
constexpr AngularMomentum GetAngularReaction(const DistanceJointConf &) noexcept
Gets the current angular reaction for the given configuration.
Definition: DistanceJointConf.hpp:170
FixtureID CreateFixture(World &world, FixtureConf def, bool resetMassData)
Creates a fixture within the specified world.
Definition: WorldFixture.cpp:48
float Real
Real-number type.
Definition: Real.hpp:69
constexpr DiskShapeConf & UseRadius(NonNegative< Length > r) noexcept
Uses the given value as the radius.
Definition: DiskShapeConf.hpp:65
Configuration for a body.
Definition: BodyConf.hpp:50
constexpr Length2 GetLocation(const Transformation &value) noexcept
Gets the location information from the given transformation.
Definition: Transformation.hpp:69
constexpr auto GetLength(const DistanceJointConf &object) noexcept
Free function for getting the length value of the given configuration.
Definition: DistanceJointConf.hpp:219
Real GetDampingRatio(const Joint &object)
Gets the given joint's damping ratio property if it has one.
Definition: Joint.cpp:389
Distance joint definition.
Definition: DistanceJointConf.hpp:52
void SetMotorSpeed(Joint &object, AngularVelocity value)
Sets the given joint's motor speed if its type supports that.
Definition: Joint.cpp:269
Vector.
Definition: Vector.hpp:49
TypeID GetType(const Shape &shape) noexcept
Gets the type info of the use of the given shape.
Definition: Shape.hpp:329
constexpr Momentum2 GetLinearReaction(const DistanceJointConf &object) noexcept
Gets the current linear reaction for the given configuration.
Definition: DistanceJointConf.hpp:163
2-D acceleration related data structure.
Definition: Acceleration.hpp:33
A joint-like constraint on one or more bodies.
Definition: Joint.hpp:144
Shape.
Definition: Shape.hpp:183
Length length
Natural length between the anchor points.
Definition: DistanceJointConf.hpp:99
Vector2< Length > Length2
2-element vector of Length quantities.
Definition: Vector2.hpp:43
void SetAccelerations(World &world, Acceleration acceleration) noexcept
Sets the accelerations of all the world's bodies to the given value.
Definition: WorldBody.cpp:558
StepStats Step(WorldImpl &world, const StepConf &conf)
Steps the given world the specified amount.
Definition: WorldImplMisc.cpp:85
bool collideConnected
Collide connected.
Definition: JointConf.hpp:43
Disk shape configuration.
Definition: DiskShapeConf.hpp:42