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::PrismaticJointConf
.
#include "UnitTests.hpp"
#include <PlayRho/Dynamics/Joints/PrismaticJointConf.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/WorldFixture.hpp>
#include <PlayRho/Dynamics/WorldMisc.hpp>
#include <PlayRho/Collision/Shapes/DiskShapeConf.hpp>
{
case 4:
break;
case 8:
break;
case 16:
break;
default:
FAIL();
break;
}
}
{
jd.bodyB = b1;
jd.localAnchorA =
Length2(4_m, 5_m);
jd.localAnchorB =
Length2(6_m, 7_m);
EXPECT_THROW(
GetMaxForce(joint), std::invalid_argument);
EXPECT_THROW(
GetRatio(joint), std::invalid_argument);
EXPECT_THROW(
SetFrequency(joint, 2_Hz), std::invalid_argument);
EXPECT_THROW(
GetTarget(joint), std::invalid_argument);
EXPECT_THROW(
GetLength(joint), std::invalid_argument);
}
{
jd.bodyB = b1;
jd.localAnchorA =
Length2(4_m, 5_m);
jd.localAnchorB =
Length2(6_m, 7_m);
}
{
jd.bodyB = b1;
jd.localAnchorA =
Length2(4_m, 5_m);
jd.localAnchorB =
Length2(6_m, 7_m);
const auto newOrigin =
Length2{1_m, 1_m};
}
{
jd.bodyB = b1;
jd.localAnchorA =
Length2(4_m, 5_m);
jd.localAnchorB =
Length2(6_m, 7_m);
}
{
jd.bodyB = b1;
jd.localAnchorA =
Length2(4_m, 5_m);
jd.localAnchorB =
Length2(6_m, 7_m);
}
{
jd.bodyB = b1;
jd.localAnchorA =
Length2(4_m, 5_m);
jd.localAnchorB =
Length2(6_m, 7_m);
}
{
jd.bodyB = b1;
jd.localAnchorA =
Length2(4_m, 5_m);
jd.localAnchorB =
Length2(6_m, 7_m);
const auto upperValue = +5_m;
const auto lowerValue = -8_m;
}
{
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);
EXPECT_EQ(
GetAnchorA(world, joint), loc0 + jd.localAnchorA);
EXPECT_EQ(
GetAnchorB(world, joint), loc1 + jd.localAnchorB);
}
{
const auto loc0 =
Length2{+1_m, -3_m};
const auto loc1 =
Length2{+1_m, +3_m};
jd.bodyB = b1;
jd.localAnchorA =
Length2(-1_m, 5_m);
jd.localAnchorB =
Length2(+1_m, 5_m);
}
{
const auto loc0 =
Length2{+1_m, -3_m};
const auto loc1 =
Length2{+1_m, +3_m};
jd.bodyB = b1;
jd.localAnchorA =
Length2(-1_m, 5_m);
jd.localAnchorB =
Length2(+1_m, 5_m);
}
{
const auto p1 =
Length2{-1_m, 0_m};
const auto p2 =
Length2{+1_m, 0_m};
const auto anchor =
Length2(2_m, 1_m);
const auto jd =
{
const auto conf = TypeCast<PrismaticJointConf>(
GetJoint(world, joint));
}
{
auto conf = TypeCast<PrismaticJointConf>(
GetJoint(world, joint));
EXPECT_NO_THROW(
SetJoint(world, joint, conf));
}
EXPECT_NO_THROW(
Step(world, 1_s));
{
auto conf = TypeCast<PrismaticJointConf>(
GetJoint(world, joint));
EXPECT_NO_THROW(
SetJoint(world, joint, conf));
}
EXPECT_NO_THROW(
Step(world, 1_s));
{
auto conf = TypeCast<PrismaticJointConf>(
GetJoint(world, joint));
}
EXPECT_NO_THROW(
Step(world, 1_s));
}
{
{
EXPECT_TRUE(conf == conf);
}
{
EXPECT_TRUE(conf == conf);
}
{
EXPECT_TRUE(conf == conf);
}
}
{
{
EXPECT_FALSE(conf != conf);
}
}
{
EXPECT_STREQ(
GetName(GetTypeID<PrismaticJointConf>()),
"d2::PrismaticJointConf");
}
{
conf.localAnchorA =
Length2(4_m, 5_m);
conf.localAnchorB =
Length2(6_m, 7_m);
conf.enableLimit = true;
conf.lowerTranslation = 3_m;
conf.upperTranslation = 44_m;
EXPECT_EQ(conf.bodyA, result.bodyA);
EXPECT_EQ(conf.bodyB, result.bodyB);
EXPECT_EQ(conf.collideConnected, result.collideConnected);
EXPECT_EQ(conf.enableLimit, result.enableLimit);
}
constexpr auto GetMaxForce(const FrictionJointConf &object) noexcept
Free function for getting the max force value of the given configuration.
Definition: FrictionJointConf.hpp:177
@ Static
Static body type.
BodyID CreateBody(World &world, const BodyConf &def)
Creates a rigid body with the given configuration.
Definition: WorldBody.cpp:58
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
Name space for 2-dimensionally related PlayRho names.
Definition: AABB.cpp:34
BodyID bodyA
1st attached body.
Definition: JointConf.hpp:36
UnitVec GetLocalYAxisA(const Joint &object)
Gets the given joint's local Y axis A if its type supports that.
Definition: Joint.cpp:242
static constexpr UnitVec GetRight() noexcept
Gets the right-ward oriented unit vector.
Definition: UnitVec.hpp:74
bool IsLimitEnabled(const Joint &object)
Gets the specified joint's limit property if it supports one.
Definition: Joint.cpp:534
constexpr auto InvalidJointID
Invalid joint ID value.
Definition: JointID.hpp:33
constexpr void SetFrequency(DistanceJointConf &object, NonNegative< Frequency > value) noexcept
Free function for setting the frequency value of the given configuration.
Definition: DistanceJointConf.hpp:205
Angle GetAngularUpperLimit(const Joint &object)
Gets the upper joint limit.
Definition: Joint.cpp:515
AngularMomentum GetAngularMotorImpulse(const Joint &object)
Gets the angular motor impulse of the joint if it has this property.
Definition: Joint.cpp:447
const char * GetName(Manifold::Type type) noexcept
Gets a unique name for the given manifold type.
Definition: Manifold.cpp:788
constexpr auto Newton
Newton unit of force.
Definition: Units.hpp:403
void SetAngularOffset(Joint &object, Angle value)
Sets the angular offset property of the specified joint if its type has one.
Definition: Joint.cpp:621
constexpr auto & GetX(T &value)
Gets the "X" element of the given value - i.e. the first element.
Definition: Math.hpp:66
Name space for all PlayRho related names.
Definition: AABB.cpp:33
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
void SetLinearOffset(Joint &object, Length2 value)
Sets the linear offset property of the specified joint if its type has one.
Definition: Joint.cpp:602
Length GetJointTranslation(const World &world, JointID id)
Gets the current joint translation.
Definition: WorldJoint.cpp:229
constexpr auto RadianPerSecond
Radian per second unit of angular velocity.
Definition: Units.hpp:384
Definition of an independent and simulatable "world".
Definition: World.hpp:129
Length2 GetAnchorB(const World &world, JointID id)
Get the anchor point on body-B in world coordinates.
Definition: WorldJoint.cpp:216
constexpr auto & UseEnableLimit(bool v) noexcept
Uses the given enable limit state value.
Definition: PrismaticJointConf.hpp:74
void EnableMotor(Joint &object, bool value)
Enables the specified joint's motor property if it supports one.
Definition: Joint.cpp:575
constexpr bool ShiftOrigin(DistanceJointConf &, Length2) noexcept
Shifts the origin notion of the given configuration.
Definition: DistanceJointConf.hpp:177
Force GetMotorForce(const World &world, JointID id, Frequency inv_dt)
Gets the current motor force for the given joint, given the inverse time step.
Definition: WorldJoint.hpp:272
bool enableLimit
Enable/disable the joint limit.
Definition: PrismaticJointConf.hpp:135
BodyID GetBodyB(const Contact &contact) noexcept
Gets the body B ID of the given contact.
Definition: Contact.hpp:588
void SetMaxMotorForce(Joint &object, Force value)
Sets the given joint's max motor force if its type supports that.
Definition: Joint.cpp:341
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 BodyConf & UseLocation(Length2 l) noexcept
Use the given location.
Definition: BodyConf.hpp:172
LimitState GetLimitState(const Joint &object)
Definition: Joint.cpp:631
bool IsMotorEnabled(const Joint &object)
Gets the specified joint's motor property value if it supports one.
Definition: Joint.cpp:560
constexpr auto Meter
Meter unit of Length.
Definition: Units.hpp:337
Length GetLinearUpperLimit(const Joint &object)
Gets the upper linear joint limit.
Definition: Joint.cpp:487
UnitVec GetLocalXAxisA(const Joint &object)
Gets the given joint's local X axis A if its type supports that.
Definition: Joint.cpp:230
void SetLinearLimits(Joint &object, Length lower, Length upper)
Sets the joint limits.
Definition: Joint.cpp:496
Torque GetMaxMotorTorque(const Joint &object)
Gets the given joint's max motor torque if its type supports that.
Definition: Joint.cpp:351
JointID CreateJoint(WorldImpl &world, const Joint &def)
Creates a new joint.
Definition: WorldImplJoint.cpp:47
Momentum GetLinearMotorImpulse(const Joint &object)
Definition: Joint.cpp:664
void SetJoint(WorldImpl &world, JointID id, const Joint &def)
Sets the identified joint's new value.
Definition: WorldImplJoint.cpp:62
Angle GetAngularLowerLimit(const Joint &object)
Gets the lower joint limit.
Definition: Joint.cpp:506
Length2 GetLocalAnchorB(const Joint &object)
Get the anchor point on body-B in local coordinates.
Definition: Joint.cpp:96
Angle GetAngle(const UnitVec value)
Gets the angle of the given unit vector.
Definition: Math.hpp:718
PLAYRHO_QUANTITY(boost::units::si::momentum) Momentum
Momentum quantity.
Definition: Units.hpp:293
Length2 GetTarget(const Joint &object)
Gets the given joint's target property if it has one.
Definition: Joint.cpp:459
Length2 GetLinearOffset(const Joint &object)
Gets the linear offset property of the specified joint if its type has one.
Definition: Joint.cpp:593
constexpr UnitVec GetRevPerpendicular(const UnitVec vector) noexcept
Gets a vector counter-clockwise (reverse-clockwise) perpendicular to the given vector.
Definition: UnitVec.hpp:330
PLAYRHO_QUANTITY(boost::units::si::angular_momentum) AngularMomentum
Angular momentum quantity.
Definition: Units.hpp:304
AngularVelocity GetMotorSpeed(const Joint &object)
Gets the given joint's motor speed if its type supports that.
Definition: Joint.cpp:254
Angle GetAngularOffset(const Joint &object)
Gets the angular offset property of the specified joint if its type has one.
Definition: Joint.cpp:612
constexpr auto GetRatio(const GearJointConf &object) noexcept
Free function for getting the ratio value of the given configuration.
Definition: GearJointConf.hpp:205
Frequency GetFrequency(const Joint &object)
Gets the frequency of the joint if it has this property.
Definition: Joint.cpp:407
RotInertia GetAngularMass(const Joint &object)
Gets the given joint's angular mass.
Definition: Joint.cpp:287
Length2 GetGroundAnchorB(const Joint &object)
Definition: Joint.cpp:655
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
Force GetMaxMotorForce(const Joint &object)
Gets the given joint's max motor force if its type supports that.
Definition: Joint.cpp:332
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
void SetTarget(Joint &object, Length2 value)
Sets the given joint's target property if it has one.
Definition: Joint.cpp:468
constexpr auto GetLength(const DistanceJointConf &object) noexcept
Free function for getting the length value of the given configuration.
Definition: DistanceJointConf.hpp:219
Prismatic joint definition.
Definition: PrismaticJointConf.hpp:57
Real GetDampingRatio(const Joint &object)
Gets the given joint's damping ratio property if it has one.
Definition: Joint.cpp:389
void SetMotorSpeed(Joint &object, AngularVelocity value)
Sets the given joint's motor speed if its type supports that.
Definition: Joint.cpp:269
constexpr auto GetMaxTorque(const FrictionJointConf &object) noexcept
Free function for getting the max torque value of the given configuration.
Definition: FrictionJointConf.hpp:191
Vector.
Definition: Vector.hpp:49
Length2 GetAnchorA(const World &world, JointID id)
Get the anchor point on body-A in world coordinates.
Definition: WorldJoint.cpp:208
constexpr Momentum2 GetLinearReaction(const DistanceJointConf &object) noexcept
Gets the current linear reaction for the given configuration.
Definition: DistanceJointConf.hpp:163
A joint-like constraint on one or more bodies.
Definition: Joint.hpp:144
Shape.
Definition: Shape.hpp:183
LinearVelocity2 GetLinearVelocity(const Body &body) noexcept
Gets the linear velocity of the center of mass.
Definition: Body.hpp:1168
constexpr auto & GetY(T &value)
Gets the "Y" element of the given value - i.e. the second element.
Definition: Math.hpp:73
Vector2< Length > Length2
2-element vector of Length quantities.
Definition: Vector2.hpp:43
Length2 GetGroundAnchorA(const Joint &object)
Definition: Joint.cpp:646
Length2 localAnchorB
The local anchor point relative to body B's origin.
Definition: PrismaticJointConf.hpp:119
StepStats Step(WorldImpl &world, const StepConf &conf)
Steps the given world the specified amount.
Definition: WorldImplMisc.cpp:85
Length GetLinearLowerLimit(const Joint &object)
Gets the lower linear joint limit.
Definition: Joint.cpp:478
void EnableLimit(Joint &object, bool value)
Enables the specified joint's limit property if it supports one.
Definition: Joint.cpp:546
PrismaticJointConf GetPrismaticJointConf(const Joint &joint)
Gets the definition data for the given joint.
Definition: PrismaticJointConf.cpp:126
PLAYRHO_QUANTITY(boost::units::si::velocity) LinearVelocity
Linear velocity quantity.
Definition: Units.hpp:167
Length2 localAnchorA
The local anchor point relative to body A's origin.
Definition: PrismaticJointConf.hpp:116
@ e_inactiveLimit
Inactive limit.
Angle referenceAngle
The constrained angle between the bodies: body B's angle minus body A's angle.
Definition: PrismaticJointConf.hpp:128
Disk shape configuration.
Definition: DiskShapeConf.hpp:42