[contrib][haskell] PyFAI.Detector
[hkl.git] / hkl / hkl-unit.c
blobf5b0f8692c607550359ae510e0111c8017fce713
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-2017 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 <gsl/gsl_nan.h> // for GSL_NAN
23 #include <gsl/gsl_sys.h> // for gsl_isnan
24 #include <stdlib.h> // for free, NULL
25 #include "hkl-macros-private.h" // for HKL_MALLOC
26 #include "hkl-unit-private.h" // for HklUnit, etc
27 #include "hkl.h" // for FALSE, HKL_DEGTORAD, etc
29 /**
30 * hkl_unit_dup: (skip)
31 * @self:
33 * copy an #Hklunit
35 * Returns: the copied #HklUnit (memory must be release with
36 * hkl_unit_free)
37 **/
38 HklUnit* hkl_unit_dup(const HklUnit *self)
40 if (!self)
41 return NULL;
43 HklUnit *dup = HKL_MALLOC(HklUnit);
44 *dup = *self;
46 return dup;
49 /**
50 * hkl_unit_free: (skip)
51 * @self:
53 * release the memory of an #HklUnit
54 **/
55 void hkl_unit_free(HklUnit *self)
57 if (self)
58 free(self);
61 /**
62 * hkl_unit_compatible: (skip)
63 * @self: the first @HklUnit
64 * @unit: the second @HklUnit to check
66 * check if two units are compatible.
68 * Returns: TRUE or FALSE
69 **/
70 int hkl_unit_compatible(const HklUnit *unit1, const HklUnit *unit2)
72 int res = FALSE;
74 if (unit1 == NULL) {
75 if (unit2 == NULL) {
76 res = TRUE;
77 }else{
78 res = FALSE;
80 }else{
81 if (unit2 == NULL){
82 res = FALSE;
83 }else{
84 res = ( (unit1->dimension.l == unit2->dimension.l)
85 && (unit1->dimension.m == unit2->dimension.m)
86 && (unit1->dimension.t == unit2->dimension.t)
87 && (unit1->dimension.i == unit2->dimension.i)
88 && (unit1->dimension.th == unit2->dimension.th)
89 && (unit1->dimension.n == unit2->dimension.n)
90 && (unit1->dimension.j == unit2->dimension.j));
93 return res;
96 /**
97 * hkl_unit_factor:
98 * @self:
99 * @unit:
101 * compute the factor to convert from one @Hklunit to another one.
102 * @self * factor = @unit
104 * Returns: the factor of the conversion.
106 double hkl_unit_factor(const HklUnit *from, const HklUnit *to)
108 double res = 1.0;
110 if (from == NULL) {
111 if (to == NULL) {
112 res = 1.0;
113 }else{
114 res = 1.0 / to->factor;
116 }else{
117 if (to == NULL){
118 res = from->factor;
119 }else{
120 res = from->factor / to->factor;
124 return res;