Skip to content

Commit

Permalink
Fix: rotate a vector of quantities with AngleAxis (#296)
Browse files Browse the repository at this point in the history
* Fix: rotate a vector of quantities with 'AngleAxis'

* Add tests

* Rename variable

* Update testset
  • Loading branch information
eliascarv authored May 18, 2024
1 parent e4be8c5 commit d932290
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/angleaxis_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions test/rotation_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d932290

Please sign in to comment.