|
2 | 2 | ### 2D Coordinate systems ###
|
3 | 3 | #############################
|
4 | 4 | """
|
5 |
| -`Polar{T}(r::T, θ::T)` - 2D polar coordinates |
| 5 | +`Polar{T,A}(r::T, θ::A)` - 2D polar coordinates |
6 | 6 | """
|
7 |
| -struct Polar{T} |
| 7 | +struct Polar{T,A} |
8 | 8 | r::T
|
9 |
| - θ::T |
| 9 | + θ::A |
10 | 10 | end
|
| 11 | +Polar(r::T, θ::A) where {T<:AbstractFloat, A<:Integer} = Polar(promote(r, θ)...) |
| 12 | +Polar(r::T, θ::A) where {T<:Integer, A<:AbstractFloat} = Polar(promote(r, θ)...) |
11 | 13 | Base.show(io::IO, x::Polar) = print(io, "Polar(r=$(x.r), θ=$(x.θ) rad)")
|
12 | 14 | Base.isapprox(p1::Polar, p2::Polar; kwargs...) = isapprox(p1.r, p2.r; kwargs...) && isapprox(p1.θ, p2.θ; kwargs...)
|
13 |
| -Base.eltype(::Polar{T}) where {T} = T |
14 |
| -Base.eltype(::Type{Polar{T}}) where {T} = T |
| 15 | +Base.eltype(::Polar{T,A}) where {T,A} = promote_type(T, A) |
| 16 | +Base.eltype(::Type{Polar{T,A}}) where {T,A} = promote_type(T, A) |
15 | 17 |
|
16 | 18 | "`PolarFromCartesian()` - transformation from `AbstractVector` of length 2 to `Polar` type"
|
17 | 19 | struct PolarFromCartesian <: Transformation; end
|
@@ -67,28 +69,34 @@ Base.convert(::Type{Polar}, v::AbstractVector) = PolarFromCartesian()(v)
|
67 | 69 | """
|
68 | 70 | Spherical(r, θ, ϕ) - 3D spherical coordinates
|
69 | 71 | """
|
70 |
| -struct Spherical{T} |
| 72 | +struct Spherical{T,A} |
71 | 73 | r::T
|
72 |
| - θ::T |
73 |
| - ϕ::T |
| 74 | + θ::A |
| 75 | + ϕ::A |
74 | 76 | end
|
| 77 | +Spherical(r::T, θ::A, ϕ::A) where {T<:AbstractFloat, A<:Integer} = Spherical(promote(r, θ, ϕ)...) |
| 78 | +Spherical(r::T, θ::A, ϕ::A) where {T<:Integer, A<:AbstractFloat} = Spherical(promote(r, θ, ϕ)...) |
75 | 79 | Base.show(io::IO, x::Spherical) = print(io, "Spherical(r=$(x.r), θ=$(x.θ) rad, ϕ=$(x.ϕ) rad)")
|
76 | 80 | Base.isapprox(p1::Spherical, p2::Spherical; kwargs...) = isapprox(p1.r, p2.r; kwargs...) && isapprox(p1.θ, p2.θ; kwargs...) && isapprox(p1.ϕ, p2.ϕ; kwargs...)
|
77 |
| -Base.eltype(::Spherical{T}) where {T} = T |
78 |
| -Base.eltype(::Type{Spherical{T}}) where {T} = T |
| 81 | +Base.eltype(::Spherical{T,A}) where {T,A} = promote_type(T, A) |
| 82 | +Base.eltype(::Type{Spherical{T,A}}) where {T,A} = promote_type(T, A) |
79 | 83 |
|
80 | 84 | """
|
81 | 85 | Cylindrical(r, θ, z) - 3D cylindrical coordinates
|
82 | 86 | """
|
83 |
| -struct Cylindrical{T} |
| 87 | +struct Cylindrical{T,A} |
84 | 88 | r::T
|
85 |
| - θ::T |
| 89 | + θ::A |
86 | 90 | z::T
|
87 | 91 | end
|
| 92 | +Cylindrical(r::T1, θ::A, z::T2) where {T1<:AbstractFloat, T2<:Integer, A<:Integer} = Cylindrical(promote(r, θ, z)...) |
| 93 | +Cylindrical(r::T1, θ::A, z::T2) where {T1<:Integer, T2<:AbstractFloat, A<:Integer} = Cylindrical(promote(r, θ, z)...) |
| 94 | +Cylindrical(r::T1, θ::A, z::T2) where {T1<:AbstractFloat, T2<:Integer, A<:AbstractFloat} = Cylindrical(promote(r, θ, z)...) |
| 95 | +Cylindrical(r::T1, θ::A, z::T2) where {T1<:Integer, T2<:AbstractFloat, A<:AbstractFloat} = Cylindrical(promote(r, θ, z)...) |
88 | 96 | Base.show(io::IO, x::Cylindrical) = print(io, "Cylindrical(r=$(x.r), θ=$(x.θ) rad, z=$(x.z))")
|
89 | 97 | Base.isapprox(p1::Cylindrical, p2::Cylindrical; kwargs...) = isapprox(p1.r, p2.r; kwargs...) && isapprox(p1.θ, p2.θ; kwargs...) && isapprox(p1.z, p2.z; kwargs...)
|
90 |
| -Base.eltype(::Cylindrical{T}) where {T} = T |
91 |
| -Base.eltype(::Type{Cylindrical{T}}) where {T} = T |
| 98 | +Base.eltype(::Cylindrical{T,A}) where {T,A} = promote_type(T, A) |
| 99 | +Base.eltype(::Type{Cylindrical{T,A}}) where {T,A} = promote_type(T, A) |
92 | 100 |
|
93 | 101 | "`SphericalFromCartesian()` - transformation from 3D point to `Spherical` type"
|
94 | 102 | struct SphericalFromCartesian <: Transformation; end
|
|
0 commit comments