1+ using NUnit . Framework ;
2+ using static Unity . Mathematics . math ;
3+ using Burst . Compiler . IL . Tests ;
4+
5+ namespace Unity . Mathematics . Tests
6+ {
7+ [ TestFixture ]
8+ class TestAffineTransform
9+ {
10+ [ TestCompiler ]
11+ public static void affine_transform_inverse ( )
12+ {
13+ const float tolerance = 1e-6f ;
14+
15+ var tx = AffineTransform ( float3 ( 5 , 6 , 7 ) , normalize ( math . float4 ( 1 , 2 , 3 , 4 ) ) , float3 ( 2 , 3 , 4 ) ) ;
16+ var invTx = inverse ( tx ) ;
17+
18+ TestUtils . AreEqual ( float4x4 . identity , float4x4 ( mul ( tx , invTx ) ) , tolerance ) ;
19+ }
20+
21+ [ TestCompiler ]
22+ public static void affine_transform_inverse_zero_rs_returns_zero ( )
23+ {
24+ const float tolerance = 1e-30f ;
25+
26+ var tx = AffineTransform ( float3 ( 5 , 6 , 7 ) , normalize ( float4 ( 1 , 2 , 3 , 4 ) ) , float3 . zero ) ;
27+ var invTx = inverse ( tx ) ;
28+
29+ TestUtils . AreEqual ( float4x4 . zero , invTx , tolerance ) ;
30+ }
31+
32+ [ TestCompiler ]
33+ public static void affine_transform_inverse_pico_scale ( )
34+ {
35+ // slightly larger tolerance (vs 1e-6f) for PS4
36+ const float tolerance = 2e-6f ;
37+
38+ var tx = AffineTransform ( float3 ( 5 , 6 , 7 ) , normalize ( float4 ( 1 , 2 , 3 , 4 ) ) , float3 ( 1e-12f , 1e-12f , 1e-12f ) ) ;
39+ var invTx = inverse ( tx ) ;
40+
41+ TestUtils . AreEqual ( float4x4 . identity , float4x4 ( mul ( tx , invTx ) ) , tolerance ) ;
42+ }
43+
44+ [ TestCompiler ]
45+ public static void affine_transform_inverse_singular ( )
46+ {
47+ // it needs a bit larger tolerance for singular
48+ // since it uses the svd iterative solver
49+ const float tolerance = 1e-1f ;
50+
51+ var tx = AffineTransform ( float3 ( 5 , 6 , 7 ) , normalize ( float4 ( 1 , 2 , 3 , 4 ) ) , float3 ( 0 , 3 , 4 ) ) ;
52+ var invTx = inverse ( tx ) ;
53+
54+ // pseudo inverse penrose #1 test
55+ var testTx = mul ( mul ( tx , invTx ) , tx ) ;
56+ TestUtils . AreEqual ( float4x4 ( tx ) , float4x4 ( testTx ) , tolerance ) ;
57+ }
58+
59+ [ TestCompiler ]
60+ public static void affine_transform_decompose ( )
61+ {
62+ const float tolerance = 1e-6f ;
63+
64+ var tx = AffineTransform ( float3 ( 5 , 6 , 7 ) , normalize ( float4 ( 1 , 2 , 3 , 4 ) ) , float3 ( 2 , 3 , 4 ) ) ;
65+ decompose ( tx , out var t , out var r , out var s ) ;
66+
67+ // Recompose matrix
68+ var testTx = AffineTransform ( t , r , s ) ;
69+ TestUtils . AreEqual ( float4x4 ( tx ) , float4x4 ( testTx ) , tolerance ) ;
70+ }
71+ }
72+ }
0 commit comments