diff --git a/qpms/latticegens.c b/qpms/latticegens.c index 17867eb..034f934 100644 --- a/qpms/latticegens.c +++ b/qpms/latticegens.c @@ -175,7 +175,7 @@ PGenSph PGenSph_zAxis_new_minMaxR(double period, double offset, double minR, boo s->ptindex = ptindex_inc(s->ptindex); break; case PGENSPH_ZAXIS_INC_TOWARDS_ORIGIN: - s->ptindex = - ceil(minR / fabs(period)); + s->ptindex = - ceil(maxR / fabs(period)); while ( (curR = fabs(s->offset + s->ptindex * period)) > maxR || (!inc_minR && curR >= maxR)) s->ptindex = ptindex_dec(s->ptindex); break; diff --git a/qpms/vectors.h b/qpms/vectors.h index 2eeaf5c..5e4e315 100644 --- a/qpms/vectors.h +++ b/qpms/vectors.h @@ -57,7 +57,11 @@ static inline sph_t cart2sph(const cart3_t cart) { static inline cart3_t sph2cart(const sph_t sph) { cart3_t cart; - double sin_th = sin(sph.theta); + double sin_th = +#ifdef QPMS_VECTORS_NICE_TRANSFORMATIONS + (sph.theta == M_PI) ? 0 : +#endif + sin(sph.theta); cart.x = sph.r * sin_th * cos(sph.phi); cart.y = sph.r * sin_th * sin(sph.phi); cart.z = sph.r * cos(sph.theta); diff --git a/tests/test_latticegens.c b/tests/test_latticegens.c index e9750ec..a7d1d82 100644 --- a/tests/test_latticegens.c +++ b/tests/test_latticegens.c @@ -1,5 +1,5 @@ //c99 -o test_latticegens -ggdb -Wall -I ../ test_latticegens.c ../qpms/latticegens.c -lm - +#define QPMS_VECTORS_NICE_TRANSFORMATIONS #include #include @@ -34,5 +34,15 @@ int main(int argc, char **argv) { dump_PGenSph(&g); DO_AND_PRINT(test3b, g = PGenSph_zAxis_new_minMaxR(0.2, 0.05, 5.05, false, 7.05, false, PGENSPH_ZAXIS_INC_TOWARDS_ORIGIN)) dump_PGenSph(&g); + DO_AND_PRINT(test4a, g = PGenSph_zAxis_new_minMaxR(0.2, 0.0, 0, false, 1, false, PGENSPH_ZAXIS_INC_FROM_ORIGIN)) + dump_PGenSph(&g); + DO_AND_PRINT(test4b, g = PGenSph_zAxis_new_minMaxR(0.2, 0.0, 0, false, 1, false, PGENSPH_ZAXIS_INC_TOWARDS_ORIGIN)) + dump_PGenSph(&g); + DO_AND_PRINT(test5a, g = PGenSph_zAxis_new_minMaxR(0.2, 0.0, 0, true, 1, true, PGENSPH_ZAXIS_INC_FROM_ORIGIN)) + dump_PGenSph(&g); + DO_AND_PRINT(test5b, g = PGenSph_zAxis_new_minMaxR(0.2, 0.0, 0, true, 1, true, PGENSPH_ZAXIS_INC_TOWARDS_ORIGIN)) + dump_PGenSph(&g); + + }