hkl-5.0.0.2569/ 0000755 0001751 0001751 00000000000 13574157101 013124 5 ustar 00picca picca 0000000 0000000 hkl-5.0.0.2569/tests/ 0000755 0001751 0001751 00000000000 13574157075 014300 5 ustar 00picca picca 0000000 0000000 hkl-5.0.0.2569/tests/hkl-pseudoaxis-k4cv-t.c 0000644 0001751 0001751 00000014622 13447477011 020511 0 ustar 00picca picca 0000000 0000000 /* This file is part of the hkl library.
*
* The hkl library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The hkl library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the hkl library. If not, see .
*
* Copyright (C) 2003-2019 Synchrotron SOLEIL
* L'Orme des Merisiers Saint-Aubin
* BP 48 91192 GIF-sur-YVETTE CEDEX
*
* Authors: Picca Frédéric-Emmanuel
*/
#include "hkl.h"
#include
#include
static void degenerated(void)
{
int res = TRUE;
HklEngineList *engines;
HklEngine *engine;
const darray_string *modes;
const char **mode;
HklGeometry *geometry;
HklDetector *detector;
HklSample *sample;
static double hkl[] = {0, 1, 0};
struct Geometry gconf = K4cv(1.54, 30., 0., 0., 60.);
geometry = newGeometry(gconf);
engines = newEngines(gconf);
sample = newSample(cu);
detector = hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D);
hkl_engine_list_init(engines, geometry, detector, sample);
engine = hkl_engine_list_engine_get_by_name(engines, "hkl", NULL);
modes = hkl_engine_modes_names_get(engine);
darray_foreach(mode, *modes) {
const darray_string *parameters;
HklGeometryList *geometries;
size_t n_params;
res &= DIAG(hkl_engine_current_mode_set(engine, *mode, NULL));
parameters = hkl_engine_parameters_names_get(engine);
n_params = darray_size(*parameters);
if(n_params){
double params[n_params];
hkl_engine_parameters_values_get(engine, params, n_params, HKL_UNIT_DEFAULT);
params[0] = 1;
res &= DIAG(hkl_engine_parameters_values_set(engine, params, n_params, HKL_UNIT_DEFAULT, NULL));
}
/* studdy this degenerated case */
geometries = hkl_engine_pseudo_axis_values_set(engine,
hkl, ARRAY_SIZE(hkl),
HKL_UNIT_DEFAULT, NULL);
if (geometries){
const HklGeometryListItem *item;
HKL_GEOMETRY_LIST_FOREACH(item, geometries){
hkl_geometry_set(geometry,
hkl_geometry_list_item_geometry_get(item));
res &= DIAG(check_pseudoaxes(engine, hkl, 3));
}
hkl_geometry_list_free(geometries);
}
}
ok(res == TRUE, "degenerated");
hkl_engine_list_free(engines);
hkl_detector_free(detector);
hkl_sample_free(sample);
hkl_geometry_free(geometry);
}
static void eulerians(void)
{
int res = TRUE;
HklEngineList *engines;
HklEngine *engine;
const darray_string *modes;
const char **mode;
HklGeometry *geometry;
HklDetector *detector;
HklSample *sample;
static double eulerians[] = {0., 90 * HKL_DEGTORAD, 0.};
struct Geometry gconf = K4cv(1.54, 0., 0., 0., 0.);
geometry = newGeometry(gconf);
engines = newEngines(gconf);
sample = newSample(cu);
detector = hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D);
hkl_engine_list_init(engines, geometry, detector, sample);
engine = hkl_engine_list_engine_get_by_name(engines, "eulerians", NULL);
modes = hkl_engine_modes_names_get(engine);
darray_foreach(mode, *modes){
const darray_string *parameters;
HklGeometryList *geometries;
size_t n_params;
res &= DIAG(hkl_engine_current_mode_set(engine, *mode, NULL));
parameters = hkl_engine_parameters_names_get(engine);
n_params = darray_size(*parameters);
if(n_params){
double params[n_params];
hkl_engine_parameters_values_get(engine, params, n_params, HKL_UNIT_DEFAULT);
params[0] = 1;
res &= DIAG(hkl_engine_parameters_values_set(engine, params, n_params, HKL_UNIT_DEFAULT, NULL));
}
/* studdy this degenerated case */
geometries = hkl_engine_pseudo_axis_values_set(engine,
eulerians, ARRAY_SIZE(eulerians),
HKL_UNIT_DEFAULT, NULL);
if (geometries) {
const HklGeometryListItem *item;
/* first solution = -180, -90, 180 */
item = hkl_geometry_list_items_first_get(geometries);
hkl_geometry_set(geometry,
hkl_geometry_list_item_geometry_get(item));
res &= DIAG(check_pseudoaxes_v(engine, -180. * HKL_DEGTORAD, -90 * HKL_DEGTORAD, 180. * HKL_DEGTORAD));
/* second solution = 0, 90, 0 */
item = hkl_geometry_list_items_next_get(geometries,item);
hkl_geometry_set(geometry,
hkl_geometry_list_item_geometry_get(item));
res &= DIAG(check_pseudoaxes_v(engine, 0., 90 * HKL_DEGTORAD, 0.));
/* no more solution */
res &= DIAG(hkl_geometry_list_items_next_get(geometries, item) == NULL);
hkl_geometry_list_free(geometries);
}
}
ok(res == TRUE, "eulerians");
hkl_engine_list_free(engines);
hkl_detector_free(detector);
hkl_sample_free(sample);
hkl_geometry_free(geometry);
}
static void q(void)
{
int res = TRUE;
HklEngineList *engines;
HklEngine *engine;
const darray_string *modes;
const char **mode;
HklGeometry *geometry;
HklDetector *detector;
HklSample *sample;
struct Geometry gconf = K4cv(1.54, 30., 0., 0., 60.);
geometry = newGeometry(gconf);
engines = newEngines(gconf);
sample = newSample(cu);
detector = hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D);
hkl_engine_list_init(engines, geometry, detector, sample);
engine = hkl_engine_list_engine_get_by_name(engines, "q", NULL);
modes = hkl_engine_modes_names_get(engine);
/* the init part */
res &= DIAG(hkl_geometry_set_values_v(geometry, HKL_UNIT_USER, NULL, 30., 0., 0., 60.));
res &= DIAG(hkl_engine_initialized_set(engine, TRUE, NULL));
darray_foreach(mode, *modes){
double q;
res &= DIAG(hkl_engine_current_mode_set(engine, *mode, NULL));
for(q=-1.; q<1.; q += 0.1){
HklGeometryList *geometries = NULL;
geometries = hkl_engine_set_values_v(engine, q, NULL);
if(NULL != geometries){
const HklGeometryListItem *item;
HKL_GEOMETRY_LIST_FOREACH(item, geometries){
hkl_geometry_set(geometry,
hkl_geometry_list_item_geometry_get(item));
res &= DIAG(check_pseudoaxes_v(engine, q));
}
hkl_geometry_list_free(geometries);
}
}
}
ok(res == TRUE, "q");
hkl_engine_list_free(engines);
hkl_detector_free(detector);
hkl_sample_free(sample);
hkl_geometry_free(geometry);
}
int main(void)
{
plan(3);
degenerated();
eulerians();
q();
return 0;
}
hkl-5.0.0.2569/tests/hkl-parameter-t.c 0000644 0001751 0001751 00000017210 13464522142 017427 0 ustar 00picca picca 0000000 0000000 /* This file is part of the hkl library.
*
* The hkl library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The hkl library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the hkl library. If not, see .
*
* Copyright (C) 2003-2019 Synchrotron SOLEIL
* L'Orme des Merisiers Saint-Aubin
* BP 48 91192 GIF-sur-YVETTE CEDEX
*
* Authors: Picca Frédéric-Emmanuel
*/
#include "hkl.h"
#include
#include
#include
#include "hkl-parameter-private.h"
static void new(void)
{
HklParameter *p;
ok(NULL == hkl_parameter_new("", "", 2, 1, 3,
FALSE, TRUE,
&hkl_unit_angle_rad, &hkl_unit_angle_deg), __func__);
ok(NULL == hkl_parameter_new("", "", 2, 1, 3,
FALSE, TRUE,
&hkl_unit_angle_rad, &hkl_unit_angle_deg), __func__);
ok(NULL == hkl_parameter_new("", "", 2, 1, 3,
FALSE, TRUE,
&hkl_unit_angle_rad, &hkl_unit_angle_deg), __func__);
ok(NULL == hkl_parameter_new("toto", "", 2, 1, 3,
FALSE, TRUE,
&hkl_unit_angle_rad, &hkl_unit_angle_deg), __func__);
ok(NULL == hkl_parameter_new("toto", "", 1, 2, 3,
FALSE, TRUE,
&hkl_unit_angle_rad, &hkl_unit_length_nm), __func__);
p = hkl_parameter_new("toto", "no description", 1, 2, 3,
FALSE, TRUE,
&hkl_unit_angle_rad, &hkl_unit_angle_deg);
ok(0 == !p, __func__);
is_double(1., p->range.min, HKL_EPSILON, __func__);
is_double(2., p->_value, HKL_EPSILON, __func__);
is_double(3., p->range.max, HKL_EPSILON, __func__);
ok(FALSE == p->fit, __func__);
ok(TRUE == p->changed, __func__);
ok(&hkl_unit_angle_rad == p->unit, __func__);
ok(&hkl_unit_angle_deg == p->punit, __func__);
hkl_parameter_free(p);
}
static void new_copy(void)
{
HklParameter *copy, *p;
p = hkl_parameter_new("toto", "no description", 1, 2, 3,
FALSE, TRUE,
&hkl_unit_angle_rad, &hkl_unit_angle_deg);
copy = hkl_parameter_new_copy(p);
ok(copy->name == p->name, __func__);
ok(copy->description == p->description, __func__);
is_double(copy->range.min, p->range.min, HKL_EPSILON, __func__);
is_double(copy->_value, p->_value, HKL_EPSILON, __func__);
is_double(copy->range.max, p->range.max, HKL_EPSILON, __func__);
ok(copy->fit == p->fit, __func__);
ok(copy->changed == p->changed, __func__);
ok(&hkl_unit_angle_rad == copy->unit, __func__);
ok(&hkl_unit_angle_deg == copy->punit, __func__);
hkl_parameter_free(copy);
hkl_parameter_free(p);
}
static void init(void)
{
HklParameter *p;
int res = TRUE;
res &= DIAG(NULL == hkl_parameter_new("", "no description", 2, NAN, 3,
FALSE, TRUE,
&hkl_unit_angle_rad, &hkl_unit_angle_deg));
res &= DIAG(NULL == hkl_parameter_new("", "no description", 2, 1, 3,
FALSE, TRUE,
&hkl_unit_angle_rad, &hkl_unit_angle_deg));
res &= DIAG(NULL == hkl_parameter_new("", "no description", 2, 1, 3,
FALSE, TRUE,
&hkl_unit_angle_rad, &hkl_unit_angle_deg));
res &= DIAG(NULL == hkl_parameter_new("toto", "no description", 2, 1, 3,
FALSE, TRUE,
&hkl_unit_angle_rad, &hkl_unit_angle_deg));
res &= DIAG(NULL == hkl_parameter_new("toto", "no description", 1, 2, 3,
FALSE, TRUE,
&hkl_unit_angle_rad, &hkl_unit_length_nm));
res &= DIAG(NULL == hkl_parameter_new("toto", "no description", 1, 2, 3,
FALSE, TRUE,
&hkl_unit_angle_rad, &hkl_unit_length_nm));
p = hkl_parameter_new("toto", "no description", 1, 2, 3,
FALSE, TRUE,
&hkl_unit_angle_rad, &hkl_unit_angle_deg);
res &= DIAG(NULL != p);
hkl_parameter_free(p);
ok(res == TRUE, __func__);
}
static void set(void)
{
HklParameter *p;
GError *error;
int res = TRUE;
p = hkl_parameter_new("toto", "no description", 1, 2, 3,
FALSE, TRUE,
&hkl_unit_angle_rad, &hkl_unit_angle_deg);
/* can not set a parameter with a NaN value */
error = NULL;
res &= DIAG(FALSE == hkl_parameter_value_set(p, NAN, HKL_UNIT_DEFAULT, &error));
res &= DIAG(error != NULL);
g_clear_error(&error);
/* set a normal value is ok */
error = NULL;
res &= DIAG(TRUE == hkl_parameter_value_set(p, 10, HKL_UNIT_DEFAULT, &error));
res &= DIAG(error == NULL);
hkl_parameter_free(p);
ok(res == TRUE, __func__);
}
static void is_valid(void)
{
HklParameter *p;
GError *error;
int res = TRUE;
p = hkl_parameter_new("toto", "no description", 1, 2, 3,
FALSE, TRUE,
&hkl_unit_angle_rad, &hkl_unit_angle_deg);
res &= DIAG(TRUE == hkl_parameter_is_valid(p));
error = NULL;
res &= DIAG(TRUE == hkl_parameter_value_set(p, 10, HKL_UNIT_DEFAULT, &error));
res &= DIAG(error == NULL);
res &= DIAG(FALSE == hkl_parameter_is_valid(p));
hkl_parameter_free(p);
ok(res == TRUE, __func__);
}
static void min_max(void)
{
HklParameter *p;
double min, max;
GError *error;
int res = TRUE;
p = hkl_parameter_new("toto", "no description", 1, 2, 3,
FALSE, TRUE,
&hkl_unit_angle_rad, &hkl_unit_angle_deg);
hkl_parameter_min_max_get(p, &min, &max, HKL_UNIT_DEFAULT);
is_double(1, min, HKL_EPSILON, __func__);
is_double(3, max, HKL_EPSILON, __func__);
res &= DIAG(TRUE == hkl_parameter_min_max_set(p, 1.1, 4, HKL_UNIT_DEFAULT, NULL));
hkl_parameter_min_max_get(p, &min, &max, HKL_UNIT_DEFAULT);
is_double(1.1, min, HKL_EPSILON, __func__);
is_double(4, max, HKL_EPSILON, __func__);
error = NULL;
res &= DIAG(FALSE == hkl_parameter_min_max_set(p, 4, 1, HKL_UNIT_DEFAULT, &error));
res &= DIAG(error != NULL);
g_clear_error(&error);
/* nothing should have changed */
hkl_parameter_min_max_get(p, &min, &max, HKL_UNIT_DEFAULT);
is_double(1.1, min, HKL_EPSILON, __func__);
is_double(4, max, HKL_EPSILON, __func__);
error = NULL;
res &= DIAG(FALSE == hkl_parameter_min_max_set(p, NAN, 1, HKL_UNIT_DEFAULT, &error));
res &= DIAG(error != NULL);
g_clear_error(&error);
/* nothing should have changed */
hkl_parameter_min_max_get(p, &min, &max, HKL_UNIT_DEFAULT);
is_double(1.1, min, HKL_EPSILON, __func__);
is_double(4, max, HKL_EPSILON, __func__);
error = NULL;
res &= DIAG(FALSE == hkl_parameter_min_max_set(p, 1, NAN, HKL_UNIT_DEFAULT, &error));
res &= DIAG(error != NULL);
g_clear_error(&error);
/* nothing should have changed */
hkl_parameter_min_max_get(p, &min, &max, HKL_UNIT_DEFAULT);
is_double(1.1, min, HKL_EPSILON, __func__);
is_double(4, max, HKL_EPSILON, __func__);
error = NULL;
res &= DIAG(FALSE == hkl_parameter_min_max_set(p, NAN, NAN, HKL_UNIT_DEFAULT, &error));
res &= DIAG(error != NULL);
g_clear_error(&error);
/* nothing should have changed */
hkl_parameter_min_max_get(p, &min, &max, HKL_UNIT_DEFAULT);
is_double(1.1, min, HKL_EPSILON, __func__);
is_double(4, max, HKL_EPSILON, __func__);
hkl_parameter_free(p);
}
static void getter(void)
{
HklParameter *p;
p = hkl_parameter_new("toto", "no description", 1, 2, 3,
FALSE, TRUE,
&hkl_unit_angle_rad, &hkl_unit_angle_deg);
ok(NULL == hkl_parameter_axis_v_get(p), __func__);
ok(NULL == hkl_parameter_quaternion_get(p), __func__);
ok(NULL != hkl_parameter_description_get(p), __func__);
hkl_parameter_free(p);
}
int main(void)
{
plan(40);
new();
new_copy();
init();
set();
is_valid();
min_max();
getter();
return 0;
}
hkl-5.0.0.2569/tests/hkl-source-t.c 0000644 0001751 0001751 00000004447 13447477011 016764 0 ustar 00picca picca 0000000 0000000 /* This file is part of the hkl library.
*
* The hkl library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The hkl library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the hkl library. If not, see .
*
* Copyright (C) 2003-2019 Synchrotron SOLEIL
* L'Orme des Merisiers Saint-Aubin
* BP 48 91192 GIF-sur-YVETTE CEDEX
*
* Authors: Picca Frédéric-Emmanuel
*/
#include "hkl.h"
#include
#include
#include "hkl-source-private.h"
static void new_copy(void)
{
HklSource s, c;
hkl_source_init(&s, 1.54, 1, 0, 0);
c = s;
is_double(c.wave_length, s.wave_length, HKL_EPSILON, __func__);
ok(FALSE == hkl_vector_cmp(&c.direction, &s.direction), __func__);
}
static void init(void)
{
HklSource s;
hkl_source_init(&s, 1, 1, 0, 0);
is_double(1., s.wave_length, HKL_EPSILON, __func__);
is_double(1., s.direction.data[0], HKL_EPSILON, __func__);
is_double(0., s.direction.data[1], HKL_EPSILON, __func__);
is_double(0., s.direction.data[2], HKL_EPSILON, __func__);
}
static void cmp(void)
{
HklSource ref, s1, s2;
hkl_source_init(&ref, 1.54, 1, 0, 0);
hkl_source_init(&s1, 1.54, 1, 0, 0);
hkl_source_init(&s2, 1, 1, 0, 0);
ok(TRUE == hkl_source_cmp(&ref, &s1), __func__);
ok(FALSE == hkl_source_cmp(&ref, &s2), __func__);
}
static void compute_ki(void)
{
HklSource s;
HklVector ki_ref = {{HKL_TAU / 1.54, 0, 0}};
HklVector ki;
hkl_source_init(&s, 1.54, 1, 0, 0);
hkl_source_compute_ki(&s, &ki);
ok(0 == hkl_vector_cmp(&ki_ref, &ki), __func__);
}
static void get_wavelength(void)
{
HklSource s;
hkl_source_init(&s, 1, 1, 0, 0);
is_double(1., hkl_source_get_wavelength(&s), HKL_EPSILON, __func__);
}
int main(void)
{
plan(10);
new_copy();
init();
cmp();
compute_ki();
get_wavelength();
return 0;
}
hkl-5.0.0.2569/tests/hkl-geometry-t.c 0000644 0001751 0001751 00000041537 13447477011 017320 0 ustar 00picca picca 0000000 0000000 /* This file is part of the hkl library.
*
* The hkl library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The hkl library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the hkl library. If not, see .
*
* Copyright (C) 2003-2019 Synchrotron SOLEIL
* L'Orme des Merisiers Saint-Aubin
* BP 48 91192 GIF-sur-YVETTE CEDEX
*
* Authors: Picca Frédéric-Emmanuel
*/
#include "hkl.h"
#include
#include
#include
/* BEWARE THESE TESTS ARE DEALING WITH HKL INTERNALS WHICH EXPOSE A
* NON PUBLIC API WHICH ALLOW TO SHOOT YOURSELF IN YOUR FOOT */
#include "hkl/ccan/container_of/container_of.h"
#include "hkl-axis-private.h" /* temporary */
#include "hkl-geometry-private.h"
static void add_holder(void)
{
HklGeometry *g = NULL;
HklHolder *holder = NULL;
g = hkl_geometry_new(NULL, &hkl_geometry_operations_defaults);
is_int(0, darray_size(g->holders), __func__);
holder = hkl_geometry_add_holder(g);
hkl_holder_add_rotation(holder, "A", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_rotation(holder, "B", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_translation(holder, "T", 1., 0., 0., &hkl_unit_angle_deg);
is_int(1, darray_size(g->holders), __func__);
holder = hkl_geometry_add_holder(g);
hkl_holder_add_rotation(holder, "A", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_rotation(holder, "C", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_translation(holder, "T", 1., 0., 0., &hkl_unit_angle_deg);
is_int(2, darray_size(g->holders), __func__);
ok(holder == darray_item(g->holders, 1), __func__);
hkl_geometry_free(g);
}
static void get_axis(void)
{
int res = TRUE;
HklGeometry *g = NULL;
HklHolder *holder = NULL;
const HklParameter *axis0;
GError *error;
g = hkl_geometry_new(NULL, &hkl_geometry_operations_defaults);
holder = hkl_geometry_add_holder(g);
hkl_holder_add_rotation(holder, "A", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_rotation(holder, "B", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_translation(holder, "T", 1., 0., 0., &hkl_unit_length_mm);
holder = hkl_geometry_add_holder(g);
hkl_holder_add_rotation(holder, "A", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_rotation(holder, "C", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_translation(holder, "T", 1., 0., 0., &hkl_unit_length_mm);
/* check the private API */
res &= DIAG(0 == !hkl_geometry_get_axis_by_name(g, "A"));
res &= DIAG(0 == !hkl_geometry_get_axis_by_name(g, "B"));
res &= DIAG(0 == !hkl_geometry_get_axis_by_name(g, "C"));
res &= DIAG(0 == !hkl_geometry_get_axis_by_name(g, "T"));
res &= DIAG(1 == !hkl_geometry_get_axis_by_name(g, "DONOTEXIST"));
/* check the public API */
/* get */
res &= DIAG(NULL != hkl_geometry_axis_get(g, "A", NULL));
res &= DIAG(NULL == hkl_geometry_axis_get(g, "DONOTEXIST", NULL));
error = NULL;
res &= DIAG(NULL != hkl_geometry_axis_get(g, "A", &error));
res &= DIAG(error == NULL);
res &= DIAG(NULL != hkl_geometry_axis_get(g, "T", &error));
res &= DIAG(error == NULL);
res &= DIAG(NULL == hkl_geometry_axis_get(g, "DONOTEXIST", &error));
res &= DIAG(error != NULL);
g_clear_error(&error);
/* set */
axis0 = hkl_geometry_axis_get(g, "A", NULL);
res &= DIAG(TRUE == hkl_geometry_axis_set(g, "A", axis0, NULL));
res &= DIAG(FALSE == hkl_geometry_axis_set(g, "B", axis0, NULL));
res &= DIAG(FALSE == hkl_geometry_axis_set(g, "T", axis0, NULL));
error = NULL;
res &= DIAG(hkl_geometry_axis_set(g, "A", axis0, &error));
res &= DIAG(error == NULL);
res &= DIAG(FALSE == hkl_geometry_axis_set(g, "B", axis0, &error));
res &= DIAG(error != NULL);
g_clear_error(&error);
res &= DIAG(FALSE == hkl_geometry_axis_set(g, "T", axis0, &error));
res &= DIAG(error != NULL);
g_clear_error(&error);
ok(res, __func__);
hkl_geometry_free(g);
}
static void update(void)
{
int res = TRUE;
HklGeometry *g = NULL;
HklHolder *holder = NULL;
HklAxis *axis1;
HklQuaternion q_ref = {{1./sqrt(2), 1./sqrt(2), 0.0, 0.0 }};
g = hkl_geometry_new(NULL, &hkl_geometry_operations_defaults);
holder = hkl_geometry_add_holder(g);
hkl_holder_add_rotation(holder, "A", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_rotation(holder, "B", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_translation(holder, "T1", 1., 0., 0., &hkl_unit_length_mm);
holder = hkl_geometry_add_holder(g);
hkl_holder_add_rotation(holder, "A", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_rotation(holder, "C", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_translation(holder, "T2", 1., 0., 0., &hkl_unit_length_mm);
axis1 = container_of(hkl_geometry_get_axis_by_name(g, "B"), HklAxis, parameter);
res &= DIAG(hkl_parameter_value_set(&axis1->parameter, M_PI_2, HKL_UNIT_DEFAULT, NULL));
/* now axis1 is dirty */
ok(TRUE == axis1->parameter.changed, __func__);
hkl_geometry_update(g);
holder = darray_item(g->holders, 0);
is_quaternion(&q_ref, &holder->q, __func__);
/* now axis1 is clean */
res &= DIAG(FALSE == axis1->parameter.changed);
ok(res, __func__);
hkl_geometry_free(g);
}
static void set(void)
{
HklGeometry *g;
HklGeometry *g1;
HklGeometry *g2;
HklHolder *holder;
HklFactory *fake_factory;
g = hkl_geometry_new(NULL, &hkl_geometry_operations_defaults);
holder = hkl_geometry_add_holder(g);
hkl_holder_add_rotation(holder, "A", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_rotation(holder, "B", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_rotation(holder, "C", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_translation(holder, "T", 1., 0., 0., &hkl_unit_length_mm);
g1 = hkl_geometry_new_copy(g);
/* it is required to use a fake factory, with the public API
* geometry contain always a real factory */
fake_factory = (HklFactory *)0x1;
g2 = hkl_geometry_new(fake_factory, &hkl_geometry_operations_defaults);
holder = hkl_geometry_add_holder(g);
hkl_holder_add_rotation(holder, "A", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_rotation(holder, "B", 1., 0., 0., &hkl_unit_angle_deg);
ok(hkl_geometry_set(g, g1), __func__);
hkl_geometry_free(g2);
hkl_geometry_free(g1);
hkl_geometry_free(g);
}
static void axis_values_get_set(void)
{
unsigned int i;
HklGeometry *g;
HklHolder *holder;
static double set_1[] = {1, 1, 1, 1};
static double set_10[] = {10, 10, 10, 10};
double values[4];
GError *error;
g = hkl_geometry_new(NULL, &hkl_geometry_operations_defaults);
holder = hkl_geometry_add_holder(g);
hkl_holder_add_rotation(holder, "A", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_rotation(holder, "B", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_rotation(holder, "C", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_translation(holder, "T", 1., 0., 0., &hkl_unit_length_mm);
/* check set DEFAULT unit */
error = NULL;
ok(TRUE == hkl_geometry_axis_values_set(g, set_1, ARRAY_SIZE(set_1), HKL_UNIT_DEFAULT, NULL), __func__);
ok(TRUE == hkl_geometry_axis_values_set(g, set_1, ARRAY_SIZE(set_1), HKL_UNIT_DEFAULT, &error), __func__);
ok(error == NULL, __func__);
for(i=0; iaxes, i), HKL_UNIT_DEFAULT), HKL_EPSILON, __func__);
/* check get DEFAULT unit */
hkl_geometry_axis_values_get(g, values, ARRAY_SIZE(values), HKL_UNIT_DEFAULT);
for(i=0; iaxes, 0),
-100 * HKL_DEGTORAD, 100 * HKL_DEGTORAD,
HKL_UNIT_DEFAULT, NULL));
res &= DIAG(FALSE == hkl_geometry_is_valid(geom));
ok(res, __func__);
hkl_geometry_free(geom);
}
static void wavelength(void)
{
HklGeometry *geom = NULL;
GError *error;
geom = hkl_geometry_new(NULL, &hkl_geometry_operations_defaults);
is_double(1.54, hkl_geometry_wavelength_get(geom, HKL_UNIT_DEFAULT), HKL_EPSILON, __func__);
ok(TRUE == hkl_geometry_wavelength_set(geom, 2, HKL_UNIT_DEFAULT, NULL), __func__);
is_double(2, hkl_geometry_wavelength_get(geom, HKL_UNIT_DEFAULT), HKL_EPSILON, __func__);
error = NULL;
ok(TRUE == hkl_geometry_wavelength_set(geom, 2, HKL_UNIT_DEFAULT, &error), __func__);
ok(error == NULL, __func__);
is_double(2, hkl_geometry_wavelength_get(geom, HKL_UNIT_DEFAULT), HKL_EPSILON, __func__);
hkl_geometry_free(geom);
}
static void xxx_rotation_get(void)
{
int res = TRUE;
size_t i, n;
HklFactory **factories;
HklDetector *detector = hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D);
HklSample *sample = hkl_sample_new("test");
factories = hkl_factory_get_all(&n);
for(i=0; igeometry->axes, 0), HKL_UNIT_DEFAULT),
HKL_EPSILON, __func__);
}
ok(res, __func__);
hkl_geometry_free(g);
hkl_geometry_list_free(list);
}
static void list_multiply_from_range(void)
{
int res = TRUE;
HklGeometry *g;
HklGeometryList *list;
HklHolder *holder;
HklParameter *axisA, *axisB, *axisC, *axisT;
g = hkl_geometry_new(NULL, &hkl_geometry_operations_defaults);
holder = hkl_geometry_add_holder(g);
hkl_holder_add_rotation(holder, "A", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_rotation(holder, "B", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_rotation(holder, "C", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_translation(holder, "T", 1., 0., 0., &hkl_unit_length_mm);
axisA = hkl_geometry_get_axis_by_name(g, "A");
axisB = hkl_geometry_get_axis_by_name(g, "B");
axisC = hkl_geometry_get_axis_by_name(g, "C");
axisT = hkl_geometry_get_axis_by_name(g, "T");
res &= DIAG(hkl_parameter_min_max_set(axisA, -190, 190, HKL_UNIT_USER, NULL));
res &= DIAG(hkl_parameter_min_max_set(axisB, -190, 190, HKL_UNIT_USER, NULL));
res &= DIAG(hkl_parameter_min_max_set(axisC, -190, 190, HKL_UNIT_USER, NULL));
res &= DIAG(hkl_parameter_min_max_set(axisT, -190, 190., HKL_UNIT_USER, NULL));
list = hkl_geometry_list_new();
res &= DIAG(hkl_geometry_set_values_v(g, HKL_UNIT_DEFAULT, NULL,
185. * HKL_DEGTORAD, -185. * HKL_DEGTORAD, 190. * HKL_DEGTORAD, 100.));
hkl_geometry_list_add(list, g);
hkl_geometry_list_multiply_from_range(list);
res &= DIAG(8 == hkl_geometry_list_n_items_get(list));
ok(res, __func__);
hkl_geometry_free(g);
hkl_geometry_list_free(list);
}
static void list_remove_invalid(void)
{
int res = TRUE;
HklGeometry *g;
HklGeometryList *list;
HklHolder *holder;
HklParameter *axisA, *axisB, *axisC, *axisT;
g = hkl_geometry_new(NULL, &hkl_geometry_operations_defaults);
holder = hkl_geometry_add_holder(g);
hkl_holder_add_rotation(holder, "A", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_rotation(holder, "B", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_rotation(holder, "C", 1., 0., 0., &hkl_unit_angle_deg);
hkl_holder_add_translation(holder, "T", 1., 0., 0., &hkl_unit_length_mm);
axisA = hkl_geometry_get_axis_by_name(g, "A");
axisB = hkl_geometry_get_axis_by_name(g, "B");
axisC = hkl_geometry_get_axis_by_name(g, "C");
axisT = hkl_geometry_get_axis_by_name(g, "T");
res &= DIAG(hkl_parameter_min_max_set(axisA, -100, 180., HKL_UNIT_USER, NULL));
res &= DIAG(hkl_parameter_min_max_set(axisB, -100., 180., HKL_UNIT_USER, NULL));
res &= DIAG(hkl_parameter_min_max_set(axisC, -100., 180., HKL_UNIT_USER, NULL));
res &= DIAG(hkl_parameter_min_max_set(axisT, 0.0, 179., HKL_UNIT_USER, NULL));
list = hkl_geometry_list_new();
res &= DIAG(hkl_geometry_set_values_v(g, HKL_UNIT_DEFAULT, NULL,
185. * HKL_DEGTORAD,
-185. * HKL_DEGTORAD,
185. * HKL_DEGTORAD,
0.1));
hkl_geometry_list_add(list, g);
res &= DIAG(hkl_geometry_set_values_v(g, HKL_UNIT_DEFAULT, NULL,
-190. * HKL_DEGTORAD,
-190. * HKL_DEGTORAD,
-190. * HKL_DEGTORAD,
0.1));
hkl_geometry_list_add(list, g);
res &= DIAG(hkl_geometry_set_values_v(g, HKL_UNIT_DEFAULT, NULL,
180. * HKL_DEGTORAD,
180. * HKL_DEGTORAD,
180. * HKL_DEGTORAD,
0.1));
hkl_geometry_list_add(list, g);
is_int(3, hkl_geometry_list_n_items_get(list), __func__);
hkl_geometry_list_remove_invalid(list);
is_int(1, hkl_geometry_list_n_items_get(list), __func__);
ok(res, __func__);
hkl_geometry_free(g);
hkl_geometry_list_free(list);
}
int main(void)
{
plan(48);
add_holder();
get_axis();
update();
set();
axis_values_get_set();
distance();
is_valid();
wavelength();
xxx_rotation_get();
list();
list_multiply_from_range();
list_remove_invalid();
return 0;
}
hkl-5.0.0.2569/tests/hkl-pseudoaxis-e6c-t.c 0000644 0001751 0001751 00000036231 13447477011 020317 0 ustar 00picca picca 0000000 0000000 /* This file is part of the hkl library.
*
* The hkl library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The hkl library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the hkl library. If not, see .
*
* Copyright (C) 2003-2019 Synchrotron SOLEIL
* L'Orme des Merisiers Saint-Aubin
* BP 48 91192 GIF-sur-YVETTE CEDEX
*
* Authors: Picca Frédéric-Emmanuel
*/
#include "hkl.h"
#include
#include
#include "hkl-axis-private.h" /* temporary */
#define CHECK_AXIS_VALUE(geometry, axis, value) fabs((value) - hkl_parameter_value_get(hkl_geometry_axis_get(geometry, axis, NULL), HKL_UNIT_DEFAULT)) < HKL_EPSILON
static int hkl_geometry_list_check_geometry_unit(const HklGeometryList *self,
double mu,
double omega,
double chi,
double phi,
double gamma,
double delta)
{
const HklGeometryListItem *item;
int res = TRUE;
HKL_GEOMETRY_LIST_FOREACH(item, self){
const HklGeometry *geometry;
geometry = hkl_geometry_list_item_geometry_get(item);
res = TRUE;
res &= CHECK_AXIS_VALUE(geometry, "mu", mu * HKL_DEGTORAD);
res &= CHECK_AXIS_VALUE(geometry, "omega", omega * HKL_DEGTORAD);
res &= CHECK_AXIS_VALUE(geometry, "chi", chi * HKL_DEGTORAD);
res &= CHECK_AXIS_VALUE(geometry, "phi", phi * HKL_DEGTORAD);
res &= CHECK_AXIS_VALUE(geometry, "gamma", gamma * HKL_DEGTORAD);
res &= CHECK_AXIS_VALUE(geometry, "delta", delta * HKL_DEGTORAD);
if (res)
break;
}
return res;
}
static void getter(void)
{
int res = TRUE;
HklEngineList *engines;
HklEngine *engine;
HklGeometry *geometry;
HklDetector *detector;
HklSample *sample;
struct Geometry gconf = E6c(1.54, 0., 30., 0., 0., 0., 60.);
geometry = newGeometry(gconf);
engines = newEngines(gconf);
sample = newSample(cu);
detector = hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D);
hkl_engine_list_init(engines, geometry, detector, sample);
engine = hkl_engine_list_engine_get_by_name(engines, "hkl", NULL);
/* geometry -> pseudo */
res &= DIAG(hkl_geometry_set_values_v(geometry, HKL_UNIT_USER, NULL, 0., 30., 0., 0., 0., 60.));
res &= DIAG(check_pseudoaxes_v(engine, 0., 0., 1.));
res &= DIAG(hkl_geometry_set_values_v(geometry, HKL_UNIT_USER, NULL, 0., 30., 0., 90., 0., 60.));
res &= DIAG(check_pseudoaxes_v(engine, 1., 0., 0.));
res &= DIAG(hkl_geometry_set_values_v(geometry, HKL_UNIT_USER, NULL, 0., 30., 0., -90., 0., 60.));
res &= DIAG(check_pseudoaxes_v(engine, -1., 0., 0.));
res &= DIAG(hkl_geometry_set_values_v(geometry, HKL_UNIT_USER, NULL, 0., 30., 0., 180., 0., 60.));
res &= DIAG(check_pseudoaxes_v(engine, 0., 0., -1.));
res &= DIAG(hkl_geometry_set_values_v(geometry, HKL_UNIT_USER, NULL, 0., 45., 0., 135., 0., 90.));
res &= DIAG(check_pseudoaxes_v(engine, 1., 0., -1.));
ok(res == TRUE, "getter");
hkl_engine_list_free(engines);
hkl_detector_free(detector);
hkl_sample_free(sample);
hkl_geometry_free(geometry);
}
static void degenerated(void)
{
int res = TRUE;
HklEngineList *engines;
HklEngine *engine;
const darray_string *modes;
const char **mode;
HklGeometry *geometry;
HklDetector *detector;
HklSample *sample;
static double hkl[] = {0, 0, 1};
struct Geometry gconf = E6c(1.54, 0., 30., 0., 0., 0., 60.);
geometry = newGeometry(gconf);
engines = newEngines(gconf);
sample = newSample(cu);
detector = hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D);
hkl_engine_list_init(engines, geometry, detector, sample);
engine = hkl_engine_list_engine_get_by_name(engines, "hkl", NULL);
modes = hkl_engine_modes_names_get(engine);
darray_foreach(mode, *modes) {
const darray_string *parameters;
HklGeometryList *geometries;
size_t n_params;
res &= DIAG(hkl_engine_current_mode_set(engine, *mode, NULL));
parameters = hkl_engine_parameters_names_get(engine);
n_params = darray_size(*parameters);
if (n_params){
double params[n_params];
hkl_engine_parameters_values_get(engine, params, n_params, HKL_UNIT_DEFAULT);
params[0] = 0;
res &= DIAG(hkl_engine_parameters_values_set(engine, params, n_params, HKL_UNIT_DEFAULT, NULL));
}
/* studdy this degenerated case */
geometries = hkl_engine_pseudo_axis_values_set(engine,
hkl, ARRAY_SIZE(hkl),
HKL_UNIT_DEFAULT, NULL);
if (geometries){
const HklGeometryListItem *item;
HKL_GEOMETRY_LIST_FOREACH(item, geometries){
hkl_geometry_set(geometry,
hkl_geometry_list_item_geometry_get(item));
res &= DIAG(check_pseudoaxes(engine, hkl, 3));
}
hkl_geometry_list_free(geometries);
}
}
ok(res == TRUE, "degenerated");
hkl_engine_list_free(engines);
hkl_detector_free(detector);
hkl_sample_free(sample);
hkl_geometry_free(geometry);
}
static void q2(void)
{
int res = TRUE;
HklEngineList *engines;
HklEngine *engine;
const char **mode;
const darray_string *modes;
HklGeometry *geometry;
HklDetector *detector;
HklSample *sample;
struct Geometry gconf = E6c(1.54, 0., 30., 0., 0., 0., 60.);
geometry = newGeometry(gconf);
engines = newEngines(gconf);
sample = newSample(cu);
detector = hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D);
hkl_engine_list_init(engines, geometry, detector, sample);
engine = hkl_engine_list_engine_get_by_name(engines, "q2", NULL);
modes = hkl_engine_modes_names_get(engine);
/* the init part */
res &= DIAG(hkl_engine_initialized_set(engine, TRUE, NULL));
darray_foreach(mode, *modes){
double q, alpha;
res &= DIAG(hkl_engine_current_mode_set(engine, *mode, NULL));
for(q=0.1; q<1.; q += 0.1)
for(alpha = -M_PI; alpha