From fe16ec7b58fb455b0a415a0b3c48b1a55f7512bd Mon Sep 17 00:00:00 2001 From: hyrodium Date: Sat, 17 Sep 2022 03:12:18 +0900 Subject: [PATCH 01/10] add docsting to quat --- src/Quaternion.jl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index d7b97338..4cfd88f6 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -66,6 +66,23 @@ Quaternion{Int64}(0, 1, 2, 3) """ quat +""" + 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]) +3-element Vector{Quaternion{Int64}}: + Quaternion{Int64}(1, 0, 0, 0, true) + Quaternion{Int64}(2, 0, 0, 0, false) + Quaternion{Int64}(3, 0, 0, 0, false) +``` +""" quat(p, v1, v2, v3) = Quaternion(p, v1, v2, v3) quat(x) = Quaternion(x) quat(s, a) = Quaternion(s, a) From 1f9759b86d93940c152a3df24444703c5b2964a3 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Sat, 17 Sep 2022 03:14:43 +0900 Subject: [PATCH 02/10] update quat(::Array) to return Array{<:Quaternion} --- src/Quaternion.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index 4cfd88f6..1157e64f 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -86,6 +86,12 @@ julia> quat([1, 2, 3]) quat(p, v1, v2, v3) = Quaternion(p, v1, v2, v3) quat(x) = Quaternion(x) quat(s, a) = Quaternion(s, a) +function quat(A::AbstractArray{T}) where T + if !isconcretetype(T) + error("`quat` not defined on abstractly-typed arrays; please convert to a more specific type") + end + convert(AbstractArray{typeof(quat(zero(T)))}, A) +end """ real(T::Type{<:Quaternion}) From b07bd74d8e7ea997742800421e9b14fbb9c12e49 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Wed, 7 Dec 2022 09:33:27 +0900 Subject: [PATCH 03/10] remove deprecated methods such as `Quaternion(s::Real, a::AbstractVector)` --- src/Quaternion.jl | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index f2f3fc10..89d147ac 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -23,14 +23,6 @@ Quaternion{T}(x::Real) where {T<:Real} = Quaternion(convert(T, x)) Quaternion{T}(q::Quaternion) where {T<:Real} = Quaternion{T}(q.s, q.v1, q.v2, q.v3) Quaternion(s::Real, v1::Real, v2::Real, v3::Real) = Quaternion(promote(s, v1, v2, v3)...) Quaternion(x::Real) = Quaternion(x, zero(x), zero(x), zero(x)) -function Quaternion(s::Real, a::AbstractVector) - Base.depwarn("`Quaternion(s::Real, a::AbstractVector)` is deprecated and will be removed in the next breaking release (v0.7.0). Please use `Quaternion(s, a[1], a[2], a[3])` instead.", :Quaternion) - Quaternion(s, a[1], a[2], a[3]) -end -function Quaternion(a::AbstractVector) - Base.depwarn("`Quaternion(a::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{Quaternion{S}}) where {T <: Real, S <: Real} = Quaternion{promote_type(T, S)} From bb5f4d80bbe4d28a3909961332d37e085dfad0b4 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Wed, 7 Dec 2022 09:34:04 +0900 Subject: [PATCH 04/10] update tests --- test/Quaternion.jl | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/test/Quaternion.jl b/test/Quaternion.jl index 51134e21..0ffaead8 100644 --- a/test/Quaternion.jl +++ b/test/Quaternion.jl @@ -49,12 +49,6 @@ end @test @inferred(Quaternion(q)) === q end end - @testset "from vector" begin - s = randn() - v = randn(3) - @test @inferred(Quaternion(s, v)) === Quaternion(s, v...) - @test @inferred(Quaternion(v)) === Quaternion(0, v) - end end @testset "==" begin @@ -90,9 +84,7 @@ end @test quat(1) === Quaternion(1) @test quat(1, 2, 3, 4) === Quaternion(1, 2, 3, 4) @test quat(Quaternion(1, 2, 3, 4)) === Quaternion(1, 2, 3, 4) - @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]) + @test quat([2, 3, 4]) == Quaternion{Int}[2, 3, 4] end @testset "random generation" begin From 74eba7bb9e7a4e47276754f3405938da35312ac0 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Wed, 7 Dec 2022 09:37:34 +0900 Subject: [PATCH 05/10] bump version to v0.7.0 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 28100ade..8e9dfbf8 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "Quaternions" uuid = "94ee1d12-ae83-5a48-8b1c-48b8ff168ae0" -version = "0.7.0-DEV" +version = "0.7.0" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" From 67d49d00f7ef28827cdeab7a469ba4f021884e9c Mon Sep 17 00:00:00 2001 From: hyrodium Date: Wed, 7 Dec 2022 09:59:12 +0900 Subject: [PATCH 06/10] fix jldoctest --- src/Quaternion.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index 89d147ac..435bf7d7 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -54,13 +54,13 @@ 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) +Quaternion{Int64}(7, 0, 0, 0) julia> quat([1, 2, 3]) 3-element Vector{Quaternion{Int64}}: - Quaternion{Int64}(1, 0, 0, 0, true) - Quaternion{Int64}(2, 0, 0, 0, false) - Quaternion{Int64}(3, 0, 0, 0, false) + Quaternion{Int64}(1, 0, 0, 0) + Quaternion{Int64}(2, 0, 0, 0) + Quaternion{Int64}(3, 0, 0, 0) ``` """ quat(p, v1, v2, v3) = Quaternion(p, v1, v2, v3) From 63990428f78131f60bbe5da8b4ed313df9b520df Mon Sep 17 00:00:00 2001 From: hyrodium Date: Wed, 7 Dec 2022 12:59:30 +0900 Subject: [PATCH 07/10] fix docstring --- src/Quaternion.jl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index 435bf7d7..43bf955c 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -40,8 +40,11 @@ Quaternion{Int64}(7, 0, 0, 0) julia> quat(1.0, 2, 3, 4) QuaternionF64(1.0, 2.0, 3.0, 4.0) -julia> quat([1, 2, 3]) # This output will be changed in the next breaking release for consistency. (#94) -Quaternion{Int64}(0, 1, 2, 3) +julia> quat([1, 2, 3]) +3-element Vector{Quaternion{Int64}}: + Quaternion{Int64}(1, 0, 0, 0) + Quaternion{Int64}(2, 0, 0, 0) + Quaternion{Int64}(3, 0, 0, 0) ``` """ quat From 1b7da0d5333aa468231584f84911fed241741833 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Wed, 7 Dec 2022 13:01:10 +0900 Subject: [PATCH 08/10] fix docstring --- src/Quaternion.jl | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index 43bf955c..b523fbbc 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -49,23 +49,6 @@ julia> quat([1, 2, 3]) """ quat -""" - 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) - -julia> quat([1, 2, 3]) -3-element Vector{Quaternion{Int64}}: - Quaternion{Int64}(1, 0, 0, 0) - Quaternion{Int64}(2, 0, 0, 0) - Quaternion{Int64}(3, 0, 0, 0) -``` -""" quat(p, v1, v2, v3) = Quaternion(p, v1, v2, v3) quat(x) = Quaternion(x) quat(s, a) = Quaternion(s, a) From fe87a0512a8cdc23f0e34a246bc514012cbeb242 Mon Sep 17 00:00:00 2001 From: Yuto Horikawa Date: Wed, 7 Dec 2022 20:38:20 +0900 Subject: [PATCH 09/10] Remove unnecessary `quat` method Co-authored-by: Seth Axen --- src/Quaternion.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index b523fbbc..c003109f 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -51,7 +51,6 @@ quat quat(p, v1, v2, v3) = Quaternion(p, v1, v2, v3) quat(x) = Quaternion(x) -quat(s, a) = Quaternion(s, a) function quat(A::AbstractArray{T}) where T if !isconcretetype(T) error("`quat` not defined on abstractly-typed arrays; please convert to a more specific type") From 67a5d5fcc0e57f853c131852beb33d58c4dd6f9f Mon Sep 17 00:00:00 2001 From: hyrodium Date: Wed, 7 Dec 2022 20:41:25 +0900 Subject: [PATCH 10/10] add test for quat(Real[1,2,3]) --- test/Quaternion.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Quaternion.jl b/test/Quaternion.jl index 0ffaead8..f4f8d687 100644 --- a/test/Quaternion.jl +++ b/test/Quaternion.jl @@ -85,6 +85,7 @@ end @test quat(1, 2, 3, 4) === Quaternion(1, 2, 3, 4) @test quat(Quaternion(1, 2, 3, 4)) === Quaternion(1, 2, 3, 4) @test quat([2, 3, 4]) == Quaternion{Int}[2, 3, 4] + @test_throws ErrorException quat(Real[1,2,3]) end @testset "random generation" begin