Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to address #560 #571

Merged
merged 2 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions Library/include/playrho/d2/Body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ class Body
/// @post <code>GetInvRotI()</code> returns <code>InvRotInertia{}</code> if
/// <code>bd.type != BodyType::Dynamic</code>, otherwise it returns value of
/// @a bd.invRotI.
/// @post <code>GetTransformation()</code> will return the value of
/// <code>::playrho::d2::GetTransformation(const BodyConf&)</code> given @a bd.
/// @post <code>GetVelocity()</code> will return the value as if
/// <code>SetVelocity(const Velocity&)</code> had been called with the values of
/// @a bd.linearVelocity and @a bd.angularVelocity as the velocity.
Expand Down Expand Up @@ -451,14 +449,10 @@ class Body
static FlagsType GetFlags(const BodyConf& bd) noexcept;

/// Transformation for body origin.
/// @note Also availble from <code>GetTransform1(m_sweep)</code>.
/// @note <code>m_xf.p == m_sweep.pos1.linear && m_xf.q ==
/// UnitVec::Get(m_sweep.pos1.angular)</code>.
/// @note This is a cache of the result of <code>GetTransform1(m_sweep)</code>.
Transformation m_xf;

/// @brief Sweep motion for CCD.
/// @note <code>m_sweep.pos1.linear == m_xf.p && UnitVec::Get(m_sweep.pos1.angular) ==
/// m_xf.q</code>.
Sweep m_sweep;

FlagsType m_flags = 0u; ///< Flags.
Expand Down Expand Up @@ -671,7 +665,7 @@ inline void Body::SetSweep(const Sweep& value) noexcept
{
assert(((m_flags & Body::e_velocityFlag) != 0) || value.pos0 == value.pos1);
m_sweep = value;
m_xf = GetTransform1(value);
m_xf = GetTransform1(m_sweep);
}

inline void Body::SetPosition0(const Position& value) noexcept
Expand All @@ -684,7 +678,7 @@ inline void Body::SetPosition1(const Position& value) noexcept
{
assert(((m_flags & Body::e_velocityFlag) != 0) || m_sweep.pos1 == value);
m_sweep.pos1 = value;
m_xf = ::playrho::d2::GetTransformation(value, m_sweep.localCenter);
m_xf = GetTransform1(m_sweep);
}

inline void Body::ResetAlpha0() noexcept
Expand Down
4 changes: 0 additions & 4 deletions Library/include/playrho/d2/BodyConf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,6 @@ constexpr BodyConf GetDefaultBodyConf() noexcept
/// @relatedalso Body
BodyConf GetBodyConf(const Body& body);

/// @brief Gets the transformation associated with the given configuration.
/// @relatedalso BodyConf
Transformation GetTransformation(const BodyConf& conf) noexcept;

/// @brief Gets the location of the given configuration.
/// @relatedalso BodyConf
constexpr auto GetLocation(const BodyConf& conf) noexcept
Expand Down
8 changes: 5 additions & 3 deletions Library/include/playrho/d2/Transformation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
// IWYU pragma: begin_exports

#include <playrho/Vector2.hpp>

#include <playrho/d2/UnitVec.hpp>

// IWYU pragma: end_exports

namespace playrho {
namespace d2 {
namespace playrho::d2 {

struct BodyConf;

Expand Down Expand Up @@ -79,7 +79,9 @@ constexpr UnitVec GetDirection(const Transformation& value) noexcept
return value.q;
}

} // namespace d2
} // namespace playrho::d2

namespace playrho {

/// @brief Determines if the given value is valid.
/// @relatedalso d2::Transformation
Expand Down
2 changes: 1 addition & 1 deletion Library/source/playrho/d2/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Body::FlagsType Body::GetFlags(const BodyConf& bd) noexcept
}

Body::Body(const BodyConf& bd)
: m_xf{::playrho::d2::GetTransformation(bd)},
: m_xf{GetTransform1(bd.sweep)},
m_sweep{bd.sweep},
m_flags{GetFlags(bd)},
m_invMass{(bd.type == playrho::BodyType::Dynamic)
Expand Down
5 changes: 0 additions & 5 deletions Library/source/playrho/d2/BodyConf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,4 @@ BodyConf GetBodyConf(const Body& body)
return def;
}

Transformation GetTransformation(const BodyConf& conf) noexcept
{
return {conf.sweep.pos0.linear, UnitVec::Get(conf.sweep.pos0.angular)};
}

} // namespace playrho::d2
16 changes: 8 additions & 8 deletions UnitTests/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ TEST(Body, InvMassOnConstruction)

TEST(Body, TransformationOnConstruction)
{
EXPECT_EQ(
Body(BodyConf{}.UseLocation(Length2{10_m, 12_m}).UseAngle(90_deg)).GetTransformation(),
::playrho::d2::GetTransformation(
BodyConf{}.UseLocation(Length2{10_m, 12_m}).UseAngle(90_deg)));
EXPECT_EQ(
Body(BodyConf{}.UseLocation(Length2{4_m, -3_m}).UseAngle(-32_deg)).GetTransformation(),
::playrho::d2::GetTransformation(
BodyConf{}.UseLocation(Length2{4_m, -3_m}).UseAngle(-32_deg)));
{
const auto conf = BodyConf{}.UseLocation(Length2{10_m, 12_m}).UseAngle(90_deg);
EXPECT_EQ(Body(conf).GetTransformation(), GetTransform1(conf.sweep));
}
{
const auto conf = BodyConf{}.UseLocation(Length2{4_m, -3_m}).UseAngle(-32_deg);
EXPECT_EQ(Body(conf).GetTransformation(), GetTransform1(conf.sweep));
}
}

TEST(Body, VelocityOnConstruction)
Expand Down