7
7
struct Polar{T,A}
8
8
r:: T
9
9
θ:: A
10
+
11
+ Polar {T, A} (r, θ) where {T, A} = new (r, θ)
12
+ end
13
+
14
+ function Polar (r, θ)
15
+ r2, θ2 = promote (r, θ)
16
+
17
+ return Polar {typeof(r2), typeof(θ2)} (r2, θ2)
10
18
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, θ)... )
19
+
13
20
Base. show (io:: IO , x:: Polar ) = print (io, " Polar(r=$(x. r) , θ=$(x. θ) rad)" )
14
21
Base. isapprox (p1:: Polar , p2:: Polar ; kwargs... ) = isapprox (p1. r, p2. r; kwargs... ) && isapprox (p1. θ, p2. θ; kwargs... )
15
22
@@ -71,9 +78,16 @@ struct Spherical{T,A}
71
78
r:: T
72
79
θ:: A
73
80
ϕ:: A
81
+
82
+ Spherical {T, A} (r, θ, ϕ) where {T, A} = new (r, θ, ϕ)
74
83
end
75
- Spherical (r:: T , θ:: A , ϕ:: A ) where {T<: AbstractFloat , A<: Integer } = Spherical (promote (r, θ, ϕ)... )
76
- Spherical (r:: T , θ:: A , ϕ:: A ) where {T<: Integer , A<: AbstractFloat } = Spherical (promote (r, θ, ϕ)... )
84
+
85
+ function Spherical (r, θ, ϕ)
86
+ r2, θ2, ϕ2 = promote (r, θ, ϕ)
87
+
88
+ return Spherical {typeof(r2), typeof(θ2)} (r2, θ2, ϕ2)
89
+ end
90
+
77
91
Base. show (io:: IO , x:: Spherical ) = print (io, " Spherical(r=$(x. r) , θ=$(x. θ) rad, ϕ=$(x. ϕ) rad)" )
78
92
Base. isapprox (p1:: Spherical , p2:: Spherical ; kwargs... ) = isapprox (p1. r, p2. r; kwargs... ) && isapprox (p1. θ, p2. θ; kwargs... ) && isapprox (p1. ϕ, p2. ϕ; kwargs... )
79
93
@@ -84,11 +98,16 @@ struct Cylindrical{T,A}
84
98
r:: T
85
99
θ:: A
86
100
z:: T
101
+
102
+ Cylindrical {T, A} (r, θ, z) where {T, A} = new (r, θ, z)
87
103
end
88
- Cylindrical (r:: T1 , θ:: A , z:: T2 ) where {T1<: AbstractFloat , T2<: Integer , A<: Integer } = Cylindrical (promote (r, θ, z)... )
89
- Cylindrical (r:: T1 , θ:: A , z:: T2 ) where {T1<: Integer , T2<: AbstractFloat , A<: Integer } = Cylindrical (promote (r, θ, z)... )
90
- Cylindrical (r:: T1 , θ:: A , z:: T2 ) where {T1<: AbstractFloat , T2<: Integer , A<: AbstractFloat } = Cylindrical (promote (r, θ, z)... )
91
- Cylindrical (r:: T1 , θ:: A , z:: T2 ) where {T1<: Integer , T2<: AbstractFloat , A<: AbstractFloat } = Cylindrical (promote (r, θ, z)... )
104
+
105
+ function Cylindrical (r, θ, z)
106
+ r2, θ2, z2 = promote (r, θ, z)
107
+
108
+ return Cylindrical {typeof(r2), typeof(θ2)} (r2, θ2, z2)
109
+ end
110
+
92
111
Base. show (io:: IO , x:: Cylindrical ) = print (io, " Cylindrical(r=$(x. r) , θ=$(x. θ) rad, z=$(x. z) )" )
93
112
Base. isapprox (p1:: Cylindrical , p2:: Cylindrical ; kwargs... ) = isapprox (p1. r, p2. r; kwargs... ) && isapprox (p1. θ, p2. θ; kwargs... ) && isapprox (p1. z, p2. z; kwargs... )
94
113
0 commit comments