From 0bb8df9b6a54db5da84d9fc9c26efcf5974fc89b Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 24 Jul 2013 16:47:21 +0200 Subject: Iteration over reflection list should include other reflections with same asymmetric indices This fixes a >2 year old bug in the reflection list, and a bug in tests/list_check.c which allowed it to go undetected for so long. The main situation where it would have caused problems is when asymmetric_indices() was called on a reflection list containing symmetrically equivalent reflections. The only core CrystFEL program which does this is partialator. compare_hkl uses asymmetric_indices(), but the reflections are already guaranteed to be asymmetric by that point (because check_list_symmetry() has been called). --- libcrystfel/src/reflist.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/reflist.c b/libcrystfel/src/reflist.c index b3b9f85b..a450d8fa 100644 --- a/libcrystfel/src/reflist.c +++ b/libcrystfel/src/reflist.c @@ -992,12 +992,20 @@ Reflection *first_refl(RefList *list, RefListIterator **piter) **/ Reflection *next_refl(Reflection *refl, RefListIterator *iter) { - int returned = 1; + /* Are there more reflections with the same indices? */ + if ( refl->next != NULL ) { + return refl->next; + } else { - do { + /* No, so rewind back to the head of the list */ + while ( refl->prev != NULL ) { + refl = refl->prev; + } + + } - if ( returned ) refl = refl->child[1]; - returned = 0; + refl = refl->child[1]; + do { if ( refl != NULL ) { @@ -1041,13 +1049,21 @@ static int recursive_depth(Reflection *refl) static int recursive_count(Reflection *refl) { int count_left, count_right; + Reflection *probe; + int n_this = 1; if ( refl == NULL ) return 0; + probe = refl; + while ( probe->next != NULL ) { + probe = probe->next; + n_this++; + } + count_left = recursive_count(refl->child[0]); count_right = recursive_count(refl->child[1]); - return 1 + count_left + count_right; + return n_this + count_left + count_right; } -- cgit v1.2.3