PlayRho
1.1.0
An Interactive Real-Time-Oriented C++ Physics Engine & Library
|
|
This is the googletest
based unit testing file for the free function interfaces to playrho::d2::World
fixture member functions and additional functionality.
#include "UnitTests.hpp"
#include <PlayRho/Dynamics/World.hpp>
#include <PlayRho/Dynamics/WorldImpl.hpp>
#include <PlayRho/Dynamics/WorldBody.hpp>
#include <PlayRho/Dynamics/WorldMisc.hpp>
#include <PlayRho/Dynamics/WorldFixture.hpp>
#include <PlayRho/Collision/Shapes/DiskShapeConf.hpp>
#include <PlayRho/Collision/Shapes/ChainShapeConf.hpp>
TEST(WorldFixture, CreateDestroy)
{
const auto fixtures = std::vector<FixtureID>{};
using ValueType = std::remove_cv_t<std::remove_reference_t<decltype(
GetFixtures(world, body))>>;
auto fixturesRange = ValueType();
EXPECT_NO_THROW(fixturesRange =
GetFixtures(world, body));
ASSERT_EQ(
size(fixturesRange), 1u);
EXPECT_EQ(*begin(fixturesRange), fixture);
EXPECT_NO_THROW(
Destroy(world, fixture));
EXPECT_NO_THROW(fixturesRange =
GetFixtures(world, body));
EXPECT_EQ(
size(fixturesRange), 0u);
}
{
const auto origFilter =
Filter{1u, 2u, 3u};
EXPECT_EQ(origFilter.categoryBits, copyFilter.categoryBits);
EXPECT_EQ(origFilter.maskBits, copyFilter.maskBits);
EXPECT_EQ(origFilter.groupIndex, copyFilter.groupIndex);
}
TEST(WorldFixture, CreateMatchesConf)
{
const auto density = 2_kgpm2;
const auto friction =
Real(0.5);
const auto restitution =
Real(0.4);
const auto isSensor = true;
const auto shapeA =
Shape(conf);
EXPECT_EQ(
GetBody(world, fixture), body);
EXPECT_EQ(
GetShape(world, fixture), shapeA);
EXPECT_EQ(
IsSensor(world, fixture), isSensor);
}
{
const auto bodyCtrPos =
Length2(1_m, 2_m);
}
TEST(WorldFixture, TestPointFreeFunction)
{
const auto bodyCtrPos =
Length2(1_m, 2_m);
EXPECT_TRUE(
TestPoint(world, fixture, bodyCtrPos));
}
const Shape & GetShape(const FixtureConf &conf) noexcept
Gets the shape of the given configuration.
Definition: FixtureConf.hpp:126
BodyID CreateBody(World &world, const BodyConf &def)
Creates a rigid body with the given configuration.
Definition: WorldBody.cpp:58
Name space for 2-dimensionally related PlayRho names.
Definition: AABB.cpp:34
NonNegative< AreaDensity > GetDensity(const Shape &shape) noexcept
Gets the density of the given shape.
Definition: Shape.hpp:304
bool IsSensor(const Contact &contact) noexcept
Gets whether the given contact is for sensors or not.
Definition: Contact.hpp:665
constexpr ConcreteConf & UseRestitution(Finite< Real > value) noexcept
Uses the given restitution.
Definition: ShapeConf.hpp:103
bool isSensor
A sensor shape collects contact information but never generates a collision response.
Definition: FixtureConf.hpp:97
void SetFilterData(FixtureConf &conf, Filter value) noexcept
Sets the filter-data of the given configuration.
Definition: FixtureConf.hpp:175
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
FixtureCounter GetFixtureRange(const World &world) noexcept
Gets the extent of the currently valid fixture range.
Definition: WorldFixture.cpp:33
bool TestPoint(const DistanceProxy &proxy, Length2 point) noexcept
Tests a point for containment in the given distance proxy.
Definition: DistanceProxy.cpp:114
Definition of an independent and simulatable "world".
Definition: World.hpp:129
SizedRange< std::vector< FixtureID >::const_iterator > GetFixtures(const World &world, BodyID id)
Gets the range of all constant fixtures attached to the given body.
Definition: WorldBody.cpp:79
Fixture definition.
Definition: FixtureConf.hpp:46
Real GetFriction(const Shape &shape) noexcept
Gets the coefficient of friction.
Definition: Shape.hpp:294
std::size_t size(const DynamicTree &tree) noexcept
Gets the "size" of the given tree.
Definition: DynamicTree.hpp:773
constexpr BodyConf & UseLocation(Length2 l) noexcept
Use the given location.
Definition: BodyConf.hpp:172
constexpr ConcreteConf & UseFriction(NonNegative< Real > value) noexcept
Uses the given friction.
Definition: ShapeConf.hpp:95
Filter GetFilterData(const FixtureConf &conf) noexcept
Gets the filter-data of the given configuration.
Definition: FixtureConf.hpp:168
detail::IndexingNamedType< FixtureCounter, struct FixtureIdentifier > FixtureID
Fixture identifier.
Definition: FixtureID.hpp:30
void Destroy(World &world, BodyID id)
Destroys the identified body.
Definition: WorldBody.cpp:73
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
Configuration for a body.
Definition: BodyConf.hpp:50
detail::IndexingNamedType< BodyCounter, struct BodyIdentifier > BodyID
Identifier for bodies.
Definition: BodyID.hpp:30
Real GetRestitution(const Shape &shape) noexcept
Gets the coefficient of restitution value of the given shape.
Definition: Shape.hpp:299
Vector.
Definition: Vector.hpp:49
BodyID GetBody(const FixtureConf &conf) noexcept
Gets the body of the given configuration.
Definition: FixtureConf.hpp:119
void SetSensor(FixtureConf &conf, bool value) noexcept
Sets whether or not the given configuration is a sensor.
Definition: FixtureConf.hpp:161
Shape.
Definition: Shape.hpp:183
A holder for contact filtering data.
Definition: Filter.hpp:33
Vector2< Length > Length2
2-element vector of Length quantities.
Definition: Vector2.hpp:43
Disk shape configuration.
Definition: DiskShapeConf.hpp:42