JuliaGeometry / Rotations.jl

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

Fix `Angle2d` constructor #224

Closed hyrodium closed 2 years ago

hyrodium commented 2 years ago

This PR fixes #212.

Before this PR

julia> using Rotations, StaticArrays

julia> Angle2d((1,0,0,1))
ERROR: MethodError: no method matching zero(::Type{NTuple{4, Int64}})
Closest candidates are:
  zero(::Union{Type{P}, P}) where P<:Dates.Period at ~/julia/julia-1.7.1/share/julia/stdlib/v1.7/Dates/src/periods.jl:53
  zero(::AbstractIrrational) at ~/julia/julia-1.7.1/share/julia/base/irrationals.jl:150
  zero(::LinearAlgebra.Diagonal{T, SVector{N, T}}) where {N, T} at ~/.julia/dev/StaticArrays/src/SDiagonal.jl:41
  ...
Stacktrace:
 [1] rot_eltype(angle_type::Type)
   @ Rotations ~/.julia/dev/Rotations/src/util.jl:49
 [2] Angle2d(theta::NTuple{4, Int64})
   @ Rotations ~/.julia/dev/Rotations/src/core_types.jl:148
 [3] top-level scope
   @ REPL[4]:1

julia> Angle2d(one(SMatrix{2,2}))
ERROR: MethodError: Angle2d(::SMatrix{2, 2, Float64, 4}) is ambiguous. Candidates:
  (::Type{SA})(a::StaticArray) where SA<:StaticArray in StaticArrays at /home/hyrodium/.julia/dev/StaticArrays/src/convert.jl:5
  (::Type{SA})(a::AbstractArray) where SA<:StaticArray in StaticArrays at /home/hyrodium/.julia/dev/StaticArrays/src/convert.jl:7
  Angle2d(theta) in Rotations at /home/hyrodium/.julia/dev/Rotations/src/core_types.jl:147
Possible fix, define
  Angle2d(::StaticArray)
Stacktrace:
 [1] top-level scope
   @ REPL[5]:1

julia> Angle2d(rand(2,2))
ERROR: MethodError: Angle2d(::Matrix{Float64}) is ambiguous. Candidates:
  (::Type{SA})(a::AbstractArray) where SA<:StaticArray in StaticArrays at /home/hyrodium/.julia/dev/StaticArrays/src/convert.jl:7
  Angle2d(theta) in Rotations at /home/hyrodium/.julia/dev/Rotations/src/core_types.jl:147
Possible fix, define
  Angle2d(::AbstractArray)
Stacktrace:
 [1] top-level scope
   @ REPL[6]:1

After this PR

julia> using Rotations, StaticArrays

julia> Angle2d((1,0,0,1))
2×2 Angle2d{Float64} with indices SOneTo(2)×SOneTo(2)(0.0):
 1.0  -0.0
 0.0   1.0

julia> Angle2d(one(SMatrix{2,2}))
2×2 Angle2d{Float64} with indices SOneTo(2)×SOneTo(2)(0.0):
 1.0  -0.0
 0.0   1.0

2×2 Angle2d{Float64} with indices SOneTo(2)×SOneTo(2)(0.896298):
 0.624506  -0.78102
 0.78102    0.624506
codecov[bot] commented 2 years ago

Codecov Report

Merging #224 (8a95e49) into master (120f397) will increase coverage by 0.06%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #224      +/-   ##
==========================================
+ Coverage   88.56%   88.63%   +0.06%     
==========================================
  Files          16       16              
  Lines        1627     1628       +1     
==========================================
+ Hits         1441     1443       +2     
+ Misses        186      185       -1     
Impacted Files Coverage Δ
src/core_types.jl 95.62% <100.00%> (+0.76%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 120f397...8a95e49. Read the comment docs.