Dali 3D User Interface Engine
utc-Dali-MathUtils.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 
18 #include <iostream>
19 
20 #include <stdlib.h>
22 #include <dali-test-suite-utils.h>
23 
24 using namespace Dali;
25 
27 {
29 }
30 
32 {
34 }
35 
37 {
38  Dali::TestApplication testApp;
40 
59 
60  END_TEST;
61 }
62 
64 {
65  Dali::TestApplication testApp;
66 
86  END_TEST;
87 }
88 
90 {
91  Dali::TestApplication testApp;
92 
93  try
94  {
95  NextPowerOfTwo( (1u << (sizeof(unsigned) * 8 - 1)) + 1);
97  }
98  catch( Dali::DaliException& e )
99  {
101  DALI_TEST_ASSERT( e, "Return type cannot represent the next power of two greater than the argument.", TEST_LOCATION );
102  }
103  catch( ... )
104  {
105  tet_printf("Assertion test failed - wrong Exception\n" );
107  }
108 
109  END_TEST;
110 }
111 
113 {
114  Dali::TestApplication testApp;
115 
116  //floats
117  DALI_TEST_EQUALS(Clamp(-1.0f, 0.0f, 1.0f), 0.0f, TEST_LOCATION);
118  DALI_TEST_EQUALS(Clamp(0.0f, -1.0f, 1.0f), 0.0f, TEST_LOCATION);
119  DALI_TEST_EQUALS(Clamp(1.0f, 0.0f, 1.0f), 1.0f, TEST_LOCATION);
120  DALI_TEST_EQUALS(Clamp(2.0f, 0.0f, 1.0f), 1.0f, TEST_LOCATION);
121 
122  // integers
123  DALI_TEST_EQUALS(Clamp(-10, 0, 10), 0, TEST_LOCATION);
124  DALI_TEST_EQUALS(Clamp(0, -10, 10), 0, TEST_LOCATION);
125  DALI_TEST_EQUALS(Clamp(20, 0, 10), 10, TEST_LOCATION);
126 
127  float value=-10.0f, min=-2.0f, max=4.0f;
128  ClampInPlace(value, min, max);
129  DALI_TEST_EQUALS(value, min, 0.001, TEST_LOCATION);
130 
131  value = 10.0f;
132  ClampInPlace(value, min, max);
133  DALI_TEST_EQUALS(value, max, 0.001, TEST_LOCATION);
134 
135  value = 3.0f;
136  ClampInPlace(value, min, max);
137  DALI_TEST_EQUALS(value, 3.0f, 0.001, TEST_LOCATION);
138  END_TEST;
139 }
140 
142 {
143  Dali::TestApplication testApp;
144 
145  float value=-10.0f, min=-2.0f, max=4.0f;
146  ClampInPlace(value, min, max);
147  DALI_TEST_EQUALS(value, min, 0.001, TEST_LOCATION);
148 
149  value = 10.0f;
150  ClampInPlace(value, min, max);
151  DALI_TEST_EQUALS(value, max, 0.001, TEST_LOCATION);
152 
153  value = 3.0f;
154  ClampInPlace(value, min, max);
155  DALI_TEST_EQUALS(value, 3.0f, 0.001, TEST_LOCATION);
156  END_TEST;
157 }
158 
160 {
161  Dali::TestApplication testApp;
162 
163  float offset=0.0f, low=-2.0f, high=4.0f;
164  DALI_TEST_EQUALS(Lerp(offset, low, high), low, 0.001, TEST_LOCATION);
165  offset = 1.0f;
166  DALI_TEST_EQUALS(Lerp(offset, low, high), high, 0.001, TEST_LOCATION);
167  offset = 0.5f;
168  DALI_TEST_EQUALS(Lerp(offset, low, high), 1.0f, 0.001, TEST_LOCATION);
169 
170  END_TEST;
171 }
172 
174 {
175  Dali::TestApplication testApp;
176 
186 
195 
202 
207 
209 
210 
220 
229 
236 
241 
243 
244 
245  END_TEST;
246 }
247 
249 {
250  Dali::TestApplication testApp;
251 
264  END_TEST;
265 }
266 
268 {
269  Dali::TestApplication testApp;
270 
278  END_TEST;
279 }
280 
282 {
283  float v=0.0f;
284 
286 
287  v = Math::PI;
288  v -= (Math::PI_2 * 2.0f);
290 
291  END_TEST;
292 }
293 
295 {
296  float w=100.0f;
297  float x=w+1e-8f;
298  DALI_TEST_CHECK( Equals(w, x, GetRangedEpsilon( w, x )) );
299  END_TEST;
300 }
301 
303 {
304  float w=100.0f;
305  float x=w+1e-8f;
306  DALI_TEST_CHECK( Equals(w, x) );
307  END_TEST;
308 }
309 
311 {
312  Dali::TestApplication testApp;
313 
314  DALI_TEST_EQUALS(Round(1.00001, 4), 1.0f, TEST_LOCATION);
315  DALI_TEST_EQUALS(Round(0.99999f, 4), 1.0f, TEST_LOCATION);
316  DALI_TEST_EQUALS(Round(-1.00001, 4), -1.0f, TEST_LOCATION);
317  DALI_TEST_EQUALS(Round(-0.99999f, 4), -1.0f, TEST_LOCATION);
318  END_TEST;
319 }
Dali Docs Home
Read more about Dali