7 #include "quaternion.h"
9 /* private hkl_holder part */
10 void hkl_holder_grow(struct hkl_holder
* holder
, size_t extra
)
12 if (holder
->len
+ extra
<= holder
->len
)
13 die("you want to use way too much memory");
16 ALLOC_GROW(holder
->idx
, holder
->len
+ extra
, holder
->alloc
);
19 void hkl_holder_init(struct hkl_holder
* holder
, size_t hint
)
24 hkl_holder_grow(holder
, hint
);
27 void hkl_holder_release(struct hkl_holder
* holder
)
31 hkl_holder_init(holder
, 0);
35 void hkl_holder_add_idx(struct hkl_holder
* holder
, size_t const idx
)
37 hkl_holder_grow(holder
, 1);
39 holder
->idx
[holder
->len
] = idx
;
40 holder
->dirty
= HKL_TRUE
;
43 /* private hkl_holders part */
44 void hkl_holders_grow(struct hkl_holders
* holders
, size_t extra
)
46 if (holders
->len
+ extra
<= holders
->len
)
47 die("you want to use way too much memory");
49 holders
->holders
= NULL
;
50 ALLOC_GROW(holders
->holders
, holders
->len
+ extra
, holders
->alloc
);
53 void hkl_holders_init(struct hkl_holders
* holders
, size_t hint
)
58 hkl_holders_grow(holders
, hint
);
61 void hkl_holders_release(struct hkl_holders
* holders
)
66 for(i
=0;i
<holders
->len
;i
++)
67 hkl_holder_release(&holders
->holders
[i
]);
68 free(holders
->holders
);
69 hkl_holders_init(holders
, 0);
74 void hkl_holder_add_rotation_axe(struct hkl_holder
* holder
, char const * name
, struct hkl_svector
const * rot_axis
)
78 struct hkl_axis
* axis
= NULL
;
80 idx
= hkl_axis_get_idx_by_name(holder
->axes
, name
);
81 if (idx
>= 0) { // found it in the axe list
82 // check that both have the same rotation axe.
83 if (hkl_svector_cmp(&holder
->axes
->axes
[idx
].axis
, rot_axis
)) {
84 // check that the axis is not already in the holder
85 for(i
=0; i
<holder
->len
; i
++)
86 if (idx
== holder
->idx
[i
])
87 die("can not add two times the \"%s\" axis to an holder.", name
);
89 // add 1 element to ther holder
90 hkl_holder_add_idx(holder
, idx
);
92 die("can not add two axis with the same name \"%s\" but different axes <%f, %f, %f> != <%f, %f, %f> into an holder",
94 axis
->axis
.data
[X
], axis
->axis
.data
[Y
], axis
->axis
.data
[Z
],
95 rot_axis
->data
[X
], rot_axis
->data
[Y
], rot_axis
->data
[Z
]);
96 } else {// not already in the axe list
97 // add a rotation axe to the holder->axes list
98 hkl_axes_add_rotation(holder
->axes
, name
, rot_axis
);
99 // set the right index in the holder idx list
100 hkl_holder_add_idx(holder
, holder
->axes
->len
);
104 struct hkl_holder
* hkl_holders_add(struct hkl_holders
* holders
)
106 struct hkl_holder
* holder
;
108 hkl_holders_grow(holders
, 1);
109 holder
= &holders
->holders
[holders
->len
++];