From 02a8161d3ea1cd642d4350e21e630b29dd6c09d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Sun, 14 Jul 2019 23:55:45 +0300 Subject: [PATCH] Vector.h more convenience inlines Former-commit-id: 4e0b0331fdb50192e9518d017f6bbc46fdf1fe1b --- qpms/vectors.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/qpms/vectors.h b/qpms/vectors.h index f6abed5..265ae96 100644 --- a/qpms/vectors.h +++ b/qpms/vectors.h @@ -293,6 +293,12 @@ static inline csph_t sph2csph(sph_t s) { return cs; } +/// Convert csph_t to sph_t, discarding the imaginary part of radial component. +static inline sph_t csph2sph(csph_t s) { + sph_t rs = {creal(s.r), s.theta, s.phi}; + return rs; +} + /// Lossy coordinate transform of ccart3_t to csph_t. /** The angle and real part of the radial coordinate are determined * from the real components of \a \cart. The imaginary part of the radial @@ -300,7 +306,8 @@ static inline csph_t sph2csph(sph_t s) { * part of \a cart *projected onto* the real part of \a cart. * * N.B. this obviously makes not much sense for purely imaginary vectors - * (and will cause NANs). TODO handle this better. + * (and will cause NANs). TODO handle this better, as purely imaginary + * vectors could make sense e.g. for evanescent waves. */ static inline csph_t ccart2csph(const ccart3_t cart) { cart3_t rcart = {creal(cart.x), creal(cart.y), creal(cart.z)};