Skip to content

Commit b04badb

Browse files
authored
Add deprecated messages for the next breaking release (v0.7.0) (#110)
* add deprecated messages to rotation-related functions * add deprecated messages to argq * add deprecated messages to normalize-related functions * update deprecated messages for Quaternion constructor * fix typo in Base.angle * add deprecated messages to the `Complex`-`Quaternion` compatibility * add deprecated messages to `norm` field * bump version to v0.6.1
1 parent 1bc31da commit b04badb

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Quaternions"
22
uuid = "94ee1d12-ae83-5a48-8b1c-48b8ff168ae0"
3-
version = "0.6.0"
3+
version = "0.6.1"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/Quaternion.jl

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,45 @@ const QuaternionF32 = Quaternion{Float32}
2121
const QuaternionF64 = Quaternion{Float64}
2222

2323
Quaternion{T}(x::Real) where {T<:Real} = Quaternion(convert(T, x))
24-
Quaternion{T}(x::Complex) where {T<:Real} = Quaternion(convert(Complex{T}, x))
24+
function Quaternion{T}(x::Complex) where {T<:Real}
25+
Base.depwarn("`Complex`-`Quaternion` compatibility is deprecated and will be removed in the next breaking release (v0.7.0).", :Quaternion)
26+
Quaternion(convert(Complex{T}, x))
27+
end
2528
Quaternion{T}(q::Quaternion) where {T<:Real} = Quaternion{T}(q.s, q.v1, q.v2, q.v3, q.norm)
26-
Quaternion(s::Real, v1::Real, v2::Real, v3::Real, n::Bool = false) =
29+
function Quaternion(s::Real, v1::Real, v2::Real, v3::Real, n::Bool = false)
30+
Base.depwarn("The `norm` field is deprecated and will be removed in the next breaking release (v0.7.0).", :Quaternion)
2731
Quaternion(promote(s, v1, v2, v3)..., n)
32+
end
2833
Quaternion(x::Real) = Quaternion(x, zero(x), zero(x), zero(x), abs(x) == one(x))
29-
Quaternion(z::Complex) = Quaternion(z.re, z.im, zero(z.re), zero(z.re), abs(z) == one(z.re))
30-
Quaternion(s::Real, a::AbstractVector) = Quaternion(s, a[1], a[2], a[3])
34+
function Quaternion(z::Complex)
35+
Base.depwarn("`Complex`-`Quaternion` compatibility is deprecated and will be removed in the next breaking release (v0.7.0).", :Quaternion)
36+
Quaternion(z.re, z.im, zero(z.re), zero(z.re), abs(z) == one(z.re))
37+
end
38+
function Quaternion(s::Real, a::AbstractVector)
39+
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)
40+
Quaternion(s, a[1], a[2], a[3])
41+
end
3142
function Quaternion(a::AbstractVector)
32-
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)
43+
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)
3344
Quaternion(0, a[1], a[2], a[3])
3445
end
3546

3647
Base.promote_rule(::Type{Quaternion{T}}, ::Type{S}) where {T <: Real, S <: Real} = Quaternion{promote_type(T, S)}
37-
Base.promote_rule(::Type{Quaternion{T}}, ::Type{Complex{S}}) where {T <: Real, S <: Real} = Quaternion{promote_type(T, S)}
48+
function Base.promote_rule(::Type{Quaternion{T}}, ::Type{Complex{S}}) where {T <: Real, S <: Real}
49+
Base.depwarn("`Complex`-`Quaternion` compatibility is deprecated and will be removed in the next breaking release (v0.7.0).", :Quaternion)
50+
Quaternion{promote_type(T, S)}
51+
end
3852
Base.promote_rule(::Type{Quaternion{T}}, ::Type{Quaternion{S}}) where {T <: Real, S <: Real} = Quaternion{promote_type(T, S)}
3953

54+
function Base.getproperty(q::Quaternion, s::Symbol)
55+
if s === :norm
56+
Base.depwarn("The `norm` field is deprecated and will be removed in the next breaking release (v0.7.0).", :Quaternion)
57+
getfield(q,:norm)
58+
else
59+
getfield(q,s)
60+
end
61+
end
62+
4063
"""
4164
quat(r, [i, j, k])
4265
@@ -152,6 +175,7 @@ Base.isnan(q::Quaternion) = isnan(real(q)) | isnan(q.v1) | isnan(q.v2) | isnan(q
152175
Base.isinf(q::Quaternion) = ~q.norm & (isinf(q.s) | isinf(q.v1) | isinf(q.v2) | isinf(q.v3))
153176

154177
function LinearAlgebra.normalize(q::Quaternion)
178+
Base.depwarn("`LinearAlgebra.normalize(q::Quaternion)` is deprecated. Please use `sign(q)` instead.", :normalize)
155179
if (q.norm)
156180
return q
157181
end
@@ -160,6 +184,7 @@ function LinearAlgebra.normalize(q::Quaternion)
160184
end
161185

162186
function normalizea(q::Quaternion)
187+
Base.depwarn("`normalizea(q::Quaternion)` is deprecated. Please use `sign(q), abs(q)` instead.", :normalizea)
163188
if (q.norm)
164189
return (q, one(q.s))
165190
end
@@ -169,6 +194,7 @@ function normalizea(q::Quaternion)
169194
end
170195

171196
function normalizeq(q::Quaternion)
197+
Base.depwarn("`normalizeq(q::Quaternion)` is deprecated. Please use `sign(q)` instead.", :normalizea)
172198
a = abs(q)
173199
if a > 0
174200
q = q / a
@@ -200,17 +226,24 @@ Base.:(==)(q::Quaternion, w::Quaternion) = (q.s == w.s) & (q.v1 == w.v1) & (q.v2
200226

201227
angleaxis(q::Quaternion) = angle(q), axis(q)
202228

203-
Base.angle(q::Quaternion) = 2 * atan(abs_imag(q), real(q))
229+
function Base.angle(q::Quaternion)
230+
Base.depwarn("`Base.angle(::Quaternion)` is deprecated. Please consider using Rotations package instead.", :angle)
231+
2 * atan(abs_imag(q), real(q))
232+
end
204233

205234
function axis(q::Quaternion)
235+
Base.depwarn("`axis(::Quaternion)` is deprecated. Please consider using Rotations package instead.", :axis)
206236
q = normalize(q)
207237
s = sin(angle(q) / 2)
208238
abs(s) > 0 ?
209239
[q.v1, q.v2, q.v3] / s :
210240
[1.0, 0.0, 0.0]
211241
end
212242

213-
argq(q::Quaternion) = normalizeq(Quaternion(0, q.v1, q.v2, q.v3))
243+
function argq(q::Quaternion)
244+
Base.depwarn("`argq(q::Quaternion)` is deprecated. Use `quat(0, imag_part(q)...)` instead.", :argq)
245+
normalizeq(Quaternion(0, q.v1, q.v2, q.v3))
246+
end
214247

215248
"""
216249
extend_analytic(f, q::Quaternion)
@@ -318,6 +351,7 @@ end
318351
## Rotations
319352

320353
function qrotation(axis::AbstractVector{T}, theta) where {T <: Real}
354+
Base.depwarn("`qrotation(::AbstractVector)` is deprecated. Please consider using Rotations package instead.", :qrotation)
321355
if length(axis) != 3
322356
error("Must be a 3-vector")
323357
end
@@ -333,6 +367,7 @@ end
333367

334368
# Variant of the above where norm(rotvec) encodes theta
335369
function qrotation(rotvec::AbstractVector{T}) where {T <: Real}
370+
Base.depwarn("`qrotation(::AbstractVector)` is deprecated. Please consider using Rotations package instead.", :qrotation)
336371
if length(rotvec) != 3
337372
error("Must be a 3-vector")
338373
end
@@ -343,6 +378,7 @@ function qrotation(rotvec::AbstractVector{T}) where {T <: Real}
343378
end
344379

345380
function qrotation(dcm::AbstractMatrix{T}) where {T<:Real}
381+
Base.depwarn("`qrotation(::AbstractMatrix)` is deprecated. Please consider using Rotations package instead.", :qrotation)
346382
# See https://arxiv.org/pdf/math/0701759.pdf
347383
a2 = 1 + dcm[1,1] + dcm[2,2] + dcm[3,3]
348384
b2 = 1 + dcm[1,1] - dcm[2,2] - dcm[3,3]
@@ -370,13 +406,15 @@ function qrotation(dcm::AbstractMatrix{T}) where {T<:Real}
370406
end
371407

372408
function qrotation(dcm::AbstractMatrix{T}, qa::Quaternion) where {T<:Real}
409+
Base.depwarn("`qrotation(::AbstractMatrix, ::Quaternion)` is deprecated. Please consider using Rotations package instead.", :qrotation)
373410
q = qrotation(dcm)
374411
abs(q-qa) < abs(q+qa) ? q : -q
375412
end
376413

377414
rotationmatrix(q::Quaternion) = rotationmatrix_normalized(normalize(q))
378415

379416
function rotationmatrix_normalized(q::Quaternion)
417+
Base.depwarn("`rotationmatrix_normalized(::Quaternion)` is deprecated. Please consider using Rotations package instead.", :rotationmatrix_normalized)
380418
sx, sy, sz = 2q.s * q.v1, 2q.s * q.v2, 2q.s * q.v3
381419
xx, xy, xz = 2q.v1^2, 2q.v1 * q.v2, 2q.v1 * q.v3
382420
yy, yz, zz = 2q.v2^2, 2q.v2 * q.v3, 2q.v3^2

0 commit comments

Comments
 (0)