From 21a3b8b895d7936257335016c104be0337957f08 Mon Sep 17 00:00:00 2001
From: Walter Van Herck <w.van.herck@fz-juelich.de>
Date: Thu, 1 Feb 2018 16:21:38 +0100
Subject: [PATCH] Removed macros: for_int, for_i

---
 GUI/ba3d/ba3d/def.h                           | 18 -----------------
 GUI/ba3d/ba3d/model/geometry.cpp              |  6 +++---
 GUI/ba3d/ba3d/model/geometry/column.cpp       |  4 ++--
 .../ba3d/model/geometry/cuboctahedron.cpp     |  2 +-
 GUI/ba3d/ba3d/model/geometry/dodecahedron.cpp |  2 +-
 GUI/ba3d/ba3d/model/geometry/sphere.cpp       |  8 ++++----
 GUI/ba3d/ba3d/model/geometry/truncbox.cpp     |  2 +-
 GUI/ba3d/demo/demo_model.cpp                  | 20 +++++++++----------
 GUI/ba3d/showcase/modelLayers.cpp             |  6 +++---
 9 files changed, 25 insertions(+), 43 deletions(-)

diff --git a/GUI/ba3d/ba3d/def.h b/GUI/ba3d/ba3d/def.h
index 89b9acfb528..33ca032a280 100644
--- a/GUI/ba3d/ba3d/def.h
+++ b/GUI/ba3d/ba3d/def.h
@@ -21,24 +21,6 @@
 #pragma GCC diagnostic ignored "-Wfloat-equal"
 #endif
 
-// a handy iteration support
-#ifdef __GNUC__
-
-template <typename T> struct mut_typ          { typedef T typ; };
-template <typename T> struct mut_typ<T const> { typedef T typ; };
-
-#define for_int(i, n) \
-  for (mut_typ<decltype(n)>::typ i = decltype(n)(0), i##End = (n); i < i##End; ++i)
-
-#else // msvc fails the above
-
-#define for_int(i, n) \
-  for (int i = 0, i##End = (n); i < i##End; ++i)
-
-#endif
-
-#define for_i(n) for_int (i, n)
-
 //------------------------------------------------------------------------------
 // coordinates
 
diff --git a/GUI/ba3d/ba3d/model/geometry.cpp b/GUI/ba3d/ba3d/model/geometry.cpp
index 2687f14165d..de3017224ca 100644
--- a/GUI/ba3d/ba3d/model/geometry.cpp
+++ b/GUI/ba3d/ba3d/model/geometry.cpp
@@ -21,7 +21,7 @@ namespace ba3d {
 Geometry::vn_t::vn_t(xyz::rc v_, xyz::rc n_) : v(v_), n(n_) {}
 
 void Geometry::xyz_vec::addVert(xyz::rc v, int n) {
-  for_i (n)
+  for(int i=0; i<n; ++i)
     append(v);
 }
 
@@ -41,7 +41,7 @@ void Geometry::xyz_vec::addQuad(Geometry::xyz_vec::rc vs,
 
 void Geometry::xyz_vec::addStrip(xyz_vec::rc vs, idx_vec::rc is) {
   Q_ASSERT(is.count() >= 3); // at least one triangle
-  for_i (is.count() - 2)
+  for(int i=0; i<is.count()-2; ++i)
     if (i%2)
       addTrig(vs.at(is.at(i)), vs.at(is.at(1+i)), vs.at(is.at(2+i)));
     else
@@ -51,7 +51,7 @@ void Geometry::xyz_vec::addStrip(xyz_vec::rc vs, idx_vec::rc is) {
 void Geometry::xyz_vec::addFan(xyz_vec::rc vs, idx_vec::rc is) {
   Q_ASSERT(is.count() >= 3); // at least one triangle
   auto &ctr = vs.at(is.at(0));
-  for_i (is.count() - 2)
+  for(int i=0; i<is.count()-2; ++i)
     addTrig(ctr, vs.at(is.at(1+i)),
                  vs.at(is.at(2+i)));
 }
diff --git a/GUI/ba3d/ba3d/model/geometry/column.cpp b/GUI/ba3d/ba3d/model/geometry/column.cpp
index e11f4267113..0e06994308b 100644
--- a/GUI/ba3d/ba3d/model/geometry/column.cpp
+++ b/GUI/ba3d/ba3d/model/geometry/column.cpp
@@ -28,7 +28,7 @@ Geometry::mesh_t Geometry::meshColumn(flt alpha, flt numSides) {
   // mesh of vertices and normals
   xyz_vec vb(slices), vt(slices), nbt(slices);
   flt const nz = (1 - Rt/Rb)*2*R;
-  for_int (s, slices) {
+  for(int s=0; s < slices; ++s) {
     flt th = flt(2*M_PI*s/slices), st = sinf(th), ct = cosf(th);
     xyz vb_(Rb*ct, Rb*st, -R), vt_(Rt*ct, Rt*st, +R);
     vb[s] = vb_; vt[s] = vt_;
@@ -41,7 +41,7 @@ Geometry::mesh_t Geometry::meshColumn(flt alpha, flt numSides) {
   xyz_vec vs; vs.reserve(nv);
   xyz_vec ns; if (smooth) ns.reserve(nv);
 
-  for_int (s, slices) {
+  for(int s=0; s < slices; ++s) {
     int s1 = s, s2 = (s+1) % slices;
 
     vs.addTrig(vb.at(s1), xyz(0,0,-R), vb.at(s2));          // bottom
diff --git a/GUI/ba3d/ba3d/model/geometry/cuboctahedron.cpp b/GUI/ba3d/ba3d/model/geometry/cuboctahedron.cpp
index d16a2886644..59d9e9b360f 100644
--- a/GUI/ba3d/ba3d/model/geometry/cuboctahedron.cpp
+++ b/GUI/ba3d/ba3d/model/geometry/cuboctahedron.cpp
@@ -27,7 +27,7 @@ Geometry::mesh_t Geometry::meshCuboctahedron(flt rH, flt alpha) { // t/D
 
   xyz_vec vs_; vs_.reserve(12);
   flt z[] = {-D, H-D, +D}, d[] = {Db, D, Dt};
-  for_i (3)
+  for(int i=0; i<3; ++i)
     for (int x : {-1, +1})
       for (int y : {-1, +1}) {
         flt di = d[i];
diff --git a/GUI/ba3d/ba3d/model/geometry/dodecahedron.cpp b/GUI/ba3d/ba3d/model/geometry/dodecahedron.cpp
index 8b1cbb92928..42f77e49d15 100644
--- a/GUI/ba3d/ba3d/model/geometry/dodecahedron.cpp
+++ b/GUI/ba3d/ba3d/model/geometry/dodecahedron.cpp
@@ -46,7 +46,7 @@ Geometry::mesh_t Geometry::meshDodecahedron() {
   //face down
   auto q = QQuaternion::rotationTo(-xyz::_z,
     cross(vs_.at(8)-vs_.at(0), vs_.at(10)-vs_.at(0)));
-  for_i (20)
+  for(int i=0; i<20; ++i)
     vs_[i] = q.rotatedVector(vs_.at(i));
 
   xyz_vec vs; vs.reserve(180);
diff --git a/GUI/ba3d/ba3d/model/geometry/sphere.cpp b/GUI/ba3d/ba3d/model/geometry/sphere.cpp
index b22803df731..513fd7a472b 100644
--- a/GUI/ba3d/ba3d/model/geometry/sphere.cpp
+++ b/GUI/ba3d/ba3d/model/geometry/sphere.cpp
@@ -51,11 +51,11 @@ Geometry::mesh_t Geometry::meshSphere(flt cut) {
 
   flt const R = .5f;
 
-  for_int (r, rings) {
+  for(int r=0; r < rings; ++r) {
     flt ph = minPh + phRge * r/rings;
     flt cp = cosf(ph), sp = sinf(ph);
 
-    for_int (s, slices) {
+    for(int s=0; s < slices; ++s) {
       flt th = flt(2*M_PI*s/slices);
       xyz v(R*cp*cosf(th), R*cp*sinf(th), R*sp);
       vs_[r][s] = v;
@@ -68,10 +68,10 @@ Geometry::mesh_t Geometry::meshSphere(flt cut) {
   xyz_vec vs; vs.reserve(nv);
   xyz_vec ns; ns.reserve(nv);
 
-  for_int (r, rings) {
+  for(int r=0; r < rings; ++r) {
     auto &vr = vs_.at(r), &nr = ns_.at(r);
 
-    for_int (s, slices) {
+    for(int s=0; s < slices; ++s) {
       int s0 = s, s1 = (s+1) % slices;
 
       auto &v0 = vr.at(s0), &v1 = vr.at(s1);
diff --git a/GUI/ba3d/ba3d/model/geometry/truncbox.cpp b/GUI/ba3d/ba3d/model/geometry/truncbox.cpp
index e0d57669e88..c422681dcf9 100644
--- a/GUI/ba3d/ba3d/model/geometry/truncbox.cpp
+++ b/GUI/ba3d/ba3d/model/geometry/truncbox.cpp
@@ -30,7 +30,7 @@ Geometry::mesh_t Geometry::meshTruncBox(flt tD) { // t/D
   auto side = [&](int ax, int ay, int az, int bx, int by, int bz,
                   xyz::rc d, bool rev) {
     xyz_vec vs_(8);
-    for_i (8)
+    for(int i=0; i<8; ++i)
       vs_[rev ? 7-i : i] =
         xyz(ax*as.at(i) + bx*bs.at(i),
             ay*as.at(i) + by*bs.at(i),
diff --git a/GUI/ba3d/demo/demo_model.cpp b/GUI/ba3d/demo/demo_model.cpp
index a8f48e9c847..1a1fa6afd33 100644
--- a/GUI/ba3d/demo/demo_model.cpp
+++ b/GUI/ba3d/demo/demo_model.cpp
@@ -100,8 +100,8 @@ void DemoModel::square(float sigma) {
     for (uint i=0; i < uint(ps.count()); ++i)
       ps.at(i)->transform(xyz::_0, activeMesh.at(i));
 
-    uint const steps = 20;
-    for_int (s, steps + 1) {
+    int const steps = 20;
+    for(int s=0; s < steps + 1; ++s) {
       for (uint i=0; i < uint(ps.count()); ++i)
         ps.at(i)->fancy(xyz::_0, flt(s) / steps);
       snooze(false);
@@ -111,8 +111,8 @@ void DemoModel::square(float sigma) {
     auto home = squareLattice(n, 0), from = activeMesh;
     for (auto& m: home)
       m = m  * spacing + xyz(0, 0, -20);
-    uint const steps = 30;
-    for_int (s, steps + 1) {
+    int const steps = 30;
+    for(int s=0; s < steps + 1; ++s) {
       for (uint i=0; i < uint(ps.count()); ++i)
         ps.at(i)->transform(xyz::_0, from.at(i).interpolateTo(home.at(i), flt(s)/steps));
       snooze(false);
@@ -166,8 +166,8 @@ void DemoModel::one() {
 }
 
 void DemoModel::oneOut() {
-  uint const steps = 40;
-  for_i (steps + 1) {
+  int const steps = 40;
+  for(int i=0; i<steps+1; ++i) {
     flt a = 360.f / steps * i / 3;
     p->fancy(xyz(a, a, a), flt(steps-i) / steps);
     snooze(false);
@@ -182,8 +182,8 @@ void DemoModel::oneIn(particle::kind kind) {
 #endif
   p->transform(xyz::_0, xyz(0, 0, -hgtLayer));
 
-  uint const steps = 140;
-  for_i (steps + 1) {
+  int const steps = 140;
+  for(int i=0; i<steps+1; ++i) {
     flt a = 360.f / steps * i;
     p->fancy(xyz(a*2, a, a), flt(i) / steps);
     snooze(false);
@@ -206,8 +206,8 @@ void DemoModel::setCamera(Camera::pos_t::rc to, bool animate) {
   if (animate) {
     auto from = camPos;
 
-    uint const frames = 45;
-    for_i (frames + 1) {
+    int const frames = 45;
+    for(int i=0; i<frames+1; ++i) {
       defCamPos = from.interpolateTo(to, flt(i) / frames);
       snooze(true);
     }
diff --git a/GUI/ba3d/showcase/modelLayers.cpp b/GUI/ba3d/showcase/modelLayers.cpp
index f4feea458be..396bdacbc11 100644
--- a/GUI/ba3d/showcase/modelLayers.cpp
+++ b/GUI/ba3d/showcase/modelLayers.cpp
@@ -50,9 +50,9 @@ void ModelLayers::showKind(particle::kind k) {
 
   flt z[] = {-10, -30, -45};
   ps.reserve(3*9*9);
-  for_int (i, 9)
-    for_int (j, 9)
-      for_int (zi, 3) {
+  for(int i=0; i<9; ++i)
+    for(int j=0; j<9; ++j)
+      for(int zi=0; zi<3; ++zi) {
         auto p = ModelShowcase::newParticle(k, 3);
         add(p); ps.append(p);
         p->transform(xyz::_0, xyz((i-4)*sz/10, (j-4)*sz/10, z[zi]+.001f));
-- 
GitLab