Skip to content

Commit f5106cf

Browse files
authored
Fix real(::Type{<:Rotation}) (#231)
* fix real(::Type{<:Rotation}) and real(::Type{<:RotationGenerator}) * add tests for real(::Type{<:Rotation}) and real(::Type{<:RotationGenerator})
1 parent ecc6595 commit f5106cf

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

src/core_types.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Base.@pure StaticArrays.Size(::Type{Rotation{N,T}}) where {N,T} = Size(N,N)
1111
Base.@pure StaticArrays.Size(::Type{R}) where {R<:Rotation} = Size(supertype(R))
1212
Base.adjoint(r::Rotation) = inv(r)
1313
Base.transpose(r::Rotation{N,T}) where {N,T<:Real} = inv(r)
14+
Base.real(R::Type{<:Rotation}) = R
1415

1516
# Generate zero-matrix with SMatrix
1617
# Note that zeros(Rotation3,dims...) is not Array{<:Rotation} but Array{<:StaticMatrix{3,3}}

src/rotation_generator.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Base.@pure StaticArrays.Size(::Type{RotationGenerator{N,T}}) where {N,T} = Size(
1111
Base.@pure StaticArrays.Size(::Type{R}) where {R<:RotationGenerator} = Size(supertype(R))
1212
Base.adjoint(r::RotationGenerator) = -r
1313
Base.transpose(r::RotationGenerator{N,T}) where {N,T<:Real} = -r
14+
Base.real(R::Type{<:RotationGenerator}) = R
1415

1516
# Generate identity-matrix with SMatrix
1617
# Note that ones(RotationGenerator3,dims...) is not Array{<:RotationGenerator} but Array{<:StaticMatrix{3,3}}

test/rotation_generator.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@
7373
@test one(RotationGenerator{3,BigFloat}) isa SMatrix{3, 3, BigFloat}
7474
end
7575

76+
@testset "real" begin
77+
@testset "$(R)" for R in all_types
78+
@test real(R) === R
79+
@test real(one(R)) === one(R)
80+
end
81+
@test real(RotationGenerator) === RotationGenerator
82+
@test real(RotMatrixGenerator) === RotMatrixGenerator
83+
end
84+
7685
@testset "minus" begin
7786
for T in all_types
7887
# TODO: These should be replaced with `r = rand(T)`

test/rotation_tests.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ all_types = (RotMatrix3, RotMatrix{3}, AngleAxis, RotationVec,
128128
@test_throws ErrorException zero(RotMatrix)
129129
end
130130

131+
###############################
132+
# Check real function
133+
###############################
134+
135+
@testset "real checks" begin
136+
@testset "$(R)" for R in all_types
137+
@test real(R) === R
138+
@test real(one(R)) === one(R)
139+
end
140+
@test real(Rotation) === Rotation
141+
@test real(RotMatrix) === RotMatrix
142+
end
143+
131144
################################
132145
# check on the inverse function
133146
################################

0 commit comments

Comments
 (0)