Code-Eli  0.3.6
fit_container_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 fit_container_test_suite_hpp
14 #define fit_container_test_suite_hpp
15 
16 #include <cmath> // cos(), sin()
17 
18 #include <typeinfo> // typeid
19 
20 #include "eli/constants/math.hpp"
22 
23 template<typename data__>
24 class fit_container_test_suite : public Test::Suite
25 {
26  private:
27  typedef Eigen::Matrix<data__, 1, 3> vector_type;
32 
33  protected:
34  void AddTests(const float &)
35  {
36  // add the tests
45  }
46  void AddTests(const double &)
47  {
48  // add the tests
57  }
58  void AddTests(const long double &)
59  {
60  // add the tests
69  }
70 
71  public:
73  {
74  AddTests(data__());
75  }
77  {
78  }
79 
80  private:
81  template<typename it__>
82  void create_points(it__ it, size_t npts)
83  {
84  for (size_t i=0; i<npts; ++i, ++it)
85  {
86  typename it__::value_type p(3);
87  p(0)=std::cos(2*eli::constants::math<data__>::pi()*static_cast<data__>(i)/npts);
88  p(1)=std::sin(2*eli::constants::math<data__>::pi()*static_cast<data__>(i)/npts);
89  p(2)=0;
90  if (i+6>npts)
91  p(0)+=0.5;
92  (*it)=p;
93  }
94  }
95 
97  {
98  fit_container_type ccon;
99  std::vector<point_type> points(20);
100 
101  // set points
102  create_points(points.begin(), points.size());
103  ccon.set_points(points.begin(), points.end());
104 
105  TEST_ASSERT(ccon.number_points()==20);
106  TEST_ASSERT(ccon.number_constraint_points()==0);
107  TEST_ASSERT(ccon.number_constraints()==0);
108  }
109 
111  {
112  int index1(2), index2(5);
113  fit_container_type ccon;
114  error_code ec;
115  constraint_info ciout;
116  std::vector<point_type> points(20);
117 
118  // set points
119  create_points(points.begin(), points.size());
120  ccon.set_points(points.begin(), points.end());
121 
122  // add constraint
123  ec=ccon.add_C0_constraint(index1);
124  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
125  TEST_ASSERT(ccon.number_constraint_points()==1);
126  TEST_ASSERT(ccon.number_constraints()==1);
127 
128  // check for the constraint
129  ec=ccon.get_constraint(index1, ciout);
130  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
131  TEST_ASSERT(ciout.using_fp()==constraint_info::NOT_USED);
132  TEST_ASSERT(ciout.using_fpp()==constraint_info::NOT_USED);
133 
134  // check for constraint that does not exist
135  ec=ccon.get_constraint(index2, ciout);
136  TEST_ASSERT(ec==fit_container_type::INDEX_NOT_FOUND);
137 
138  // add another constraint
139  ec=ccon.add_C0_constraint(index2);
140  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
141  TEST_ASSERT(ccon.number_constraint_points()==2);
142  TEST_ASSERT(ccon.number_constraints()==2);
143 
144  // check for the constraint
145  ec=ccon.get_constraint(index2, ciout);
146  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
147  TEST_ASSERT(ciout.using_fp()==constraint_info::NOT_USED);
148  TEST_ASSERT(ciout.using_fpp()==constraint_info::NOT_USED);
149 
150  // replace constraint
151  ec=ccon.add_C0_constraint(index1);
152  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
153  TEST_ASSERT(ccon.number_constraint_points()==2);
154  TEST_ASSERT(ccon.number_constraints()==2);
155 
156  // check for the constraint
157  ec=ccon.get_constraint(index1, ciout);
158  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
159  TEST_ASSERT(ciout.using_fp()==constraint_info::NOT_USED);
160  TEST_ASSERT(ciout.using_fpp()==constraint_info::NOT_USED);
161  }
162 
164  {
165  int index1(2), index2(5), index3(4);
166  vector_type v(3), vout(3);
167  fit_container_type ccon;
168  error_code ec;
169  constraint_info ciout;
170  std::vector<point_type> points(20);
171 
172  // set points
173  create_points(points.begin(), points.size());
174  ccon.set_points(points.begin(), points.end());
175 
176  // add constraint
177  v[0]=1; v[1]=2; v[2]=3;
178  ec=ccon.add_C1_constraint(index1, v);
179  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
180  TEST_ASSERT(ccon.number_constraint_points()==1);
181  TEST_ASSERT(ccon.number_constraints()==2);
182 
183  // check for the constraint
184  ec=ccon.get_constraint(index1, ciout);
185  vout=ciout.get_fp();
186  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
187  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
188  TEST_ASSERT((vout[0]==v[0]) && (vout[1]==v[1]) && (vout[2]==v[2]));
189  TEST_ASSERT(ciout.using_fpp()==constraint_info::NOT_USED);
190 
191  // check for constraint that does not exist
192  ec=ccon.get_constraint(index2, ciout);
193  TEST_ASSERT(ec==fit_container_type::INDEX_NOT_FOUND);
194 
195  // add another constraint
196  ec=ccon.add_C1_constraint(index2, v);
197  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
198  TEST_ASSERT(ccon.number_constraint_points()==2);
199  TEST_ASSERT(ccon.number_constraints()==4);
200 
201  // check for the constraint
202  ec=ccon.get_constraint(index2, ciout);
203  vout=ciout.get_fp();
204  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
205  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
206  TEST_ASSERT((vout[0]==v[0]) && (vout[1]==v[1]) && (vout[2]==v[2]));
207  TEST_ASSERT(ciout.using_fpp()==constraint_info::NOT_USED);
208 
209  // replace constraint
210  ec=ccon.add_C1_constraint(index1, v);
211  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
212  TEST_ASSERT(ccon.number_constraint_points()==2);
213  TEST_ASSERT(ccon.number_constraints()==4);
214 
215  // check for the constraint
216  ec=ccon.get_constraint(index1, ciout);
217  vout=ciout.get_fp();
218  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
219  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
220  TEST_ASSERT((vout[0]==v[0]) && (vout[1]==v[1]) && (vout[2]==v[2]));
221  TEST_ASSERT(ciout.using_fpp()==constraint_info::NOT_USED);
222 
223  // add finite difference constraint
224  ec=ccon.add_C1_constraint(index3);
225  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
226  TEST_ASSERT(ccon.number_constraint_points()==3);
227  TEST_ASSERT(ccon.number_constraints()==6);
228 
229  // check for the constraint
230  data__ t=2*eli::constants::math<data__>::pi()*static_cast<data__>(index3)/points.size();
231  v[0]=-std::sin(t);
232  v[1]=std::cos(t);
233  v[2]=0;
234  ec=ccon.get_constraint(index3, ciout);
235  vout=ciout.get_fp();
236  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
237  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
238  TEST_ASSERT_DELTA(vout[0], v[0], 2e-2);
239  TEST_ASSERT_DELTA(vout[1], v[1], 5e-3);
240  TEST_ASSERT(vout[2]==v[2]);
241  TEST_ASSERT(ciout.using_fpp()==constraint_info::NOT_USED);
242  }
243 
245  {
246  int index1(2), index2(5), index3(4), index4(6);
247  vector_type v1(3), v2(3), v1out(3), v2out(3);
248  fit_container_type ccon;
249  error_code ec;
250  constraint_info ciout;
251  std::vector<point_type> points(20);
252 
253  // set points
254  create_points(points.begin(), points.size());
255  ccon.set_points(points.begin(), points.end());
256 
257  // add constraint
258  v1[0]=1; v1[1]=2; v1[2]=3;
259  v2[0]=0; v2[1]=-1; v2[2]=-2;
260  ec=ccon.add_C2_constraint(index1, v1, v2);
261  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
262  TEST_ASSERT(ccon.number_constraint_points()==1);
263  TEST_ASSERT(ccon.number_constraints()==3);
264 
265  // check for the constraint
266  ec=ccon.get_constraint(index1, ciout);
267  v1out=ciout.get_fp();
268  v2out=ciout.get_fpp();
269  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
270  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
271  TEST_ASSERT((v1out[0]==v1[0]) && (v1out[1]==v1[1]) && (v1out[2]==v1[2]));
272  TEST_ASSERT(ciout.using_fpp()==constraint_info::SET);
273  TEST_ASSERT((v2out[0]==v2[0]) && (v2out[1]==v2[1]) && (v2out[2]==v2[2]));
274 
275  // check for constraint that does not exist
276  ec=ccon.get_constraint(index2, ciout);
277  TEST_ASSERT(ec==fit_container_type::INDEX_NOT_FOUND);
278 
279  // add another constraint
280  ec=ccon.add_C2_constraint(index2, v1, v2);
281  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
282  TEST_ASSERT(ccon.number_constraint_points()==2);
283  TEST_ASSERT(ccon.number_constraints()==6);
284 
285  // check for the constraint
286  ec=ccon.get_constraint(index2, ciout);
287  v1out=ciout.get_fp();
288  v2out=ciout.get_fpp();
289  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
290  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
291  TEST_ASSERT((v1out[0]==v1[0]) && (v1out[1]==v1[1]) && (v1out[2]==v1[2]));
292  TEST_ASSERT(ciout.using_fpp()==constraint_info::SET);
293  TEST_ASSERT((v2out[0]==v2[0]) && (v2out[1]==v2[1]) && (v2out[2]==v2[2]));
294 
295  // replace constraint
296  ec=ccon.add_C2_constraint(index1, v1, v2);
297  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
298  TEST_ASSERT(ccon.number_constraint_points()==2);
299  TEST_ASSERT(ccon.number_constraints()==6);
300 
301  // check for the constraint
302  ec=ccon.get_constraint(index1, ciout);
303  v1out=ciout.get_fp();
304  v2out=ciout.get_fpp();
305  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
306  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
307  TEST_ASSERT((v1out[0]==v1[0]) && (v1out[1]==v1[1]) && (v1out[2]==v1[2]));
308  TEST_ASSERT(ciout.using_fpp()==constraint_info::SET);
309  TEST_ASSERT((v2out[0]==v2[0]) && (v2out[1]==v2[1]) && (v2out[2]==v2[2]));
310 
311  // add finite difference 2nd derivative constraint
312  ec=ccon.add_C2_constraint(index3, v1);
313  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
314  TEST_ASSERT(ccon.number_constraint_points()==3);
315  TEST_ASSERT(ccon.number_constraints()==9);
316 
317  // check for the constraint
318  data__ t=2*eli::constants::math<data__>::pi()*static_cast<data__>(index3)/points.size();
319  v2[0]=-std::cos(t);
320  v2[1]=-std::sin(t);
321  v2[2]=0;
322  ec=ccon.get_constraint(index3, ciout);
323  v1out=ciout.get_fp();
324  v2out=ciout.get_fpp();
325  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
326  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
327  TEST_ASSERT((v1out[0]==v1[0]) && (v1out[1]==v1[1]) && (v1out[2]==v1[2]));
328  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
329  TEST_ASSERT_DELTA(v2out[0], v2[0], 4*std::numeric_limits<data__>::epsilon());
330  TEST_ASSERT_DELTA(v2out[1], v2[1], 11*std::numeric_limits<data__>::epsilon());
331  TEST_ASSERT(v2out[2]==v2[2]);
332 
333  // add finite difference 1st and 2nd derivative constraint
334  ec=ccon.add_C2_constraint(index4);
335  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
336  TEST_ASSERT(ccon.number_constraint_points()==4);
337  TEST_ASSERT(ccon.number_constraints()==12);
338 
339  // check for the constraint
340  t=2*eli::constants::math<data__>::pi()*static_cast<data__>(index4)/points.size();
341  v1[0]=-std::sin(t);
342  v1[1]=std::cos(t);
343  v1[2]=0;
344  v2[0]=-std::cos(t);
345  v2[1]=-std::sin(t);
346  v2[2]=0;
347  ec=ccon.get_constraint(index4, ciout);
348  v1out=ciout.get_fp();
349  v2out=ciout.get_fpp();
350  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
351  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
352  TEST_ASSERT_DELTA(v1out[0], v1[0], 2e-2);
353  TEST_ASSERT_DELTA(v1out[1], v1[1], 5e-3);
354  TEST_ASSERT(v1out[2]==v1[2]);
355  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
356  TEST_ASSERT_DELTA(v2out[0], v2[0], 11*std::numeric_limits<data__>::epsilon());
357  TEST_ASSERT_DELTA(v2out[1], v2[1], 15*std::numeric_limits<data__>::epsilon());
358  TEST_ASSERT(v2out[2]==v2[2]);
359  }
360 
362  {
363  int index;
364  vector_type v1(3), v2(3), v1out(3), v2out(3);
365  fit_container_type ccon;
366  error_code ec;
367  constraint_info ciout;
368  std::vector<point_type> points(20);
369  data__ ts(0), te(2*eli::constants::math<data__>::pi()*static_cast<data__>(points.size()-1)/points.size());
370 
371  v1[0]=1; v1[1]=2; v1[2]=3;
372  v2[0]=0; v2[1]=-1; v2[2]=-2;
373 
374  // set points
375  create_points(points.begin(), points.size());
376  ccon.set_points(points.begin(), points.end());
377 
378  // add C0 constraint at start
379  ec=ccon.add_start_C0_constraint();
380  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
381  TEST_ASSERT(ccon.number_constraint_points()==1);
382  TEST_ASSERT(ccon.number_constraints()==1);
383 
384  // check for the constraint
385  index=0;
386  ec=ccon.get_constraint(index, ciout);
387  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
388  TEST_ASSERT(ciout.using_fp()==constraint_info::NOT_USED);
389  TEST_ASSERT(ciout.using_fpp()==constraint_info::NOT_USED);
390 
391  // add C0 constraint at end
392  ec=ccon.add_end_C0_constraint();
393  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
394  TEST_ASSERT(ccon.number_constraint_points()==2);
395  TEST_ASSERT(ccon.number_constraints()==2);
396 
397  // check for the constraint
398  index=static_cast<int>(ccon.number_points())-1;
399  ec=ccon.get_constraint(index, ciout);
400  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
401  TEST_ASSERT(ciout.using_fp()==constraint_info::NOT_USED);
402  TEST_ASSERT(ciout.using_fpp()==constraint_info::NOT_USED);
403 
404  // add C1 constraint at start
405  ec=ccon.add_start_C1_constraint(v1);
406  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
407  TEST_ASSERT(ccon.number_constraint_points()==2);
408  TEST_ASSERT(ccon.number_constraints()==3);
409 
410  // check for the constraint
411  index=0;
412  ec=ccon.get_constraint(index, ciout);
413  v1out=ciout.get_fp();
414  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
415  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
416  TEST_ASSERT((v1out[0]==v1[0]) && (v1out[1]==v1[1]) && (v1out[2]==v1[2]));
417  TEST_ASSERT(ciout.using_fpp()==constraint_info::NOT_USED);
418 
419  // add C1 constraint at end
420  ec=ccon.add_end_C1_constraint(v1);
421  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
422  TEST_ASSERT(ccon.number_constraint_points()==2);
423  TEST_ASSERT(ccon.number_constraints()==4);
424 
425  // check for the constraint
426  index=static_cast<int>(ccon.number_points())-1;
427  ec=ccon.get_constraint(index, ciout);
428  v1out=ciout.get_fp();
429  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
430  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
431  TEST_ASSERT((v1out[0]==v1[0]) && (v1out[1]==v1[1]) && (v1out[2]==v1[2]));
432  TEST_ASSERT(ciout.using_fpp()==constraint_info::NOT_USED);
433 
434  // add C2 constraint at start
435  ec=ccon.add_start_C2_constraint(v1, v2);
436  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
437  TEST_ASSERT(ccon.number_constraint_points()==2);
438  TEST_ASSERT(ccon.number_constraints()==5);
439 
440  // check for the constraint
441  index=0;
442  ec=ccon.get_constraint(index, ciout);
443  v1out=ciout.get_fp();
444  v2out=ciout.get_fpp();
445  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
446  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
447  TEST_ASSERT((v1out[0]==v1[0]) && (v1out[1]==v1[1]) && (v1out[2]==v1[2]));
448  TEST_ASSERT(ciout.using_fpp()==constraint_info::SET);
449  TEST_ASSERT((v2out[0]==v2[0]) && (v2out[1]==v2[1]) && (v2out[2]==v2[2]));
450 
451  // add C2 constraint at end
452  ec=ccon.add_end_C2_constraint(v1, v2);
453  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
454  TEST_ASSERT(ccon.number_constraint_points()==2);
455  TEST_ASSERT(ccon.number_constraints()==6);
456 
457  // check for the constraint
458  index=static_cast<int>(ccon.number_points())-1;
459  ec=ccon.get_constraint(index, ciout);
460  v1out=ciout.get_fp();
461  v2out=ciout.get_fpp();
462  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
463  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
464  TEST_ASSERT((v1out[0]==v1[0]) && (v1out[1]==v1[1]) && (v1out[2]==v1[2]));
465  TEST_ASSERT(ciout.using_fpp()==constraint_info::SET);
466  TEST_ASSERT((v2out[0]==v2[0]) && (v2out[1]==v2[1]) && (v2out[2]==v2[2]));
467 
468  // add C1 start finite difference constraint
469  ec=ccon.add_start_C1_constraint();
470  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
471  TEST_ASSERT(ccon.number_constraint_points()==2);
472  TEST_ASSERT(ccon.number_constraints()==5);
473 
474  // check for the constraint
475  index=0;
476  v1[0]=-std::sin(ts);
477  v1[1]=std::cos(ts);
478  v1[2]=0;
479  ec=ccon.get_constraint(index, ciout);
480  v1out=ciout.get_fp();
481  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
482  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
483  TEST_ASSERT_DELTA(v1out[0], v1[0], 8e-3);
484  TEST_ASSERT_DELTA(v1out[1], v1[1], 4e-2);
485  TEST_ASSERT(v1out[2]==v1[2]);
486  TEST_ASSERT(ciout.using_fpp()==constraint_info::NOT_USED);
487 
488  // add C1 end finite difference constraint
489  ec=ccon.add_end_C1_constraint();
490  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
491  TEST_ASSERT(ccon.number_constraint_points()==2);
492  TEST_ASSERT(ccon.number_constraints()==4);
493 
494  // check for the constraint
495  index=static_cast<int>(ccon.number_points())-1;
496  v1[0]=-std::sin(te);
497  v1[1]=std::cos(te);
498  v1[2]=0;
499  ec=ccon.get_constraint(index, ciout);
500  v1out=ciout.get_fp();
501  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
502  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
503  TEST_ASSERT_DELTA(v1out[0], v1[0], 2e-2);
504  TEST_ASSERT_DELTA(v1out[1], v1[1], 4e-2);
505  TEST_ASSERT(v1out[2]==v1[2]);
506  TEST_ASSERT(ciout.using_fpp()==constraint_info::NOT_USED);
507 
508  // add C2 start finite difference 2nd derivative constraint
509  v1[0]=1; v1[1]=2; v1[2]=3;
510  ec=ccon.add_start_C2_constraint(v1);
511  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
512  TEST_ASSERT(ccon.number_constraint_points()==2);
513  TEST_ASSERT(ccon.number_constraints()==5);
514 
515  // check for the constraint
516  index=0;
517  v2[0]=-std::cos(ts);
518  v2[1]=-std::sin(ts);
519  v2[2]=0;
520  ec=ccon.get_constraint(index, ciout);
521  v1out=ciout.get_fp();
522  v2out=ciout.get_fpp();
523  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
524  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
525  TEST_ASSERT((v1out[0]==v1[0]) && (v1out[1]==v1[1]) && (v1out[2]==v1[2]));
526  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
527  TEST_ASSERT_DELTA(v2out[0], v2[0], 1e-1);
528  TEST_ASSERT_DELTA(v2out[1], v2[1], 4e-2);
529  TEST_ASSERT(v2out[2]==v2[2]);
530 
531  // add C2 end finite difference 2nd derivative constraint
532  v1[0]=1; v1[1]=2; v1[2]=3;
533  ec=ccon.add_end_C2_constraint(v1);
534  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
535  TEST_ASSERT(ccon.number_constraint_points()==2);
536  TEST_ASSERT(ccon.number_constraints()==6);
537 
538  // check for the constraint
539  index=static_cast<int>(ccon.number_points())-1;
540  v2[0]=-std::cos(te);
541  v2[1]=-std::sin(te);
542  v2[2]=0;
543  ec=ccon.get_constraint(index, ciout);
544  v1out=ciout.get_fp();
545  v2out=ciout.get_fpp();
546  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
547  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
548  TEST_ASSERT((v1out[0]==v1[0]) && (v1out[1]==v1[1]) && (v1out[2]==v1[2]));
549  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
550  TEST_ASSERT_DELTA(v2out[0], v2[0], 8e-2);
551  TEST_ASSERT_DELTA(v2out[1], v2[1], 6e-2);
552  TEST_ASSERT(v2out[2]==v2[2]);
553 
554  // add C2 start finite difference 1st and 2nd derivative constraint
555  ec=ccon.add_start_C2_constraint();
556  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
557  TEST_ASSERT(ccon.number_constraint_points()==2);
558  TEST_ASSERT(ccon.number_constraints()==6);
559 
560  // check for the constraint
561  index=0;
562  v1[0]=-std::sin(ts);
563  v1[1]=std::cos(ts);
564  v1[2]=0;
565  v2[0]=-std::cos(ts);
566  v2[1]=-std::sin(ts);
567  v2[2]=0;
568  ec=ccon.get_constraint(index, ciout);
569  v1out=ciout.get_fp();
570  v2out=ciout.get_fpp();
571  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
572  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
573  TEST_ASSERT_DELTA(v1out[0], v1[0], 8e-3);
574  TEST_ASSERT_DELTA(v1out[1], v1[1], 4e-2);
575  TEST_ASSERT(v1out[2]==v1[2]);
576  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
577  TEST_ASSERT_DELTA(v2out[0], v2[0], 1e-1);
578  TEST_ASSERT_DELTA(v2out[1], v2[1], 4e-2);
579  TEST_ASSERT(v2out[2]==v2[2]);
580 
581  // add C2 end finite difference 1st and 2nd derivative constraint
582  ec=ccon.add_end_C2_constraint();
583  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
584  TEST_ASSERT(ccon.number_constraint_points()==2);
585  TEST_ASSERT(ccon.number_constraints()==6);
586 
587  // check for the constraint
588  index=static_cast<int>(ccon.number_points())-1;
589  v1[0]=-std::sin(te);
590  v1[1]=std::cos(te);
591  v1[2]=0;
592  v2[0]=-std::cos(te);
593  v2[1]=-std::sin(te);
594  v2[2]=0;
595  ec=ccon.get_constraint(index, ciout);
596  v1out=ciout.get_fp();
597  v2out=ciout.get_fpp();
598  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
599  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
600  TEST_ASSERT_DELTA(v1out[0], v1[0], 2e-2);
601  TEST_ASSERT_DELTA(v1out[1], v1[1], 4e-2);
602  TEST_ASSERT(v1out[2]==v1[2]);
603  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
604  TEST_ASSERT_DELTA(v2out[0], v2[0], 8e-2);
605  TEST_ASSERT_DELTA(v2out[1], v2[1], 6e-2);
606  TEST_ASSERT(v2out[2]==v2[2]);
607  }
608 
610  {
611  // test no FD constraints
612  {
613  int index1(2), index;
614  vector_type v1(3), v2(3), v1out(3), v2out(3);
615  fit_container_type ccon;
616  error_code ec;
617  constraint_info ciout;
618  std::vector<point_type> points(20);
619 
620  // set points
621  create_points(points.begin(), points.size());
622  ccon.set_points(points.begin(), points.end());
623 
624  // add constraint
625  v1[0]=1; v1[1]=2; v1[2]=3;
626  v2[0]=0; v2[1]=-1; v2[2]=-2;
627  ec=ccon.add_C2_constraint(index1, v1, v2);
628  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
629  TEST_ASSERT(ccon.number_constraint_points()==1);
630  TEST_ASSERT(ccon.number_constraints()==3);
631 
632  // add C2 constraint at start
633  ec=ccon.add_start_C2_constraint(v1, v2);
634  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
635  TEST_ASSERT(ccon.number_constraint_points()==2);
636  TEST_ASSERT(ccon.number_constraints()==6);
637 
638  // add C2 constraint at end
639  ec=ccon.add_end_C2_constraint(v1, v2);
640  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
641  TEST_ASSERT(ccon.number_constraint_points()==3);
642  TEST_ASSERT(ccon.number_constraints()==9);
643 
644  // check for the constraint
645  ec=ccon.get_constraint(index1, ciout);
646  v1out=ciout.get_fp();
647  v2out=ciout.get_fpp();
648  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
649  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
650  TEST_ASSERT((v1out[0]==v1[0]) && (v1out[1]==v1[1]) && (v1out[2]==v1[2]));
651  TEST_ASSERT(ciout.using_fpp()==constraint_info::SET);
652  TEST_ASSERT((v2out[0]==v2[0]) && (v2out[1]==v2[1]) && (v2out[2]==v2[2]));
653 
654  // check for the constraint
655  index=0;
656  ec=ccon.get_constraint(index, ciout);
657  v1out=ciout.get_fp();
658  v2out=ciout.get_fpp();
659  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
660  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
661  TEST_ASSERT((v1out[0]==v1[0]) && (v1out[1]==v1[1]) && (v1out[2]==v1[2]));
662  TEST_ASSERT(ciout.using_fpp()==constraint_info::SET);
663  TEST_ASSERT((v2out[0]==v2[0]) && (v2out[1]==v2[1]) && (v2out[2]==v2[2]));
664 
665  // check for the constraint
666  index=static_cast<int>(ccon.number_points())-1;
667  ec=ccon.get_constraint(index, ciout);
668  v1out=ciout.get_fp();
669  v2out=ciout.get_fpp();
670  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
671  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
672  TEST_ASSERT((v1out[0]==v1[0]) && (v1out[1]==v1[1]) && (v1out[2]==v1[2]));
673  TEST_ASSERT(ciout.using_fpp()==constraint_info::SET);
674  TEST_ASSERT((v2out[0]==v2[0]) && (v2out[1]==v2[1]) && (v2out[2]==v2[2]));
675 
676  // change to closed curve
678  TEST_ASSERT(ccon.closed());
679 
680  // check for the constraint
681  ec=ccon.get_constraint(index1, ciout);
682  v1out=ciout.get_fp();
683  v2out=ciout.get_fpp();
684  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
685  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
686  TEST_ASSERT((v1out[0]==v1[0]) && (v1out[1]==v1[1]) && (v1out[2]==v1[2]));
687  TEST_ASSERT(ciout.using_fpp()==constraint_info::SET);
688 
689  // check for the constraint
690  index=0;
691  ec=ccon.get_constraint(index, ciout);
692  v1out=ciout.get_fp();
693  v2out=ciout.get_fpp();
694  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
695  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
696  TEST_ASSERT((v1out[0]==v1[0]) && (v1out[1]==v1[1]) && (v1out[2]==v1[2]));
697  TEST_ASSERT(ciout.using_fpp()==constraint_info::SET);
698  TEST_ASSERT((v2out[0]==v2[0]) && (v2out[1]==v2[1]) && (v2out[2]==v2[2]));
699 
700  // check for the constraint
701  index=static_cast<int>(ccon.number_points())-1;
702  ec=ccon.get_constraint(index, ciout);
703  v1out=ciout.get_fp();
704  v2out=ciout.get_fpp();
705  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
706  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
707  TEST_ASSERT((v1out[0]==v1[0]) && (v1out[1]==v1[1]) && (v1out[2]==v1[2]));
708  TEST_ASSERT(ciout.using_fpp()==constraint_info::SET);
709  TEST_ASSERT((v2out[0]==v2[0]) && (v2out[1]==v2[1]) && (v2out[2]==v2[2]));
710  }
711 
712  // test only FD C1 constraints
713  {
714  int index0, index1, indexnm2, indexnm1;
715  vector_type vp(3), vp0(3), vp1(3), vpnm2(3), vpnm1(3);
716  fit_container_type ccon;
717  error_code ec;
718  constraint_info ciout;
719  std::vector<point_type> points(20);
720  data__ t0(0), t1(2*eli::constants::math<data__>::pi()/points.size()), tnm2(2*eli::constants::math<data__>::pi()*static_cast<data__>(points.size()-1)/points.size()), tnm1(2*eli::constants::math<data__>::pi()*static_cast<data__>(points.size()-1)/points.size());
721 
722  // set points
723  create_points(points.begin(), points.size());
724  ccon.set_points(points.begin(), points.end());
725 
726  // set the reference values
727  index0=0;
728  index1=1;
729  indexnm2=static_cast<int>(points.size())-2;
730  indexnm1=static_cast<int>(points.size())-1;
731  t0 =2*eli::constants::math<data__>::pi()*static_cast<data__>(index0)/points.size();
732  t1 =2*eli::constants::math<data__>::pi()*static_cast<data__>(index1)/points.size();
733  tnm2=2*eli::constants::math<data__>::pi()*static_cast<data__>(indexnm2)/points.size();
734  tnm1=2*eli::constants::math<data__>::pi()*static_cast<data__>(indexnm1)/points.size();
735  vp0(0)=-std::sin(t0);
736  vp0(1)=std::cos(t0);
737  vp0(2)=0;
738  vp1(0)=-std::sin(t1);
739  vp1(1)=std::cos(t1);
740  vp1(2)=0;
741  vpnm2(0)=-std::sin(tnm2);
742  vpnm2(1)=std::cos(tnm2);
743  vpnm2(2)=0;
744  vpnm1(0)=-std::sin(tnm1);
745  vpnm1(1)=std::cos(tnm1);
746  vpnm1(2)=0;
747 
748  // add C1 constraint at start
749  ec=ccon.add_start_C1_constraint();
750  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
751  TEST_ASSERT(ccon.number_constraint_points()==1);
752  TEST_ASSERT(ccon.number_constraints()==2);
753 
754  // add C1 constraint at start+1
755  ec=ccon.add_C1_constraint(1);
756  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
757  TEST_ASSERT(ccon.number_constraint_points()==2);
758  TEST_ASSERT(ccon.number_constraints()==4);
759 
760  // add C1 constraint at end-1
761  ec=ccon.add_C1_constraint(static_cast<int>(points.size())-2);
762  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
763  TEST_ASSERT(ccon.number_constraint_points()==3);
764  TEST_ASSERT(ccon.number_constraints()==6);
765 
766  // add C1 constraint at end
767  ec=ccon.add_end_C1_constraint();
768  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
769  TEST_ASSERT(ccon.number_constraint_points()==4);
770  TEST_ASSERT(ccon.number_constraints()==8);
771 
772  // check all derivatives
773  ec=ccon.get_constraint(index0, ciout);
774  vp=ciout.get_fp();
775  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
776  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
777  TEST_ASSERT_DELTA(vp(0), vp0(0), 8e-3);
778  TEST_ASSERT_DELTA(vp(1), vp0(1), 4e-2);
779  TEST_ASSERT(vp(2)==vp0(2));
780  TEST_ASSERT(ciout.using_fpp()==constraint_info::NOT_USED);
781  ec=ccon.get_constraint(index1, ciout);
782  vp=ciout.get_fp();
783  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
784  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
785  TEST_ASSERT_DELTA(vp(0), vp1(0), 4e-3);
786  TEST_ASSERT_DELTA(vp(1), vp1(1), 2e-2);
787  TEST_ASSERT(vp(2)==vp1(2));
788  TEST_ASSERT(ciout.using_fpp()==constraint_info::NOT_USED);
789  ec=ccon.get_constraint(indexnm2, ciout);
790  vp=ciout.get_fp();
791  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
792  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
793  TEST_ASSERT_DELTA(vp(0), vpnm2(0), 8e-3);
794  TEST_ASSERT_DELTA(vp(1), vpnm2(1), 1e-2);
795  TEST_ASSERT(vp(2)==vpnm2(2));
796  TEST_ASSERT(ciout.using_fpp()==constraint_info::NOT_USED);
797  ec=ccon.get_constraint(indexnm1, ciout);
798  vp=ciout.get_fp();
799  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
800  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
801  TEST_ASSERT_DELTA(vp(0), vpnm1(0), 2e-2);
802  TEST_ASSERT_DELTA(vp(1), vpnm1(1), 4e-2);
803  TEST_ASSERT(vp(2)==vpnm1(2));
804  TEST_ASSERT(ciout.using_fpp()==constraint_info::NOT_USED);
805 
806  // change to closed curve
808  TEST_ASSERT(ccon.closed());
809 
810  // check all derivatives
811  ec=ccon.get_constraint(index0, ciout);
812  vp=ciout.get_fp();
813  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
814  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
815  TEST_ASSERT_DELTA(vp(0), vp0(0), 4e-1);
816  TEST_ASSERT_DELTA(vp(1), vp0(1), 2e-1);
817  TEST_ASSERT(vp(2)==vp0(2));
818  TEST_ASSERT(ciout.using_fpp()==constraint_info::NOT_USED);
819  ec=ccon.get_constraint(index1, ciout);
820  vp=ciout.get_fp();
821  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
822  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
823  TEST_ASSERT_DELTA(vp(0), vp1(0), 4e-3);
824  TEST_ASSERT_DELTA(vp(1), vp1(1), 2e-2);
825  TEST_ASSERT(vp(2)==vp1(2));
826  TEST_ASSERT(ciout.using_fpp()==constraint_info::NOT_USED);
827  ec=ccon.get_constraint(indexnm2, ciout);
828  vp=ciout.get_fp();
829  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
830  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
831  TEST_ASSERT_DELTA(vp(0), vpnm2(0), 8e-3);
832  TEST_ASSERT_DELTA(vp(1), vpnm2(1), 1e-2);
833  TEST_ASSERT(vp(2)==vpnm2(2));
834  TEST_ASSERT(ciout.using_fpp()==constraint_info::NOT_USED);
835  ec=ccon.get_constraint(indexnm1, ciout);
836  vp=ciout.get_fp();
837  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
838  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
839  TEST_ASSERT_DELTA(vp(0), vpnm1(0), 4e-1);
840  TEST_ASSERT_DELTA(vp(1), vpnm1(1), 2e-1);
841  TEST_ASSERT(vp(2)==vpnm1(2));
842  TEST_ASSERT(ciout.using_fpp()==constraint_info::NOT_USED);
843  }
844 
845  // test FD C2 & set C1 constraints
846  {
847  int index0, index1, indexnm2, indexnm1;
848  vector_type v1(3), vp(3), vpp(3), vpp0(3), vpp1(3), vppnm2(3), vppnm1(3);
849  fit_container_type ccon;
850  error_code ec;
851  constraint_info ciout;
852  std::vector<point_type> points(20);
853  data__ t0(0), t1(2*eli::constants::math<data__>::pi()/points.size()), tnm2(2*eli::constants::math<data__>::pi()*static_cast<data__>(points.size()-1)/points.size()), tnm1(2*eli::constants::math<data__>::pi()*static_cast<data__>(points.size()-1)/points.size());
854 
855  // set points
856  create_points(points.begin(), points.size());
857  ccon.set_points(points.begin(), points.end());
858 
859  // set the reference values
860  v1(0)=1; v1(1)=2; v1(2)=3;
861  index0=0;
862  index1=1;
863  indexnm2=static_cast<int>(points.size())-2;
864  indexnm1=static_cast<int>(points.size())-1;
865  t0 =2*eli::constants::math<data__>::pi()*static_cast<data__>(index0)/points.size();
866  t1 =2*eli::constants::math<data__>::pi()*static_cast<data__>(index1)/points.size();
867  tnm2=2*eli::constants::math<data__>::pi()*static_cast<data__>(indexnm2)/points.size();
868  tnm1=2*eli::constants::math<data__>::pi()*static_cast<data__>(indexnm1)/points.size();
869  vpp0(0)=-std::cos(t0);
870  vpp0(1)=-std::sin(t0);
871  vpp0(2)=0;
872  vpp1(0)=-std::cos(t1);
873  vpp1(1)=-std::sin(t1);
874  vpp1(2)=0;
875  vppnm2(0)=-std::cos(tnm2);
876  vppnm2(1)=-std::sin(tnm2);
877  vppnm2(2)=0;
878  vppnm1(0)=-std::cos(tnm1);
879  vppnm1(1)=-std::sin(tnm1);
880  vppnm1(2)=0;
881 
882  // add C2 constraint at start
883  ec=ccon.add_start_C2_constraint(v1);
884  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
885  TEST_ASSERT(ccon.number_constraint_points()==1);
886  TEST_ASSERT(ccon.number_constraints()==3);
887 
888  // add C2 constraint at start+1
889  ec=ccon.add_C2_constraint(1, v1);
890  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
891  TEST_ASSERT(ccon.number_constraint_points()==2);
892  TEST_ASSERT(ccon.number_constraints()==6);
893 
894  // add C2 constraint at end-1
895  ec=ccon.add_C2_constraint(static_cast<int>(points.size())-2, v1);
896  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
897  TEST_ASSERT(ccon.number_constraint_points()==3);
898  TEST_ASSERT(ccon.number_constraints()==9);
899 
900  // add C2 constraint at end
901  ec=ccon.add_end_C2_constraint(v1);
902  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
903  TEST_ASSERT(ccon.number_constraint_points()==4);
904  TEST_ASSERT(ccon.number_constraints()==12);
905 
906  // check all derivatives
907  ec=ccon.get_constraint(index0, ciout);
908  vp=ciout.get_fp();
909  vpp=ciout.get_fpp();
910  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
911  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
912  TEST_ASSERT((vp(0)==v1(0)) && (vp(1)==v1(1)) && (vp(2)==v1(2)));
913  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
914  TEST_ASSERT_DELTA(vpp(0), vpp0(0), 1e-1);
915  TEST_ASSERT_DELTA(vpp(1), vpp0(1), 4e-2);
916  TEST_ASSERT(vpp(2)==vpp0(2));
917  ec=ccon.get_constraint(index1, ciout);
918  vp=ciout.get_fp();
919  vpp=ciout.get_fpp();
920  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
921  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
922  TEST_ASSERT((vp(0)==v1(0)) && (vp(1)==v1(1)) && (vp(2)==v1(2)));
923  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
924  TEST_ASSERT_DELTA(vpp(0), vpp1(0), 16*std::numeric_limits<data__>::epsilon());
925  TEST_ASSERT_DELTA(vpp(1), vpp1(1), 11*std::numeric_limits<data__>::epsilon());
926  TEST_ASSERT(vpp(2)==vpp1(2));
927  ec=ccon.get_constraint(indexnm2, ciout);
928  vp=ciout.get_fp();
929  vpp=ciout.get_fpp();
930  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
931  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
932  TEST_ASSERT((vp(0)==v1(0)) && (vp(1)==v1(1)) && (vp(2)==v1(2)));
933  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
934  TEST_ASSERT_DELTA(vpp(0), vppnm2(0), 33*std::numeric_limits<data__>::epsilon());
935  TEST_ASSERT_DELTA(vpp(1), vppnm2(1), 33*std::numeric_limits<data__>::epsilon());
936  TEST_ASSERT(vpp(2)==vppnm2(2));
937  ec=ccon.get_constraint(indexnm1, ciout);
938  vp=ciout.get_fp();
939  vpp=ciout.get_fpp();
940  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
941  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
942  TEST_ASSERT((vp(0)==v1(0)) && (vp(1)==v1(1)) && (vp(2)==v1(2)));
943  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
944  TEST_ASSERT_DELTA(vpp(0), vppnm1(0), 8e-2);
945  TEST_ASSERT_DELTA(vpp(1), vppnm1(1), 6e-2);
946  TEST_ASSERT(vpp(2)==vppnm1(2));
947 
948  // change to closed curve
950  TEST_ASSERT(ccon.closed());
951 
952  // check all derivatives
953  ec=ccon.get_constraint(index0, ciout);
954  vp=ciout.get_fp();
955  vpp=ciout.get_fpp();
956  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
957  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
958  TEST_ASSERT((vp(0)==v1(0)) && (vp(1)==v1(1)) && (vp(2)==v1(2)));
959  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
960  TEST_ASSERT_DELTA(vpp(0), vpp0(0), 3.5);
961  TEST_ASSERT_DELTA(vpp(1), vpp0(1), 1.4);
962  TEST_ASSERT(vpp(2)==vpp0(2));
963  ec=ccon.get_constraint(index1, ciout);
964  vp=ciout.get_fp();
965  vpp=ciout.get_fpp();
966  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
967  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
968  TEST_ASSERT((vp(0)==v1(0)) && (vp(1)==v1(1)) && (vp(2)==v1(2)));
969  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
970  TEST_ASSERT_DELTA(vpp(0), vpp1(0), 16*std::numeric_limits<data__>::epsilon());
971  TEST_ASSERT_DELTA(vpp(1), vpp1(1), 16*std::numeric_limits<data__>::epsilon());
972  TEST_ASSERT(vpp(2)==vpp1(2));
973  ec=ccon.get_constraint(indexnm2, ciout);
974  vp=ciout.get_fp();
975  vpp=ciout.get_fpp();
976  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
977  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
978  TEST_ASSERT((vp(0)==v1(0)) && (vp(1)==v1(1)) && (vp(2)==v1(2)));
979  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
980  TEST_ASSERT_DELTA(vpp(0), vppnm2(0), 33*std::numeric_limits<data__>::epsilon());
981  TEST_ASSERT_DELTA(vpp(1), vppnm2(1), 33*std::numeric_limits<data__>::epsilon());
982  TEST_ASSERT(vpp(2)==vppnm2(2));
983  ec=ccon.get_constraint(indexnm1, ciout);
984  vp=ciout.get_fp();
985  vpp=ciout.get_fpp();
986  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
987  TEST_ASSERT(ciout.using_fp()==constraint_info::SET);
988  TEST_ASSERT((vp(0)==v1(0)) && (vp(1)==v1(1)) && (vp(2)==v1(2)));
989  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
990  TEST_ASSERT_DELTA(vpp(0), vppnm1(0), 3.0);
991  TEST_ASSERT_DELTA(vpp(1), vppnm1(1), 1.5);
992  TEST_ASSERT(vpp(2)==vppnm1(2));
993  }
994 
995  // test FD C1 and C2 constraints
996  {
997  int index0, index1, indexnm2, indexnm1;
998  vector_type vp(3), vp0(3), vp1(3), vpnm2(3), vpnm1(3), vpp(3), vpp0(3), vpp1(3), vppnm2(3), vppnm1(3);
999  fit_container_type ccon;
1000  error_code ec;
1001  constraint_info ciout;
1002  std::vector<point_type> points(20);
1003  data__ t0(0), t1(2*eli::constants::math<data__>::pi()/points.size()), tnm2(2*eli::constants::math<data__>::pi()*static_cast<data__>(points.size()-1)/points.size()), tnm1(2*eli::constants::math<data__>::pi()*static_cast<data__>(points.size()-1)/points.size());
1004 
1005  // set points
1006  create_points(points.begin(), points.size());
1007  ccon.set_points(points.begin(), points.end());
1008 
1009  // set the reference values
1010  index0=0;
1011  index1=1;
1012  indexnm2=static_cast<int>(points.size())-2;
1013  indexnm1=static_cast<int>(points.size())-1;
1014  t0 =2*eli::constants::math<data__>::pi()*static_cast<data__>(index0)/points.size();
1015  t1 =2*eli::constants::math<data__>::pi()*static_cast<data__>(index1)/points.size();
1016  tnm2=2*eli::constants::math<data__>::pi()*static_cast<data__>(indexnm2)/points.size();
1017  tnm1=2*eli::constants::math<data__>::pi()*static_cast<data__>(indexnm1)/points.size();
1018  vp0(0)=-std::sin(t0);
1019  vp0(1)=std::cos(t0);
1020  vp0(2)=0;
1021  vp1(0)=-std::sin(t1);
1022  vp1(1)=std::cos(t1);
1023  vp1(2)=0;
1024  vpnm2(0)=-std::sin(tnm2);
1025  vpnm2(1)=std::cos(tnm2);
1026  vpnm2(2)=0;
1027  vpnm1(0)=-std::sin(tnm1);
1028  vpnm1(1)=std::cos(tnm1);
1029  vpnm1(2)=0;
1030  vpp0(0)=-std::cos(t0);
1031  vpp0(1)=-std::sin(t0);
1032  vpp0(2)=0;
1033  vpp1(0)=-std::cos(t1);
1034  vpp1(1)=-std::sin(t1);
1035  vpp1(2)=0;
1036  vppnm2(0)=-std::cos(tnm2);
1037  vppnm2(1)=-std::sin(tnm2);
1038  vppnm2(2)=0;
1039  vppnm1(0)=-std::cos(tnm1);
1040  vppnm1(1)=-std::sin(tnm1);
1041  vppnm1(2)=0;
1042 
1043  // add C2 constraint at start
1044  ec=ccon.add_start_C2_constraint();
1045  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1046  TEST_ASSERT(ccon.number_constraint_points()==1);
1047  TEST_ASSERT(ccon.number_constraints()==3);
1048 
1049  // add C2 constraint at start+1
1050  ec=ccon.add_C2_constraint(1);
1051  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1052  TEST_ASSERT(ccon.number_constraint_points()==2);
1053  TEST_ASSERT(ccon.number_constraints()==6);
1054 
1055  // add C2 constraint at end-1
1056  ec=ccon.add_C2_constraint(static_cast<int>(points.size())-2);
1057  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1058  TEST_ASSERT(ccon.number_constraint_points()==3);
1059  TEST_ASSERT(ccon.number_constraints()==9);
1060 
1061  // add C2 constraint at end
1062  ec=ccon.add_end_C2_constraint();
1063  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1064  TEST_ASSERT(ccon.number_constraint_points()==4);
1065  TEST_ASSERT(ccon.number_constraints()==12);
1066 
1067  // check all derivatives
1068  ec=ccon.get_constraint(index0, ciout);
1069  vp=ciout.get_fp();
1070  vpp=ciout.get_fpp();
1071  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1072  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
1073  TEST_ASSERT_DELTA(vp(0), vp0(0), 8e-3);
1074  TEST_ASSERT_DELTA(vp(1), vp0(1), 4e-2);
1075  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
1076  TEST_ASSERT_DELTA(vpp(0), vpp0(0), 1e-1);
1077  TEST_ASSERT_DELTA(vpp(1), vpp0(1), 4e-2);
1078  TEST_ASSERT(vpp(2)==vpp0(2));
1079  ec=ccon.get_constraint(index1, ciout);
1080  vp=ciout.get_fp();
1081  vpp=ciout.get_fpp();
1082  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1083  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
1084  TEST_ASSERT_DELTA(vp(0), vp1(0), 4e-3);
1085  TEST_ASSERT_DELTA(vp(1), vp1(1), 2e-2);
1086  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
1087  TEST_ASSERT_DELTA(vpp(0), vpp1(0), 16*std::numeric_limits<data__>::epsilon());
1088  TEST_ASSERT_DELTA(vpp(1), vpp1(1), 11*std::numeric_limits<data__>::epsilon());
1089  TEST_ASSERT(vpp(2)==vpp1(2));
1090  ec=ccon.get_constraint(indexnm2, ciout);
1091  vp=ciout.get_fp();
1092  vpp=ciout.get_fpp();
1093  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1094  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
1095  TEST_ASSERT_DELTA(vp(0), vpnm2(0), 8e-3);
1096  TEST_ASSERT_DELTA(vp(1), vpnm2(1), 1e-2);
1097  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
1098  TEST_ASSERT_DELTA(vpp(0), vppnm2(0), 33*std::numeric_limits<data__>::epsilon());
1099  TEST_ASSERT_DELTA(vpp(1), vppnm2(1), 33*std::numeric_limits<data__>::epsilon());
1100  TEST_ASSERT(vpp(2)==vppnm2(2));
1101  ec=ccon.get_constraint(indexnm1, ciout);
1102  vp=ciout.get_fp();
1103  vpp=ciout.get_fpp();
1104  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1105  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
1106  TEST_ASSERT_DELTA(vp(0), vpnm1(0), 2e-2);
1107  TEST_ASSERT_DELTA(vp(1), vpnm1(1), 4e-2);
1108  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
1109  TEST_ASSERT_DELTA(vpp(0), vppnm1(0), 8e-2);
1110  TEST_ASSERT_DELTA(vpp(1), vppnm1(1), 6e-2);
1111  TEST_ASSERT(vpp(2)==vppnm1(2));
1112 
1113  // change to closed curve
1115  TEST_ASSERT(ccon.closed());
1116 
1117  // check all derivatives
1118  ec=ccon.get_constraint(index0, ciout);
1119  vp=ciout.get_fp();
1120  vpp=ciout.get_fpp();
1121  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1122  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
1123  TEST_ASSERT_DELTA(vp(0), vp0(0), 4e-1);
1124  TEST_ASSERT_DELTA(vp(1), vp0(1), 2e-1);
1125  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
1126  TEST_ASSERT_DELTA(vpp(0), vpp0(0), 3.5);
1127  TEST_ASSERT_DELTA(vpp(1), vpp0(1), 1.4);
1128  TEST_ASSERT(vpp(2)==vpp0(2));
1129  ec=ccon.get_constraint(index1, ciout);
1130  vp=ciout.get_fp();
1131  vpp=ciout.get_fpp();
1132  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1133  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
1134  TEST_ASSERT_DELTA(vp(0), vp1(0), 4e-3);
1135  TEST_ASSERT_DELTA(vp(1), vp1(1), 2e-2);
1136  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
1137  TEST_ASSERT_DELTA(vpp(0), vpp1(0), 16*std::numeric_limits<data__>::epsilon());
1138  TEST_ASSERT_DELTA(vpp(1), vpp1(1), 16*std::numeric_limits<data__>::epsilon());
1139  TEST_ASSERT(vpp(2)==vpp1(2));
1140  ec=ccon.get_constraint(indexnm2, ciout);
1141  vp=ciout.get_fp();
1142  vpp=ciout.get_fpp();
1143  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1144  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
1145  TEST_ASSERT_DELTA(vp(0), vpnm2(0), 8e-3);
1146  TEST_ASSERT_DELTA(vp(1), vpnm2(1), 1e-2);
1147  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
1148  TEST_ASSERT_DELTA(vpp(0), vppnm2(0), 33*std::numeric_limits<data__>::epsilon());
1149  TEST_ASSERT_DELTA(vpp(1), vppnm2(1), 33*std::numeric_limits<data__>::epsilon());
1150  TEST_ASSERT(vpp(2)==vppnm2(2));
1151  ec=ccon.get_constraint(indexnm1, ciout);
1152  vp=ciout.get_fp();
1153  vpp=ciout.get_fpp();
1154  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1155  TEST_ASSERT(ciout.using_fp()==constraint_info::FD);
1156  TEST_ASSERT_DELTA(vp(0), vpnm1(0), 4e-1);
1157  TEST_ASSERT_DELTA(vp(1), vpnm1(1), 2e-1);
1158  TEST_ASSERT(ciout.using_fpp()==constraint_info::FD);
1159  TEST_ASSERT_DELTA(vpp(0), vppnm1(0), 3.0);
1160  TEST_ASSERT_DELTA(vpp(1), vppnm1(1), 1.5);
1161  TEST_ASSERT(vpp(2)==vppnm1(2));
1162  }
1163  }
1164 
1166  {
1167  int index1(2), index2(5);
1168  vector_type v1(3), v2(3);
1169  fit_container_type ccon;
1170  error_code ec;
1171  constraint_info ciout;
1172  std::vector<point_type> points(20);
1173 
1174  v1[0]=0; v2[1]=2; v2[2]=4;
1175  v2[0]=1; v2[1]=3; v2[2]=5;
1176 
1177  // set points
1178  create_points(points.begin(), points.size());
1179  ccon.set_points(points.begin(), points.end());
1180 
1181  // add some constraints
1182  ec=ccon.add_C0_constraint(index1);
1183  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1184  ec=ccon.add_C0_constraint(index2);
1185  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1186  ec=ccon.add_C1_constraint(index2-index1, v1);
1187  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1188  ec=ccon.add_C2_constraint(index2+index1, v1, v2);
1189  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1190  TEST_ASSERT(ccon.number_constraint_points()==4);
1191  TEST_ASSERT(ccon.number_constraints()==7);
1192 
1193  // remove constraint
1194  ec=ccon.remove_constraint(index2-index1);
1195  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1196  TEST_ASSERT(ccon.number_constraint_points()==3);
1197  TEST_ASSERT(ccon.number_constraints()==5);
1198  ec=ccon.get_constraint(index2-index1, ciout);
1199  TEST_ASSERT(ec==fit_container_type::INDEX_NOT_FOUND);
1200 
1201  // try to remove constraint that is not there
1202  ec=ccon.remove_constraint(index2-1);
1203  TEST_ASSERT(ec==fit_container_type::INDEX_NOT_FOUND);
1204  }
1205 
1207  {
1208  int index1(2), index2(5);
1209  vector_type v1(3), v2(3);
1210  fit_container_type ccon;
1211  error_code ec;
1212  constraint_info ciout;
1213  std::vector<point_type> points(20);
1214 
1215  v1[0]=0; v2[1]=2; v2[2]=4;
1216  v2[0]=1; v2[1]=3; v2[2]=5;
1217 
1218  // set points
1219  create_points(points.begin(), points.size());
1220  ccon.set_points(points.begin(), points.end());
1221 
1222  // add some constraints
1223  ec=ccon.add_C0_constraint(index1);
1224  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1225  ec=ccon.add_C0_constraint(index2);
1226  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1227  ec=ccon.add_C1_constraint(index2-index1, v1);
1228  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1229  ec=ccon.add_C2_constraint(index2+index1, v1, v2);
1230  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1231  TEST_ASSERT(ccon.number_constraint_points()==4);
1232  TEST_ASSERT(ccon.number_constraints()==7);
1233 
1234  // get list of constraint indexes
1235  std::vector<int> indexes(ccon.number_constraint_points());
1236  ec=ccon.get_constraint_indexes(indexes.begin());
1237  TEST_ASSERT(ec==fit_container_type::NO_ERRORS);
1238  TEST_ASSERT(indexes[0]==index1);
1239  TEST_ASSERT(indexes[1]==(index2-index1));
1240  TEST_ASSERT(indexes[2]==index2);
1241  TEST_ASSERT(indexes[3]==index2+index1);
1242  }
1243 };
1244 
1245 #endif
1246 
void add_C1_constraints_test()
Definition: fit_container_test_suite.hpp:163
error_code add_start_C2_constraint()
Definition: fit_container.hpp:517
use_states using_fp() const
Definition: fit_container.hpp:88
error_code add_C0_constraint(const index_type &i)
Definition: fit_container.hpp:562
Eigen::Matrix< data__, 1, 3 > vector_type
Definition: fit_container_test_suite.hpp:27
Definition: fit_container.hpp:45
size_t number_constraint_points() const
Definition: fit_container.hpp:375
error_code add_C2_constraint(const index_type &i)
Definition: fit_container.hpp:611
size_t number_points() const
Definition: fit_container.hpp:374
fit_container_type::constraint_info constraint_info
Definition: fit_container_test_suite.hpp:29
Definition: fit_container.hpp:34
void add_end_constraints_test()
Definition: fit_container_test_suite.hpp:361
void AddTests(const double &)
Definition: fit_container_test_suite.hpp:46
~fit_container_test_suite()
Definition: fit_container_test_suite.hpp:76
void add_C0_constraints_test()
Definition: fit_container_test_suite.hpp:110
void create_points(it__ it, size_t npts)
Definition: fit_container_test_suite.hpp:82
use_states using_fpp() const
Definition: fit_container.hpp:89
Definition: math.hpp:25
error_code add_start_C0_constraint()
Definition: fit_container.hpp:502
void closed_constraints_test()
Definition: fit_container_test_suite.hpp:609
fit_container_type::point_type point_type
Definition: fit_container_test_suite.hpp:30
Definition: fit_container.hpp:43
error_code remove_constraint(const index_type &i)
Definition: fit_container.hpp:673
error_code add_end_C0_constraint()
Definition: fit_container.hpp:532
error_code add_start_C1_constraint()
Definition: fit_container.hpp:507
error_code get_constraint(const index_type &i, constraint_info &ci) const
Definition: fit_container.hpp:476
Definition: continuity.hpp:27
point_type get_fpp() const
Definition: fit_container.hpp:87
void remove_constraints_test()
Definition: fit_container_test_suite.hpp:1165
void add_C2_constraints_test()
Definition: fit_container_test_suite.hpp:244
fit_container_type::error_code error_code
Definition: fit_container_test_suite.hpp:31
error_code add_C1_constraint(const index_type &i)
Definition: fit_container.hpp:575
void AddTests(const long double &)
Definition: fit_container_test_suite.hpp:58
Definition: fit_container_test_suite.hpp:24
void set_end_flag(const eli::geom::general::continuity &op)
Definition: fit_container.hpp:399
void list_constraints_test()
Definition: fit_container_test_suite.hpp:1206
fit_container_test_suite()
Definition: fit_container_test_suite.hpp:72
point_type get_fp() const
Definition: fit_container.hpp:86
void construction_test()
Definition: fit_container_test_suite.hpp:96
error_code
Definition: fit_container.hpp:41
void AddTests(const float &)
Definition: fit_container_test_suite.hpp:34
Definition: fit_container.hpp:50
error_code add_end_C2_constraint()
Definition: fit_container.hpp:547
void set_points(it__ itb, it__ ite)
Definition: fit_container.hpp:444
error_code add_end_C1_constraint()
Definition: fit_container.hpp:537
eli::geom::curve::fit_container< data__, int, 3, 3 > fit_container_type
Definition: fit_container_test_suite.hpp:28
size_t number_constraints(bool fit=true) const
Definition: fit_container.hpp:377
error_code get_constraint_indexes(it__ itout) const
Definition: fit_container.hpp:688
Eigen::Matrix< data_type, 1, dim__ > point_type
Definition: fit_container.hpp:39
bool closed() const
Definition: fit_container.hpp:396