From a04f64ccaadca148cd3bb4fed1e404689159e2e2 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sat, 3 Jan 2026 15:04:35 +0100 Subject: [PATCH] BraggPredictionRotation: Minor fixes to improve readability --- .../BraggPredictionRotation.cpp | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/image_analysis/bragg_prediction/BraggPredictionRotation.cpp b/image_analysis/bragg_prediction/BraggPredictionRotation.cpp index a1305e52..40b90114 100644 --- a/image_analysis/bragg_prediction/BraggPredictionRotation.cpp +++ b/image_analysis/bragg_prediction/BraggPredictionRotation.cpp @@ -138,22 +138,22 @@ int BraggPredictionRotation::Calc(const DiffractionExperiment &experiment, if (i >= max_reflections) continue; - const float g0_x = AhBk_x + Cstar.x * l; - const float g0_y = AhBk_y + Cstar.y * l; - const float g0_z = AhBk_z + Cstar.z * l; - const float g02 = g0_x * g0_x + g0_y * g0_y + g0_z * g0_z; + const float recip_x = AhBk_x + Cstar.x * l; + const float recip_y = AhBk_y + Cstar.y * l; + const float recip_z = AhBk_z + Cstar.z * l; + const float recip_sq = recip_x * recip_x + recip_y * recip_y + recip_z * recip_z; - if (g02 <= 0.0f || g02 > one_over_dmax_sq) + if (recip_sq <= 0.0f || recip_sq > one_over_dmax_sq) continue; - const float g_par_s = g0_x * w.x + g0_y * w.y + g0_z * w.z; + const float g_par_s = recip_x * w.x + recip_y * w.y + recip_z * w.z; const float g_par_x = w.x * g_par_s; const float g_par_y = w.y * g_par_s; const float g_par_z = w.z * g_par_s; - const float g_perp_x = g0_x - g_par_x; - const float g_perp_y = g0_y - g_par_y; - const float g_perp_z = g0_z - g_par_z; + const float g_perp_x = recip_x - g_par_x; + const float g_perp_y = recip_y - g_par_y; + const float g_perp_z = recip_z - g_par_z; const float g_perp2 = g_perp_x * g_perp_x + g_perp_y * g_perp_y + g_perp_z * g_perp_z; if (g_perp2 < 1e-12f) @@ -205,8 +205,8 @@ int BraggPredictionRotation::Calc(const DiffractionExperiment &experiment, if (x < 0.0f || x >= det_width_pxl || y < 0.0f || y >= det_height_pxl) continue; - - float d = 1.0f / sqrtf(g02); + float dist_ewald_sphere = std::fabs(sqrtf(S_x * S_x + S_y * S_y + S_z * S_z) - one_over_wavelength); + float d = 1.0f / sqrtf(recip_sq); const float phi_deg = rad_to_deg(phi); reflections[i] = Reflection{ .h = h, @@ -216,7 +216,7 @@ int BraggPredictionRotation::Calc(const DiffractionExperiment &experiment, .predicted_x = x, .predicted_y = y, .d = d, - .dist_ewald = sqrtf(S_x * S_x + S_y * S_y + S_z * S_z) - one_over_wavelength + .dist_ewald = dist_ewald_sphere }; ++i; }