diff --git a/.travis.yml b/.travis.yml index 9a12fc41..acea1217 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ os: - osx julia: - 0.6 + - 0.7 - nightly matrix: diff --git a/REQUIRE b/REQUIRE index fc8e66e3..e3a71d00 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,2 +1,3 @@ julia 0.6 +Compat 0.33 DualNumbers diff --git a/src/Octonion.jl b/src/Octonion.jl index 0265292a..64b4a5c2 100644 --- a/src/Octonion.jl +++ b/src/Octonion.jl @@ -135,7 +135,7 @@ function log(o::Octonion) o, a = normalizea(o) s = o.s M = abs(Octonion(imag(o))) - th = atan2(M, s) + th = atan(M, s) if M > 0 M = th / M return Octonion(log(a), diff --git a/src/Quaternion.jl b/src/Quaternion.jl index 8cdd2acd..048705fc 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -6,6 +6,9 @@ struct Quaternion{T<:Real} <: Number norm::Bool end +(::Type{Quaternion{T}})(x::Real) where {T} = Quaternion{T}(x, 0, 0, 0, false) +(::Type{Quaternion{T}})(q::Quaternion{T}) where {T<:Real} = q +(::Type{Quaternion{T}})(q::Quaternion) where {T<:Real} = Quaternion{T}(q.s, q.v1, q.v2, q.v3, q.norm) Quaternion(s::Real, v1::Real, v2::Real, v3::Real, n::Bool = false) = Quaternion(promote(s, v1, v2, v3)..., n) Quaternion(x::Real) = Quaternion(x, zero(x), zero(x), zero(x), abs(x) == one(x)) @@ -94,7 +97,7 @@ end angleaxis(q::Quaternion) = angle(q), axis(q) -angle(q::Quaternion) = 2 * atan2(√(q.v1^2 + q.v2^2 + q.v3^2), q.s) +angle(q::Quaternion) = 2 * atan(√(q.v1^2 + q.v2^2 + q.v3^2), q.s) function axis(q::Quaternion) q = normalize(q) @@ -121,7 +124,7 @@ function log(q::Quaternion) q, a = normalizea(q) s = q.s M = abs_imag(q) - th = atan2(M, s) + th = atan(M, s) if M > 0 M = th / M return Quaternion(log(a), q.v1 * M, q.v2 * M, q.v3 * M) @@ -208,7 +211,7 @@ function qrotation(rotvec::Vector{T}) where {T <: Real} Quaternion(one(T), zero(T), zero(T), zero(T), true) end -function qrotation{T<:Real}(dcm::Matrix{T}) +function qrotation(dcm::Matrix{T}) where {T<:Real} # See https://arxiv.org/pdf/math/0701759.pdf a2 = 1 + dcm[1,1] + dcm[2,2] + dcm[3,3] b2 = 1 + dcm[1,1] - dcm[2,2] - dcm[3,3] @@ -230,7 +233,7 @@ function qrotation{T<:Real}(dcm::Matrix{T}) end end -function qrotation{T<:Real}(dcm::Matrix{T}, qa::Quaternion) +function qrotation(dcm::Matrix{T}, qa::Quaternion) where {T<:Real} q = qrotation(dcm) abs(q-qa) < abs(q+qa) ? q : -q end diff --git a/src/Quaternions.jl b/src/Quaternions.jl index 4d934ce3..7422db46 100644 --- a/src/Quaternions.jl +++ b/src/Quaternions.jl @@ -1,7 +1,13 @@ __precompile__() module Quaternions - importall Base + + using Compat + + import Base: +, -, *, /, ^ + import Base: abs, abs2, angle, conj, cos, exp, inv, isfinite, log, real, sin, sqrt + import Base: convert, promote_rule + import Compat.LinearAlgebra: norm, normalize include("Quaternion.jl") include("Octonion.jl") diff --git a/test/runtests.jl b/test/runtests.jl index a4eb73ca..a11cf76e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,4 @@ -using Base.Test +using Compat.Test using Quaternions test_associative(x, y, z, ⊗) = @test (x ⊗ y) ⊗ z ≈ x ⊗ (y ⊗ z) diff --git a/test/test_Quaternion.jl b/test/test_Quaternion.jl index 648df908..a27878fe 100644 --- a/test/test_Quaternion.jl +++ b/test/test_Quaternion.jl @@ -1,5 +1,7 @@ -import Quaternions.argq +using Quaternions: argq +using Compat +using Compat.LinearAlgebra # creating random examples sample(QT::Type{Quaternion{T}}) where {T <: Integer} = QT(rand(-100:100, 4)..., false)