From 7b863f1d1eb4080a4da9df83ee674160a098420d Mon Sep 17 00:00:00 2001
From: Giovanni La Mura <giovanni.lamura@inaf.it>
Date: Tue, 13 Feb 2024 16:12:05 +0100
Subject: [PATCH] Use configuration count in comparison operator

---
 src/libnptm/Configuration.cpp | 42 +++++++++++++++++------------------
 1 file changed, 20 insertions(+), 22 deletions(-)

diff --git a/src/libnptm/Configuration.cpp b/src/libnptm/Configuration.cpp
index 572b2d12..7c0b63d9 100644
--- a/src/libnptm/Configuration.cpp
+++ b/src/libnptm/Configuration.cpp
@@ -1113,36 +1113,34 @@ bool ScattererConfiguration::operator ==(ScattererConfiguration &other) {
     if (scale_vec[svi] != other.scale_vec[svi]) {
       return false;
     }
-  int dj_index = 0;
+  int configurations = 0;
   int dim3 = (idfc == 0) ? number_of_scales : 1;
-  for (int dj = 0; dj < number_of_spheres; dj++) {
-    bool check_matrixes = false;
-    if (iog_vec[dj] >= dj + 1) {
-      dj_index = iog_vec[dj] - 1;
-      check_matrixes = true;
-    }
-    if (iog_vec[dj] != other.iog_vec[dj]) {
+  for (int ci = 1; ci <= number_of_spheres; ci++) {
+    if (iog_vec[ci - 1] != other.iog_vec[ci - 1]) {
       return false;
     }
-    if (radii_of_spheres[dj_index] != other.radii_of_spheres[dj_index]) {
+    if (iog_vec[ci - 1] < ci) continue;
+    configurations++;
+  }
+  for (int ri = 0; ri < configurations; ri++) {
+    if (radii_of_spheres[ri] != other.radii_of_spheres[ri]) {
       return false;
     }
-    int layers = nshl_vec[dj_index];
-    if (layers != other.nshl_vec[dj_index]) {
+    if (nshl_vec[ri] != other.nshl_vec[ri]) {
       return false;
     }
-    if (check_matrixes) {
-      for (int di = 0; di < layers; di++) {
-	if (rcf[dj_index][di] != other.rcf[dj_index][di]) {
+    for (int rj = 0; rj < nshl_vec[ri]; rj++) {
+      if (rcf[ri][rj] != other.rcf[ri][rj]) {
+	return false;
+      }
+    } // rj loop
+    for (int dj = 0; dj < number_of_spheres; dj++) {
+      for (int dk = 0; dk < dim3; dk++) {
+	if (dc0_matrix[ri][dj][dk] != other.dc0_matrix[ri][dj][dk]) {
 	  return false;
 	}
-	for (int dk = 0; dk < dim3; dk++) {
-	  if (dc0_matrix[di][dj_index][dk] != other.dc0_matrix[di][dj_index][dk]) {
-	    return false;
-	  }
-	} // dk loop
-      } // di loop
-    }
-  } // dj loop
+      } // dk loop
+    } // dj loop
+  } // ri loop
   return true;
 }
-- 
GitLab