Skip to content

Commit 569c7bf

Browse files
authored
Merge pull request #17 from FugroRoames/rename-affine-map-05
Rename affine map
2 parents f3d249c + 7a85cdc commit 569c7bf

File tree

3 files changed

+62
-62
lines changed

3 files changed

+62
-62
lines changed

src/CoordinateTransformations.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export SphericalFromCartesian, CartesianFromSpherical,
2424
CylindricalFromSpherical, SphericalFromCylindrical
2525

2626
# Common transformations
27-
export AbstractAffineTransformation, AbstractLinearTransformation, AbstractTranslation
28-
export AffineTransformation, LinearTransformation, Translation, transformation_matrix, translation_vector, translation_vector_reverse
27+
export AbstractAffineMap
28+
export AffineMap, LinearMap, Translation
2929

3030
include("core.jl")
3131
include("coordinatesystems.jl")

src/affine.jl

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
abstract AbstractAffineTransformation <: Transformation
1+
abstract AbstractAffineMap <: Transformation
22

33
"""
4-
Translation(v) <: AbstractAffineTransformation
4+
Translation(v) <: AbstractAffineMap
55
Translation(dx, dy) (2D)
66
Translation(dx, dy, dz) (3D)
77
88
Construct the `Translation` transformation for translating Cartesian points by
99
an offset `v = (dx, dy, ...)`
1010
"""
11-
immutable Translation{V <: AbstractVector} <: AbstractAffineTransformation
11+
immutable Translation{V <: AbstractVector} <: AbstractAffineMap
1212
v::V
1313
end
1414
Translation(x::Tuple) = Translation(SVector(x))
@@ -35,72 +35,72 @@ end
3535

3636

3737
"""
38-
LinearTransformation <: AbstractAffineTransformation
39-
LinearTransformation(M)
38+
LinearMap <: AbstractAffineMap
39+
LinearMap(M)
4040
41-
A general linear transformation, constructed using `LinearTransformation(M)`
41+
A general linear transformation, constructed using `LinearMap(M)`
4242
for any `AbstractMatrix` `M`.
4343
"""
44-
immutable LinearTransformation{M <: AbstractMatrix} <: AbstractAffineTransformation
44+
immutable LinearMap{M <: AbstractMatrix} <: AbstractAffineMap
4545
m::M
4646
end
47-
Base.show(io::IO, trans::LinearTransformation) = print(io, "LinearTransformation($(trans.M))") # TODO make this output more petite
47+
Base.show(io::IO, trans::LinearMap) = print(io, "LinearMap($(trans.M))") # TODO make this output more petite
4848

49-
function (trans::LinearTransformation{M}){M}(x)
49+
function (trans::LinearMap{M}){M}(x)
5050
trans.m * x
5151
end
5252

53-
Base.inv(trans::LinearTransformation) = LinearTransformation(inv(trans.m))
53+
Base.inv(trans::LinearMap) = LinearMap(inv(trans.m))
5454

55-
compose(t1::LinearTransformation, t2::LinearTransformation) = LinearTransformation(t1.m * t2.m)
55+
compose(t1::LinearMap, t2::LinearMap) = LinearMap(t1.m * t2.m)
5656

57-
function Base.isapprox(t1::LinearTransformation, t2::LinearTransformation; kwargs...)
57+
function Base.isapprox(t1::LinearMap, t2::LinearMap; kwargs...)
5858
isapprox(t1.m, t2.m; kwargs...)
5959
end
6060

61-
function Base.isapprox(t1::LinearTransformation, t2::Translation; kwargs...)
61+
function Base.isapprox(t1::LinearMap, t2::Translation; kwargs...)
6262
isapprox(vecnorm(t1.m), 0; kwargs...) &&
6363
isapprox(vecnorm(t2.v),0; kwargs...)
6464
end
6565

66-
function Base.isapprox(t1::Translation, t2::LinearTransformation; kwargs...)
66+
function Base.isapprox(t1::Translation, t2::LinearMap; kwargs...)
6767
isapprox(vecnorm(t1.v), 0; kwargs...) &&
6868
isapprox(vecnorm(t2.m),0; kwargs...)
6969
end
7070

71-
function Base.:(==)(t1::LinearTransformation, t2::Translation)
71+
function Base.:(==)(t1::LinearMap, t2::Translation)
7272
vecnorm(t1.m) == 0 &&
7373
0 == vecnorm(t2.v)
7474
end
7575

76-
function Base.:(==)(t1::Translation, t2::LinearTransformation)
76+
function Base.:(==)(t1::Translation, t2::LinearMap)
7777
vecnorm(t1.v) == 0 &&
7878
vecnorm(t2.m) == 0
7979
end
8080

81-
transform_deriv(trans::LinearTransformation, x) = trans.m
81+
transform_deriv(trans::LinearMap, x) = trans.m
8282
# TODO transform_deriv_params
8383

8484
"""
85-
AffineTransformation <: AbstractAffineTransformation
85+
AffineMap <: AbstractAffineMap
8686
8787
A concrete affine transformation. To construct the mapping `x -> M*x + v`, use
8888
89-
AffineTransformation(M, v)
89+
AffineMap(M, v)
9090
9191
where `M` is a matrix and `v` a vector. An arbitrary `Transformation` may be
9292
converted into an affine approximation by linearizing about a point `x` using
9393
94-
AffineTransformation(trans, [x])
94+
AffineMap(trans, [x])
9595
9696
For transformations which are already affine, `x` may be omitted.
9797
"""
98-
immutable AffineTransformation{M <: AbstractMatrix, V <: AbstractVector} <: AbstractAffineTransformation
98+
immutable AffineMap{M <: AbstractMatrix, V <: AbstractVector} <: AbstractAffineMap
9999
m::M
100100
v::V
101101
end
102102

103-
function (trans::AffineTransformation{M,V}){M,V}(x)
103+
function (trans::AffineMap{M,V}){M,V}(x)
104104
trans.m * x + trans.v
105105
end
106106

@@ -109,98 +109,98 @@ end
109109
# translation won't fix things, because then we'd have `Tx*(x-x0)` which
110110
# also can incur large cancellation error in `x-x0`.
111111
"""
112-
AffineTransformation(trans::Transformation, x0)
112+
AffineMap(trans::Transformation, x0)
113113
114114
Create an Affine transformation corresponding to the differential transformation
115115
of `x0 + dx` according to `trans`, i.e. the Affine transformation that is
116116
locally most accurate in the vicinity of `x0`.
117117
"""
118-
function AffineTransformation(trans::Transformation, x0)
118+
function AffineMap(trans::Transformation, x0)
119119
dT = transform_deriv(trans, x0)
120120
Tx = trans(x0)
121-
AffineTransformation(dT, Tx - dT*x0)
121+
AffineMap(dT, Tx - dT*x0)
122122
end
123123

124-
Base.show(io::IO, trans::AffineTransformation) = print(io, "AffineTransformation($(trans.M), $(trans.v))") # TODO make this output more petite
124+
Base.show(io::IO, trans::AffineMap) = print(io, "AffineMap($(trans.M), $(trans.v))") # TODO make this output more petite
125125

126-
function compose(t1::Translation, t2::LinearTransformation)
127-
AffineTransformation(t2.m, t1.v)
126+
function compose(t1::Translation, t2::LinearMap)
127+
AffineMap(t2.m, t1.v)
128128
end
129129

130-
function compose(t1::LinearTransformation, t2::Translation)
131-
AffineTransformation(t1.m, t1.m * t2.v)
130+
function compose(t1::LinearMap, t2::Translation)
131+
AffineMap(t1.m, t1.m * t2.v)
132132
end
133133

134-
function compose(t1::AffineTransformation, t2::AffineTransformation)
135-
AffineTransformation(t1.m * t2.m, t1.v + t1.m * t2.v)
134+
function compose(t1::AffineMap, t2::AffineMap)
135+
AffineMap(t1.m * t2.m, t1.v + t1.m * t2.v)
136136
end
137137

138-
function compose(t1::AffineTransformation, t2::LinearTransformation)
139-
AffineTransformation(t1.m * t2.m, t1.v)
138+
function compose(t1::AffineMap, t2::LinearMap)
139+
AffineMap(t1.m * t2.m, t1.v)
140140
end
141141

142-
function compose(t1::LinearTransformation, t2::AffineTransformation)
143-
AffineTransformation(t1.m * t2.m, t1.m * t2.v)
142+
function compose(t1::LinearMap, t2::AffineMap)
143+
AffineMap(t1.m * t2.m, t1.m * t2.v)
144144
end
145145

146-
function compose(t1::AffineTransformation, t2::Translation)
147-
AffineTransformation(t1.m, t1.v + t1.m * t2.v)
146+
function compose(t1::AffineMap, t2::Translation)
147+
AffineMap(t1.m, t1.v + t1.m * t2.v)
148148
end
149149

150-
function compose(t1::Translation, t2::AffineTransformation)
151-
AffineTransformation(t2.m, t1.v + t2.v)
150+
function compose(t1::Translation, t2::AffineMap)
151+
AffineMap(t2.m, t1.v + t2.v)
152152
end
153153

154-
function Base.inv(trans::AffineTransformation)
154+
function Base.inv(trans::AffineMap)
155155
m_inv = inv(trans.m)
156-
AffineTransformation(m_inv, m_inv * (-trans.v))
156+
AffineMap(m_inv, m_inv * (-trans.v))
157157
end
158158

159-
function Base.isapprox(t1::AffineTransformation, t2::AffineTransformation; kwargs...)
159+
function Base.isapprox(t1::AffineMap, t2::AffineMap; kwargs...)
160160
isapprox(t1.m, t2.m; kwargs...) &&
161161
isapprox(t1.v, t2.v; kwargs...)
162162
end
163163

164-
function Base.isapprox(t1::AffineTransformation, t2::Translation; kwargs...)
164+
function Base.isapprox(t1::AffineMap, t2::Translation; kwargs...)
165165
isapprox(vecnorm(t1.m), 0; kwargs...) &&
166166
isapprox(t1.v, t2.v; kwargs...)
167167
end
168168

169-
function Base.isapprox(t1::Translation, t2::AffineTransformation; kwargs...)
169+
function Base.isapprox(t1::Translation, t2::AffineMap; kwargs...)
170170
isapprox(vecnorm(t2.m), 0; kwargs...) &&
171171
isapprox(t1.v, t2.v; kwargs...)
172172
end
173173

174-
function Base.isapprox(t1::AffineTransformation, t2::LinearTransformation; kwargs...)
174+
function Base.isapprox(t1::AffineMap, t2::LinearMap; kwargs...)
175175
isapprox(t1.m, t2.m; kwargs...) &&
176176
isapprox(vecnorm(t1.v), 0; kwargs...)
177177
end
178178

179-
function Base.isapprox(t1::LinearTransformation, t2::AffineTransformation; kwargs...)
179+
function Base.isapprox(t1::LinearMap, t2::AffineMap; kwargs...)
180180
isapprox(t1.m, t2.m; kwargs...) &&
181181
isapprox(0, vecnorm(t2.v); kwargs...)
182182
end
183183

184184

185-
function Base.:(==)(t1::AffineTransformation, t2::Translation)
185+
function Base.:(==)(t1::AffineMap, t2::Translation)
186186
vecnorm(t1.m) == 0 &&
187187
t1.v == t2.v
188188
end
189189

190-
function Base.:(==)(t1::Translation, t2::AffineTransformation)
190+
function Base.:(==)(t1::Translation, t2::AffineMap)
191191
vecnorm(t2.m) == 0 &&
192192
t1.v == t2.v
193193
end
194194

195-
function Base.:(==)(t1::AffineTransformation, t2::LinearTransformation)
195+
function Base.:(==)(t1::AffineMap, t2::LinearMap)
196196
t1.m == t2.m &&
197197
vecnorm(t1.v) == 0
198198
end
199199

200-
function Base.:(==)(t1::LinearTransformation, t2::AffineTransformation)
200+
function Base.:(==)(t1::LinearMap, t2::AffineMap)
201201
t1.m == t2.m &&
202202
0 == vecnorm(t2.v)
203203
end
204204

205-
transform_deriv(trans::AffineTransformation, x) = trans.m
205+
transform_deriv(trans::AffineMap, x) = trans.m
206206
# TODO transform_deriv_params

test/affine.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ CoordinateTransformations.transform_deriv(::SquareMe, x0) = diagm(2*x0)
66

77

88
@testset "Common Transformations" begin
9-
@testset "AffineTransformation" begin
9+
@testset "AffineMap" begin
1010
@testset "Simple" begin
1111
M = [1 2; 3 4]
1212
v = [-1, 1]
1313
x = [1,0]
1414
y = [0.0,1.0]
15-
A = AffineTransformation(M,v)
15+
A = AffineMap(M,v)
1616
@test A(x) == M*x + v
1717
end
1818

1919
@testset "composition " begin
2020
M1 = [1 2; 3 4]
2121
v1 = [-1, 1]
22-
A1 = AffineTransformation(M1,v1)
22+
A1 = AffineMap(M1,v1)
2323
M2 = [0 1; 1 0]
2424
v2 = [-2, 0]
25-
A2 = AffineTransformation(M2,v2)
25+
A2 = AffineMap(M2,v2)
2626
x = [1,0]
2727
y = [0,1]
2828
@test A1(x) == M1*x + v1
@@ -36,7 +36,7 @@ CoordinateTransformations.transform_deriv(::SquareMe, x0) = diagm(2*x0)
3636
v = [-1.0, 1.0]
3737
x = [1,0]
3838
y = [0.0,1.0]
39-
A = AffineTransformation(M,v)
39+
A = AffineMap(M,v)
4040
@test inv(A)(A(x)) x
4141
@test inv(A)(A(y)) y
4242
end
@@ -45,16 +45,16 @@ CoordinateTransformations.transform_deriv(::SquareMe, x0) = diagm(2*x0)
4545
S = SquareMe()
4646
x0 = [1,2,3]
4747
dx = 0.1*[1,-1,1]
48-
A = AffineTransformation(S, x0)
48+
A = AffineMap(S, x0)
4949
@test isapprox(S(x0 + dx), A(x0 + dx), atol=maximum(2*dx.^2))
5050
end
5151
end
5252

53-
@testset "LinearTransformation" begin
53+
@testset "LinearMap" begin
5454
M = [1 2; 3 4]
5555
x = [1,0]
5656
y = [0,1]
57-
L = LinearTransformation(M)
57+
L = LinearMap(M)
5858
@test L(x) == M*x
5959
@test inv(L)(x) == inv(M)*x
6060
@test inv(L)(y) == inv(M)*y

0 commit comments

Comments
 (0)