Skip to content

Commit

Permalink
update quat(::Array) to return Array{<:Quaternion} (#95)
Browse files Browse the repository at this point in the history
* add docsting to quat

* update quat(::Array) to return Array{<:Quaternion}

* remove deprecated methods such as `Quaternion(s::Real, a::AbstractVector)`

* update tests

* bump version to v0.7.0

* fix jldoctest

* fix docstring

* fix docstring

* Remove unnecessary `quat` method

Co-authored-by: Seth Axen <seth@sethaxen.com>

* add test for quat(Real[1,2,3])

Co-authored-by: Seth Axen <seth@sethaxen.com>
  • Loading branch information
hyrodium and sethaxen committed Dec 7, 2022
1 parent 3ab59a0 commit 0f57093
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
22 changes: 11 additions & 11 deletions src/Quaternion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand All @@ -48,15 +40,23 @@ 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

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})
Expand Down
11 changes: 2 additions & 9 deletions test/Quaternion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -90,9 +84,8 @@ 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]
@test_throws ErrorException quat(Real[1,2,3])
end

@testset "random generation" begin
Expand Down

2 comments on commit 0f57093

@hyrodium
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/73647

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.0 -m "<description of version>" 0f5709343a40e565676c3fa016f1e389f95f45db
git push origin v0.7.0

Please sign in to comment.