Code-Eli  0.3.6
piecewise_superellipse_creator_test_suite.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2 * Copyright (c) 2013 David D. Marshall <ddmarsha@calpoly.edu>
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * David D. Marshall - initial code and implementation
11 ********************************************************************************/
12 
13 #ifndef piecewise_superellipse_creator_test_suite_hpp
14 #define piecewise_superellipse_creator_test_suite_hpp
15 
16 #include <cmath> // std::pow, std::exp
17 
18 #include <typeinfo> // typeid
19 #include <string> // std::string
20 #include <sstream> // std::stringstream
21 #include <iomanip> // std::setw
22 #include <limits> // std::numeric_limits
23 
24 #include "eli/constants/math.hpp"
27 
28 template<typename data__>
30 {
31  private:
39 
40  tolerance_type tol;
41 
42  protected:
43  void AddTests(const float &)
44  {
45  // add the tests
53  }
54  void AddTests(const double &)
55  {
56  // add the tests
64  }
65  void AddTests(const long double &)
66  {
67  // add the tests
75  }
76 
77  public:
79  {
80  AddTests(data__());
81  }
83  {
84  }
85 
86  private:
87  void octave_print(int figno, const piecewise_curve_type &pc) const
88  {
89  index_type i, pp, ns;
90  data_type tmin, tmax;
91 
92  ns=pc.number_segments();
93  pc.get_parameter_min(tmin);
94  pc.get_parameter_max(tmax);
95 
96  std::cout << "figure(" << figno << ");" << std::endl;
97 
98  // get control points and print
99  std::cout << "cp_x=[";
100  for (pp=0; pp<ns; ++pp)
101  {
102  curve_type bez;
103  pc.get(bez, pp);
104  for (i=0; i<=bez.degree(); ++i)
105  {
106  std::cout << bez.get_control_point(i).x();
107  if (i<bez.degree())
108  std::cout << ", ";
109  else if (pp<ns-1)
110  std::cout << "; ";
111  }
112  std::cout << std::endl;
113  }
114  std::cout << "];" << std::endl;
115 
116  std::cout << "cp_y=[";
117  for (pp=0; pp<ns; ++pp)
118  {
119  curve_type bez;
120  pc.get(bez, pp);
121  for (i=0; i<=bez.degree(); ++i)
122  {
123  std::cout << bez.get_control_point(i).y();
124  if (i<bez.degree())
125  std::cout << ", ";
126  else if (pp<ns-1)
127  std::cout << "; ";
128  }
129  std::cout << std::endl;
130  }
131  std::cout << "];" << std::endl;
132 
133  // initialize the t parameters
134  std::vector<data__> t(129);
135  for (i=0; i<static_cast<index_type>(t.size()); ++i)
136  {
137  t[i]=tmin+(tmax-tmin)*static_cast<data__>(i)/(t.size()-1);
138  }
139 
140  // set the curve points
141  std::cout << "curve_x=[";
142  for (i=0; i<static_cast<index_type>(t.size()); ++i)
143  {
144  std::cout << pc.f(t[i]).x();
145  if (i<static_cast<index_type>(t.size()-1))
146  std::cout << ", ";
147  }
148  std::cout << "];" << std::endl;
149 
150  std::cout << "curve_y=[";
151  for (i=0; i<static_cast<index_type>(t.size()); ++i)
152  {
153  std::cout << pc.f(t[i]).y();
154  if (i<static_cast<index_type>(t.size()-1))
155  std::cout << ", ";
156  }
157  std::cout << "];" << std::endl;
158 
159  std::cout << "setenv('GNUTERM', 'x11');" << std::endl;
160  std::cout << "plot(curve_x, curve_y, '-k');" << std::endl;
161  std::cout << "hold on;" << std::endl;
162  std::cout << "plot(cp_x', cp_y', '-or', 'MarkerFaceColor', [0 0 0]);" << std::endl;
163  std::cout << "hold off;" << std::endl;
164  }
165 
167  {
168  superellipse_creator_type he_creator(4);
169  data_type dt0(3), dt1(2), dt2(3), dt3(2), t0(-1);
170  point_type f, fref;
171 
172  // set the times
173  he_creator.set_t0(t0);
174  he_creator.set_segment_dt(dt0, 0);
175  he_creator.set_segment_dt(dt1, 1);
176  he_creator.set_segment_dt(dt2, 2);
177  he_creator.set_segment_dt(dt3, 3);
178 
179  he_creator.set_exponents(2., 2.);
180  he_creator.set_max_degree(3);
181 
182  // create an x-degenerate ellipse
183  {
184  piecewise_curve_type pc;
185 
186  he_creator.set_axis(0, 3);
187  TEST_ASSERT(he_creator.create(pc));
188 
189  fref << 0, 1.5, 0;
190  f=pc.f(t0+dt0/2);
191  TEST_ASSERT((f-fref).norm() < 5e-6);
192 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
193 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
194 // if (typeid(data_type)==typeid(double))
195 // octave_print(1, pc);
196  }
197 
198  // create an y-degenerate ellipse
199  {
200  piecewise_curve_type pc;
201 
202  he_creator.set_axis(2, 0);
203  TEST_ASSERT(he_creator.create(pc));
204 
205  fref << 1, 0, 0;
206  f=pc.f(t0+dt0/2);
207  TEST_ASSERT((f-fref).norm() < 5e-6);
208 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
209 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
210 // if (typeid(data_type)==typeid(double))
211 // octave_print(1, pc);
212  }
213 
214  // create an x- and y-degenerate ellipse
215  {
216  piecewise_curve_type pc;
217 
218  he_creator.set_axis(0, 0);
219  TEST_ASSERT(he_creator.create(pc));
220 
221  fref << 0, 0, 0;
222  f=pc.f(t0+dt0/2);
223  TEST_ASSERT((f-fref).norm() < 5e-6);
224 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
225 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
226 // if (typeid(data_type)==typeid(double))
227 // octave_print(1, pc);
228  }
229  }
230 
232  {
233  superellipse_creator_type he_creator(4);
234  data_type dt0(3), dt1(2), dt2(3), dt3(2), t0(-1);
235  point_type f, fref;
236 
237  // set the times
238  he_creator.set_t0(t0);
239  he_creator.set_segment_dt(dt0, 0);
240  he_creator.set_segment_dt(dt1, 1);
241  he_creator.set_segment_dt(dt2, 2);
242  he_creator.set_segment_dt(dt3, 3);
243 
244  he_creator.set_axis(2, 3);
245  he_creator.set_max_degree(3);
246 
247  // create an ellipse
248  {
249  piecewise_curve_type pc;
250  he_creator.set_exponents(2., 2.);
251 
252  TEST_ASSERT(he_creator.create(pc));
253 
254  fref << static_cast<data_type>(1.547913), static_cast<data_type>(1.903984), 0;
255  f=pc.f(t0+dt0/2);
256  TEST_ASSERT((f-fref).norm() < 5e-6);
257 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
258 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
259  }
260 
261  // create a moderately concave
262  {
263  piecewise_curve_type pc;
264  he_creator.set_exponents(1./2., 1./2.);
265 
266  TEST_ASSERT(he_creator.create(pc));
267 
268  fref << static_cast<data_type>(0.397104), static_cast<data_type>(1.058210), 0;
269  f=pc.f(t0+dt0/2);
270  TEST_ASSERT((f-fref).norm() < 5e-6);
271 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
272 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
273  }
274 
275  // create a severely concave
276  {
277  piecewise_curve_type pc;
278  he_creator.set_exponents(static_cast<data_type>(1./5.), static_cast<data_type>(1./5.));
279 
280  TEST_ASSERT(he_creator.create(pc));
281 
282  fref << static_cast<data_type>(0.134030), static_cast<data_type>(1.149813), 0;
283  f=pc.f(t0+dt0/2);
284  TEST_ASSERT((f-fref).norm() < 5e-6);
285 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
286 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
287  }
288 
289  // create a moderately convex
290  {
291  piecewise_curve_type pc;
292  he_creator.set_exponents(static_cast<data_type>(1.2), static_cast<data_type>(1.2));
293 
294  TEST_ASSERT(he_creator.create(pc));
295 
296  fref << static_cast<data_type>(1.173693), static_cast<data_type>(1.617232), 0;
297  f=pc.f(t0+dt0/2);
298  TEST_ASSERT((f-fref).norm() < 5e-6);
299 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
300 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
301  }
302 
303  // create a severely convex
304  {
305  piecewise_curve_type pc;
306  he_creator.set_exponents(5., 5.);
307 
308  TEST_ASSERT(he_creator.create(pc));
309 
310  fref << static_cast<data_type>(1.76445), static_cast<data_type>(1.897658), 0;
311  f=pc.f(t0+dt0/2);
312  TEST_ASSERT((f-fref).norm() < 5e-6);
313 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
314 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
315  }
316 
317  // create a mixed concave-convex
318  {
319  piecewise_curve_type pc;
320  he_creator.set_exponents(static_cast<data_type>(1./3.), static_cast<data_type>(3.));
321 
322  TEST_ASSERT(he_creator.create(pc));
323 
324  fref << static_cast<data_type>(1.1199889), static_cast<data_type>(1.604568), 0;
325  f=pc.f(t0+dt0/2);
326  TEST_ASSERT((f-fref).norm() < 5e-6);
327 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
328 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
329  }
330 
331  // create a mixed concave-convex
332  {
333  piecewise_curve_type pc;
334  he_creator.set_exponents(static_cast<data_type>(3.), static_cast<data_type>(1./3.));
335 
336  TEST_ASSERT(he_creator.create(pc));
337 
338  fref << static_cast<data_type>(1.149061), static_cast<data_type>(1.645629), 0;
339  f=pc.f(t0+dt0/2);
340  TEST_ASSERT((f-fref).norm() < 5e-6);
341 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
342 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
343  }
344 
345 // if (typeid(data_type)==typeid(double))
346 // octave_print(1, pc);
347  }
348 
350  {
351  superellipse_creator_type he_creator(4);
352  data_type dt0(3), dt1(2), dt2(3), dt3(2), t0(-1);
353  point_type f, fref;
354 
355  // set the times
356  he_creator.set_t0(t0);
357  he_creator.set_segment_dt(dt0, 0);
358  he_creator.set_segment_dt(dt1, 1);
359  he_creator.set_segment_dt(dt2, 2);
360  he_creator.set_segment_dt(dt3, 3);
361 
362  he_creator.set_axis(2, 3);
363  he_creator.set_max_degree(6);
364 
365  // create an ellipse
366  {
367  piecewise_curve_type pc;
368  he_creator.set_exponents(2., 2.);
369 
370  TEST_ASSERT(he_creator.create(pc));
371 
372  fref << static_cast<data_type>(1.544666), static_cast<data_type>(1.904765), 0;
373  f=pc.f(t0+dt0/2);
374  TEST_ASSERT((f-fref).norm() < 6e-6);
375 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
376 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
377  }
378 
379  // create a moderately concave
380  {
381  piecewise_curve_type pc;
382  he_creator.set_exponents(1./2., 1./2.);
383 
384  TEST_ASSERT(he_creator.create(pc));
385 
386  fref << static_cast<data_type>(0.360349), static_cast<data_type>(1.00602), 0;
387  f=pc.f(t0+dt0/2);
388  TEST_ASSERT((f-fref).norm() < 5e-6);
389 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
390 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
391  }
392 
393  // create a severely concave
394  {
395  piecewise_curve_type pc;
396  he_creator.set_exponents(static_cast<data_type>(1./5.), static_cast<data_type>(1./5.));
397 
398  TEST_ASSERT(he_creator.create(pc));
399 
400  if (typeid(data_type)==typeid(float))
401  {
402 #if defined(_MSC_VER)
403 # if (!defined(_WIN64) && (_MSC_VER==1600))
404  fref << static_cast<data_type>(46.939301), static_cast<data_type>(3.475554), 0;
405 # else
406  fref << static_cast<data_type>(47.022247), static_cast<data_type>(3.483002), 0;
407 # endif
408 #elif defined(__GNUC__) && defined(__clang__)
409  fref << static_cast<data_type>(47.022247), static_cast<data_type>(3.483002), 0;
410 #elif defined(__GNUC__) && !defined(__clang__)
411  fref << static_cast<data_type>(47.022247), static_cast<data_type>(3.483002), 0;
412 #else
413  fref << static_cast<data_type>(47.022301), static_cast<data_type>(3.482945), 0;
414 #endif
415  }
416  else
417  {
418  fref << static_cast<data_type>(46.87239), static_cast<data_type>(3.468185), 0;
419  }
420  f=pc.f(t0+dt0/2);
421  TEST_ASSERT((f-fref).norm() < 5e-6);
422 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
423 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
424  }
425 
426  // create a moderately convex
427  {
428  piecewise_curve_type pc;
429  he_creator.set_exponents(static_cast<data_type>(1.2), static_cast<data_type>(1.2));
430 
431  TEST_ASSERT(he_creator.create(pc));
432 
433  fref << static_cast<data_type>(1.168557), static_cast<data_type>(1.614039), 0;
434  f=pc.f(t0+dt0/2);
435  TEST_ASSERT((f-fref).norm() < 5e-6);
436 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
437 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
438  }
439 
440  // create a severely convex
441  {
442  piecewise_curve_type pc;
443  he_creator.set_exponents(5., 5.);
444 
445  TEST_ASSERT(he_creator.create(pc));
446 
447  if (typeid(data_type)==typeid(float))
448  {
449 #ifdef _MSC_VER
450 # if (!defined(_WIN64) && (_MSC_VER==1600))
451  fref << static_cast<data_type>(1.351444), static_cast<data_type>(2.2766607), 0;
452 # else
453  fref << static_cast<data_type>(1.351675), static_cast<data_type>(2.2758243), 0;
454 # endif
455 #else
456  fref << static_cast<data_type>(1.351337), static_cast<data_type>(2.2768044), 0;
457 #endif
458  }
459  else
460  {
461  fref << static_cast<data_type>(1.349747), static_cast<data_type>(2.277204), 0;
462  }
463  f=pc.f(t0+dt0/2);
464  TEST_ASSERT((f-fref).norm() < 6e-6);
465 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
466 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
467  }
468 
469  // create a mixed concave-convex
470  {
471  piecewise_curve_type pc;
472  he_creator.set_exponents(static_cast<data_type>(1./3.), static_cast<data_type>(3.));
473 
474  TEST_ASSERT(he_creator.create(pc));
475 
476  fref << static_cast<data_type>(1.203145), static_cast<data_type>(1.619022), 0;
477  f=pc.f(t0+dt0/2);
478  TEST_ASSERT((f-fref).norm() < 5e-6);
479 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
480 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
481  }
482 
483  // create a mixed concave-convex
484  {
485  piecewise_curve_type pc;
486  he_creator.set_exponents(static_cast<data_type>(3.), static_cast<data_type>(1./3.));
487 
488  TEST_ASSERT(he_creator.create(pc));
489 
490  fref << static_cast<data_type>(1.135717), static_cast<data_type>(1.623672), 0;
491  f=pc.f(t0+dt0/2);
492  TEST_ASSERT((f-fref).norm() < 5e-6);
493 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
494 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
495 
496 // if (typeid(data_type)==typeid(double))
497 // {
498 // std::cout << std::setprecision(6);
499 // octave_print(1, pc);
500 // }
501  }
502  }
503 
505  {
506  superellipse_creator_type he_creator(6);
507  data_type dt0(3), dt1(2), dt2(3), dt3(2), dt4(3), dt5(2), t0(-1);
508  point_type f, fref;
509 
510  // set the times
511  he_creator.set_t0(t0);
512  he_creator.set_segment_dt(dt0, 0);
513  he_creator.set_segment_dt(dt1, 1);
514  he_creator.set_segment_dt(dt2, 2);
515  he_creator.set_segment_dt(dt3, 3);
516  he_creator.set_segment_dt(dt4, 4);
517  he_creator.set_segment_dt(dt5, 5);
518 
519  he_creator.set_axis(2, 3);
520  he_creator.set_max_degree(3);
521 
522  // create an ellipse
523  {
524  piecewise_curve_type pc;
525  he_creator.set_exponents(2., 2.);
526 
527  TEST_ASSERT(he_creator.create(pc));
528 
529  fref << static_cast<data_type>(1.819996), static_cast<data_type>(1.243964), 0;
530  f=pc.f(t0+dt0/2);
531  TEST_ASSERT((f-fref).norm() < 5e-6);
532 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
533 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
534 // if (typeid(data_type)==typeid(double))
535 // octave_print(1, pc);
536  }
537 
538  // create a moderately concave
539  {
540  piecewise_curve_type pc;
541  he_creator.set_exponents(1./2., 1./2.);
542 
543  TEST_ASSERT(he_creator.create(pc));
544 
545  fref << static_cast<data_type>(1.019236), static_cast<data_type>(0.267005), 0;
546  f=pc.f(t0+dt0/2);
547  TEST_ASSERT((f-fref).norm() < 5e-6);
548 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
549 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
550 // if (typeid(data_type)==typeid(double))
551 // octave_print(1, pc);
552  }
553 
554  // create a severely concave
555  {
556  piecewise_curve_type pc;
557  he_creator.set_exponents(static_cast<data_type>(1./5.), static_cast<data_type>(1./5.));
558 
559  TEST_ASSERT(he_creator.create(pc));
560 
561  fref << static_cast<data_type>(1.108429), static_cast<data_type>(0.525021), 0;
562  f=pc.f(t0+dt0/2);
563  TEST_ASSERT((f-fref).norm() < 7e-6);
564 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
565 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
566 // if (typeid(data_type)==typeid(double))
567 // octave_print(1, pc);
568  }
569 
570  // create a moderately convex
571  {
572  piecewise_curve_type pc;
573  he_creator.set_exponents(static_cast<data_type>(1.2), static_cast<data_type>(1.2));
574 
575  TEST_ASSERT(he_creator.create(pc));
576 
577  fref << static_cast<data_type>(1.530603), static_cast<data_type>(1.024579), 0;
578  f=pc.f(t0+dt0/2);
579  TEST_ASSERT((f-fref).norm() < 5e-6);
580 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
581 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
582 // if (typeid(data_type)==typeid(double))
583 // octave_print(1, pc);
584  }
585 
586  // create a severely convex
587  {
588  piecewise_curve_type pc;
589  he_creator.set_exponents(5., 5.);
590 
591  TEST_ASSERT(he_creator.create(pc));
592 
593  fref << static_cast<data_type>(1.926631), static_cast<data_type>(1.313695), 0;
594  f=pc.f(t0+dt0/2);
595  TEST_ASSERT((f-fref).norm() < 5e-6);
596 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
597 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
598 // if (typeid(data_type)==typeid(double))
599 // octave_print(1, pc);
600  }
601 
602  // create a mixed concave-convex
603  {
604  piecewise_curve_type pc;
605  he_creator.set_exponents(static_cast<data_type>(1./3.), static_cast<data_type>(3.));
606 
607  TEST_ASSERT(he_creator.create(pc));
608 
609  fref << static_cast<data_type>(1.664021), static_cast<data_type>(1.092592), 0;
610  f=pc.f(t0+dt0/2);
611  TEST_ASSERT((f-fref).norm() < 5e-6);
612 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
613 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
614 // if (typeid(data_type)==typeid(double))
615 // octave_print(1, pc);
616  }
617 
618  // create a mixed concave-convex
619  {
620  piecewise_curve_type pc;
621  he_creator.set_exponents(static_cast<data_type>(3.), static_cast<data_type>(1./3.));
622 
623  TEST_ASSERT(he_creator.create(pc));
624 
625  fref << static_cast<data_type>(1.333809), static_cast<data_type>(0.985460), 0;
626  f=pc.f(t0+dt0/2);
627  TEST_ASSERT((f-fref).norm() < 5e-6);
628 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
629 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
630 // if (typeid(data_type)==typeid(double))
631 // octave_print(1, pc);
632  }
633  }
634 
636  {
637  superellipse_creator_type he_creator(6);
638  data_type dt0(3), dt1(2), dt2(3), dt3(2), dt4(3), dt5(2), t0(-1);
639  point_type f, fref;
640 
641  // set the times
642  he_creator.set_t0(t0);
643  he_creator.set_segment_dt(dt0, 0);
644  he_creator.set_segment_dt(dt1, 1);
645  he_creator.set_segment_dt(dt2, 2);
646  he_creator.set_segment_dt(dt3, 3);
647  he_creator.set_segment_dt(dt4, 4);
648  he_creator.set_segment_dt(dt5, 5);
649 
650  he_creator.set_axis(2, 3);
651  he_creator.set_max_degree(6);
652 
653  // create an ellipse
654  {
655  piecewise_curve_type pc;
656  he_creator.set_exponents(2., 2.);
657 
658  TEST_ASSERT(he_creator.create(pc));
659 
660  fref << static_cast<data_type>(1.791588), static_cast<data_type>(1.333412), 0;
661  f=pc.f(t0+dt0/2);
662  TEST_ASSERT((f-fref).norm() < 5e-6);
663 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
664 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
665 // if (typeid(data_type)==typeid(float))
666 // {
667 // std::cout << std::setprecision(6);
668 // octave_print(1, pc);
669 // }
670  }
671 
672  // create a moderately concave
673  {
674  piecewise_curve_type pc;
675  he_creator.set_exponents(1./2., 1./2.);
676 
677  TEST_ASSERT(he_creator.create(pc));
678 
679  fref << static_cast<data_type>(0.931743), static_cast<data_type>(0.302345), 0;
680  f=pc.f(t0+dt0/2);
681  TEST_ASSERT((f-fref).norm() < 5e-6);
682 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
683 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
684 // if (typeid(data_type)==typeid(double))
685 // {
686 // std::cout << std::setprecision(6);
687 // octave_print(1, pc);
688 // }
689  }
690 
691  // create a severely concave
692  {
693  piecewise_curve_type pc;
694  he_creator.set_exponents(static_cast<data_type>(1./5.), static_cast<data_type>(1./5.));
695 
696  TEST_ASSERT(he_creator.create(pc));
697 
698  if (typeid(data_type)==typeid(float))
699  {
700 #if defined(_MSC_VER)
701 # if (!defined(_WIN64) && (_MSC_VER==1600))
702  fref << static_cast<data_type>(-23.633450), static_cast<data_type>(11.261473), 0;
703 # else
704  fref << static_cast<data_type>(-23.633438), static_cast<data_type>(11.261538), 0;
705 # endif
706 #elif defined(__GNUC__) && defined(__clang__)
707  fref << static_cast<data_type>(-23.633438), static_cast<data_type>(11.261538), 0;
708 #elif defined(__GNUC__) && !defined(__clang__)// && defined(NDEBUG)
709  fref << static_cast<data_type>(-23.633438), static_cast<data_type>(11.261538), 0;
710 #else
711  fref << static_cast<data_type>(-19.968788), static_cast<data_type>(9.096475), 0;
712 #endif
713  }
714  else
715  {
716  fref << static_cast<data_type>(-14.07074), static_cast<data_type>(6.209714), 0;
717  }
718  f=pc.f(t0+dt0/2);
719  TEST_ASSERT((f-fref).norm() < 5e-6);
720 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
721 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
722 // if (typeid(data_type)==typeid(double))
723 // {
724 // std::cout << std::setprecision(6);
725 // octave_print(1, pc);
726 // }
727  }
728 
729  // create a moderately convex
730  {
731  piecewise_curve_type pc;
732  he_creator.set_exponents(static_cast<data_type>(1.2), static_cast<data_type>(1.2));
733 
734  TEST_ASSERT(he_creator.create(pc));
735 
736  fref << static_cast<data_type>(1.471385), static_cast<data_type>(1.124692), 0;
737  f=pc.f(t0+dt0/2);
738  TEST_ASSERT((f-fref).norm() < 5e-6);
739 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
740 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
741 // if (typeid(data_type)==typeid(double))
742 // {
743 // std::cout << std::setprecision(6);
744 // octave_print(1, pc);
745 // }
746  }
747 
748  // create a severely convex
749  {
750  piecewise_curve_type pc;
751  he_creator.set_exponents(5., 5.);
752 
753  TEST_ASSERT(he_creator.create(pc));
754 
755  if (typeid(data_type)==typeid(float))
756  {
757 #ifdef _MSC_VER
758 # if (!defined(_WIN64) && (_MSC_VER==1600))
759  fref << static_cast<data_type>(1.928875), static_cast<data_type>(1.436862), 0;
760 # else
761  fref << static_cast<data_type>(1.930066), static_cast<data_type>(1.438622), 0;
762 # endif
763 #else
764  fref << static_cast<data_type>(1.928891), static_cast<data_type>(1.436470), 0;
765 #endif
766  }
767  else
768  {
769  fref << static_cast<data_type>(1.935626), static_cast<data_type>(1.432817), 0;
770  }
771  f=pc.f(t0+dt0/2);
772  TEST_ASSERT((f-fref).norm() < 6e-6);
773 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
774 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
775 // if (typeid(data_type)==typeid(double))
776 // {
777 // std::cout << std::setprecision(6);
778 // octave_print(1, pc);
779 // }
780  }
781 
782  // create a mixed concave-convex
783  {
784  piecewise_curve_type pc;
785  he_creator.set_exponents(static_cast<data_type>(1./3.), static_cast<data_type>(3.));
786 
787  TEST_ASSERT(he_creator.create(pc));
788 
789  fref << static_cast<data_type>(1.647633), static_cast<data_type>(1.190923), 0;
790  f=pc.f(t0+dt0/2);
791  TEST_ASSERT((f-fref).norm() < 5e-6);
792 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
793 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
794 // if (typeid(data_type)==typeid(double))
795 // {
796 // std::cout << std::setprecision(6);
797 // octave_print(1, pc);
798 // }
799  }
800 
801  // create a mixed concave-convex
802  {
803  piecewise_curve_type pc;
804  he_creator.set_exponents(static_cast<data_type>(3.), static_cast<data_type>(1./3.));
805 
806  TEST_ASSERT(he_creator.create(pc));
807 
808  fref << static_cast<data_type>(1.314240), static_cast<data_type>(1.100464), 0;
809  f=pc.f(t0+dt0/2);
810  TEST_ASSERT((f-fref).norm() < 5e-6);
811 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
812 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
813 // if (typeid(data_type)==typeid(double))
814 // {
815 // std::cout << std::setprecision(6);
816 // octave_print(1, pc);
817 // }
818  }
819  }
820 
822  {
823  superellipse_creator_type he_creator(8);
824  data_type dt0(3), dt1(2), dt2(3), dt3(2), dt4(2), dt5(1), dt6(2), dt7(1), t0(-1);
825  point_type f, fref;
826 
827  // set the times
828  he_creator.set_t0(t0);
829  he_creator.set_segment_dt(dt0, 0);
830  he_creator.set_segment_dt(dt1, 1);
831  he_creator.set_segment_dt(dt2, 2);
832  he_creator.set_segment_dt(dt3, 3);
833  he_creator.set_segment_dt(dt4, 4);
834  he_creator.set_segment_dt(dt5, 5);
835  he_creator.set_segment_dt(dt6, 6);
836  he_creator.set_segment_dt(dt7, 7);
837 
838  he_creator.set_axis(2, 3);
839  he_creator.set_max_degree(3);
840 
841  // create an ellipse
842  {
843  piecewise_curve_type pc;
844  he_creator.set_exponents(2., 2.);
845 
846  TEST_ASSERT(he_creator.create(pc));
847 
848  fref << static_cast<data_type>(1.859473), static_cast<data_type>(1.104687), 0;
849  f=pc.f(t0+dt0/2);
850  TEST_ASSERT((f-fref).norm() < 5e-6);
851 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
852 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
853  }
854 
855  // create a moderately concave
856  {
857  piecewise_curve_type pc;
858  he_creator.set_exponents(1./2., 1./2.);
859 
860  TEST_ASSERT(he_creator.create(pc));
861 
862  fref << static_cast<data_type>(1.147263), static_cast<data_type>(0.188791), 0;
863  f=pc.f(t0+dt0/2);
864  TEST_ASSERT((f-fref).norm() < 5e-6);
865 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
866 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
867  }
868 
869  // create a severely concave
870  {
871  piecewise_curve_type pc;
872  he_creator.set_exponents(static_cast<data_type>(1./5.), static_cast<data_type>(1./5.));
873 
874  TEST_ASSERT(he_creator.create(pc));
875 
876  fref << static_cast<data_type>(1.209256), static_cast<data_type>(0.430468), 0;
877  f=pc.f(t0+dt0/2);
878  TEST_ASSERT((f-fref).norm() < 5e-5);
879 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
880 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
881  }
882 
883  // create a moderately convex
884  {
885  piecewise_curve_type pc;
886  he_creator.set_exponents(static_cast<data_type>(1.2), static_cast<data_type>(1.2));
887 
888  TEST_ASSERT(he_creator.create(pc));
889 
890  fref << static_cast<data_type>(1.616116), static_cast<data_type>(0.869995), 0;
891  f=pc.f(t0+dt0/2);
892  TEST_ASSERT((f-fref).norm() < 5e-6);
893 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
894 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
895  }
896 
897  // create a severely convex
898  {
899  piecewise_curve_type pc;
900  he_creator.set_exponents(5., 5.);
901 
902  TEST_ASSERT(he_creator.create(pc));
903 
904  fref << static_cast<data_type>(1.937615), static_cast<data_type>(1.281272), 0;
905  f=pc.f(t0+dt0/2);
906  TEST_ASSERT((f-fref).norm() < 5e-6);
907 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
908 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
909  }
910 
911  // create a mixed concave-convex
912  {
913  piecewise_curve_type pc;
914  he_creator.set_exponents(static_cast<data_type>(1./3.), static_cast<data_type>(3.));
915 
916  TEST_ASSERT(he_creator.create(pc));
917 
918  fref << static_cast<data_type>(1.774508), static_cast<data_type>(0.938826), 0;
919  f=pc.f(t0+dt0/2);
920  TEST_ASSERT((f-fref).norm() < 5e-6);
921 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
922 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
923  }
924 
925  // create a mixed concave-convex
926  {
927  piecewise_curve_type pc;
928  he_creator.set_exponents(static_cast<data_type>(3.), static_cast<data_type>(1./3.));
929 
930  TEST_ASSERT(he_creator.create(pc));
931 
932  fref << static_cast<data_type>(1.407137), static_cast<data_type>(0.785128), 0;
933  f=pc.f(t0+dt0/2);
934  TEST_ASSERT((f-fref).norm() < 5e-6);
935 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
936 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
937  }
938 
939 // if (typeid(data_type)==typeid(double))
940 // octave_print(1, pc);
941  }
942 
944  {
945  superellipse_creator_type he_creator(8);
946  data_type dt0(3), dt1(2), dt2(3), dt3(2), dt4(2), dt5(1), dt6(2), dt7(1), t0(-1);
947  point_type f, fref;
948 
949  // set the times
950  he_creator.set_t0(t0);
951  he_creator.set_segment_dt(dt0, 0);
952  he_creator.set_segment_dt(dt1, 1);
953  he_creator.set_segment_dt(dt2, 2);
954  he_creator.set_segment_dt(dt3, 3);
955  he_creator.set_segment_dt(dt4, 4);
956  he_creator.set_segment_dt(dt5, 5);
957  he_creator.set_segment_dt(dt6, 6);
958  he_creator.set_segment_dt(dt7, 7);
959 
960  he_creator.set_axis(2, 3);
961  he_creator.set_max_degree(6);
962 
963  // create an ellipse
964  {
965  piecewise_curve_type pc;
966  he_creator.set_exponents(2., 2.);
967 
968  TEST_ASSERT(he_creator.create(pc));
969 
970  fref << static_cast<data_type>(1.859616), static_cast<data_type>(1.104135), 0;
971  f=pc.f(t0+dt0/2);
972  TEST_ASSERT((f-fref).norm() < 5e-6);
973 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
974 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
975  }
976 
977  // create a moderately concave
978  {
979  piecewise_curve_type pc;
980  he_creator.set_exponents(static_cast<data_type>(1./2.), static_cast<data_type>(1./2.));
981 
982  TEST_ASSERT(he_creator.create(pc));
983 
984  fref << static_cast<data_type>(1.148073), static_cast<data_type>(0.176278), 0;
985  f=pc.f(t0+dt0/2);
986  TEST_ASSERT((f-fref).norm() < 5e-6);
987 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
988 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
989  }
990 
991  // create a severely concave
992  {
993  piecewise_curve_type pc;
994  he_creator.set_exponents(static_cast<data_type>(1./5.), static_cast<data_type>(1./5.));
995 
996  TEST_ASSERT(he_creator.create(pc));
997 
998  if (typeid(data_type)==typeid(float))
999  {
1000 #if defined(_MSC_VER)
1001 # if (!defined(_WIN64) && (_MSC_VER==1600))
1002  fref << static_cast<data_type>(-1.200153), static_cast<data_type>(2.997783), 0;
1003 # else
1004  fref << static_cast<data_type>(-1.328213), static_cast<data_type>(3.102814), 0;
1005 # endif
1006 #elif defined(__GNUC__) && defined(__clang__)
1007  fref << static_cast<data_type>(-1.328212), static_cast<data_type>(3.102814), 0;
1008 #elif defined(__GNUC__) && !defined(__clang__)
1009  fref << static_cast<data_type>(-1.328212), static_cast<data_type>(3.102814), 0;
1010 #else
1011  fref << static_cast<data_type>(-1.324945), static_cast<data_type>(3.099777), 0;
1012 #endif
1013  }
1014  else
1015  {
1016  fref << static_cast<data_type>(-1.799115), static_cast<data_type>(3.268398), 0;
1017  }
1018  f=pc.f(t0+dt0/2);
1019  TEST_ASSERT((f-fref).norm() < 5e-6);
1020 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
1021 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
1022  }
1023 
1024  // create a moderately convex
1025  {
1026  piecewise_curve_type pc;
1027  he_creator.set_exponents(static_cast<data_type>(1.2), static_cast<data_type>(1.2));
1028 
1029  TEST_ASSERT(he_creator.create(pc));
1030 
1031  fref << static_cast<data_type>(1.615210), static_cast<data_type>(0.869275), 0;
1032  f=pc.f(t0+dt0/2);
1033  TEST_ASSERT((f-fref).norm() < 5e-6);
1034 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
1035 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
1036  }
1037 
1038  // create a severely convex
1039  {
1040  piecewise_curve_type pc;
1041  he_creator.set_exponents(5., 5.);
1042 
1043  TEST_ASSERT(he_creator.create(pc));
1044 
1045  if (typeid(data_type)==typeid(float))
1046  {
1047 #ifdef _MSC_VER
1048 # if (!defined(_WIN64) && (_MSC_VER==1600))
1049  fref << static_cast<data_type>(1.970994), static_cast<data_type>(1.330452), 0;
1050 # else
1051  fref << static_cast<data_type>(1.970389), static_cast<data_type>(1.330017), 0;
1052 # endif
1053 #else
1054  fref << static_cast<data_type>(1.975022), static_cast<data_type>(1.332086), 0;
1055 #endif
1056  }
1057  else
1058  {
1059  fref << static_cast<data_type>(1.971965), static_cast<data_type>(1.328557), 0;
1060  }
1061  f=pc.f(t0+dt0/2);
1062  TEST_ASSERT((f-fref).norm() < 6e-6);
1063 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
1064 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
1065  }
1066 
1067  // create a mixed concave-convex
1068  {
1069  piecewise_curve_type pc;
1070  he_creator.set_exponents(static_cast<data_type>(1./3.), static_cast<data_type>(3.));
1071 
1072  TEST_ASSERT(he_creator.create(pc));
1073 
1074  fref << static_cast<data_type>(1.822104), static_cast<data_type>(0.938021), 0;
1075  f=pc.f(t0+dt0/2);
1076  TEST_ASSERT((f-fref).norm() < 5e-6);
1077 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
1078 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
1079  }
1080 
1081  // create a mixed concave-convex
1082  {
1083  piecewise_curve_type pc;
1084  he_creator.set_exponents(static_cast<data_type>(3.), static_cast<data_type>(1./3.));
1085 
1086  TEST_ASSERT(he_creator.create(pc));
1087 
1088  fref << static_cast<data_type>(1.423473), static_cast<data_type>(0.786496), 0;
1089  f=pc.f(t0+dt0/2);
1090  TEST_ASSERT((f-fref).norm() < 5e-6);
1091 // std::cout << "f=" << std::setprecision(12) << f << std::endl;
1092 // std::cout << "diff=" << std::setprecision(12) << (f-fref).norm() << std::endl;
1093 
1094 // if (typeid(data_type)==typeid(double))
1095 // {
1096 // std::cout << std::setprecision(6);
1097 // octave_print(1, pc);
1098 // }
1099  }
1100  }
1101 };
1102 
1103 #endif
1104 
virtual bool create(piecewise< bezier, data_type, dim__, tolerance_type > &pc) const
Definition: piecewise_superellipse_creator.hpp:144
void AddTests(const double &)
Definition: piecewise_superellipse_creator_test_suite.hpp:54
void set_max_degree(const index_type &md)
Definition: piecewise_superellipse_creator.hpp:135
tolerance_type tol
Definition: piecewise_superellipse_creator_test_suite.hpp:40
void set_segment_dt(const data_type &dtt, const index_type &i)
Definition: piecewise_creator_base.hpp:64
tol__ tolerance_type
Definition: piecewise.hpp:278
eli::geom::curve::piecewise< eli::geom::curve::bezier, data__, 3 > piecewise_curve_type
Definition: piecewise_superellipse_creator_test_suite.hpp:32
data__ data_type
Definition: piecewise.hpp:276
piecewise_curve_type::point_type point_type
Definition: piecewise_superellipse_creator_test_suite.hpp:34
data_type get_parameter_min() const
Definition: piecewise.hpp:366
eli::geom::curve::piecewise_superellipse_creator< data__, 3, tolerance_type > superellipse_creator_type
Definition: piecewise_superellipse_creator_test_suite.hpp:38
curve_type::index_type index_type
Definition: piecewise.hpp:271
index_type number_segments() const
Definition: piecewise.hpp:419
void set_exponents(const data_type &mm, const data_type &nn)
Definition: piecewise_superellipse_creator.hpp:106
void create_6seg3deg_test()
Definition: piecewise_superellipse_creator_test_suite.hpp:504
Definition: piecewise.hpp:244
piecewise_superellipse_creator_test_suite()
Definition: piecewise_superellipse_creator_test_suite.hpp:78
curve__< data__, dim__, tol__ > curve_type
Definition: piecewise.hpp:270
void create_8seg3deg_test()
Definition: piecewise_superellipse_creator_test_suite.hpp:821
void octave_print(int figno, const piecewise_curve_type &pc) const
Definition: piecewise_superellipse_creator_test_suite.hpp:87
piecewise_curve_type::curve_type curve_type
Definition: piecewise_superellipse_creator_test_suite.hpp:33
void create_6seg6deg_test()
Definition: piecewise_superellipse_creator_test_suite.hpp:635
void AddTests(const long double &)
Definition: piecewise_superellipse_creator_test_suite.hpp:65
void create_4seg6deg_test()
Definition: piecewise_superellipse_creator_test_suite.hpp:349
void create_8seg6deg_test()
Definition: piecewise_superellipse_creator_test_suite.hpp:943
data_type get_parameter_max() const
Definition: piecewise.hpp:374
void create_4seg3deg_test()
Definition: piecewise_superellipse_creator_test_suite.hpp:231
void set_axis(const data_type &aa, const data_type &bb)
Definition: piecewise_superellipse_creator.hpp:77
point_type f(const data_type &t) const
Definition: piecewise.hpp:1732
Definition: piecewise_superellipse_creator_test_suite.hpp:29
void AddTests(const float &)
Definition: piecewise_superellipse_creator_test_suite.hpp:43
void create_degenerate_test()
Definition: piecewise_superellipse_creator_test_suite.hpp:166
error_code get(curve_type &curve, const index_type &index) const
Definition: piecewise.hpp:729
piecewise_curve_type::index_type index_type
Definition: piecewise_superellipse_creator_test_suite.hpp:36
Definition: piecewise_superellipse_creator.hpp:63
curve_type::point_type point_type
Definition: piecewise.hpp:272
piecewise_curve_type::data_type data_type
Definition: piecewise_superellipse_creator_test_suite.hpp:35
void set_t0(const data_type &tt0)
Definition: piecewise_creator_base.hpp:61
~piecewise_superellipse_creator_test_suite()
Definition: piecewise_superellipse_creator_test_suite.hpp:82
piecewise_curve_type::tolerance_type tolerance_type
Definition: piecewise_superellipse_creator_test_suite.hpp:37