diff options
author | Thomas White <taw@physics.org> | 2019-02-28 10:53:43 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2019-03-11 16:49:37 +0100 |
commit | 3e850c6c2ed2a3dbc0fe0be27d36c0d1e6b57614 (patch) | |
tree | d5b9f2c02a9b71ac909bde1579d764441fdc79f0 /libcrystfel/src/rational.c | |
parent | 2dad9da2661389cf5c34a49e933dab20bd6d943c (diff) |
New way of doing cell comparisons, similar to match_cell()
Diffstat (limited to 'libcrystfel/src/rational.c')
-rw-r--r-- | libcrystfel/src/rational.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/libcrystfel/src/rational.c b/libcrystfel/src/rational.c index 5db83165..0f2bcaee 100644 --- a/libcrystfel/src/rational.c +++ b/libcrystfel/src/rational.c @@ -226,6 +226,39 @@ char *rtnl_format(Rational rt) } +Rational *rtnl_list(signed int num_min, signed int num_max, + signed int den_min, signed int den_max, + int *pn) +{ + signed int num, den; + Rational *list; + int n = 0; + + list = malloc((1+num_max-num_min)*(1+den_max-den_min)*sizeof(Rational)); + if ( list == NULL ) return NULL; + + for ( num=num_min; num<=num_max; num++ ) { + for ( den=den_min; den<=den_max; den++ ) { + + Rational r = rtnl(num, den); + + /* Denominator zero? */ + if ( den == 0 ) continue; + + /* Same as last entry? */ + if ( (n>0) && (rtnl_cmp(list[n-1], r)==0) ) continue; + + /* Can be reduced? */ + if ( gcd(num, den) != 1 ) continue; + + list[n++] = r; + } + } + *pn = n; + return list; +} + + /** * SECTION:rational_matrix * @short_description: Rational matrices |