1
1
abstract AbstractAffineTransformation <: Transformation
2
+ abstract AbstractLinearTransformation <: AbstractAffineTransformation
2
3
3
-
4
- # Composite affine transformation.
5
- """
6
- A composite of two affine transformations
7
- """
8
- immutable ComposedAffineTransformation{T1 <: AbstractAffineTransformation , T2 <: AbstractAffineTransformation } <: AbstractAffineTransformation
9
- comp:: ComposedTransformation{T1,T2}
10
- end
11
-
12
- ComposedAffineTransformation (t1, t2) = ComposedAffineTransformation (ComposedTransformation (t1,t2))
13
-
14
- # The repetition below is required since we can't inherit both from
15
- # AbstractAffineTransformation and AbstractComposedTransformation. (Needs
16
- # traits!)
17
- Base. show (io:: IO , trans:: ComposedAffineTransformation ) = show (io, trans. comp)
18
- @compat @inline (trans:: ComposedAffineTransformation )(x) = trans. comp (x)
19
- Base. inv (trans:: ComposedAffineTransformation ) = ComposedAffineTransformation (inv (trans. comp))
20
- transform_deriv (trans:: ComposedAffineTransformation , x) = transform_deriv (trans. comp, x)
21
- transform_deriv_params (trans:: ComposedAffineTransformation , x) = transform_deriv_params (trans. comp, x)
22
-
23
- compose (t1:: AbstractAffineTransformation , t2:: AbstractAffineTransformation ) = ComposedAffineTransformation (t1,t2)
24
-
4
+ # Helper to compute a zeroed input point for an affine transformation
5
+ # FIXME : deal with general input dimension and type.
6
+ zeroed_input (trans:: AbstractAffineTransformation ) = Vec (0 ,0 ,0 )
25
7
26
8
# transform_deriv for AbstractAffineTransformation is independent of the point
27
9
# about which we're linearizing.
28
10
function transform_deriv (trans:: AbstractAffineTransformation )
29
- x = Vec (0 ,0 ,0 ) # FIXME : deal with general input dimension and type.
30
- transform_deriv (trans, x)
11
+ transform_deriv (trans, zeroed_input (trans))
31
12
end
32
13
14
+
33
15
# -------------------------------------------------------------------------------
34
16
# Linear Transformations
35
17
36
- immutable LinearTransformation{MatrixT} <: AbstractAffineTransformation
18
+ """
19
+ LinearTransformation <: AbstractLinearTransformation
20
+
21
+ A general linear transformation, constructed using `LinearTransformation(M)`
22
+ for any matrix `M`. Other abstract linear transformations can be converted
23
+ into a general linear transformation using `LinearTransformation(trans)`
24
+ """
25
+ immutable LinearTransformation{MatrixT} <: AbstractLinearTransformation
37
26
M:: MatrixT
38
27
end
39
28
29
+ LinearTransformation (trans:: LinearTransformation ) = trans
30
+
31
+ function LinearTransformation (trans:: AbstractLinearTransformation )
32
+ LinearTransformation (transform_deriv (trans, zeroed_input (trans)))
33
+ end
34
+
40
35
Base. show (io:: IO , trans:: LinearTransformation ) = print (io, " LinearTransformation($(trans. M) )" )
41
36
42
37
@compat function (trans:: LinearTransformation )(x)
@@ -47,7 +42,12 @@ Base.inv(trans::LinearTransformation) = LinearTransformation(inv(trans.M))
47
42
48
43
compose (t1:: LinearTransformation , t2:: LinearTransformation ) = LinearTransformation (t1. M* t2. M)
49
44
50
- transform_deriv (trans:: LinearTransformation ) = trans. M
45
+ transform_deriv (trans:: LinearTransformation , x) = trans. M
46
+
47
+
48
+ function compose (t1:: AbstractLinearTransformation , t2:: AbstractLinearTransformation )
49
+ LinearTransformation (t1) ∘ LinearTransformation (t2)
50
+ end
51
51
52
52
53
53
# -------------------------------------------------------------------------------
@@ -72,11 +72,15 @@ immutable AffineTransformation{MatrixT, VectorT} <: AbstractAffineTransformation
72
72
end
73
73
74
74
function AffineTransformation (trans:: AbstractAffineTransformation )
75
- # FIXME : How do we deal with general input dimension and type?
76
- x = Vec (0 ,0 ,0 )
75
+ x = zeroed_input (trans)
77
76
AffineTransformation (transform_deriv (trans, x), trans (x))
78
77
end
79
78
79
+ function AffineTransformation (trans:: AbstractLinearTransformation )
80
+ x = zeroed_input (trans)
81
+ AffineTransformation (transform_deriv (trans, x), x)
82
+ end
83
+
80
84
function AffineTransformation (trans:: Transformation , x)
81
85
AffineTransformation (transform_deriv (trans, x), trans (x))
82
86
end
@@ -100,6 +104,10 @@ function compose(t1::AffineTransformation, t2::AffineTransformation)
100
104
AffineTransformation (t1. M* t2. M, t1. v + t1. M* t2. v)
101
105
end
102
106
107
+ function compose (t1:: AbstractAffineTransformation , t2:: AbstractAffineTransformation )
108
+ AffineTransformation (t1) ∘ AffineTransformation (t2)
109
+ end
110
+
103
111
"""
104
112
affine_decomposition_T_of_L(trans)
105
113
175
183
Construct the `Rotation2D` transformation for rotating 2D Cartesian points
176
184
(i.e. `FixedVector{2}`s) about the origin.
177
185
"""
178
- immutable Rotation2D{T} <: AbstractAffineTransformation
186
+ immutable Rotation2D{T} <: AbstractLinearTransformation
179
187
angle:: T
180
188
sin:: T
181
189
cos:: T
@@ -251,7 +259,7 @@ compose(t1::Rotation2D, t2::Rotation2D) = Rotation2D(t1.angle + t2.angle)
251
259
Construct the `Rotation` transformation for rotating 3D Cartesian points
252
260
(i.e. `FixedVector{3}`s) about the origin. I
253
261
"""
254
- immutable Rotation{R, T} <: AbstractAffineTransformation
262
+ immutable Rotation{R, T} <: AbstractLinearTransformation
255
263
rotation:: R
256
264
matrix:: Mat{3,3,T} # Should we enforce this storage, or merely "suggest" it
257
265
end
@@ -391,7 +399,7 @@ the Z axis).
391
399
392
400
(see also `Rotation`, `RotationYZ`, `RotationZX` and `euler_rotation`)
393
401
"""
394
- immutable RotationXY{T} <: AbstractAffineTransformation
402
+ immutable RotationXY{T} <: AbstractLinearTransformation
395
403
angle:: T
396
404
sin:: T
397
405
cos:: T
@@ -405,7 +413,7 @@ the X axis).
405
413
406
414
(see also `Rotation`, `RotationXY`, `RotationZX` and `euler_rotation`)
407
415
"""
408
- immutable RotationYZ{T} <: AbstractAffineTransformation
416
+ immutable RotationYZ{T} <: AbstractLinearTransformation
409
417
angle:: T
410
418
sin:: T
411
419
cos:: T
@@ -419,7 +427,7 @@ the Y axis).
419
427
420
428
(see also `Rotation`, `RotationXY`, `RotationYZ` and `euler_rotation`)
421
429
"""
422
- immutable RotationZX{T} <: AbstractAffineTransformation
430
+ immutable RotationZX{T} <: AbstractLinearTransformation
423
431
angle:: T
424
432
sin:: T
425
433
cos:: T
0 commit comments