@@ -41,40 +41,43 @@ namespace d2 {
4141class Sweep
4242{
4343public:
44-
4544 // / @brief Default constructor.
4645 Sweep () = default ;
47-
46+
4847 // / @brief Copy constructor.
4948 constexpr Sweep (const Sweep& copy) = default;
50-
49+
5150 // / @brief Initializing constructor.
52- constexpr Sweep (const Position p0, const Position p1,
53- const Length2 lc = Length2{0_m, 0_m},
54- Real a0 = 0 ) noexcept :
55- pos0{p0}, pos1{p1}, localCenter{lc}, alpha0{a0}
51+ constexpr Sweep (const Position p0, const Position p1, const Length2 lc = Length2{0_m, 0_m},
52+ Real a0 = 0 ) noexcept
53+ : pos0{p0}, pos1{p1}, localCenter{lc}, alpha0{a0}
5654 {
5755 assert (a0 >= 0 );
5856 assert (a0 < 1 );
5957 }
60-
58+
6159 // / @brief Initializing constructor.
62- constexpr explicit Sweep (const Position p,
63- const Length2 lc = Length2{0_m, 0_m}):
64- Sweep{p, p, lc, 0 }
60+ constexpr explicit Sweep (const Position p, const Length2 lc = Length2{0_m, 0_m})
61+ : Sweep{p, p, lc, 0 }
6562 {
6663 // Intentionally empty.
6764 }
68-
65+
6966 // / @brief Gets the local center of mass position.
7067 // / @note This value can only be set via a sweep constructed using an initializing
7168 // / constructor.
72- Length2 GetLocalCenter () const noexcept { return localCenter; }
73-
69+ Length2 GetLocalCenter () const noexcept
70+ {
71+ return localCenter;
72+ }
73+
7474 // / @brief Gets the alpha 0 for this sweep.
7575 // / @return Value between 0 and less than 1.
76- Real GetAlpha0 () const noexcept { return alpha0; }
77-
76+ Real GetAlpha0 () const noexcept
77+ {
78+ return alpha0;
79+ }
80+
7881 // / @brief Advances the sweep by a factor of the difference between the given time alpha
7982 // / and the sweep's alpha 0.
8083 // / @details This advances position 0 (<code>pos0</code>) of the sweep towards position
@@ -85,22 +88,22 @@ class Sweep
8588 // / undefined if value is invalid.
8689 // /
8790 void Advance0 (Real alpha) noexcept ;
88-
91+
8992 // / @brief Resets the alpha 0 value back to zero.
9093 // / @post Getting the alpha 0 value after calling this method will return zero.
9194 void ResetAlpha0 () noexcept ;
92-
95+
9396 // / @brief Center world position and world angle at time "0".
9497 Position pos0;
9598
9699 // / @brief Center world position and world angle at time "1".
97100 Position pos1;
98-
101+
99102private:
100103 // / @brief Local center of mass position.
101104 // / @note 8-bytes.
102105 Length2 localCenter = Length2{0_m, 0_m};
103-
106+
104107 // / @brief Fraction of the current time step in the range [0,1]
105108 // / @note <code>pos0.linear</code> and <code>pos0.angular</code> are the positions at
106109 // / <code>alpha0</code>.
@@ -114,7 +117,7 @@ inline void Sweep::Advance0(const Real alpha) noexcept
114117 assert (alpha >= 0 );
115118 assert (alpha < 1 );
116119 assert (alpha0 < 1 );
117-
120+
118121 const auto beta = (alpha - alpha0) / (1 - alpha0);
119122 pos0 = GetPosition (pos0, pos1, beta);
120123 alpha0 = alpha;
@@ -127,15 +130,32 @@ inline void Sweep::ResetAlpha0() noexcept
127130
128131// Free functions...
129132
133+ // / @brief Equals operator.
134+ // / @relatedalso Sweep
135+ constexpr bool operator ==(const Sweep& lhs, const Sweep& rhs)
136+ {
137+ return lhs.pos0 == rhs.pos0 && //
138+ lhs.pos1 == rhs.pos1 && //
139+ lhs.GetLocalCenter () == rhs.GetLocalCenter () && //
140+ lhs.GetAlpha0 () == rhs.GetAlpha0 ();
141+ }
142+
143+ // / @brief Not-equals operator.
144+ // / @relatedalso Sweep
145+ constexpr bool operator !=(const Sweep& lhs, const Sweep& rhs)
146+ {
147+ return !(lhs == rhs);
148+ }
149+
130150} // namespace d2
131151
132152// / @brief Determines if the given value is valid.
133- // / @relatedalso d2::Transformation
153+ // / @relatedalso d2::Sweep
134154template <>
135155constexpr bool IsValid (const d2::Sweep& value) noexcept
136156{
137- return IsValid (value.pos0 ) && IsValid (value.pos1 )
138- && IsValid (value. GetLocalCenter ()) && IsValid (value.GetAlpha0 ());
157+ return IsValid (value.pos0 ) && IsValid (value.pos1 ) && IsValid (value. GetLocalCenter ()) &&
158+ IsValid (value.GetAlpha0 ());
139159}
140160
141161} // namespace playrho
0 commit comments