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/float.h>
26 #include "hkl-vector-private.h"
27 #include "hkl-matrix-private.h" /* we will check also the private API */
29 static void init(void)
33 hkl_matrix_init(&m
, 1, 1, 0, 0, 1, 0, 0, 0, 1);
34 is_double(1., m
.data
[0][0], HKL_EPSILON
, __func__
);
35 is_double(1., m
.data
[0][1], HKL_EPSILON
, __func__
);
36 is_double(0., m
.data
[0][2], HKL_EPSILON
, __func__
);
37 is_double(0., m
.data
[1][0], HKL_EPSILON
, __func__
);
38 is_double(1., m
.data
[1][1], HKL_EPSILON
, __func__
);
39 is_double(0., m
.data
[1][2], HKL_EPSILON
, __func__
);
40 is_double(0., m
.data
[2][0], HKL_EPSILON
, __func__
);
41 is_double(0., m
.data
[2][1], HKL_EPSILON
, __func__
);
42 is_double(1., m
.data
[2][2], HKL_EPSILON
, __func__
);
47 HklMatrix m1
= {{{0.0, 1.0, 2.0},
51 HklMatrix m2
= {{{1.0, 1.0, 2.0},
55 ok(TRUE
== hkl_matrix_cmp(&m1
, &m1
), __func__
);
56 ok(FALSE
== hkl_matrix_cmp(&m1
, &m2
), __func__
);
61 HklMatrix m1
= {{{0.0, 1.0, 2.0},
66 m
= hkl_matrix_dup(&m1
);
67 ok(TRUE
== hkl_matrix_cmp(&m1
, m
), __func__
);
71 static void assignement(void)
73 HklMatrix m1
= {{{0.0, 1.0, 2.0},
79 ok(TRUE
== hkl_matrix_cmp(&m1
, &m
), __func__
);
82 static void init_from_euler(void)
84 HklMatrix m_ref
= {{{ 1./2., -1./2., sqrt(2)/2.},
85 { sqrt(2.)/4.+1./2., -sqrt(2.)/4.+1./2., -1./2.},
86 {-sqrt(2.)/4.+1./2., sqrt(2.)/4.+1./2., 1./2.}}};
89 hkl_matrix_init_from_euler(&m
, 45.*HKL_DEGTORAD
, 45.*HKL_DEGTORAD
, 45.*HKL_DEGTORAD
);
90 ok(TRUE
== hkl_matrix_cmp(&m_ref
, &m
), __func__
);
93 static void init_from_two_vector(void)
95 HklVector v1
= {{0.0, 1.0, 2.0}};
96 HklVector v2
= {{1.0, 2.0, 3.0}};
97 HklMatrix m_ref
= {{{0.0, 5.0 / sqrt(30.0), -1.0 / sqrt(6.0)},
98 {1.0 / sqrt(5.0), 2.0 / sqrt(30.0), 2.0 / sqrt(6.0)},
99 {2.0 / sqrt(5.0),-1.0 / sqrt(30.0), -1.0 / sqrt(6.0)}}
103 hkl_matrix_init_from_two_vector(&m
, &v1
, &v2
);
104 ok(TRUE
== hkl_matrix_cmp(&m_ref
, &m
), __func__
);
107 static void times_vector(void)
109 HklMatrix m
= {{{ 1.0, 3.0,-2.0},
113 HklVector v
= {{1, 2, 3}};
114 HklVector v_ref
= {{1, 35, 1}};
116 hkl_matrix_times_vector(&m
, &v
);
117 ok(0 == hkl_vector_cmp(&v_ref
, &v
), __func__
);
120 static void times_matrix(void)
122 HklMatrix m_ref
= {{{37., 14., 13.},
127 HklMatrix m
= {{{ 1., 3.,-2.},
132 hkl_matrix_times_matrix(&m
, &m
);
133 ok(TRUE
== hkl_matrix_cmp(&m_ref
, &m
), __func__
);
136 static void transpose(void)
138 HklMatrix m_ref
= {{{37., 14., 13.},
143 HklMatrix m
= {{{37., 45., 17.},
148 hkl_matrix_transpose(&m
);
149 ok(TRUE
== hkl_matrix_cmp(&m_ref
, &m
), __func__
);
161 init_from_two_vector();