From d932290bd943e3d75fc11685749212875ff428dd Mon Sep 17 00:00:00 2001 From: Elias Carvalho <73039601+eliascarv@users.noreply.github.com> Date: Sat, 18 May 2024 12:04:58 -0300 Subject: [PATCH] Fix: rotate a vector of quantities with `AngleAxis` (#296) * Fix: rotate a vector of quantities with 'AngleAxis' * Add tests * Rename variable * Update testset --- src/angleaxis_types.jl | 2 +- test/rotation_tests.jl | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/angleaxis_types.jl b/src/angleaxis_types.jl index eeb526a..85cf09e 100644 --- a/src/angleaxis_types.jl +++ b/src/angleaxis_types.jl @@ -110,7 +110,7 @@ function Base.:*(aa::AngleAxis, v::StaticVector) st, ct = sincos(aa.theta) w_cross_pt = cross(w, v) m = dot(v, w) * (one(w_cross_pt[1]) - ct) - T = promote_type(eltype(aa), eltype(v)) + T = Base.promote_op(*, eltype(aa), eltype(v)) return similar_type(v,T)(v[1] * ct + w_cross_pt[1] * st + w[1] * m, v[2] * ct + w_cross_pt[2] * st + w[2] * m, v[3] * ct + w_cross_pt[3] * st + w[3] * m) diff --git a/test/rotation_tests.jl b/test/rotation_tests.jl index 16a3f8e..ec64170 100644 --- a/test/rotation_tests.jl +++ b/test/rotation_tests.jl @@ -209,6 +209,28 @@ all_types = (RotMatrix3, RotMatrix{3}, AngleAxis, RotationVec, end end + @testset "Rotation result eltype" begin + QuantityF64 = typeof(1.0u"m") + QuantityF32 = typeof(1.0f0u"m") + @testset "$(R)" for R in all_types + r1 = rand(R{Float64}) + r2 = rand(R{Float32}) + v1 = rand(SVector{3,Float64}) + v2 = rand(SVector{3,Float32}) + v3 = rand(SVector{3,QuantityF64}) + v4 = rand(SVector{3,QuantityF32}) + + @test eltype(r1*v1) <: Float64 + @test eltype(r1*v2) <: Float64 + @test eltype(r1*v3) <: QuantityF64 + @test eltype(r1*v4) <: QuantityF64 + @test eltype(r2*v1) <: Float64 + @test eltype(r2*v2) <: Float32 + @test eltype(r2*v3) <: QuantityF64 + @test eltype(r2*v4) <: QuantityF32 + end + end + @testset "Quaternion double cover" begin repeats = 100 Q = QuatRotation