Skip to content

Commit 273a04f

Browse files
committed
Additional AffineTransformation tests
1 parent e418cae commit 273a04f

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

test/affine.jl

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

77

88
@testset "Common Transformations" begin
9+
@testset "AffineTransformation" begin
10+
@testset "Simple" begin
11+
M = [1 2; 3 4]
12+
v = [-1, 1]
13+
x = [1,0]
14+
y = [0.0,1.0]
15+
A = AffineTransformation(M,v)
16+
@test A(x) == M*x + v
17+
end
918

10-
@testset "Local Affine transformation" begin
11-
S = SquareMe()
12-
x0 = [1,2,3]
13-
dx = 0.1*[1,-1,1]
14-
A = AffineTransformation(S, x0)
15-
@test isapprox(S(x0 + dx), A(x0 + dx), atol=1.01*vecnorm(dx))
16-
end
19+
@testset "composition " begin
20+
M1 = [1 2; 3 4]
21+
v1 = [-1, 1]
22+
A1 = AffineTransformation(M1,v1)
23+
M2 = [0 1; 1 0]
24+
v2 = [-2, 0]
25+
A2 = AffineTransformation(M2,v2)
26+
x = [1,0]
27+
y = [0,1]
28+
@test A1(x) == M1*x + v1
29+
@test A1(y) == M1*y + v1
30+
@test (A2A1)(x) == M2*(M1*x + v1) + v2
31+
@test (A2A1)(y) == M2*(M1*y + v1) + v2
32+
end
1733

18-
# TODO LinearTransformation and AffineTransformation
34+
@testset "inverse" begin
35+
M = [1.0 2.0; 3.0 4.0]
36+
v = [-1.0, 1.0]
37+
x = [1,0]
38+
y = [0.0,1.0]
39+
A = AffineTransformation(M,v)
40+
@test inv(A)(A(x)) x
41+
@test inv(A)(A(y)) y
42+
end
1943

44+
@testset "Affine approximation" begin
45+
S = SquareMe()
46+
x0 = [1,2,3]
47+
dx = 0.1*[1,-1,1]
48+
A = AffineTransformation(S, x0)
49+
@test isapprox(S(x0 + dx), A(x0 + dx), atol=maximum(2*dx.^2))
50+
end
51+
end
2052

2153
@testset "Translation" begin
2254
x = SVector(1.0, 2.0)

0 commit comments

Comments
 (0)