2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
20 #include <dali/dali.h>
21 #include <dali-test-suite-utils.h>
26 void utc_dali_matrix3_startup(void)
28 test_return_value = TET_UNDEF;
31 void utc_dali_matrix3_cleanup(void)
33 test_return_value = TET_PASS;
40 -18.6f, 1.88e-09f, -6.85e-09f,
42 -1.36e-08f,13.2f, -13.2f);
45 -18.6f,6.91e-06f, 6.76e-06f,
46 8.04e-09f,13.2f, 13.2f,
47 3.01e-06f,13.2f, -13.2f);
51 -17.6f,-4.46f, -4.37f,
52 -0.0641f,13.2f, -13.2f);
57 -0.0371f,13.1f, -13.3f);
62 -0.257f,13.0f, -13.4f);
65 -2.43f, -13.2f, -200.9f,
67 0.257f, 13.0f, 13.4f);
98 -18.6f, 0.0f, -1.36e-08f,
99 1.88e-09f,13.2f, 13.2f,
100 -6.85e-09f,13.2f, -13.2f);
103 -18.6f,8.04e-09f, 3.01e-06f,
104 6.91e-06f,13.2f, 13.2f,
105 6.76e-06f,13.2f, -13.2f);
108 6.24f,-17.6f, -0.0641f,
109 -12.4f,-4.46f, 13.2f,
110 -12.4f, -4.37f, -13.2f);
113 -16.3f,9.05f, -0.0371f,
115 6.38f,11.4f, -13.3f);
118 -2.43f,18.5f, -0.257f,
120 12.9f, 1.51f, -13.4f);
124 Matrix3* matrices[5] = { &m1, &m2, &m3, &m4, &m5 };
125 Matrix3* inverseMatrices[5] = { &i1, &i2, &i3, &i4, &i5 };
126 Matrix3* transposeMatrices[5] = { &t1, &t2, &t3, &t4, &t5 };
128 } // anonymous namespace
130 int UtcDaliMatrix3FromMatrix(void)
132 float els0[] = { 0.0f, 1.0f, 2.0f, 3.0f,
133 4.0f, 5.0f, 6.0f, 7.0f,
134 8.0f, 9.0f, 10.0f, 11.0f,
135 12.0f, 13.0f, 14.0f, 15.0f};
137 Matrix3 m1(0.0f, 1.0f, 2.0f,
143 DALI_TEST_EQUALS(m1, m2, 0.001, TEST_LOCATION);
147 int UtcDaliMatrix3OperatorAssign01(void)
149 float els0[] = { 0.0f, 1.0f, 2.0f, 3.0f,
150 4.0f, 5.0f, 6.0f, 7.0f,
151 8.0f, 9.0f, 10.0f, 11.0f,
152 12.0f, 13.0f, 14.0f, 15.0f};
155 Matrix3 m1(0.0f, 1.0f, 2.0f,
161 m2 = m2; // Test branch
163 DALI_TEST_EQUALS(m1, m2, 0.001, TEST_LOCATION);
168 int UtcDaliMatrix3OperatorAssign02(void)
170 Matrix3 m0(0.0f, 1.0f, 2.0f,
174 Matrix3 m1(0.0f, 1.0f, 2.0f,
181 DALI_TEST_EQUALS(m1, m2, 0.001, TEST_LOCATION);
188 int UtcDaliMatrix3AsFloat(void)
190 float values[] = {0.0f, 1.0f, 2.0f,
194 Matrix3 m1(values[0], values[1], values[2], values[3],values[4], values[5], values[6], values[7],values[8]);
196 for (int i=0;i<9;++i)
198 DALI_TEST_EQUALS(m1.AsFloat()[i], values[i], TEST_LOCATION);
205 int UtcDaliMatrix3Invert(void)
207 // We're going to invert a whole load of different matrices to make sure we don't
208 // fail on particular orientations.
209 for (int i=0;i<5;++i)
211 Matrix3 m = *matrices[i];
212 Matrix3 inverseResult1 = *inverseMatrices[i];
214 // Convert to Mat4, perform inverse, and convert back to Mat3
215 float* mf = m.AsFloat();
216 float els[] = { mf[0], mf[1], mf[2], 0.0f,
217 mf[3], mf[4], mf[5], 0.0f,
218 mf[6], mf[7], mf[8], 0.0f,
219 0.0f, 0.0f, 0.0f, 1.0f };
222 Matrix3 inverseResult2 = mat4;
227 DALI_TEST_EQUALS(mInv, inverseResult1, 0.01f, TEST_LOCATION);
228 DALI_TEST_EQUALS(mInv, inverseResult2, 0.01f, TEST_LOCATION);
231 m2.Invert(); // double invert - should be back to m
233 DALI_TEST_EQUALS(m, m2, 0.01f, TEST_LOCATION);
238 int UtcDaliMatrix3Transpose(void)
240 for (int i=0;i<5;++i)
242 Matrix3 m0 = *matrices[i];
243 Matrix3 trans = *transposeMatrices[i];
248 DALI_TEST_EQUALS(m1, trans, 0.001f, TEST_LOCATION);
253 DALI_TEST_EQUALS(m0, m2, 0.001f, TEST_LOCATION);
259 int UtcDaliMatrix3SetIdentity(void)
261 Matrix3 m( 0.0f, 1.0f, 2.0f,
266 DALI_TEST_EQUALS(m, Matrix3::IDENTITY, 0.001f, TEST_LOCATION);
271 int UtcDaliMatrix3Scale(void)
273 Matrix3 m1( 0.0f, 1.0f, 2.0f,
277 Matrix3 m2( 0.0f, 3.0f, 6.0f,
279 24.0f, 27.0f, 30.0f);
283 DALI_TEST_EQUALS(m1, m2, 0.001, TEST_LOCATION);
287 int UtcDaliMatrix3Magnitude(void)
289 Matrix3 m1( 0.0f, 1.0f, -2.0f,
293 DALI_TEST_EQUALS(Matrix3::IDENTITY.Magnitude(), 1.0f, 0.001f, TEST_LOCATION);
294 DALI_TEST_EQUALS(m1.Magnitude(), 12.0f, 0.001f, TEST_LOCATION);
300 int UtcDaliMatrix3ScaleInverseTranspose(void)
302 Matrix3* matrices[6] = { &m1, &m2, &m3, &m4, &m5, &m6 };
305 for (int i=0;i<6;++i)
307 Matrix3 m0 = *matrices[i];
312 m1.Scale(3.0f/(m1.Magnitude()));
315 m2.ScaledInverseTranspose();
317 DALI_TEST_EQUALS(m1, m2, 0.001f, TEST_LOCATION);
322 int UtcDaliMatrix3OStreamOperator(void)
324 std::ostringstream oss;
326 Matrix3 matrix( 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f );
330 std::string expectedOutput = "[ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]";
332 DALI_TEST_EQUALS( oss.str(), expectedOutput, TEST_LOCATION);
336 int UtcDaliMatrix3Multiply(void)
338 Matrix3 m1( 0.0f, 3.0f, 6.0f,
340 24.0f, 27.0f, 30.0f);
342 Matrix3 m2( 0.0f, 1.0f, 0.0f,
346 Matrix3 m3( -3.0f, 0.0f, 6.0f,
347 -15.0f, 12.0f, 18.0f,
348 -27.0f, 24.0f, 30.0f);
351 Matrix3::Multiply(result, m1, m2);
353 DALI_TEST_EQUALS(m3, result, 0.01f, TEST_LOCATION);
357 int UtcDaliMatrix3EqualityOperator(void)
359 Matrix3 m1( 0.0f, 3.0f, 6.0f,
361 24.0f, 27.0f, 30.0f);
363 Matrix3 m2( 0.0f, 3.0f, 6.0f,
365 24.0f, 27.0f, 30.0f);
367 DALI_TEST_CHECK(m1 == m2);
371 int UtcDaliMatrix3InequalityOperator(void)
373 Matrix3 m1( 1.0f, 0.0f, 0.0f,
377 Matrix3 m2( 0.0f, 3.0f, 6.0f,
379 24.0f, 27.0f, 30.0f);
381 DALI_TEST_CHECK(m1 != m2);