JuliaGeometry / Rotations.jl

Julia implementations for different rotation parameterizations
https://juliageometry.github.io/Rotations.jl
MIT License
176 stars 44 forks source link

Fix: rotate a vector of quantities with `AngleAxis` #296

Closed eliascarv closed 3 months ago

eliascarv commented 3 months ago

In the current version of Rotations.jl, rotating a vector of quantities with AngleAxis returns a new vector with incorrect eltype:

julia> R = AngleAxis(π / 2, 0, 0, 1)
3×3 AngleAxis{Float64} with indices SOneTo(3)×SOneTo(3)(1.5708, 0.0, 0.0, 1.0):
 2.22045e-16  -1.0          0.0
 1.0           2.22045e-16  0.0
 0.0           0.0          1.0

julia> v = SVector(1.0, 1.0, 1.0) * u"m"
3-element SVector{3, Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}} with indices SOneTo(3):
 1.0 m
 1.0 m
 1.0 m

julia> R * v
3-element SVector{3, Quantity{Float64}} with indices SOneTo(3):
 -0.9999999999999999 m
                 1.0 m
                 1.0 m

This PR fixes this bug:

julia> R = AngleAxis(π / 2, 0, 0, 1)
3×3 AngleAxis{Float64} with indices SOneTo(3)×SOneTo(3)(1.5708, 0.0, 0.0, 1.0):
 2.22045e-16  -1.0          0.0
 1.0           2.22045e-16  0.0
 0.0           0.0          1.0

julia> v = SVector(1.0, 1.0, 1.0) * u"m"
3-element SVector{3, Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}} with indices SOneTo(3):
 1.0 m
 1.0 m
 1.0 m

julia> R * v
3-element SVector{3, Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}} with indices SOneTo(3):
 -0.9999999999999999 m
                 1.0 m
                 1.0 m
hyrodium commented 3 months ago

Thank you for the PR! Could you add tests for the fix?

eliascarv commented 3 months ago

@hyrodium tests added. Can you check if they follow the code style?

eliascarv commented 3 months ago

@hyrodium can you release a patch version with this PR?