From 892e3edb0dfee7308bde250fb4e9f48e994a1885 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Sat, 17 Sep 2022 11:55:27 +0900 Subject: [PATCH 01/29] add docstrings for real and Quaternion --- src/Quaternion.jl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index 1c1dfea9..50356621 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -1,3 +1,13 @@ +""" + Quaternion{T<:Real} <: Number + +Quaternion number type with real and imaginary part of type `T`. + +`QuaternionF16`, `QuaternionF32` and `QuaternionF64` are aliases for +`Quaternion{Float16}`, `Quaternion{Float32}` and `Quaternion{Float64}` respectively. + +See also: [`quat`](@ref), [`real`](@ref), [`imag_part`](@ref). +""" struct Quaternion{T<:Real} <: Number s::T v1::T @@ -29,6 +39,19 @@ quat(p, v1, v2, v3, n) = Quaternion(p, v1, v2, v3, n) quat(x) = Quaternion(x) quat(s, a) = Quaternion(s, a) +""" + real(q::Quaternion) + +Return the real part of the quaternion `q`. + +See also: [`imag_part`](@ref), [`quat`](@ref), [`isreal`](@ref). + +# Examples +```jldoctest +julia> real(quat(1,2,3,4)) +1 +``` +""" real(::Type{Quaternion{T}}) where {T} = T real(q::Quaternion) = q.s imag_part(q::Quaternion) = (q.v1, q.v2, q.v3) From b7118eb286719848f85e9094d47ac1b5c85d1315 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Sat, 17 Sep 2022 11:55:51 +0900 Subject: [PATCH 02/29] add api.md --- docs/make.jl | 1 + docs/src/api.md | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 docs/src/api.md diff --git a/docs/make.jl b/docs/make.jl index 892b1486..a93c4869 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -14,6 +14,7 @@ makedocs(; ), pages=[ "Home" => "index.md", + "APIs" => "api.md", ], ) diff --git a/docs/src/api.md b/docs/src/api.md new file mode 100644 index 00000000..0d829785 --- /dev/null +++ b/docs/src/api.md @@ -0,0 +1,17 @@ +# APIs + +```@docs +Quaternion +``` + +```@docs +quat +``` + +```@docs +real(::Quaternion) +``` + +```@docs +imag_part +``` From 32516f464e2ca41c7d380f22d4254a854cc13e37 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Sat, 17 Sep 2022 11:56:48 +0900 Subject: [PATCH 03/29] remove invisible character (U+00ad) --- src/Quaternion.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index 50356621..a8aa408e 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -153,7 +153,7 @@ See Theorem 5 of [^Sudbery1970] for details. [^Sudbery1970] Sudbery (1979). Quaternionic analysis. Mathematical Proceedings of the Cambridge - Philosophical Society,85, pp 199­225 + Philosophical Society,85, pp 199225 doi:[10.1017/S030500410005563](https://doi.org/10.1017/S0305004100055638) """ function extend_analytic(f, q::Quaternion) From 59e006b609e718a7c862d47f101343269dac277b Mon Sep 17 00:00:00 2001 From: hyrodium Date: Sat, 17 Sep 2022 12:27:16 +0900 Subject: [PATCH 04/29] add docstrings for conj and imag_part --- src/Quaternion.jl | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index a8aa408e..f461c64b 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -54,6 +54,21 @@ julia> real(quat(1,2,3,4)) """ real(::Type{Quaternion{T}}) where {T} = T real(q::Quaternion) = q.s + +""" + imag_part(q::Quaternion{T}) + +Return the imaginary part of the quaternion `q` with type `Tuple{T,T,T}`. +Note that this function is different from `Base.imag` which returns `Real`. + +See also: [`conj`](@ref). + +# Examples +```jldoctest +julia> imag_part(Quaternion(1,2,3,4)) +(2, 3, 4) +``` +""" imag_part(q::Quaternion) = (q.v1, q.v2, q.v3) @deprecate imag(q::Quaternion) collect(imag_part(q)) false @@ -61,6 +76,17 @@ imag_part(q::Quaternion) = (q.v1, q.v2, q.v3) (*)(q::Quaternion, x::Real) = Quaternion(q.s * x, q.v1 * x, q.v2 * x, q.v3 * x) (*)(x::Real, q::Quaternion) = q * x +""" + conj(q::Quaternion) + +Compute the quaternion conjugate of a quaternion `q`. + +# Examples +```jldoctest +julia> conj(Quaternion(1,2,3,4)) +Quaternion{Int64}(1, -2, -3, -4, false) +``` +""" conj(q::Quaternion) = Quaternion(q.s, -q.v1, -q.v2, -q.v3, q.norm) abs(q::Quaternion) = sqrt(abs2(q)) float(q::Quaternion{T}) where T = convert(Quaternion{float(T)}, q) From 0933d52fd8bf4220f2249c856b6254ac010f304d Mon Sep 17 00:00:00 2001 From: hyrodium Date: Sat, 17 Sep 2022 12:27:54 +0900 Subject: [PATCH 05/29] update api.md --- docs/src/api.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/src/api.md b/docs/src/api.md index 0d829785..6b63f002 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -15,3 +15,11 @@ real(::Quaternion) ```@docs imag_part ``` + +```@docs +conj +``` + +```@docs +Quaternions.extend_analytic +``` From 86941c09b6277838d34c9d41409f757cec6c0eed Mon Sep 17 00:00:00 2001 From: Yuto Horikawa Date: Mon, 19 Sep 2022 20:13:40 +0900 Subject: [PATCH 06/29] Update docstring of `imag_part` Co-authored-by: Seth Axen --- src/Quaternion.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index f461c64b..e8dfa7e3 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -61,7 +61,7 @@ real(q::Quaternion) = q.s Return the imaginary part of the quaternion `q` with type `Tuple{T,T,T}`. Note that this function is different from `Base.imag` which returns `Real`. -See also: [`conj`](@ref). +See also: [`real`](@ref), [`conj`](@ref). # Examples ```jldoctest From 20964ce4e54a4d4a49f9cf662b48e4c25851ac67 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Mon, 19 Sep 2022 20:31:40 +0900 Subject: [PATCH 07/29] add docstring of `real(::Type{Quaternion{T}})` --- src/Quaternion.jl | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index e8dfa7e3..dc69e974 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -39,6 +39,21 @@ quat(p, v1, v2, v3, n) = Quaternion(p, v1, v2, v3, n) quat(x) = Quaternion(x) quat(s, a) = Quaternion(s, a) +""" + real(T::Type) + +Return the type that represents the real part of a value of type `T`. +e.g: for `T == Quaternion{R}`, returns `R`. +Equivalent to `typeof(real(zero(T)))`. + +# Examples +```jldoctest +julia> real(Quaternion{Int}) +Int64 +``` +""" +real(::Type{Quaternion{T}}) where {T} = T + """ real(q::Quaternion) @@ -52,7 +67,6 @@ julia> real(quat(1,2,3,4)) 1 ``` """ -real(::Type{Quaternion{T}}) where {T} = T real(q::Quaternion) = q.s """ From f89702f572c32062d12a63761bc6ed29e55dae38 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Mon, 19 Sep 2022 20:34:06 +0900 Subject: [PATCH 08/29] add an example `real(::Array{<:Quaternion})` --- src/Quaternion.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index dc69e974..c1b834f2 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -65,6 +65,11 @@ See also: [`imag_part`](@ref), [`quat`](@ref), [`isreal`](@ref). ```jldoctest julia> real(quat(1,2,3,4)) 1 + +julia> real([quat(5,6,7,8), 9]) +2-element Vector{Int64}: + 5 + 9 ``` """ real(q::Quaternion) = q.s From 10ba11d1ae0baa989824a612ad8afbcd72e1d404 Mon Sep 17 00:00:00 2001 From: Yuto Horikawa Date: Mon, 19 Sep 2022 20:46:17 +0900 Subject: [PATCH 09/29] Update the docstrings of `Quaternion` Co-authored-by: Seth Axen --- src/Quaternion.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index c1b834f2..769822ef 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -4,7 +4,7 @@ Quaternion number type with real and imaginary part of type `T`. `QuaternionF16`, `QuaternionF32` and `QuaternionF64` are aliases for -`Quaternion{Float16}`, `Quaternion{Float32}` and `Quaternion{Float64}` respectively. +`Quaternion{Float16}`, `Quaternion{Float32}`, and `Quaternion{Float64}`, respectively. See also: [`quat`](@ref), [`real`](@ref), [`imag_part`](@ref). """ From 0ba8e280a1a0d9db55f94b8ddc3852ae04346b4a Mon Sep 17 00:00:00 2001 From: hyrodium Date: Thu, 6 Oct 2022 21:27:27 +0900 Subject: [PATCH 10/29] update README.md --- README.md | 56 +++---------------------------------------------------- 1 file changed, 3 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 05f61855..6c76b768 100644 --- a/README.md +++ b/README.md @@ -7,57 +7,7 @@ A Julia implementation of quaternions. [![codecov](https://codecov.io/gh/JuliaGeometry/Quaternions.jl/branch/master/graph/badge.svg?token=dJBiR91dCD)](https://codecov.io/gh/JuliaGeometry/Quaternions.jl) [Quaternions](http://en.wikipedia.org/wiki/Quaternion) are best known for their suitability -as representations of 3D rotational orientation. They can also be viewed as an extension of complex numbers. +as representations of 3D rotational orientation. +They can also be viewed as an extension of complex numbers. -Implemented functions are: - - +-*/^ - real - imag_part (tuple) - conj - abs - abs2 - normalize - normalizea (return normalized quaternion and absolute value as a pair) - angleaxis (taken as an orientation, return the angle and axis (3 vector) as a tuple) - angle - axis - sqrt - exp - exp2 - exp10 - expm1 - log2 - log10 - log1p - sin - cos - tan - asin - acos - atan - sinh - cosh - tanh - asinh - acosh - atanh - csc - sec - cot - acsc - asec - acot - csch - sech - coth - acsch - asech - acoth - sinpi - cospi - sincos - sincospi - slerp - rand - randn +In JuliaGeometry organization, there is also [Octonions.jl](https://github.com/JuliaGeometry/Octonions.jl). From 2e0239803aef5c3c3819fde63e8ca18626f630be Mon Sep 17 00:00:00 2001 From: hyrodium Date: Thu, 6 Oct 2022 21:36:00 +0900 Subject: [PATCH 11/29] update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c76b768..326165a6 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,4 @@ A Julia implementation of quaternions. as representations of 3D rotational orientation. They can also be viewed as an extension of complex numbers. -In JuliaGeometry organization, there is also [Octonions.jl](https://github.com/JuliaGeometry/Octonions.jl). +In JuliaGeometry organization, there is also [Octonions.jl](https://github.com/JuliaGeometry/Octonions.jl) package. From a425e7a7c36ad052e2fc1caa9bbeff21a42771b8 Mon Sep 17 00:00:00 2001 From: Yuto Horikawa Date: Sat, 15 Oct 2022 21:08:41 +0900 Subject: [PATCH 12/29] more specific type in docstring Co-authored-by: Seth Axen --- src/Quaternion.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index cb222935..6509e9a6 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -40,7 +40,7 @@ quat(x) = Quaternion(x) quat(s, a) = Quaternion(s, a) """ - real(T::Type) + real(T::Type{<:Quaternion}) Return the type that represents the real part of a value of type `T`. e.g: for `T == Quaternion{R}`, returns `R`. From 58d5778f0228df14083384112dcbe6a6f9192718 Mon Sep 17 00:00:00 2001 From: Yuto Horikawa Date: Sat, 15 Oct 2022 22:11:13 +0900 Subject: [PATCH 13/29] Add docstring for `Base.real(::AbstractArray{<:Quaternion})` Co-authored-by: Seth Axen --- src/Quaternion.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index d31e943e..d502b0fa 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -74,6 +74,21 @@ julia> real([quat(5,6,7,8), 9]) """ Base.real(q::Quaternion) = q.s +""" + real(A::AbstractArray{<:Quaternion}) + +Return an array containing the real part of each quaternion in `A`. + +# Examples +```jldoctest +julia> real([quat(5,6,7,8), 9]) +2-element Vector{Int64}: + 5 + 9 +``` +""" +Base.real(::AbstractArray{<:Quaternion}) + """ imag_part(q::Quaternion{T}) From 66acd301cf0ea06b70eb8acdf97773b299c7a16b Mon Sep 17 00:00:00 2001 From: hyrodium Date: Sat, 15 Oct 2022 22:13:42 +0900 Subject: [PATCH 14/29] remove duplicated jldoctest for `Base.real` --- src/Quaternion.jl | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index d502b0fa..a06ab1fe 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -65,11 +65,6 @@ See also: [`imag_part`](@ref), [`quat`](@ref), [`isreal`](@ref). ```jldoctest julia> real(quat(1,2,3,4)) 1 - -julia> real([quat(5,6,7,8), 9]) -2-element Vector{Int64}: - 5 - 9 ``` """ Base.real(q::Quaternion) = q.s From cffcb626b7ed3f8b74230f4ff071f9bd9cf29e21 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Sat, 15 Oct 2022 22:20:23 +0900 Subject: [PATCH 15/29] add docstring for `quat` --- src/Quaternion.jl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index a06ab1fe..ec26f5c7 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -34,6 +34,22 @@ Base.promote_rule(::Type{Quaternion{T}}, ::Type{S}) where {T <: Real, S <: Real} Base.promote_rule(::Type{Quaternion{T}}, ::Type{Complex{S}}) where {T <: Real, S <: Real} = Quaternion{promote_type(T, S)} Base.promote_rule(::Type{Quaternion{T}}, ::Type{Quaternion{S}}) where {T <: Real, S <: Real} = Quaternion{promote_type(T, S)} +""" + quat(r, [i, j, k]) + +Convert real numbers or arrays to quaternion. `i, j, k` defaults to zero. + +# Examples +```jldoctest +julia> quat(7) +Quaternion{Int64}(7, 0, 0, 0, false) + +julia> quat([1, 2, 3]) # The output will be changed in the next breaking release for consistency. (#94) +Quaternion{Int64}(0, 1, 2, 3, false) +``` +""" +quat + quat(p, v1, v2, v3) = Quaternion(p, v1, v2, v3) quat(p, v1, v2, v3, n) = Quaternion(p, v1, v2, v3, n) quat(x) = Quaternion(x) From 362c168beb53b386d8e4286d7c73dfd708594040 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Sun, 16 Oct 2022 10:51:48 +0900 Subject: [PATCH 16/29] update wording --- src/Quaternion.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index ec26f5c7..b084d1be 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -44,7 +44,7 @@ Convert real numbers or arrays to quaternion. `i, j, k` defaults to zero. julia> quat(7) Quaternion{Int64}(7, 0, 0, 0, false) -julia> quat([1, 2, 3]) # The output will be changed in the next breaking release for consistency. (#94) +julia> quat([1, 2, 3]) # This output will be changed in the next breaking release for consistency. (#94) Quaternion{Int64}(0, 1, 2, 3, false) ``` """ From 083ad7b04d4a5245d154e7b30c924efa1d9a26d2 Mon Sep 17 00:00:00 2001 From: Yuto Horikawa Date: Mon, 17 Oct 2022 20:35:53 +0900 Subject: [PATCH 17/29] rename APIs to API Co-authored-by: Seth Axen --- docs/src/api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/api.md b/docs/src/api.md index 6b63f002..202622de 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -1,4 +1,4 @@ -# APIs +# API ```@docs Quaternion From 286452c0de0319fe34ff4fbb125802936036213b Mon Sep 17 00:00:00 2001 From: Yuto Horikawa Date: Mon, 17 Oct 2022 20:36:47 +0900 Subject: [PATCH 18/29] Fix docstring with plural Co-authored-by: Seth Axen --- src/Quaternion.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index b084d1be..6ef909e6 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -1,7 +1,7 @@ """ Quaternion{T<:Real} <: Number -Quaternion number type with real and imaginary part of type `T`. +Quaternion number type with real and imaginary parts of type `T`. `QuaternionF16`, `QuaternionF32` and `QuaternionF64` are aliases for `Quaternion{Float16}`, `Quaternion{Float32}`, and `Quaternion{Float64}`, respectively. From aa48327135403866eb3d35d62d06aba6f9dfc9c7 Mon Sep 17 00:00:00 2001 From: Yuto Horikawa Date: Mon, 17 Oct 2022 20:37:24 +0900 Subject: [PATCH 19/29] Use Oxford comma in docstring Co-authored-by: Seth Axen --- src/Quaternion.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index 6ef909e6..109e6210 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -3,7 +3,7 @@ Quaternion number type with real and imaginary parts of type `T`. -`QuaternionF16`, `QuaternionF32` and `QuaternionF64` are aliases for +`QuaternionF16`, `QuaternionF32`, and `QuaternionF64` are aliases for `Quaternion{Float16}`, `Quaternion{Float32}`, and `Quaternion{Float64}`, respectively. See also: [`quat`](@ref), [`real`](@ref), [`imag_part`](@ref). From fd870d15d59a11d4817f311fd6bb29ccf8b7296c Mon Sep 17 00:00:00 2001 From: Yuto Horikawa Date: Mon, 17 Oct 2022 20:38:05 +0900 Subject: [PATCH 20/29] add more jidoctests for `quat` Co-authored-by: Seth Axen --- src/Quaternion.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index 109e6210..e4ecfab7 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -44,6 +44,9 @@ Convert real numbers or arrays to quaternion. `i, j, k` defaults to zero. julia> quat(7) Quaternion{Int64}(7, 0, 0, 0, false) +julia> quat(1.0, 2, 3, 4) +QuaternionF64(1.0, 2.0, 3.0, 4.0, false) + julia> quat([1, 2, 3]) # This output will be changed in the next breaking release for consistency. (#94) Quaternion{Int64}(0, 1, 2, 3, false) ``` From 959b0e83ac1b586aa878d74b145c360699a50199 Mon Sep 17 00:00:00 2001 From: Yuto Horikawa Date: Mon, 17 Oct 2022 20:38:24 +0900 Subject: [PATCH 21/29] update docstring of `imag_part` Co-authored-by: Seth Axen --- src/Quaternion.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index e4ecfab7..bd17baa7 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -104,7 +104,7 @@ julia> real([quat(5,6,7,8), 9]) Base.real(::AbstractArray{<:Quaternion}) """ - imag_part(q::Quaternion{T}) + imag_part(q::Quaternion{T}) -> NTuple{3, T} Return the imaginary part of the quaternion `q` with type `Tuple{T,T,T}`. Note that this function is different from `Base.imag` which returns `Real`. From d013c0169fe74702f78520f79ed541e926bbb5d0 Mon Sep 17 00:00:00 2001 From: Yuto Horikawa Date: Mon, 17 Oct 2022 20:38:35 +0900 Subject: [PATCH 22/29] update docstring of `imag_part` Co-authored-by: Seth Axen --- src/Quaternion.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index bd17baa7..acda7995 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -106,7 +106,8 @@ Base.real(::AbstractArray{<:Quaternion}) """ imag_part(q::Quaternion{T}) -> NTuple{3, T} -Return the imaginary part of the quaternion `q` with type `Tuple{T,T,T}`. +Return the imaginary part of the quaternion `q`. + Note that this function is different from `Base.imag` which returns `Real`. See also: [`real`](@ref), [`conj`](@ref). From 584cd6dfc03eaf009f9963350243f29919b77f4c Mon Sep 17 00:00:00 2001 From: Yuto Horikawa Date: Mon, 17 Oct 2022 20:38:49 +0900 Subject: [PATCH 23/29] update docstring of `imag_part` Co-authored-by: Seth Axen --- src/Quaternion.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index acda7995..25e06514 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -108,7 +108,7 @@ Base.real(::AbstractArray{<:Quaternion}) Return the imaginary part of the quaternion `q`. -Note that this function is different from `Base.imag` which returns `Real`. +Note that this function is different from `Base.imag`, which returns `Real` for complex numbers. See also: [`real`](@ref), [`conj`](@ref). From a361fb8b725cf9042462e08295677340148968a5 Mon Sep 17 00:00:00 2001 From: Yuto Horikawa Date: Mon, 17 Oct 2022 20:41:07 +0900 Subject: [PATCH 24/29] update docstring of `real` Co-authored-by: Seth Axen --- src/Quaternion.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index 25e06514..9ae46183 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -78,7 +78,7 @@ Base.real(::Type{Quaternion{T}}) where {T} = T Return the real part of the quaternion `q`. -See also: [`imag_part`](@ref), [`quat`](@ref), [`isreal`](@ref). +See also: [`imag_part`](@ref), [`quat`](@ref) # Examples ```jldoctest From df0c10def63d094b9cf114259ade28b2c009c262 Mon Sep 17 00:00:00 2001 From: Yuto Horikawa Date: Mon, 17 Oct 2022 20:41:50 +0900 Subject: [PATCH 25/29] update docstring of `extend_analytic` Co-authored-by: Seth Axen --- src/Quaternion.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index 9ae46183..36bc16bd 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -225,7 +225,7 @@ is the extension of `f` to the quaternions, where ``z = a + s i`` is a complex a See Theorem 5 of [^Sudbery1970] for details. -[^Sudbery1970] +[^Sudbery1970]: Sudbery (1979). Quaternionic analysis. Mathematical Proceedings of the Cambridge Philosophical Society,85, pp 199225 doi:[10.1017/S030500410005563](https://doi.org/10.1017/S0305004100055638) From 4ed5156852cad5c0861f4430eb13ce36036b96bc Mon Sep 17 00:00:00 2001 From: hyrodium Date: Mon, 17 Oct 2022 20:46:35 +0900 Subject: [PATCH 26/29] add depwarn to Quaternion(a::AbstractVector) --- src/Quaternion.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index 36bc16bd..7b509510 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -28,7 +28,10 @@ Quaternion(s::Real, v1::Real, v2::Real, v3::Real, n::Bool = false) = Quaternion(x::Real) = Quaternion(x, zero(x), zero(x), zero(x), abs(x) == one(x)) Quaternion(z::Complex) = Quaternion(z.re, z.im, zero(z.re), zero(z.re), abs(z) == one(z.re)) Quaternion(s::Real, a::AbstractVector) = Quaternion(s, a[1], a[2], a[3]) -Quaternion(a::AbstractVector) = Quaternion(0, a[1], a[2], a[3]) +function Quaternion(a::AbstractVector) + Base.depwarn("`Quaternion(::AbstractVector)` is deprecated and will be removed in the next breaking release (v0.7.0). Please use Quaternion(0, a[1], a[2], a[3]) instead.", :Quaternion) + Quaternion(0, a[1], a[2], a[3]) +end Base.promote_rule(::Type{Quaternion{T}}, ::Type{S}) where {T <: Real, S <: Real} = Quaternion{promote_type(T, S)} Base.promote_rule(::Type{Quaternion{T}}, ::Type{Complex{S}}) where {T <: Real, S <: Real} = Quaternion{promote_type(T, S)} From c0deff121b6668d96db1d2d04d97e49465ca6fdc Mon Sep 17 00:00:00 2001 From: hyrodium Date: Mon, 17 Oct 2022 20:51:59 +0900 Subject: [PATCH 27/29] add `@test_deprecated` for `quat` --- test/Quaternion.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Quaternion.jl b/test/Quaternion.jl index a063859d..8f3b65aa 100644 --- a/test/Quaternion.jl +++ b/test/Quaternion.jl @@ -111,6 +111,7 @@ Base.:(/)(a::MyReal, b::Real) = a.val / b @test quat(1, 2, 3, 4, true).norm == true # respect the .norm input (even if wrong) @test quat(1, [2, 3, 4]) === Quaternion(1, 2, 3, 4) @test quat([2, 3, 4]) === Quaternion(0, 2, 3, 4) + @test_deprecated quat([2, 3, 4]) end @testset "random generation" begin From 56224b4c45c9d1bd88fa05c7be05aa90cfb915c5 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Mon, 17 Oct 2022 21:13:48 +0900 Subject: [PATCH 28/29] add docstring of `slerp` --- src/Quaternion.jl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index 7b509510..81393e59 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -385,6 +385,29 @@ function rotationmatrix_normalized(q::Quaternion) xz - sy yz + sx 1 - (xx + yy)] end +""" + slerp(qa::Quaternion, qb::Quaternion, t::Real) + +Spherical linear interpolation (Slerp) between the inputs `qa` and `qb`. +Since the input is normalized inside the function, the absolute value of the return value will be 1. + +# Examples +```jldoctest +julia> using Quaternions + +julia> qa = Quaternion(1,0,0,0) +Quaternion{Int64}(1, 0, 0, 0, false) + +julia> qb = Quaternion(0,1,0,0) +Quaternion{Int64}(0, 1, 0, 0, false) + +julia> slerp(qa, qb, 0.6) +QuaternionF64(0.5877852522924731, 0.8090169943749475, 0.0, 0.0, true) + +julia> ans ≈ Quaternion(cospi(0.3), sinpi(0.3), 0, 0) +true +``` +""" @inline function slerp(qa0::Quaternion{T}, qb0::Quaternion{T}, t::T) where T<:Real # http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/ iszero(qa0) && throw(DomainError(qa0, "The input quaternion must be non-zero.")) From d385a99748cc3beba12bfe4276dcf2869f7fea19 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Mon, 17 Oct 2022 21:25:49 +0900 Subject: [PATCH 29/29] add more `@docs` in api.md --- docs/src/api.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/src/api.md b/docs/src/api.md index 202622de..9cfe2307 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -10,6 +10,8 @@ quat ```@docs real(::Quaternion) +real(::AbstractArray{<:Quaternion}) +real(::Type{Quaternion{T}}) where {T} ``` ```@docs @@ -20,6 +22,10 @@ imag_part conj ``` +```@docs +slerp +``` + ```@docs Quaternions.extend_analytic ```