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-2013 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"
28 #define MODEL_FILENAME "data/diffabs.yaml"
30 static void check_model_validity(Hkl3D
*hkl3d
)
40 /* imported 1 config files with 7 Hkl3DObjects */
41 res
&= hkl3d
->config
->len
== 1;
42 res
&= hkl3d
->config
->models
[0]->len
== 7;
44 /* all Hkl3DObjects must have a different axis_name */
45 len
= hkl3d
->config
->models
[0]->len
;
47 obji
= hkl3d
->config
->models
[0]->objects
[i
];
48 for (j
=1; j
<len
-i
; ++j
){
49 objj
= hkl3d
->config
->models
[0]->objects
[i
+j
];
50 if(!(strcmp(obji
->axis_name
, objj
->axis_name
))){
58 /* check the _movingObjects validity, all Hkl3DAxis must have a size of 1 */
60 res
&= hkl3d
->geometry
->axes
[i
]->len
== 1;
62 ok(res
== TRUE
, "no identical objects");
65 /* check the collision and that the right axes are colliding */
66 static void check_collision(Hkl3D
*hkl3d
)
72 /* check the collision and that the right axes are colliding */
74 hkl_geometry_set_values_unit_v(hkl3d
->geometry
->geometry
,
75 23., 0., 0., 0., 0., 0.);
77 res
&= hkl3d_is_colliding(hkl3d
) == TRUE
;
80 /* now check that only delta and mu are colliding */
81 for(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"))
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 */
108 hkl_geometry_set_values_unit_v(hkl3d
->geometry
->geometry
,
109 0., 0., 0., 0., 0., 0.);
111 for(i
=0; i
<=360; i
=i
+10){
112 hkl_geometry_set_values_unit_v(hkl3d
->geometry
->geometry
,
113 0., i
, 0., 0., 0., 0.);
114 res
&= hkl3d_is_colliding(hkl3d
) == FALSE
;
118 for(i
=0; i
<=360; i
=i
+10){
119 hkl_geometry_set_values_unit_v(hkl3d
->geometry
->geometry
,
120 0., 0., i
, 0., 0., 0.);
121 res
&= hkl3d_is_colliding(hkl3d
) == FALSE
;
125 for(i
=0; i
<=360; i
=i
+10){
126 hkl_geometry_set_values_unit_v(hkl3d
->geometry
->geometry
,
127 0., 0., 0., i
, 0., 0.);
128 res
&= hkl3d_is_colliding(hkl3d
) == FALSE
;
130 ok(res
== TRUE
, "no-collision");
133 int main(int argc
, char** argv
)
136 const HklFactory
*factory
;
137 HklGeometry
*geometry
;
140 factory
= hkl_factory_get_by_name("K6C");
141 geometry
= hkl_factory_create_new_geometry(factory
);
143 /* compute the filename of the diffractometer config file */
144 filename
= test_file_path(MODEL_FILENAME
);
145 hkl3d
= hkl3d_new(filename
, geometry
);
148 check_model_validity(hkl3d
);
149 check_collision(hkl3d
);
150 check_no_collision(hkl3d
);
151 /* TODO add/remove object*/
154 test_file_path_free(filename
);
155 hkl_geometry_free(geometry
);