Skip to content

Commit d932290

Browse files
authored
Fix: rotate a vector of quantities with AngleAxis (#296)
* Fix: rotate a vector of quantities with 'AngleAxis' * Add tests * Rename variable * Update testset
1 parent e4be8c5 commit d932290

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/angleaxis_types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function Base.:*(aa::AngleAxis, v::StaticVector)
110110
st, ct = sincos(aa.theta)
111111
w_cross_pt = cross(w, v)
112112
m = dot(v, w) * (one(w_cross_pt[1]) - ct)
113-
T = promote_type(eltype(aa), eltype(v))
113+
T = Base.promote_op(*, eltype(aa), eltype(v))
114114
return similar_type(v,T)(v[1] * ct + w_cross_pt[1] * st + w[1] * m,
115115
v[2] * ct + w_cross_pt[2] * st + w[2] * m,
116116
v[3] * ct + w_cross_pt[3] * st + w[3] * m)

test/rotation_tests.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,28 @@ all_types = (RotMatrix3, RotMatrix{3}, AngleAxis, RotationVec,
209209
end
210210
end
211211

212+
@testset "Rotation result eltype" begin
213+
QuantityF64 = typeof(1.0u"m")
214+
QuantityF32 = typeof(1.0f0u"m")
215+
@testset "$(R)" for R in all_types
216+
r1 = rand(R{Float64})
217+
r2 = rand(R{Float32})
218+
v1 = rand(SVector{3,Float64})
219+
v2 = rand(SVector{3,Float32})
220+
v3 = rand(SVector{3,QuantityF64})
221+
v4 = rand(SVector{3,QuantityF32})
222+
223+
@test eltype(r1*v1) <: Float64
224+
@test eltype(r1*v2) <: Float64
225+
@test eltype(r1*v3) <: QuantityF64
226+
@test eltype(r1*v4) <: QuantityF64
227+
@test eltype(r2*v1) <: Float64
228+
@test eltype(r2*v2) <: Float32
229+
@test eltype(r2*v3) <: QuantityF64
230+
@test eltype(r2*v4) <: QuantityF32
231+
end
232+
end
233+
212234
@testset "Quaternion double cover" begin
213235
repeats = 100
214236
Q = QuatRotation

0 commit comments

Comments
 (0)