Parcourir la source

Observe: fix rounded time

Eric Ramat il y a 1 an
Parent
commit
4cc7ffe0f4
1 fichiers modifiés avec 5 ajouts et 2 suppressions
  1. 5 2
      src/artis-star/common/observer/Observer.hpp

+ 5 - 2
src/artis-star/common/observer/Observer.hpp

@@ -75,11 +75,12 @@ public:
     if (_step == 0) {
     if (_step == 0) {
       observe(t);
       observe(t);
     } else {
     } else {
-      double time = std::ceil(t / _step) * _step;
+      double time = std::floor((t + epsilon) / _step) * _step;
 
 
-      while (time < next_t) {
+      while (time < next_t and std::abs(time - next_t) > epsilon) {
         observe(time);
         observe(time);
         time += _step;
         time += _step;
+        time = std::floor((time + epsilon) / _step) * _step;
       }
       }
     }
     }
   }
   }
@@ -99,6 +100,8 @@ private:
     }
     }
   }
   }
 
 
+  const double epsilon = 1e-6;
+
   double _step;
   double _step;
   const common::Model<Time> *_model;
   const common::Model<Time> *_model;
   Views _views;
   Views _views;