hkl-5.1.7/ 0000775 0001750 0001750 00000000000 15144640572 011274 5 ustar 00picca picca hkl-5.1.7/tests/ 0000775 0001750 0001750 00000000000 15144640566 012441 5 ustar 00picca picca hkl-5.1.7/tests/hkl-vector-t.c 0000664 0001750 0001750 00000014572 14677222567 015144 0 ustar 00picca picca /* 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-vector-private.h" /* use to test also the private API */
static void init(void)
{
HklVector v;
hkl_vector_init(&v, 1, 2, 3);
is_double(1., v.data[0], HKL_EPSILON, __func__);
is_double(2., v.data[1], HKL_EPSILON, __func__);
is_double(3., v.data[2], HKL_EPSILON, __func__);
}
static void cmp(void)
{
HklVector v1 = {{0.0, 1.0, 2.0}};
HklVector v2 = {{1.0, 2.0, 3.0}};
ok(0 == hkl_vector_cmp(&v1, &v1), __func__);
ok(1 == hkl_vector_cmp(&v1, &v2), __func__);
}
static void is_opposite(void)
{
HklVector v_ref = {{0, 1, 2}};
HklVector v1 = {{1, 2, 3}};
HklVector v2 = {{0, -1, -2}};
ok(FALSE == hkl_vector_is_opposite(&v_ref, &v1), __func__);
ok(TRUE == hkl_vector_is_opposite(&v_ref, &v2), __func__);
}
static void norm2(void)
{
HklVector v1 = {{0.0, 1.0, 2.0}};
HklVector v2 = {{-1.0, 1.0, 2.0}};
is_double(sqrt(5.0), hkl_vector_norm2(&v1), HKL_EPSILON, __func__);
is_double(sqrt(6.0), hkl_vector_norm2(&v2), HKL_EPSILON, __func__);
}
static void normalize(void)
{
HklVector v_ref = {{1. /sqrt(2.), 1. / sqrt(2.), 0.}};
HklVector v = {{1., 1., 0.}};
hkl_vector_normalize(&v);
ok(0 == hkl_vector_cmp(&v_ref, &v), __func__);
}
static void scalar_product(void)
{
HklVector v = {{0.0, 1.0, 2.0}};
double scalar = hkl_vector_scalar_product(&v, &v);
is_double( 5.0, scalar, HKL_EPSILON, __func__ );
}
static void vectorial_product(void)
{
HklVector v = {{0.0, 1.0, 2.0}};
HklVector v1 = {{1.0, 2.0, 3.0}};
HklVector v_ref = {{-1.0, 2.0, -1.0}};
hkl_vector_vectorial_product(&v, &v1);
ok(0 == hkl_vector_cmp(&v_ref, &v), __func__);
}
static void angle(void)
{
double angle;
HklVector v = {{1., 0., 0.}};
HklVector v1 = {{1., 1., 0.}};
HklVector v2 = {{1., 1., .5}};
HklVector v3 = {{1., .5, -1}};
HklVector v4 = {{0., 1., 0.}};
HklVector v5 = {{0., -1., 0.}};
angle = hkl_vector_angle(&v, &v);
is_double(0., angle, HKL_EPSILON, __func__);
angle = hkl_vector_angle(&v, &v1);
is_double(acos(1./sqrt(2.)), angle, HKL_EPSILON, __func__);
angle = hkl_vector_angle(&v2, &v3);
is_double(acos(1./2.25), angle, HKL_EPSILON, __func__);
angle = hkl_vector_angle(&v, &v4);
is_double(90 * HKL_DEGTORAD, angle, HKL_EPSILON, __func__);
angle = hkl_vector_angle(&v, &v5);
is_double(90 * HKL_DEGTORAD, angle, HKL_EPSILON, __func__);
}
static void oriented_angle(void)
{
double angle;
HklVector v = {{1., 0., 0.}};
HklVector v1 = {{1., 1., 0.}};
HklVector v2 = {{0., 1., 0.}};
HklVector v3 = {{0., -1., 0.}};
HklVector ref = {{0, 0, 1}};
angle = hkl_vector_oriented_angle(&v, &v, &ref);
is_double(0., angle, HKL_EPSILON, __func__);
angle = hkl_vector_oriented_angle(&v, &v1, &ref);
is_double(acos(1./sqrt(2.)), angle, HKL_EPSILON, __func__);
angle = hkl_vector_oriented_angle(&v, &v2, &ref);
is_double(90 * HKL_DEGTORAD, angle, HKL_EPSILON, __func__);
angle = hkl_vector_oriented_angle(&v, &v3, &ref);
is_double(-90 * HKL_DEGTORAD, angle, HKL_EPSILON, __func__);
}
static void oriented_angle_points(void)
{
double angle;
HklVector v = {{1., 0., 1.}};
HklVector v1 = {{1., 1., 1.}};
HklVector v2 = {{0., 1., 1.}};
HklVector v3 = {{0., -1., 1.}};
HklVector ref = {{0, 0, 1}};
angle = hkl_vector_oriented_angle_points(&v, &ref, &v, &ref);
is_double(0., angle, HKL_EPSILON, __func__);
angle = hkl_vector_oriented_angle_points(&v, &ref, &v1, &ref);
is_double(acos(1./sqrt(2.)), angle, HKL_EPSILON, __func__);
angle = hkl_vector_oriented_angle_points(&v, &ref, &v2, &ref);
is_double(90 * HKL_DEGTORAD, angle, HKL_EPSILON, __func__);
angle = hkl_vector_oriented_angle_points(&v, &ref, &v3, &ref);
is_double(-90 * HKL_DEGTORAD, angle, HKL_EPSILON, __func__);
}
static void rotated_around_vector(void)
{
HklVector x = {{1, 0, 0}};
HklVector z = {{0, 0, 1}};
HklVector y_ref = {{0, 1, 0}};
hkl_vector_rotated_around_vector(&x, &z, 90*HKL_DEGTORAD);
ok(0 == hkl_vector_cmp(&y_ref, &x), __func__);
}
static void rotated_around_line(void)
{
HklVector x = {{1, 0, 0}};
HklVector c1 = {{0, 0, 0}};
HklVector c2 = {{0, 0, 1}};
HklVector x_ref = {{1, 0, 0}};
HklVector y_ref = {{0, 1, 0}};
hkl_vector_rotated_around_line(&x, 0*HKL_DEGTORAD, &c1, &c2);
ok(0 == hkl_vector_cmp(&x_ref, &x), __func__);
hkl_vector_rotated_around_line(&x, 90*HKL_DEGTORAD, &c1, &c2);
ok(0 == hkl_vector_cmp(&y_ref, &x), __func__);
}
static void times_matrix(void)
{
HklMatrix *m = hkl_matrix_new_full(1.0, 3.0,-2.0,
10.0, 5.0, 5.0,
-3.0, 2.0, 0.0);
HklVector v = {{1.0, 2.0, 3.0}};
HklVector v_ref = {{12., 19., 8.}};
hkl_vector_times_matrix(&v, m);
ok(0 == hkl_vector_cmp(&v_ref, &v), __func__);
hkl_matrix_free(m);
}
static void project_on_plan(void)
{
HklVector v;
HklVector v_ref = {{1, 0, 0}};
HklVector v1_ref = {{1, 0, 1}};
HklVector v2_ref = {{1, 0, -2}};
HklVector v1 = {{1, 0, 2}};
HklVector plan = {{0, 0, 1}};
HklVector point1 = {{0, 0, 1}};
HklVector point2 = {{0, 0, -2}};
v = v1;
hkl_vector_project_on_plan(&v, &plan);
ok(0 == hkl_vector_cmp(&v_ref, &v), __func__);
v = v1;
hkl_vector_project_on_plan_with_point(&v, &plan, &point1);
ok(0 == hkl_vector_cmp(&v1_ref, &v), __func__);
v = v1;
hkl_vector_project_on_plan_with_point(&v, &plan, &point2);
ok(0 == hkl_vector_cmp(&v2_ref, &v), __func__);
}
int main(void)
{
plan(32);
init();
cmp();
is_opposite();
norm2();
normalize();
scalar_product();
vectorial_product();
angle();
oriented_angle();
oriented_angle_points();
rotated_around_vector();
rotated_around_line();
times_matrix();
project_on_plan();
return 0;
}
hkl-5.1.7/tests/hkl-pseudoaxis-e4ch-t.c 0000664 0001750 0001750 00000026601 14677222567 016643 0 ustar 00picca picca /* 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, 2021 Synchrotron SOLEIL
* L'Orme des Merisiers Saint-Aubin
* BP 48 91192 GIF-sur-YVETTE CEDEX
*
* Authors: Picca Frédéric-Emmanuel
* Jens Krüger
*/
#include "hkl.h"
#include
#include
#include "hkl/ccan/generator/generator.h"
#include "hkl-geometry-private.h"
#include "hkl-trajectory-private.h"
static void getter(void)
{
int res = TRUE;
HklEngineList *engines;
HklEngine *engine;
HklGeometry *geometry;
HklDetector *detector;
HklSample *sample;
Geometry gconf = E4ch(1.54, VALUES(0., 0., 0., 0.));
struct Sample cu = CU;
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, 30., 0., 0., 60.));
res &= DIAG(check_pseudoaxes_v(engine, 0., 1., 0.));
res &= DIAG(hkl_geometry_set_values_v(geometry, HKL_UNIT_USER, NULL, 30., 0., 90., 60.));
res &= DIAG(check_pseudoaxes_v(engine, 1., 0., 0.));
res &= DIAG(hkl_geometry_set_values_v(geometry, HKL_UNIT_USER, NULL, 30., 0., -90., 60.));
res &= DIAG(check_pseudoaxes_v(engine, -1., 0., 0.));
res &= DIAG(hkl_geometry_set_values_v(geometry, HKL_UNIT_USER, NULL, 30., 0., 180., 60.));
res &= DIAG(check_pseudoaxes_v(engine, 0., -1., 0.));
res &= DIAG(hkl_geometry_set_values_v(geometry, HKL_UNIT_USER, NULL, 45., 0., 135., 90.));
res &= DIAG(check_pseudoaxes_v(engine, 1., -1., 0.));
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 char **mode;
const darray_string *modes;
HklGeometry *geometry;
HklDetector *detector;
HklSample *sample;
Geometry gconf = E4ch(1.54, VALUES(0., 0., 0., 0.));
struct Sample cu = CU;
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){
static double values[] = {0, 0, 1};
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);
values[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, values, ARRAY_SIZE(values),
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, values, 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 psi_getter(void)
{
int res = TRUE;
HklEngineList *engines;
HklEngine *engine;
HklGeometry *geometry;
HklDetector *detector;
HklSample *sample;
double hkl[3];
Geometry gconf = E4ch(1.54, VALUES(30., 0., 0., 60.));
struct Sample cu = CU;
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, "psi", NULL);
/* the getter part */
res &= DIAG(hkl_engine_initialized_set(engine, TRUE, NULL));
hkl[0] = 1, hkl[1] = 0, hkl[2] = 0;
res &= DIAG(hkl_engine_parameters_values_set(engine, hkl, ARRAY_SIZE(hkl),
HKL_UNIT_DEFAULT, NULL));
res &= DIAG(check_pseudoaxes_v(engine, 0.));
/* here Q and _ref are colinear must FAIL */
hkl[0] = 0, hkl[1] = 1, hkl[2] = 0;
res &= DIAG(hkl_engine_parameters_values_set(engine, hkl, ARRAY_SIZE(hkl),
HKL_UNIT_DEFAULT, NULL));
res &= DIAG(!check_pseudoaxes_v(engine, 0.));
hkl[0] = -1, hkl[1] = 0, hkl[2] = 0;
res &= DIAG(hkl_engine_parameters_values_set(engine, hkl, ARRAY_SIZE(hkl),
HKL_UNIT_DEFAULT, NULL));
res &= DIAG(check_pseudoaxes_v(engine, 180. * HKL_DEGTORAD));
hkl[0] = 0, hkl[1] = 0, hkl[2] = -1;
res &= DIAG(hkl_engine_parameters_values_set(engine, hkl, ARRAY_SIZE(hkl),
HKL_UNIT_DEFAULT, NULL));
res &= DIAG(check_pseudoaxes_v(engine, 90. * HKL_DEGTORAD));
/* Q and _ref are colinear so must FAIL */
hkl[0] = 0, hkl[1] = -1, hkl[2] = 0;
res &= DIAG(hkl_engine_parameters_values_set(engine, hkl, ARRAY_SIZE(hkl),
HKL_UNIT_DEFAULT, NULL));
res &= DIAG(!check_pseudoaxes_v(engine, 0.));
ok(res == TRUE, "psi getter");
hkl_engine_list_free(engines);
hkl_detector_free(detector);
hkl_sample_free(sample);
hkl_geometry_free(geometry);
}
static void psi_setter(void)
{
int res = TRUE;
HklEngineList *engines;
HklEngine *engine;
const darray_string *modes;
const char **mode;
HklGeometry *geometry;
HklDetector *detector;
HklSample *sample;
static double hkl[] = {1, 0, 0};
Geometry gconf = E4ch(1.54, VALUES(30., 0., 0., 60.));
struct Sample cu = CU;
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, "psi", NULL);
modes = hkl_engine_modes_names_get(engine);
/* the init part */
res &= DIAG(hkl_engine_parameters_values_set(engine, hkl, ARRAY_SIZE(hkl),
HKL_UNIT_DEFAULT, NULL));
res &= DIAG(hkl_engine_initialized_set(engine, TRUE, NULL));
darray_foreach(mode, *modes){
double psi;
res &= DIAG(hkl_engine_current_mode_set(engine, *mode, NULL));
for(psi=-180 * HKL_DEGTORAD;psi<180 * HKL_DEGTORAD;psi += HKL_DEGTORAD){
HklGeometryList *geometries;
geometries = hkl_engine_pseudo_axis_values_set(engine, &psi, 1,
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_v(engine, psi));
}
hkl_geometry_list_free(geometries);
}
}
}
ok(res == TRUE, "psi setter");
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;
Geometry gconf = E4ch(1.54, VALUES(30., 0., 0., 60.));
struct Sample cu = CU;
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_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;
geometries = hkl_engine_pseudo_axis_values_set(engine, &q, 1,
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, &q, 1));
}
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);
}
static void hkl_psi_constant_horizontal(void)
{
int res = TRUE;
HklEngineList *engines;
HklEngine *engine;
HklGeometry *geometry;
HklGeometryList *geometries;
HklDetector *detector;
HklSample *sample;
static double hkl[] = {1, 0, 1};
static double hkl2[] = {1, 1, 0};
Geometry gconf = E4ch(1.54, VALUES(30., 0., 0., 60.));
struct Sample cu = CU;
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);
res &= DIAG(hkl_engine_current_mode_set(engine, "psi_constant", NULL));
/* the init part */
res &= DIAG(hkl_engine_parameters_values_set(engine, hkl2, ARRAY_SIZE(hkl2),
HKL_UNIT_DEFAULT, NULL));
res &= DIAG(hkl_engine_initialized_set(engine, TRUE, NULL));
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, ARRAY_SIZE(hkl)));
}
hkl_geometry_list_free(geometries);
}
ok(res == TRUE, "psi constant horizontal");
hkl_engine_list_free(engines);
hkl_detector_free(detector);
hkl_sample_free(sample);
hkl_geometry_free(geometry);
}
static void petra3_p01(void)
{
int res = TRUE;
HklGeometryList *solutions;
struct Sample sample = {
.name = "Sample",
.lattice = Tetragonal(5.4, 11.9),
.ux = -90 * HKL_DEGTORAD,
.uy = 9 * HKL_DEGTORAD,
.uz = -45 * HKL_DEGTORAD,
};
Geometry gconfig = E4ch(4.3687, VALUES(0., 0., 6., 0.));
Mode mode = ModeHklE4CHConstantPhi();
/* move between each step */
struct Trajectory tconfig1 = TrajectoryHklFromTo(0, 0, 4, 1, 1, 4, 30, mode);
solutions = Trajectory_solve(tconfig1, gconfig, sample, TRUE);
res &= DIAG(NULL != solutions);
hkl_geometry_list_free(solutions);
ok(res == TRUE, __func__);
}
int main(void)
{
plan(7);
getter();
degenerated();
psi_getter();
psi_setter();
q();
hkl_psi_constant_horizontal();
petra3_p01();
return 0;
}
hkl-5.1.7/tests/hkl-quaternion-t.c 0000664 0001750 0001750 00000010462 14677222567 016021 0 ustar 00picca picca /* 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-vector-private.h"
#include "hkl-quaternion-private.h"
static void assignment(void)
{
HklQuaternion q = {{1, 0, 0, 0}};
HklQuaternion copy = q;
is_double(1., copy.data[0], HKL_EPSILON, __func__);
is_double(0., copy.data[1], HKL_EPSILON, __func__);
is_double(0., copy.data[2], HKL_EPSILON, __func__);
is_double(0., copy.data[3], HKL_EPSILON, __func__);
}
static void cmp(void)
{
HklQuaternion q_ref = {{1., 2., 3., 4.}};
HklQuaternion q = {{1., 2., 3., 4.}};
HklQuaternion q1 = {{1., 1., 3., 4.}};
ok(TRUE == hkl_quaternion_cmp(&q_ref, &q), __func__);
ok(FALSE == hkl_quaternion_cmp(&q_ref, &q1), __func__);
/* test the assignation */
q1 = q_ref;
ok(TRUE == hkl_quaternion_cmp(&q_ref, &q1), __func__);
}
static void init_from_vector(void)
{
HklQuaternion q_ref = {{0, 1, -1, .5}};
HklVector v = {{1., -1., .5}};
HklQuaternion q;
hkl_quaternion_init_from_vector(&q, &v);
ok(TRUE == hkl_quaternion_cmp(&q_ref, &q), __func__);
}
static void init_from_angle_and_axe(void)
{
HklQuaternion q_ref1 = {{1, 0, 0, 0}};
HklQuaternion q_ref2 = {{sqrt(2.)/2., sqrt(2./9.), -sqrt(2./9.), sqrt(1./18.)}};
HklVector v_ref2 = {{1., -1., .5}};
HklQuaternion q;
hkl_quaternion_init_from_angle_and_axe(&q, 0, &v_ref2);
ok(TRUE == hkl_quaternion_cmp(&q_ref1, &q), __func__);
hkl_quaternion_init_from_angle_and_axe(&q, 90. * HKL_DEGTORAD, &v_ref2);
ok(TRUE == hkl_quaternion_cmp(&q_ref2, &q), __func__);
}
static void times_quaternion(void)
{
HklQuaternion q_ref = {{-28., 4., 6., 8.}};
HklQuaternion q = {{1., 2., 3., 4.}};
hkl_quaternion_times_quaternion(&q, &q);
ok(TRUE == hkl_quaternion_cmp(&q_ref, &q), __func__);
}
static void norm2(void)
{
HklQuaternion q = {{1., 2., 3., 4.}};
is_double(sqrt(30.), hkl_quaternion_norm2(&q), HKL_EPSILON, __func__);
}
static void conjugate(void)
{
HklQuaternion q_ref = {{1., -2., -3., -4.}};
HklQuaternion q = {{1., 2., 3., 4.}};
hkl_quaternion_conjugate(&q);
ok(TRUE == hkl_quaternion_cmp(&q_ref, &q), __func__);
}
static void to_matrix(void)
{
HklQuaternion q_ref = {{1./sqrt(2), 0, 0, 1./sqrt(2)}};
HklMatrix *m_ref = hkl_matrix_new_full(0,-1, 0,
1, 0, 0,
0, 0, 1);
HklMatrix *m = hkl_matrix_new();
hkl_quaternion_to_matrix(&q_ref, m);
is_matrix(m_ref, m, __func__);
hkl_matrix_free(m_ref);
hkl_matrix_free(m);
}
static void to_angle_and_axe(void)
{
HklVector v_ref = {{0 ,0, 1}};
HklVector v_null = {{0 ,0, 0}};
HklQuaternion q_I = {{1, 0, 0, 0}};
int i;
double angle_ref;
double angle;
HklVector v;
HklQuaternion q;
/* test the q = (1, 0, 0, 0) solution axe == (0, 0, 0) and angle = 0. */
hkl_quaternion_to_angle_and_axe(&q_I, &angle, &v);
ok(0 == hkl_vector_cmp(&v_null, &v), __func__);
is_double(0., angle, HKL_EPSILON, __func__);
/* test other cases */
for(i=-180; i<180; i++) {
angle_ref = i * HKL_DEGTORAD;
hkl_quaternion_init_from_angle_and_axe(&q, angle_ref, &v_ref);
hkl_quaternion_to_angle_and_axe(&q, &angle, &v);
if (!hkl_vector_cmp(&v_ref, &v))
is_double(angle_ref, angle, HKL_EPSILON, __func__);
else if (hkl_vector_is_opposite(&v, &v_ref))
is_double(angle_ref, -angle, HKL_EPSILON, __func__);
}
}
int main(void)
{
plan(375);
assignment();
cmp();
init_from_vector();
init_from_angle_and_axe();
times_quaternion();
norm2();
conjugate();
to_matrix();
to_angle_and_axe();
return 0;
}
hkl-5.1.7/tests/hkl-pseudoaxis-e6c-t.c 0000664 0001750 0001750 00000036401 14677222567 016474 0 ustar 00picca picca /* 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, 2021 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;
Geometry gconf = E6c(1.54, VALUES(0., 30., 0., 0., 0., 60.));
struct Sample cu = CU;
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};
Geometry gconf = E6c(1.54, VALUES(0., 30., 0., 0., 0., 60.));
struct Sample cu = CU;
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;
Geometry gconf = E6c(1.54, VALUES(0., 30., 0., 0., 0., 60.));
struct Sample cu = CU;
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