From df7248039553b3ebd338380c3ef0428b0e046e79 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 14 Aug 2020 09:38:45 -0400 Subject: common: Make use of [[nodiscard]] where applicable Now that clang-format makes [[nodiscard]] attributes format sensibly, we can apply them to several functions within the common library to allow the compiler to complain about any misuses of the functions. --- src/common/quaternion.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/common/quaternion.h') diff --git a/src/common/quaternion.h b/src/common/quaternion.h index 370198ae0..da44f35cd 100644 --- a/src/common/quaternion.h +++ b/src/common/quaternion.h @@ -14,35 +14,36 @@ public: Vec3 xyz; T w{}; - Quaternion Inverse() const { + [[nodiscard]] Quaternion Inverse() const { return {-xyz, w}; } - Quaternion operator+(const Quaternion& other) const { + [[nodiscard]] Quaternion operator+(const Quaternion& other) const { return {xyz + other.xyz, w + other.w}; } - Quaternion operator-(const Quaternion& other) const { + [[nodiscard]] Quaternion operator-(const Quaternion& other) const { return {xyz - other.xyz, w - other.w}; } - Quaternion operator*(const Quaternion& other) const { + [[nodiscard]] Quaternion operator*( + const Quaternion& other) const { return {xyz * other.w + other.xyz * w + Cross(xyz, other.xyz), w * other.w - Dot(xyz, other.xyz)}; } - Quaternion Normalized() const { + [[nodiscard]] Quaternion Normalized() const { T length = std::sqrt(xyz.Length2() + w * w); return {xyz / length, w / length}; } }; template -auto QuaternionRotate(const Quaternion& q, const Vec3& v) { +[[nodiscard]] auto QuaternionRotate(const Quaternion& q, const Vec3& v) { return v + 2 * Cross(q.xyz, Cross(q.xyz, v) + v * q.w); } -inline Quaternion MakeQuaternion(const Vec3& axis, float angle) { +[[nodiscard]] inline Quaternion MakeQuaternion(const Vec3& axis, float angle) { return {axis * std::sin(angle / 2), std::cos(angle / 2)}; } -- cgit v1.2.3