Skip to content

Commit bba4143

Browse files
committed
Reduce AffineMap application to Linear and Translation
1 parent 35b7b05 commit bba4143

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
julia 0.6
1+
julia 0.7
22
StaticArrays
33
Rotations 0.3.0
44
Compat 0.69

src/affine.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ struct AffineMap{M, V} <: AbstractAffineMap
100100
translation::V
101101
end
102102

103-
function (trans::AffineMap{M, V})(x) where {M, V}
104-
trans.linear * x + trans.translation
103+
function (trans::AffineMap)(x)
104+
l = LinearMap(trans.linear)
105+
t = Translation(trans.translation)
106+
t(l(x))
105107
end
106108

107109
# Note: the expression `Tx - dT*Tx` will have large cancellation error for

test/affine.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ struct SquareMe <: Transformation; end
44
(::SquareMe)(x) = x.^2
55
CoordinateTransformations.transform_deriv(::SquareMe, x0) = Matrix(Diagonal(2*x0))
66

7+
struct Ray37
8+
origin::Vector
9+
direction::Vector
10+
end
11+
function (m::LinearMap)(r::Ray37)
12+
Ray37(m(r.origin),
13+
m(r.direction))
14+
end
15+
function (t::Translation)(r::Ray37)
16+
Ray37(t(r.origin),
17+
r.direction)
18+
end
719

820
@testset "Common Transformations" begin
921
@testset "AffineMap" begin
@@ -97,6 +109,18 @@ CoordinateTransformations.transform_deriv(::SquareMe, x0) = Matrix(Diagonal(2*x0
97109
end
98110
end
99111

112+
@testset "application of AffineMap in terms of LinearMap and Translation" begin
113+
origin = randn(3)
114+
direction = randn(3)
115+
linear = randn(3,3)
116+
trans = randn(3)
117+
r = Ray37(origin, direction)
118+
expected = Ray37(linear*origin+trans, linear*direction)
119+
result = AffineMap(linear, trans)(r)
120+
@test expected.origin result.origin
121+
@test expected.direction result.direction
122+
end
123+
100124
#=
101125
@testset "Rotation2D on Polar" begin
102126
p = Polar(2.0, 1.0)

0 commit comments

Comments
 (0)