From 6ce1ae480b2d42591bdf7b1d572480bc6aa9e903 Mon Sep 17 00:00:00 2001 From: Ben Zinberg Date: Fri, 12 Nov 2021 15:31:11 -0500 Subject: [PATCH] Attempt to fix https://github.com/probcomp/PoseComposition.jl/issues/5 --- src/PoseComposition.jl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/PoseComposition.jl b/src/PoseComposition.jl index 327eb4b..d84c7d1 100644 --- a/src/PoseComposition.jl +++ b/src/PoseComposition.jl @@ -294,8 +294,14 @@ interp(a::Pose, b::Pose, t::Real) = a * interp(a ⦸ b, t) function quatPow(q::UnitQuaternion, t::Real) # TODO: Once https://github.com/JuliaGeometry/Rotations.jl/issues/126 is - # fixed, this special case won't be necessary - if t == 0 || q == one(UnitQuaternion) || q == -one(UnitQuaternion) + # fixed, this special case won't be necessary. + # + # For an example showing why we need an approximately-equal check rather than an exact equality check, see + # https://github.com/probcomp/PoseComposition.jl/issues/5 + ε = 1e-30 + if (isapprox(t, 0; atol=ε) + || isapprox(q, one(UnitQuaternion); atol=ε) + || isapprox(q, -one(UnitQuaternion); atol=ε)) return one(UnitQuaternion) end return exp(t * log(q))