OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
Point_unit_test.hpp
1/*
2 * Point_unit_test.hpp
3 *
4 * Created on: Aug 11, 2015
5 * Author: i-bird
6 */
7
8#ifndef SRC_SPACE_SHAPE_POINT_UNIT_TEST_HPP_
9#define SRC_SPACE_SHAPE_POINT_UNIT_TEST_HPP_
10
11#include <iostream>
12#include "Space/Shape/Point.hpp"
13#include "Grid/comb.hpp"
14#include "util/convert.hpp"
15
16BOOST_AUTO_TEST_SUITE( Point_test_suite )
17
18BOOST_AUTO_TEST_CASE( Point_use )
19{
20 std::cout << "Point unit test start" << "\n";
21
23
25
26 p.get(0) = 1.0;
27 p.get(1) = 2.0;
28 p.get(2) = 3.0;
29
30 p = pmul(p,p) + p;
31
32 BOOST_REQUIRE_EQUAL(p.get(0),2.0);
33 BOOST_REQUIRE_EQUAL(p.get(1),6.0);
34 BOOST_REQUIRE_EQUAL(p.get(2),12.0);
35
36 // Combination 3D
37 comb<3> c;
38 c.c[0] = 1;
39 c.c[1] = 1;
40 c.c[2] = 1;
42
44 // fill the point with one
45 one.one();
46 Point<3,float> middle = p / 2.0;
47
48 // middle * (one + comb_p) = 0
49 p = p + pmul(middle,(one + pc));
50
51 BOOST_REQUIRE_EQUAL(p.get(0),4.0);
52 BOOST_REQUIRE_EQUAL(p.get(1),12.0);
53 BOOST_REQUIRE_EQUAL(p.get(2),24.0);
54
56
58
59 Point<3,float> pn({1.0,1.0,1.0});
60
61 BOOST_REQUIRE_CLOSE(pn.norm(),1.732050,0.0001);
62
64
65 // distance between two points
66
67 Point<3,float> p1({1.0,1.0,1.0});
68 Point<3,float> p2({2.0,3.0,4.0});
69
70 BOOST_REQUIRE_EQUAL(p1.distance(p2),p2.distance(p1));
71 BOOST_REQUIRE_CLOSE(p1.distance(p2),3.74165738677,0.0001);
72
73 BOOST_REQUIRE_EQUAL(p1.distance2(p2),p2.distance2(p1));
74 BOOST_REQUIRE_CLOSE(p1.distance2(p2),14.0,0.0001);
75
76 std::cout << "Point unit test stop" << "\n";
77
78 // check two point are equal
79
80 BOOST_REQUIRE( p1 != p2 );
81 BOOST_REQUIRE( p1 == p1 );
82
83 // Check division and operator*
84
85 p2 /= 2.0;
86 p1 = p1 * 2.0;
87
88 BOOST_REQUIRE_CLOSE(p2.get(0),1.0,0.001);
89 BOOST_REQUIRE_CLOSE(p2.get(1),1.5,0.001);
90 BOOST_REQUIRE_CLOSE(p2.get(2),2.0,0.001);
91
92 BOOST_REQUIRE_CLOSE(p1.get(0),2.0,0.001);
93 BOOST_REQUIRE_CLOSE(p1.get(1),2.0,0.001);
94 BOOST_REQUIRE_CLOSE(p1.get(2),2.0,0.001);
95
96
97}
98
99
100BOOST_AUTO_TEST_CASE( Point_expression_usage )
101{
102 float scal = 0.0;
103
104 Point<3,float> p1({1.0,1.0,1.0});
105 Point<3,float> p2({2.0,3.0,4.0});
106 Point<3,float> p3({6.0,7.0,9.0});
107
108 p3 = p1 + 2.0;
109 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),p1.get(i) + 2.0);}
110 p3 = 2.0 + p2;
111 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),2.0 + p2.get(i));}
112 p3 = p2 + p1;
113 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),p2.get(i) + p1.get(i));}
114
115 p3 = p1 - 2.0;
116 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),p1.get(i) - 2.0);}
117 p3 = 2.0 - p2;
118 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),2.0 - p2.get(i));}
119 p3 = p2 - p1;
120 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),p2.get(i) - p1.get(i));}
121
122 p3 = p1 * 2.0;
123 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),p1.get(i) * 2.0);}
124 p3 = 2.0f * p2;
125 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),2.0 * p2.get(i));}
126 p3 = p2 * p1;
127 for (size_t i = 0 ; i < 3 ; i++) {scal += p1.get(i) * p2.get(i);}
128 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),scal);}
129
130 p3 = p1 / 2.0;
131 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),p1.get(i) / 2.0);}
132 p3 = 2.0 / p2;
133 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),(float)2.0 / p2.get(i));}
134 p3 = p2 / p1;
135 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),p2.get(i) / p1.get(i));}
136
137 // Variuos combination 3 operator
138
139 p3 = p1 + (p2 + p1);
140 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),p1.get(i) + (p2.get(i) + p1.get(i))) ;}
141 p3 = (p1 + p2) + p2;
142 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),(p1.get(i) + p2.get(i)) + p2.get(i)) ;}
143 p3 = (p1 + p2) + (p1 + p2);
144 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),(p1.get(i) + p2.get(i)) + (p2.get(i) + p1.get(i))) ;}
145
146 p3 = p2 - (p1 + p2);
147 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),p2.get(i) - (p1.get(i) + p2.get(i))) ;}
148 p3 = (p1 + p2) - p2;
149 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),(p1.get(i) + p2.get(i)) - p2.get(i)) ;}
150 p3 = (p1 + p2) - (p1 + p2);
151 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),(p1.get(i) + p2.get(i)) - (p1.get(i) + p2.get(i))) ;}
152
153 scal = 0;
154 p3 = p2 * (p1 + p2);
155 for (size_t i = 0 ; i < 3 ; i++) {scal += p2.get(i) * (p2.get(i) + p1.get(i));}
156 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),scal) ;}
157
158 p3 = (p1 + p2) * p2;
159 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),scal) ;}
160 scal = 0;
161 p3 = (p1 + p2) * (p1 + p2);
162 for (size_t i = 0 ; i < 3 ; i++) {scal += (p2.get(i) + p1.get(i)) * (p2.get(i) + p1.get(i));}
163 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),scal) ;}
164
165 // norm test
166 p3 = p1 / norm(p1);
167 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),p1.get(i) / p1.norm()) ;}
168 // distance calculation
169 float dist = norm(p1 - p2);
170 float dist2 = 0.0;
171 for (size_t i = 0 ; i < 3 ; i++) {dist2 += (p1.get(i) - p2.get(i)) * (p1.get(i) - p2.get(i));}
172 dist2 = sqrt(dist2);
173 BOOST_REQUIRE_EQUAL(dist,dist2);
174 float dist3 = distance(p1,p2);
175 BOOST_REQUIRE_EQUAL(dist,dist3);
176
177 p3 = p2 / (p1 + p2);
178 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),p2.get(i) / (p2.get(i) + p1.get(i))) ;}
179 p3 = (p1 + p2) / p2;
180 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),(p2.get(i) + p1.get(i)) / p2.get(i) ) ;}
181 p3 = (p1 + p2) / (p1 + p2);
182 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),(p2.get(i) + p1.get(i)) / (p2.get(i) + p1.get(i)) ) ;}
183
184
185 // Point function test
186
187 p3 = abs(p1 + p2);
188 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::abs(p1.get(i) + p2.get(i))) ;}
189 p3 = exp(p1 - p2);
190 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::exp(p1.get(i) - p2.get(i))) ;}
191 p3 = exp2(p1 + p2);
192 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::exp2(p1.get(i) + p2.get(i))) ;}
193 p3 = expm1(p1 + p2);
194 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::expm1(p1.get(i) + p2.get(i))) ;}
195 p3 = log(p1 + p2);
196 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::log(p1.get(i) + p2.get(i))) ;}
197 p3 = log10(p1 + p2);
198 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::log10(p1.get(i) + p2.get(i))) ;}
199 p3 = log2(p1 + p2);
200 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::log2(p1.get(i) + p2.get(i))) ;}
201 p3 = log1p(p1 + p2);
202 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::log1p(p1.get(i) + p2.get(i))) ;}
203 p3 = sqrt(p1 + p2);
204 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::sqrt(p1.get(i) + p2.get(i))) ;}
205 p3 = cbrt(p1 + p2);
206 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::cbrt(p1.get(i) + p2.get(i))) ;}
207 p3 = sin(p1 + p2);
208 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::sin(p1.get(i) + p2.get(i))) ;}
209 p3 = cos(p1 + p2);
210 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::cos(p1.get(i) + p2.get(i))) ;}
211 p3 = tan(p1 + p2);
212 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::tan(p1.get(i) + p2.get(i))) ;}
213 p3 = atan(p1 + p2);
214 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::atan(p1.get(i) + p2.get(i))) ;}
215 p3 = asin(p1/5.0f + p2/6.0f);
216 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::asin(p1.get(i)/5.0f + p2.get(i)/6.0f)) ;}
217 p3 = acos(p1/5.0f + p2/6.0f);
218 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::acos(p1.get(i)/5.0f + p2.get(i)/6.0f)) ;}
219 p3 = sinh(p1 + p2);
220 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::sinh(p1.get(i) + p2.get(i))) ;}
221 p3 = cosh(p1 + p2);
222 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::cosh(p1.get(i) + p2.get(i))) ;}
223 p3 = tanh(p1 + p2);
224 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::tanh(p1.get(i) + p2.get(i))) ;}
225 p3 = atanh(p1/5.0f + p2/6.0f);
226 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::atanh(p1.get(i)/5.0f + p2.get(i)/6.0f)) ;}
227 p3 = asinh(p1 + p2);
228 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::asinh(p1.get(i) + p2.get(i))) ;}
229 p3 = acosh(p1 + p2);
230 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::acosh(p1.get(i) + p2.get(i))) ;}
231 p3 = erf(p1 + p2);
232 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::erf(p1.get(i) + p2.get(i))) ;}
233 p3 = erfc(p1 + p2);
234 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::erfc(p1.get(i) + p2.get(i))) ;}
235 p3 = tgamma(p1 + p2);
236 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::tgamma(p1.get(i) + p2.get(i))) ;}
237 p3 = lgamma(p1 + p2);
238 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::lgamma(p1.get(i) + p2.get(i))) ;}
239 p3 = ceil(p1 + p2);
240 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::ceil(p1.get(i) + p2.get(i))) ;}
241 p3 = floor(p1 + p2);
242 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::floor(p1.get(i) + p2.get(i))) ;}
243 p3 = trunc(p1 + p2);
244 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::trunc(p1.get(i) + p2.get(i))) ;}
245 p3 = round(p1 + p2);
246 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::round(p1.get(i) + p2.get(i))) ;}
247 p3 = nearbyint(p1 + p2);
248 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::nearbyint(p1.get(i) + p2.get(i))) ;}
249 p3 = rint(p1 + p2);
250 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),std::rint(p1.get(i) + p2.get(i))) ;}
251
252
253 double tmp = 5.0 + (p1 * p2);
254 BOOST_REQUIRE_EQUAL(tmp,14.0);
255 p3 = 5.0 + (p1 * p2);
256 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),14.0) ;}
257 tmp = 5.0 - (p1 * p2);
258 BOOST_REQUIRE_EQUAL(tmp,-4.0);
259 p3 = 5.0 - (p1 * p2);
260 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),-4.0) ;}
261 tmp = 5.0 * (p1 * p2);
262 BOOST_REQUIRE_EQUAL(tmp,45.0);
263 p3 = 5.0 * (p1 * p2);
264 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),45.0) ;}
265 tmp = 5.0f / (p1 * p2);
266 BOOST_REQUIRE_EQUAL(tmp,5.0f/9.0f);
267 p3 = 5.0f / (p1 * p2);
268 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),5.0f/9.0f) ;}
269
270 float p[3] = {1.0,2.0,3.0};
271 auto p_e = getExprR(p);
272
273 p3 = p_e - p1;
274 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),p[i]-p1.get(i)) ;}
275 p3 = p_e + p1;
276 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),p[i]+p1.get(i)) ;}
277
278 tmp = norm(p_e);
279 BOOST_REQUIRE_EQUAL(tmp,sqrtf(14.0));
280
281 Point<3,float> p4({1.0,2.0,3.0});
282
283 p4 += p2;
284 BOOST_REQUIRE_EQUAL(p4.get(0),3.0);
285 BOOST_REQUIRE_EQUAL(p4.get(1),5.0);
286 BOOST_REQUIRE_EQUAL(p4.get(2),7.0);
287
288
289 p4 = Point<3,float>({1.0,2.0,3.0});
290
291 p4 += p2 + p1;
292
293 BOOST_REQUIRE_EQUAL(p4.get(0),4.0);
294 BOOST_REQUIRE_EQUAL(p4.get(1),6.0);
295 BOOST_REQUIRE_EQUAL(p4.get(2),8.0);
296
297 double s = 0.0;
298 s += p1+(p1+p2);
299 BOOST_REQUIRE_EQUAL(s,4.0);
300
301 // Scalar product
302
303 Point<3,float> p5({1.0,2.0,3.0});
304
305 p4 = (p1*p2) * p5;
306
307 BOOST_REQUIRE_EQUAL(p4.get(0),9.0);
308 BOOST_REQUIRE_EQUAL(p4.get(1),18.0);
309 BOOST_REQUIRE_EQUAL(p4.get(2),27.0);
310
311 p4 = p5 * (p1*p2);
312
313 BOOST_REQUIRE_EQUAL(p4.get(0),9.0);
314 BOOST_REQUIRE_EQUAL(p4.get(1),18.0);
315 BOOST_REQUIRE_EQUAL(p4.get(2),27.0);
316
317
318 p4 = p2 * (p1*p2);
319
320 BOOST_REQUIRE_EQUAL(p4.get(0),18.0);
321 BOOST_REQUIRE_EQUAL(p4.get(1),27.0);
322 BOOST_REQUIRE_EQUAL(p4.get(2),36.0);
323
324 p4 = (p1*p2) * p2;
325
326 BOOST_REQUIRE_EQUAL(p4.get(0),18.0);
327 BOOST_REQUIRE_EQUAL(p4.get(1),27.0);
328 BOOST_REQUIRE_EQUAL(p4.get(2),36.0);
329
330 p4 = (p1*p2) * (p2*p1);
331
332 BOOST_REQUIRE_EQUAL(p4.get(0),81.0);
333 BOOST_REQUIRE_EQUAL(p4.get(1),81.0);
334 BOOST_REQUIRE_EQUAL(p4.get(2),81.0);
335}
336
337
338BOOST_AUTO_TEST_CASE( Point_expression_usage_with_array )
339{
340 float scal = 0.0;
341
342 float p1_p[] = {1.0,1.0,1.0};
343 float p2_p[] = {2.0,3.0,4.0};
344 float p3_p[] = {6.0,7.0,9.0};
345
346 Point<3,float> pp1({1.0,1.0,1.0});
347 Point<3,float> pp2({2.0,3.0,4.0});
348 Point<3,float> pp3({6.0,7.0,9.0});
349
350 auto p1 = getExprR(p1_p);
351 auto p2 = getExprR(p2_p);
352
353 auto p3L = getExprL(p3_p);
354
355 p3L = p1 + 2.0;
356 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],p1_p[i] + 2.0);}
357 p3L = 2.0 + p2;
358 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],2.0 + p2_p[i]);}
359 p3L = p2 + p1;
360 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],p2_p[i] + p1_p[i]);}
361
362 p3L = p1 - 2.0;
363 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],p1_p[i] - 2.0);}
364 p3L = 2.0 - p2;
365 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],2.0 - p2_p[i]);}
366 p3L = p2 - p1;
367 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],p2_p[i] - p1_p[i]);}
368
369 p3L = p1 * 2.0;
370 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],p1_p[i] * 2.0);}
371 p3L = 2.0f * p2;
372 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],2.0 * p2_p[i]);}
373 p3L = p2 * p1;
374 for (size_t i = 0 ; i < 3 ; i++) {scal += p1_p[i] * p2_p[i];}
375 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],scal);}
376
377 p3L = p1 / 2.0;
378 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],p1_p[i] / 2.0);}
379 p3L = 2.0 / p2;
380 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],(float)2.0 / p2_p[i]);}
381 p3L = p2 / p1;
382 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],p2_p[i] / p1_p[i]);}
383
384 // Some 2 operator combination
385
386 p3L = p1 + p2;
387 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],p1_p[i] + p2_p[i]);}
388 p3L = p1 + pp2;
389 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],p1_p[i] + pp2.get(i));}
390 p3L = pp2 + p1;
391 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],pp2.get(i) + p1_p[i]);}
392
393 // Variuos combination 3 operator
394
395 p3L = p1 + (p2 + p1);
396 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],p1_p[i] + (p2_p[i] + p1_p[i])) ;}
397 p3L = (p1 + p2) + p2;
398 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],(p1_p[i] + p2_p[i]) + p2_p[i]) ;}
399 p3L = (p1 + p2) + (p1 + p2);
400 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],(p1_p[i] + p2_p[i]) + (p2_p[i] + p1_p[i])) ;}
401
402 p3L = p2 - (p1 + p2);
403 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],p2_p[i] - (p1_p[i] + p2_p[i])) ;}
404 p3L = (p1 + p2) - p2;
405 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],(p1_p[i] + p2_p[i]) - p2_p[i]) ;}
406 p3L = (p1 + p2) - (p1 + p2);
407 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],(p1_p[i] + p2_p[i]) - (p1_p[i] + p2_p[i])) ;}
408
409 scal = 0;
410 p3L = p2 * (p1 + p2);
411 for (size_t i = 0 ; i < 3 ; i++) {scal += p2_p[i] * (p2_p[i] + p1_p[i]);}
412 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],scal) ;}
413 p3L = (p1 + p2) * p2;
414 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],scal) ;}
415 scal = 0;
416 p3L = (p1 + p2) * (p1 + p2);
417 for (size_t i = 0 ; i < 3 ; i++) {scal += (p2_p[i] + p1_p[i]) * (p2_p[i] + p1_p[i]);}
418 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],scal) ;}
419
420 // norm test
421 p3L = p1 / norm(p1);
422 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],p1_p[i] / sqrtf(3.0)) ;}
423 // distance calculation
424 float dist = norm(p1 - p2);
425 float dist2 = 0.0;
426 for (size_t i = 0 ; i < 3 ; i++) {dist2 += (p1_p[i] - p2_p[i]) * (p1_p[i] - p2_p[i]);}
427 dist2 = sqrt(dist2);
428 BOOST_REQUIRE_EQUAL(dist,dist2);
429 float dist3 = distance(p1,p2);
430 BOOST_REQUIRE_EQUAL(dist,dist3);
431
432 p3L = p2 / (p1 + p2);
433 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],p2_p[i] / (p2_p[i] + p1_p[i])) ;}
434 p3L = (p1 + p2) / p2;
435 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],(p2_p[i] + p1_p[i]) / p2_p[i] ) ;}
436 p3L = (p1 + p2) / (p1 + p2);
437 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],(p2_p[i] + p1_p[i]) / (p2_p[i] + p1_p[i]) ) ;}
438
439
440 // Point function test
441
442 p3L = abs(p1 + p2);
443 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::abs(p1_p[i] + p2_p[i])) ;}
444 p3L = exp(p1 - p2);
445 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::exp(p1_p[i] - p2_p[i])) ;}
446 p3L = exp2(p1 + p2);
447 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::exp2(p1_p[i] + p2_p[i])) ;}
448 p3L = expm1(p1 + p2);
449 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::expm1(p1_p[i] + p2_p[i])) ;}
450 p3L = log(p1 + p2);
451 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::log(p1_p[i] + p2_p[i])) ;}
452 p3L = log10(p1 + p2);
453 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::log10(p1_p[i] + p2_p[i])) ;}
454 p3L = log2(p1 + p2);
455 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::log2(p1_p[i] + p2_p[i])) ;}
456 p3L = log1p(p1 + p2);
457 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::log1p(p1_p[i] + p2_p[i])) ;}
458 p3L = sqrt(p1 + p2);
459 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::sqrt(p1_p[i] + p2_p[i])) ;}
460 p3L = cbrt(p1 + p2);
461 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::cbrt(p1_p[i] + p2_p[i])) ;}
462 p3L = sin(p1 + p2);
463 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::sin(p1_p[i] + p2_p[i])) ;}
464 p3L = cos(p1 + p2);
465 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::cos(p1_p[i] + p2_p[i])) ;}
466 p3L = tan(p1 + p2);
467 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::tan(p1_p[i] + p2_p[i])) ;}
468 p3L = atan(p1 + p2);
469 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::atan(p1_p[i] + p2_p[i])) ;}
470 p3L = asin(p1/5.0f + p2/6.0f);
471 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_CLOSE(p3_p[i],std::asin(p1_p[i]/5.0f + p2_p[i]/6.0f),0.1) ;}
472 p3L = acos(p1/5.0f + p2/6.0f);
473 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::acos(p1_p[i]/5.0f + p2_p[i]/6.0f)) ;}
474 p3L = sinh(p1 + p2);
475 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::sinh(p1_p[i] + p2_p[i])) ;}
476 p3L = cosh(p1 + p2);
477 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::cosh(p1_p[i] + p2_p[i])) ;}
478 p3L = tanh(p1 + p2);
479 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::tanh(p1_p[i] + p2_p[i])) ;}
480 p3L = atanh(p1/5.0f + p2/6.0f);
481 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::atanh(p1_p[i]/5.0f + p2_p[i]/6.0f)) ;}
482 p3L = acosh(p1 + p2);
483 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::acosh(p1_p[i] + p2_p[i])) ;}
484 p3L = erf(p1 + p2);
485 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::erf(p1_p[i] + p2_p[i])) ;}
486 p3L = erfc(p1 + p2);
487 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::erfc(p1_p[i] + p2_p[i])) ;}
488 p3L = tgamma(p1 + p2);
489 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::tgamma(p1_p[i] + p2_p[i])) ;}
490 p3L = lgamma(p1 + p2);
491 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::lgamma(p1_p[i] + p2_p[i])) ;}
492 p3L = ceil(p1 + p2);
493 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::ceil(p1_p[i] + p2_p[i])) ;}
494 p3L = floor(p1 + p2);
495 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::floor(p1_p[i] + p2_p[i])) ;}
496 p3L = trunc(p1 + p2);
497 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::trunc(p1_p[i] + p2_p[i])) ;}
498 p3L = round(p1 + p2);
499 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::round(p1_p[i] + p2_p[i])) ;}
500 p3L = nearbyint(p1 + p2);
501 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::nearbyint(p1_p[i] + p2_p[i])) ;}
502 p3L = rint(p1 + p2);
503 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::rint(p1_p[i] + p2_p[i])) ;}
504
505
506 double tmp = 5.0 + (p1 * p2);
507 BOOST_REQUIRE_EQUAL(tmp,14.0);
508 p3L = 5.0 + (p1 * p2);
509 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],14.0) ;}
510 tmp = 5.0 - (p1 * p2);
511 BOOST_REQUIRE_EQUAL(tmp,-4.0);
512 p3L = 5.0 - (p1 * p2);
513 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],-4.0) ;}
514 tmp = 5.0 * (p1 * p2);
515 BOOST_REQUIRE_EQUAL(tmp,45.0);
516 p3L = 5.0 * (p1 * p2);
517 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],45.0) ;}
518 tmp = 5.0f / (p1 * p2);
519 BOOST_REQUIRE_EQUAL(tmp,5.0f/9.0f);
520 p3L = 5.0f / (p1 * p2);
521 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],5.0f/9.0f) ;}
522}
523
524BOOST_AUTO_TEST_CASE( Point_expression_usage_with_conversion )
525{
526 float scal = 0.0;
527
528 Point<3,float> p1({0.1,0.1,0.1});
529 Point<3,float> p2({0.2,0.3,0.4});
530 Point<3,float> p3({0.6,0.7,0.9});
531
532 p3 = p1 + 2;
533 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),p1.get(i) + 2);}
534 p3 = 2 + p2;
535 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),2 + p2.get(i));}
536
537 p3 = p1 - 2;
538 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),p1.get(i) - 2);}
539 p3 = 2 - p2;
540 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),2 - p2.get(i));}
541
542 p3 = p1 * 2;
543 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),p1.get(i) * 2);}
544 p3 = 2 * p2;
545 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),2 * p2.get(i));}
546
547 p3 = p1 / 2;
548 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),p1.get(i) / 2.0);}
549 p3 = 2 / p2;
550 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),(float)2 / p2.get(i));}
551
552 // Point function test
553
554 double tmp = 5 + (p1 * p2);
555 double check = 5 + p1.get(0)*p2.get(0) + p1.get(1)*p2.get(1) + p1.get(2)*p2.get(2);
556 BOOST_REQUIRE_EQUAL(tmp,check);
557 p3 = 5.0 + (p1 * p2);
558 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),check) ;}
559 tmp = 5 - (p1 * p2);
560 check = 5 - p1.get(0)*p2.get(0) - p1.get(1)*p2.get(1) - p1.get(2)*p2.get(2);
561 BOOST_REQUIRE_EQUAL(tmp,check);
562 p3 = 5 - (p1 * p2);
563 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),check) ;}
564 tmp = 5 * (p1 * p2);
565 check = 5*(p1.get(0)*p2.get(0) + p1.get(1)*p2.get(1) + p1.get(2)*p2.get(2));
566 BOOST_REQUIRE_EQUAL(tmp,check);
567 p3 = 5 * (p1 * p2);
568 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),check) ;}
569 tmp = 5 / (p1 * p2);
570 check = 5/(p1.get(0)*p2.get(0) + p1.get(1)*p2.get(1) + p1.get(2)*p2.get(2));
571 BOOST_REQUIRE_EQUAL(tmp,check);
572 p3 = 5 / (p1 * p2);
573 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3.get(i),check) ;}
574
575 p3 = 2*(p1*p2)*p1;
576 for (size_t i = 0 ; i < 3 ; i++)
577 {
578 check = 2*(p1.get(0)*p2.get(0) + p1.get(1)*p2.get(1) + p1.get(2)*p2.get(2))*p1.get(i);
579 BOOST_REQUIRE_EQUAL(p3[i],check) ;
580 }
581 p3 = (p1*p2)*2*p1;
582 for (size_t i = 0 ; i < 3 ; i++)
583 {
584 check = 2*(p1.get(0)*p2.get(0) + p1.get(1)*p2.get(1) + p1.get(2)*p2.get(2))*p1.get(i);
585 BOOST_REQUIRE_EQUAL(p3[i],check) ;
586 }
587 p3 = (p1*p2)*p1*2;
588 for (size_t i = 0 ; i < 3 ; i++)
589 {
590 check = 2*(p1.get(0)*p2.get(0) + p1.get(1)*p2.get(1) + p1.get(2)*p2.get(2))*p1.get(i);
591 BOOST_REQUIRE_EQUAL(p3[i],check) ;
592 }
593
594}
595
596BOOST_AUTO_TEST_CASE( Point_expression_usage_with_conversion_array )
597{
598 float scal = 0.0;
599
600 float p1_p[] = {0.1,0.1,0.1};
601 float p2_p[] = {0.2,0.3,0.4};
602 float p3_p[] = {0.6,0.7,0.9};
603
604 Point<3,float> pp1({0.1,0.1,0.1});
605 Point<3,float> pp2({0.2,0.3,0.4});
606 Point<3,float> pp3({0.6,0.7,0.9});
607
608 auto p1 = getExprR(p1_p);
609 auto p2 = getExprR(p2_p);
610
611 auto p3L = getExprL(p3_p);
612
613 p3L = p1 + 2;
614 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],p1_p[i] + 2);}
615 p3L = 2 + p2;
616 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],2 + p2_p[i]);}
617
618 p3L = p1 - 2;
619 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],p1_p[i] - 2);}
620 p3L = 2 - p2;
621 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],2 - p2_p[i]);}
622
623 p3L = p1 * 2;
624 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],p1_p[i] * 2);}
625 p3L = 2 * p2;
626 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],2 * p2_p[i]);}
627
628 p3L = p1 / 2;
629 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],p1_p[i] / 2);}
630 p3L = 2 / p2;
631 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],2 / p2_p[i]);}
632
633 // Point function test
634
635 p3L = asin(p1/5 + p2/6);
636 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_CLOSE(p3_p[i],std::asin(p1_p[i]/5 + p2_p[i]/6),0.1) ;}
637 p3L = acos(p1/5 + p2/6);
638 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],std::acos(p1_p[i]/5 + p2_p[i]/6)) ;}
639
640
641 double tmp = 5 + (p1 * p2);
642 double check = 5 + pp1.get(0)*pp2.get(0) + pp1.get(1)*pp2.get(1) + pp1.get(2)*pp2.get(2);
643 BOOST_REQUIRE_EQUAL(tmp,check);
644 p3L = 5 + (p1 * p2);
645 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],check) ;}
646 tmp = 5 - (p1 * p2);
647 check = 5 - pp1.get(0)*pp2.get(0) - pp1.get(1)*pp2.get(1) - pp1.get(2)*pp2.get(2);
648 BOOST_REQUIRE_EQUAL(tmp,check);
649 p3L = 5 - (p1 * p2);
650 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],check) ;}
651 tmp = 5 * (p1 * p2);
652 check = 5*(pp1.get(0)*pp2.get(0) + pp1.get(1)*pp2.get(1) + pp1.get(2)*pp2.get(2));
653 BOOST_REQUIRE_EQUAL(tmp,check);
654 p3L = 5 * (p1 * p2);
655 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],check) ;}
656 tmp = 5 / (p1 * p2);
657 check = 5/(pp1.get(0)*pp2.get(0) + pp1.get(1)*pp2.get(1) + pp1.get(2)*pp2.get(2));
658 BOOST_REQUIRE_EQUAL(tmp,check);
659 p3L = 2*(p1*p2)*p1;
660 for (size_t i = 0 ; i < 3 ; i++)
661 {
662 check = 2*(pp1.get(0)*pp2.get(0) + pp1.get(1)*pp2.get(1) + pp1.get(2)*pp2.get(2))*pp1.get(i);
663 BOOST_REQUIRE_EQUAL(p3_p[i],check) ;
664 }
665 p3L = (p1*p2)*2*p1;
666 for (size_t i = 0 ; i < 3 ; i++)
667 {
668 check = 2*(pp1.get(0)*pp2.get(0) + pp1.get(1)*pp2.get(1) + pp1.get(2)*pp2.get(2))*pp1.get(i);
669 BOOST_REQUIRE_EQUAL(p3_p[i],check) ;
670 }
671 p3L = (p1*p2)*p1*2;
672 for (size_t i = 0 ; i < 3 ; i++)
673 {
674 check = 2*(pp1.get(0)*pp2.get(0) + pp1.get(1)*pp2.get(1) + pp1.get(2)*pp2.get(2))*pp1.get(i);
675 BOOST_REQUIRE_EQUAL(p3_p[i],check) ;
676 }
677 p3L = 5 / (p1 * p2);
678 check = 5/(pp1.get(0)*pp2.get(0) + pp1.get(1)*pp2.get(1) + pp1.get(2)*pp2.get(2));
679 for (size_t i = 0 ; i < 3 ; i++) {BOOST_REQUIRE_EQUAL(p3_p[i],check) ;}
680}
681
682BOOST_AUTO_TEST_SUITE_END()
683
684
685
686
687#endif /* SRC_SPACE_SHAPE_POINT_UNIT_TEST_HPP_ */
This class implement the point shape in an N-dimensional space.
Definition Point.hpp:28
void one()
Set to one the point coordinate.
Definition Point.hpp:296
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
Definition Point.hpp:172
static Point< dim, St > convert(const comb< dim > &c)
Return the combination converted to point.
Definition convert.hpp:25
Position of the element of dimension d in the hyper-cube of dimension dim.
Definition comb.hpp:35
signed char c[dim]
Array that store the combination.
Definition comb.hpp:37