1 /* This file is part of the hkl3d library.
3 * The hkl library is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * The hkl library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with the hkl library. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright (C) 2010-2017 Synchrotron SOLEIL
17 * L'Orme des Merisiers Saint-Aubin
18 * BP 48 91192 GIF-sur-YVETTE CEDEX
20 * Authors: Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>
21 * Oussama Sboui <sboui@synchrotron-soleil.fr>
26 #include "tap/basic.h"
27 #include "tap/hkl-tap.h"
29 #define MODEL_FILENAME "data/diffabs.yaml"
31 static void check_model_validity(Hkl3D
*hkl3d
)
41 /* imported 1 config files with 7 Hkl3DObjects */
42 res
&= DIAG(hkl3d
->config
->len
== 1);
43 res
&= DIAG(hkl3d
->config
->models
[0]->len
== 7);
45 /* all Hkl3DObjects must have a different axis_name */
46 len
= hkl3d
->config
->models
[0]->len
;
48 obji
= hkl3d
->config
->models
[0]->objects
[i
];
49 for (j
=1; j
<len
-i
; ++j
){
50 objj
= hkl3d
->config
->models
[0]->objects
[i
+j
];
51 if(!(strcmp(obji
->axis_name
, objj
->axis_name
))){
59 /* check the _movingObjects validity, all Hkl3DAxis must have a size of 1 */
61 res
&= DIAG(hkl3d
->geometry
->axes
[i
]->len
== 1);
63 ok(res
== TRUE
, "no identical objects");
66 /* check the collision and that the right axes are colliding */
67 static void check_collision(Hkl3D
*hkl3d
)
72 /* check the collision and that the right axes are colliding */
73 res
&= DIAG(hkl_geometry_set_values_v(hkl3d
->geometry
->geometry
,
75 23., 0., 0., 0., 0., 0.));
77 res
&= DIAG(hkl3d_is_colliding(hkl3d
) == TRUE
);
80 /* now check that only delta and mu are colliding */
81 for(size_t i
=0; i
<hkl3d
->config
->models
[0]->len
; ++i
){
85 name
= hkl3d
->config
->models
[0]->objects
[i
]->axis_name
;
86 tmp
= hkl3d
->config
->models
[0]->objects
[i
]->is_colliding
== TRUE
;
87 /* add the colliding axes to the buffer */
93 if(!strcmp(name
, "mu") || !strcmp(name
, "delta"))
94 res
&= DIAG(tmp
== TRUE
);
96 res
&= DIAG(tmp
== FALSE
);
98 ok(res
== TRUE
, "collision [%s]", buffer
);
101 static void check_no_collision(Hkl3D
*hkl3d
)
106 /* check that rotating around komega/kappa/kphi do not create collisison */
107 res
&= DIAG(hkl_geometry_set_values_v(hkl3d
->geometry
->geometry
,
109 0., 0., 0., 0., 0., 0.));
111 for(i
=0; i
<=360; i
=i
+10){
112 res
&= DIAG(hkl_geometry_set_values_v(hkl3d
->geometry
->geometry
,
114 0., i
, 0., 0., 0., 0.));
115 res
&= DIAG(hkl3d_is_colliding(hkl3d
) == FALSE
);
119 for(i
=0; i
<=360; i
=i
+10){
120 res
&= DIAG(hkl_geometry_set_values_v(hkl3d
->geometry
->geometry
,
122 0., 0., i
, 0., 0., 0.));
123 res
&= DIAG(hkl3d_is_colliding(hkl3d
) == FALSE
);
127 for(i
=0; i
<=360; i
=i
+10){
128 res
&= DIAG(hkl_geometry_set_values_v(hkl3d
->geometry
->geometry
,
130 0., 0., 0., i
, 0., 0.));
131 res
&= DIAG(hkl3d_is_colliding(hkl3d
) == FALSE
);
133 ok(res
== TRUE
, "no-collision");
139 const HklFactory
*factory
;
140 HklGeometry
*geometry
;
143 factory
= hkl_factory_get_by_name("K6C", NULL
);
144 geometry
= hkl_factory_create_new_geometry(factory
);
146 /* compute the filename of the diffractometer config file */
147 filename
= test_file_path(MODEL_FILENAME
);
148 hkl3d
= hkl3d_new(filename
, geometry
);
151 check_model_validity(hkl3d
);
152 check_collision(hkl3d
);
153 check_no_collision(hkl3d
);
154 /* TODO add/remove object*/
157 test_file_path_free(filename
);
158 hkl_geometry_free(geometry
);