Skip to content

Commit

Permalink
Merge pull request #383 from louis-langholtz/thanksgiving-2020
Browse files Browse the repository at this point in the history
Thanksgiving 2020
  • Loading branch information
louis-langholtz authored Nov 29, 2020
2 parents 7912a53 + cc1b191 commit 38bc039
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 41 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ endforeach()

# Set name for entire project. This establishes the project name in <PROJECT_NAME>_* variables.
# Details at: https://cmake.org/cmake/help/latest/command/project.html#command:project
project(PlayRho VERSION 0.13.1)
project(PlayRho VERSION 0.14.0)
# Now PlayRho_VERSION set to version above.
# PlayRho_VERSION_MAJOR set to first component.
# PlayRho_VERSION_MINOR set to second component.
Expand Down
2 changes: 1 addition & 1 deletion PlayRho/Collision/RayCastOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ RayCastOutput RayCast(Length radius, Length2 location, const RayCastInput& input
return RayCastOutput{};
}

RayCastOutput RayCast(const AABB& aabb, const RayCastInput& input) noexcept
RayCastOutput RayCast(const ::playrho::detail::AABB<2>& aabb, const RayCastInput& input) noexcept
{
// From Real-time Collision Detection, p179.

Expand Down
3 changes: 1 addition & 2 deletions PlayRho/Collision/RayCastOutput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ RayCastOutput RayCast(Length radius, Length2 location, const RayCastInput& input
/// @brief Cast a ray against the given AABB.
/// @param aabb Axis Aligned Bounding Box.
/// @param input the ray-cast input parameters.
RayCastOutput RayCast(const ::playrho::detail::AABB<2>& aabb,
const RayCastInput& input) noexcept;
RayCastOutput RayCast(const ::playrho::detail::AABB<2>& aabb, const RayCastInput& input) noexcept;

/// @brief Cast a ray against the distance proxy.
/// @param proxy Distance-proxy object (in local coordinates).
Expand Down
5 changes: 4 additions & 1 deletion PlayRho/Common/ArrayList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@

namespace playrho {

/// Array list.
/// @brief Array list.
/// @details This is a <code>std::array</code> backed <code>std::vector</code> like container. It
/// provides vector like behavior whose max size is capped at the size given by the template max
/// size parameter without using dynamic storage.
template <typename VALUE_TYPE, std::size_t MAXSIZE, typename SIZE_TYPE = std::size_t>
class ArrayList
{
Expand Down
15 changes: 10 additions & 5 deletions PlayRho/Common/BlockAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@

namespace playrho {

static_assert(size(AllocatorBlockSizes) == 14,
static_assert(size(BlockAllocator::AllocatorBlockSizes) == 14,
"Invalid number of elements of AllocatorBlockSizes");
static_assert(BlockAllocator::GetMaxBlockSize() == 640,
"Invalid maximum block size of AllocatorBlockSizes");

namespace {

#if 0
struct LookupTable
{
Expand All @@ -40,7 +42,7 @@ struct LookupTable
elements[0] = 0;
for (auto i = std::size_t{1}; i < maxIndex; ++i)
{
if (i > AllocatorBlockSizes[j])
if (i > BlockAllocator::AllocatorBlockSizes[j])
{
++j;
}
Expand All @@ -50,11 +52,12 @@ struct LookupTable

std::uint8_t elements[BlockAllocator::GetMaxBlockSize() + 1];
};
static constexpr LookupTable BlockSizeLookup;

constexpr LookupTable BlockSizeLookup;
#endif

/// @brief Block size lookup array.
static constexpr std::uint8_t s_blockSizeLookup[BlockAllocator::GetMaxBlockSize() + 1] =
constexpr std::uint8_t s_blockSizeLookup[BlockAllocator::GetMaxBlockSize() + 1] =
{
0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1-16
Expand All @@ -81,12 +84,14 @@ static constexpr std::uint8_t s_blockSizeLookup[BlockAllocator::GetMaxBlockSize(
};

/// @brief Gets the block size index for the given data block size.
static inline std::uint8_t GetBlockSizeIndex(std::size_t n)
inline std::uint8_t GetBlockSizeIndex(std::size_t n)
{
assert(n < size(s_blockSizeLookup));
return s_blockSizeLookup[n];
}

} // namespace

/// @brief Chunk.
struct BlockAllocator::Chunk
{
Expand Down
13 changes: 6 additions & 7 deletions PlayRho/Common/BlockAllocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@

namespace playrho {

/// @brief Allocator block sizes array data.
constexpr std::size_t AllocatorBlockSizes[] =
{
16, 32, 64, 96, 128, 160, 192, 224, 256, 320, 384, 448, 512, 640,
};

/// Block allocator.
///
/// This is a small object allocator used for allocating small
Expand All @@ -40,10 +34,15 @@ namespace playrho {
class BlockAllocator
{
public:

/// @brief Size type.
using size_type = std::size_t;

/// @brief Allocator block sizes array data.
static constexpr std::size_t AllocatorBlockSizes[] =
{
16, 32, 64, 96, 128, 160, 192, 224, 256, 320, 384, 448, 512, 640,
};

/// @brief Chunk size.
static constexpr auto ChunkSize = size_type{16 * 1024};

Expand Down
5 changes: 4 additions & 1 deletion PlayRho/Common/Math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@ constexpr auto GetZ(const T& value)
return get<2>(value);
}

/// @brief Makes the given value into an unsigned value.
/// @brief Makes the given **value** into an **unsigned value**.
/// @note If the given value is negative, this will result in an unsigned value which is the
/// two's complement modulo-wrapped value.
/// @note This is different from <code>std::make_unsigned</code> in that this changes the **value**
/// to the value in the type that's the unsigned type equivalent of the input value.
/// <code>std::make_unsigned</code> merely provides the unsigned **type** equivalent.
template <typename T>
constexpr std::enable_if_t<std::is_signed<T>::value, std::make_unsigned_t<T>>
MakeUnsigned(const T& arg) noexcept
Expand Down
23 changes: 7 additions & 16 deletions PlayRho/Common/Templates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,13 @@ using std::swap;

namespace detail {

/// @brief Voiding template class.
template<class...> struct Voidify {
/// @brief Type alias.
using type = void;
};

/// @brief Void type templated alias.
template<class... Ts> using VoidT = typename Voidify<Ts...>::type;

/// @brief Low-level implementation of the is-iterable default value trait.
template<class T, class = void>
struct IsIterableImpl: std::false_type {};

/// @brief Low-level implementation of the is-iterable true value trait.
template<class T>
struct IsIterableImpl<T, VoidT<
struct IsIterableImpl<T, std::void_t<
decltype(begin(std::declval<T>())),
decltype(end(std::declval<T>())),
decltype(++std::declval<decltype(begin(std::declval<T&>()))&>()),
Expand Down Expand Up @@ -183,39 +174,39 @@ struct IsEqualityComparable: std::false_type {};

/// @brief Template specialization for equality comparable types.
template<class T1, class T2>
struct IsEqualityComparable<T1, T2, detail::VoidT<decltype(T1{} == T2{})> >: std::true_type {};
struct IsEqualityComparable<T1, T2, std::void_t<decltype(T1{} == T2{})> >: std::true_type {};

/// @brief Template for determining if the given type is an inequality comparable type.
template<class T1, class T2, class = void>
struct IsInequalityComparable: std::false_type {};

/// @brief Template specialization for inequality comparable types.
template<class T1, class T2>
struct IsInequalityComparable<T1, T2, detail::VoidT<decltype(T1{} != T2{})> >: std::true_type {};
struct IsInequalityComparable<T1, T2, std::void_t<decltype(T1{} != T2{})> >: std::true_type {};

/// @brief Template for determining if the given types are addable.
template<class T1, class T2 = T1, class = void>
struct IsAddable: std::false_type {};

/// @brief Template specializing for addable types.
template<class T1, class T2>
struct IsAddable<T1, T2, detail::VoidT<decltype(T1{} + T2{})> >: std::true_type {};
struct IsAddable<T1, T2, std::void_t<decltype(T1{} + T2{})> >: std::true_type {};

/// @brief Template for determining if the given types are multipliable.
template<class T1, class T2, class = void>
struct IsMultipliable: std::false_type {};

/// @brief Template specializing for multipliable types.
template<class T1, class T2>
struct IsMultipliable<T1, T2, detail::VoidT<decltype(T1{} * T2{})> >: std::true_type {};
struct IsMultipliable<T1, T2, std::void_t<decltype(T1{} * T2{})> >: std::true_type {};

/// @brief Template for determining if the given types are divisable.
template<class T1, class T2, class = void>
struct IsDivisable: std::false_type {};

/// @brief Template specializing for divisable types.
template<class T1, class T2>
struct IsDivisable<T1, T2, detail::VoidT<decltype(T1{} / T2{})> >: std::true_type {};
struct IsDivisable<T1, T2, std::void_t<decltype(T1{} / T2{})> >: std::true_type {};

/// @brief Template for determining if the given type is an "arithmetic" type.
/// @note In the context of this library, "arithmetic" types are all types which
Expand All @@ -225,7 +216,7 @@ struct IsArithmetic: std::false_type {};

/// @brief Template specialization for valid/acceptable "arithmetic" types.
template<class T>
struct IsArithmetic<T, detail::VoidT<
struct IsArithmetic<T, std::void_t<
decltype(T{} + T{}), decltype(T{} - T{}), decltype(T{} * T{}), decltype(T{} / T{})
> >: std::true_type {};

Expand Down
7 changes: 0 additions & 7 deletions UnitTests/DistanceJoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,7 @@ TEST(DistanceJointConf, SetMotorSpeedThrows)

TEST(DistanceJointConf, SetFrequencyFreeFunction)
{
auto world = World{};
const auto bA = CreateBody(world);
ASSERT_NE(bA, InvalidBodyID);
const auto bB = CreateBody(world);
ASSERT_NE(bB, InvalidBodyID);
auto def = DistanceJointConf{};
def.bodyA = bA;
def.bodyB = bB;
def.collideConnected = false;
def.localAnchorA = Length2(21_m, -2_m);
def.localAnchorB = Length2(13_m, 12_m);
Expand Down
12 changes: 12 additions & 0 deletions UnitTests/TargetJoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,15 @@ TEST(TargetJointConf, GetName)
{
EXPECT_STREQ(GetName(GetTypeID<TargetJointConf>()), "d2::TargetJointConf");
}

TEST(TargetJointConf, SetFrequencyFreeFunction)
{
auto def = TargetJointConf{};
const auto frequencyA = 67_Hz;
const auto frequencyB = 2_Hz;
def.frequency = frequencyA;
auto joint = Joint(def);
EXPECT_EQ(GetFrequency(joint), frequencyA);
EXPECT_NO_THROW(SetFrequency(joint, frequencyB));
EXPECT_EQ(GetFrequency(joint), frequencyB);
}
12 changes: 12 additions & 0 deletions UnitTests/WeldJoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,15 @@ TEST(WeldJointConf, GetName)
{
EXPECT_STREQ(GetName(GetTypeID<WeldJointConf>()), "d2::WeldJointConf");
}

TEST(WeldJointConf, SetFrequencyFreeFunction)
{
auto def = WeldJointConf{};
const auto frequencyA = 67_Hz;
const auto frequencyB = 2_Hz;
def.frequency = frequencyA;
auto joint = Joint(def);
EXPECT_EQ(GetFrequency(joint), frequencyA);
EXPECT_NO_THROW(SetFrequency(joint, frequencyB));
EXPECT_EQ(GetFrequency(joint), frequencyB);
}
12 changes: 12 additions & 0 deletions UnitTests/WheelJoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,18 @@ TEST(WheelJointConf, WithDynamicCircles)
0.1);
}

TEST(WheelJointConf, GetAngularVelocity)
{
auto world = World{};
const auto bodyA = world.CreateBody();
const auto bodyB = world.CreateBody();
auto conf = WheelJointConf{bodyA, bodyB};
auto angularVelocity = AngularVelocity{};
EXPECT_NO_THROW(angularVelocity = GetAngularVelocity(world, conf));
EXPECT_EQ(angularVelocity, 0_rpm);
// TODO: add tests for angularVelocity other than 0 rpm
}

TEST(WheelJointConf, ShiftOrigin)
{
auto jd = WheelJointConf{BodyID(0u), BodyID(1u)};
Expand Down
2 changes: 2 additions & 0 deletions UnitTests/WorldJoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ TEST(WorldJoint, GetSetMotorSpeed)
EXPECT_EQ(GetMotorSpeed(world, id), motorSpeed);
EXPECT_NO_THROW(SetMotorSpeed(world, id, newValue));
EXPECT_EQ(GetMotorSpeed(world, id), newValue);
EXPECT_THROW(GetLocalXAxisA(world, id), std::invalid_argument);
EXPECT_THROW(GetLocalYAxisA(world, id), std::invalid_argument);
}

TEST(WorldJoint, GetWorldIndexFreeFunction)
Expand Down

0 comments on commit 38bc039

Please sign in to comment.