1 /* This file is part of the hkl 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) 2003-2014 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>
23 #include <tap/basic.h>
25 #include "hkl-axis-private.h" /* temporary */
26 #include "hkl-detector-private.h"
30 HklDetector
*detector1
;
31 HklDetector
*detector2
;
33 detector1
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
34 ok(1 == detector1
->idx
, __func__
);
35 ok(NULL
== detector1
->holder
, __func__
);
37 detector2
= hkl_detector_new_copy(detector1
);
39 ok(detector1
->idx
== detector2
->idx
, __func__
);
40 ok(detector1
->holder
== detector2
->holder
, __func__
);
42 hkl_detector_free(detector1
);
43 hkl_detector_free(detector2
);
46 static void attach_to_holder(void)
48 HklDetector
*detector
= NULL
;
49 HklGeometry
*geometry
= NULL
;
50 HklHolder
*holder
= NULL
;
52 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
53 geometry
= hkl_geometry_new(NULL
);
54 holder
= hkl_geometry_add_holder(geometry
);
55 hkl_detector_attach_to_holder(detector
, holder
);
57 ok(1 == detector
->idx
, __func__
);
58 ok(holder
== detector
->holder
, __func__
);
60 hkl_geometry_free(geometry
);
61 hkl_detector_free(detector
);
64 static void compute_kf(void)
66 HklDetector
*detector
= NULL
;
67 HklGeometry
*geometry
= NULL
;
68 HklAxis
*axis1
= NULL
;
69 HklAxis
*axis2
= NULL
;
70 HklHolder
*holder
= NULL
;
72 HklVector kf_ref
= {{0, HKL_TAU
/ HKL_SOURCE_DEFAULT_WAVE_LENGTH
, 0}};
74 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
75 geometry
= hkl_geometry_new(NULL
);
76 /* add a fake first holder */
77 holder
= hkl_geometry_add_holder(geometry
);
78 /* for now all detectors MUST be connected to the second
79 * holder. We will decide about a better API to connect
80 * geometry and detector */
81 holder
= hkl_geometry_add_holder(geometry
);
82 hkl_holder_add_rotation_axis(holder
, "a", 1, 0, 0);
83 hkl_holder_add_rotation_axis(holder
, "b", 0, 1, 0);
85 hkl_parameter_value_set(darray_item(geometry
->axes
, 0), M_PI_2
, HKL_UNIT_DEFAULT
, NULL
);
86 hkl_parameter_value_set(darray_item(geometry
->axes
, 1), M_PI_2
, HKL_UNIT_DEFAULT
, NULL
);
88 hkl_detector_attach_to_holder(detector
, holder
);
89 hkl_detector_compute_kf(detector
, geometry
, &kf
);
90 ok(0 == hkl_vector_cmp(&kf_ref
, &kf
), __func__
);
92 hkl_geometry_free(geometry
);
93 hkl_detector_free(detector
);
96 int main(int argc
, char** argv
)