Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: rotate a vector of quantities with AngleAxis #296

Merged
merged 4 commits into from
May 18, 2024

Conversation

eliascarv
Copy link
Member

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

@eliascarv eliascarv requested a review from hyrodium May 15, 2024 18:10
@hyrodium
Copy link
Collaborator

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

@eliascarv
Copy link
Member Author

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

Copy link
Collaborator

@hyrodium hyrodium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding tests!

@@ -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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand the practical reason why Base.promote_op is avoided, but Base.promote_op is already used in other places in Rotations. jl like in this PR, so I will approve this PR.

@hyrodium hyrodium merged commit d932290 into JuliaGeometry:master May 18, 2024
8 checks passed
@eliascarv eliascarv deleted the angle-axis-fix branch May 18, 2024 21:04
@eliascarv
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants