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-2019 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>
24 #include <tap/hkl-tap.h>
26 #include "hkl-axis-private.h" /* temporary */
27 #include "hkl-detector-private.h"
31 HklDetector
*detector1
;
32 HklDetector
*detector2
;
34 detector1
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
35 ok(1 == detector1
->idx
, __func__
);
36 ok(NULL
== detector1
->holder
, __func__
);
38 detector2
= hkl_detector_new_copy(detector1
);
40 ok(detector1
->idx
== detector2
->idx
, __func__
);
41 ok(detector1
->holder
== detector2
->holder
, __func__
);
43 hkl_detector_free(detector1
);
44 hkl_detector_free(detector2
);
47 static void attach_to_holder(void)
49 HklDetector
*detector
= NULL
;
50 HklGeometry
*geometry
= NULL
;
51 HklHolder
*holder
= NULL
;
53 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
54 geometry
= hkl_geometry_new(NULL
, &hkl_geometry_operations_defaults
);
55 holder
= hkl_geometry_add_holder(geometry
);
56 hkl_detector_attach_to_holder(detector
, holder
);
58 ok(1 == detector
->idx
, __func__
);
59 ok(holder
== detector
->holder
, __func__
);
61 hkl_geometry_free(geometry
);
62 hkl_detector_free(detector
);
65 static void compute_kf(void)
68 HklDetector
*detector
= NULL
;
69 HklGeometry
*geometry
= 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
, &hkl_geometry_operations_defaults
);
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(holder
, "a", 1, 0, 0, &hkl_unit_angle_deg
);
83 hkl_holder_add_rotation(holder
, "b", 0, 1, 0, &hkl_unit_angle_deg
);
85 res
&= DIAG(hkl_parameter_value_set(darray_item(geometry
->axes
, 0), M_PI_2
, HKL_UNIT_DEFAULT
, NULL
));
86 res
&= DIAG(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 res
&= DIAG(0 == hkl_vector_cmp(&kf_ref
, &kf
));
94 hkl_geometry_free(geometry
);
95 hkl_detector_free(detector
);