From 753f89281e59ae93d8ddd43f1a734db73d7d7ef8 Mon Sep 17 00:00:00 2001 From: Thad House Date: Fri, 9 Feb 2024 23:18:22 -0800 Subject: [PATCH] Remove duplicate calls to norm() in Quaternion::Log() --- .../main/java/edu/wpi/first/math/geometry/Quaternion.java | 5 +++-- wpimath/src/main/native/cpp/geometry/Quaternion.cpp | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/wpimath/src/main/java/edu/wpi/first/math/geometry/Quaternion.java b/wpimath/src/main/java/edu/wpi/first/math/geometry/Quaternion.java index ea0be3cfdd6..5e1b581e54a 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/geometry/Quaternion.java +++ b/wpimath/src/main/java/edu/wpi/first/math/geometry/Quaternion.java @@ -285,11 +285,12 @@ public Quaternion log(Quaternion end) { * @return The logarithm of this quaternion. */ public Quaternion log() { - var scalar = Math.log(norm()); + var norm = norm(); + var scalar = Math.log(norm); var v_norm = Math.sqrt(getX() * getX() + getY() * getY() + getZ() * getZ()); - var s_norm = getW() / norm(); + var s_norm = getW() / norm; if (Math.abs(s_norm + 1) < 1e-9) { return new Quaternion(scalar, -Math.PI, 0, 0); diff --git a/wpimath/src/main/native/cpp/geometry/Quaternion.cpp b/wpimath/src/main/native/cpp/geometry/Quaternion.cpp index ea9b179ca82..136f48db0c6 100644 --- a/wpimath/src/main/native/cpp/geometry/Quaternion.cpp +++ b/wpimath/src/main/native/cpp/geometry/Quaternion.cpp @@ -136,11 +136,12 @@ Quaternion Quaternion::Log(const Quaternion& other) const { } Quaternion Quaternion::Log() const { - double scalar = std::log(Norm()); + double norm = Norm(); + double scalar = std::log(norm); double v_norm = m_v.norm(); - double s_norm = W() / Norm(); + double s_norm = W() / norm; if (std::abs(s_norm + 1) < 1e-9) { return Quaternion{scalar, -std::numbers::pi, 0, 0};