remove hkl_axis_is_value_compatible_with_range
[hkl.git] / test / hkl / axis-t.c
blobac9c71766674ccc196e4ad37ed4630455ce73524
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-2010 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>
22 #include <hkl.h>
23 #include <tap/basic.h>
25 static void new(void)
27 HklAxis *axis;
28 static HklVector v = {{1, 0, 0}};
30 axis = hkl_axis_new("omega", &v);
32 is_string("omega", ((HklParameter *)axis)->name, __func__);
33 is_double(-M_PI, ((HklParameter *)axis)->range.min, HKL_EPSILON, __func__);
34 is_double(M_PI, ((HklParameter *)axis)->range.max, HKL_EPSILON, __func__);
35 is_double(0., hkl_parameter_get_value(&axis->parameter), HKL_EPSILON, __func__);
36 ok(HKL_TRUE == ((HklParameter *)axis)->fit, __func__);
37 ok(HKL_TRUE == ((HklParameter *)axis)->changed, __func__);
39 hkl_axis_free(axis);
42 static void get_quaternions(void)
44 HklAxis *axis;
45 static HklVector v = {{1, 0, 0}};
47 axis = hkl_axis_new("omega", &v);
49 is_double(1., axis->q.data[0], HKL_EPSILON, __func__);
50 is_double(0., axis->q.data[1], HKL_EPSILON, __func__);
51 is_double(0., axis->q.data[2], HKL_EPSILON, __func__);
52 is_double(0., axis->q.data[3], HKL_EPSILON, __func__);
54 hkl_parameter_set_value(&axis->parameter, -M_PI_2);
55 is_double(1./sqrt(2.), axis->q.data[0], HKL_EPSILON, __func__);
56 is_double(-1./sqrt(2.), axis->q.data[1], HKL_EPSILON, __func__);
57 is_double(0., axis->q.data[2], HKL_EPSILON, __func__);
58 is_double(0., axis->q.data[3], HKL_EPSILON, __func__);
60 hkl_axis_free(axis);
63 static void is_valid(void)
65 HklAxis *axis1;
66 static HklVector v = {{1, 0, 0}};
68 axis1 = hkl_axis_new("omega", &v);
70 hkl_parameter_set_value_unit(&axis1->parameter, 45);
71 ok(HKL_TRUE == hkl_parameter_is_valid(&axis1->parameter), __func__);
73 /* change the range of axis1 */
74 hkl_parameter_set_range_unit(&axis1->parameter, -270, 0);
75 ok(HKL_FALSE == hkl_parameter_is_valid(&axis1->parameter), __func__);
77 hkl_parameter_set_value_unit(&axis1->parameter, -45);
78 ok(HKL_TRUE == hkl_parameter_is_valid(&axis1->parameter), __func__);
80 hkl_parameter_set_range_unit(&axis1->parameter, 350, 450);
81 hkl_parameter_set_value_unit(&axis1->parameter, 45);
82 ok(HKL_TRUE == hkl_parameter_is_valid(&axis1->parameter), __func__);
83 hkl_parameter_set_value_unit(&axis1->parameter, -45);
84 ok(HKL_FALSE == hkl_parameter_is_valid(&axis1->parameter), __func__);
86 hkl_parameter_set_range_unit(&axis1->parameter, -10, 90);
87 hkl_parameter_set_value_unit(&axis1->parameter, 405);
88 ok(HKL_TRUE == hkl_parameter_is_valid(&axis1->parameter), __func__);
89 hkl_parameter_set_value_unit(&axis1->parameter, -405);
90 ok(HKL_FALSE == hkl_parameter_is_valid(&axis1->parameter), __func__);
92 hkl_axis_free(axis1);
95 static void set_value_smallest_in_range(void)
97 HklAxis *axis;
98 static HklVector v = {{1, 0, 0}};
100 axis = hkl_axis_new("omega", &v);
102 hkl_parameter_set_range_unit(&axis->parameter, -190, 190);
104 hkl_parameter_set_value_unit(&axis->parameter, 185);
105 hkl_axis_set_value_smallest_in_range(axis);
106 is_double(-175., hkl_parameter_get_value_unit(&axis->parameter), HKL_EPSILON, __func__);
108 hkl_parameter_set_value_unit(&axis->parameter, 545);
109 hkl_axis_set_value_smallest_in_range(axis);
110 is_double(-175., hkl_parameter_get_value_unit(&axis->parameter), HKL_EPSILON, __func__);
112 hkl_parameter_set_value_unit(&axis->parameter, -185);
113 hkl_axis_set_value_smallest_in_range(axis);
114 is_double(-185., hkl_parameter_get_value_unit(&axis->parameter), HKL_EPSILON, __func__);
116 hkl_parameter_set_value_unit(&axis->parameter, 175);
117 hkl_axis_set_value_smallest_in_range(axis);
118 is_double(-185., hkl_parameter_get_value_unit(&axis->parameter), HKL_EPSILON, __func__);
120 hkl_parameter_set_value_unit(&axis->parameter, 190);
121 hkl_axis_set_value_smallest_in_range(axis);
122 is_double(-170., hkl_parameter_get_value_unit(&axis->parameter), HKL_EPSILON, __func__);
124 hkl_parameter_set_value_unit(&axis->parameter, -190);
125 hkl_axis_set_value_smallest_in_range(axis);
126 is_double(-190., hkl_parameter_get_value_unit(&axis->parameter), HKL_EPSILON, __func__);
128 hkl_axis_free(axis);
131 static void get_value_closest(void)
133 HklAxis *axis1, *axis2;
134 static HklVector v = {{1, 0, 0}};
136 axis1 = hkl_axis_new("omega", &v);
137 axis2 = hkl_axis_new("omega", &v);
139 hkl_parameter_set_value_unit(&axis1->parameter, 0);
140 hkl_parameter_set_value_unit(&axis2->parameter, 0);
141 is_double(0., hkl_parameter_get_value_closest(&axis1->parameter,
142 &axis2->parameter),
143 HKL_EPSILON, __func__);
145 /* change the range of axis1 */
146 hkl_parameter_set_range_unit(&axis1->parameter, -270, 180);
147 hkl_parameter_set_value_unit(&axis1->parameter, 100);
149 hkl_parameter_set_value_unit(&axis2->parameter, -75);
150 is_double(100 * HKL_DEGTORAD, hkl_parameter_get_value_closest(&axis1->parameter,
151 &axis2->parameter),
152 HKL_EPSILON, __func__);
154 hkl_parameter_set_value_unit(&axis2->parameter, -85);
155 is_double(-260 * HKL_DEGTORAD, hkl_parameter_get_value_closest(&axis1->parameter,
156 &axis2->parameter),
157 HKL_EPSILON, __func__);
159 hkl_axis_free(axis1);
160 hkl_axis_free(axis2);
163 int main(int argc, char** argv)
165 plan(30);
167 new();
168 get_quaternions();
169 is_valid();
170 set_value_smallest_in_range();
171 get_value_closest();
173 return 0;