fix all the references
[hkl.git] / tests / hkl-matrix-t.c
blobfc6607021a7830e1d01180608f01c5acd6a7d495
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-2014 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>
24 #include <tap/float.h>
26 #include "hkl-matrix-private.h" /* we will check also the private API */
28 static void init(void)
30 HklMatrix m;
32 hkl_matrix_init(&m, 1, 1, 0, 0, 1, 0, 0, 0, 1);
33 is_double(1., m.data[0][0], HKL_EPSILON, __func__);
34 is_double(1., m.data[0][1], HKL_EPSILON, __func__);
35 is_double(0., m.data[0][2], HKL_EPSILON, __func__);
36 is_double(0., m.data[1][0], HKL_EPSILON, __func__);
37 is_double(1., m.data[1][1], HKL_EPSILON, __func__);
38 is_double(0., m.data[1][2], HKL_EPSILON, __func__);
39 is_double(0., m.data[2][0], HKL_EPSILON, __func__);
40 is_double(0., m.data[2][1], HKL_EPSILON, __func__);
41 is_double(1., m.data[2][2], HKL_EPSILON, __func__);
44 static void cmp(void)
46 HklMatrix m1 = {{{0.0, 1.0, 2.0},
47 {3.0, 4.0, 5.0},
48 {6.0, 7.0, 8.0}}};
50 HklMatrix m2 = {{{1.0, 1.0, 2.0},
51 {3.0, 4.0, 5.0},
52 {6.0, 7.0, 8.0}}};
54 ok(TRUE == hkl_matrix_cmp(&m1, &m1), __func__);
55 ok(FALSE == hkl_matrix_cmp(&m1, &m2), __func__);
58 static void assignement(void)
60 HklMatrix m1 = {{{0.0, 1.0, 2.0},
61 {3.0, 4.0, 5.0},
62 {6.0, 7.0, 8.0}}};
63 HklMatrix m;
65 m = m1;
66 ok(TRUE == hkl_matrix_cmp(&m1, &m), __func__);
69 static void init_from_euler(void)
71 HklMatrix m_ref = {{{ 1./2., -1./2., sqrt(2)/2.},
72 { sqrt(2.)/4.+1./2., -sqrt(2.)/4.+1./2., -1./2.},
73 {-sqrt(2.)/4.+1./2., sqrt(2.)/4.+1./2., 1./2.}}};
74 HklMatrix m;
76 hkl_matrix_init_from_euler(&m, 45.*HKL_DEGTORAD, 45.*HKL_DEGTORAD, 45.*HKL_DEGTORAD);
77 ok(TRUE == hkl_matrix_cmp(&m_ref, &m), __func__);
80 static void init_from_two_vector(void)
82 HklVector v1 = {{0.0, 1.0, 2.0}};
83 HklVector v2 = {{1.0, 2.0, 3.0}};
84 HklMatrix m_ref = {{{0.0, 5.0 / sqrt(30.0), -1.0 / sqrt(6.0)},
85 {1.0 / sqrt(5.0), 2.0 / sqrt(30.0), 2.0 / sqrt(6.0)},
86 {2.0 / sqrt(5.0),-1.0 / sqrt(30.0), -1.0 / sqrt(6.0)}}
88 HklMatrix m;
90 hkl_matrix_init_from_two_vector(&m, &v1, &v2);
91 ok(TRUE == hkl_matrix_cmp(&m_ref, &m), __func__);
94 static void times_vector(void)
96 HklMatrix m = {{{ 1.0, 3.0,-2.0},
97 {10.0, 5.0, 5.0},
98 {-3.0, 2.0, 0.0}}
100 HklVector v = {{1, 2, 3}};
101 HklVector v_ref = {{1, 35, 1}};
103 hkl_matrix_times_vector(&m, &v);
104 ok(0 == hkl_vector_cmp(&v_ref, &v), __func__);
107 static void times_matrix(void)
109 HklMatrix m_ref = {{{37., 14., 13.},
110 {45., 65., 5.},
111 {17., 1., 16.}}
114 HklMatrix m = {{{ 1., 3.,-2.},
115 {10., 5., 5.},
116 {-3., 2., 0.}}
119 hkl_matrix_times_matrix(&m, &m);
120 ok(TRUE == hkl_matrix_cmp(&m_ref, &m), __func__);
123 static void transpose(void)
125 HklMatrix m_ref = {{{37., 14., 13.},
126 {45., 65., 5.},
127 {17., 1., 16.}}
130 HklMatrix m = {{{37., 45., 17.},
131 {14., 65., 1.},
132 {13., 5., 16.}}
135 hkl_matrix_transpose(&m);
136 ok(TRUE == hkl_matrix_cmp(&m_ref, &m), __func__);
139 int main(int argc, char** argv)
141 plan(17);
143 init();
144 cmp();
145 assignement();
146 init_from_euler();
147 init_from_two_vector();
148 times_vector();
149 times_matrix();
150 transpose();
152 return 0;