Quellcode durchsuchen

Observe: fix rounded time

Eric Ramat vor 1 Jahr
Ursprung
Commit
4cc7ffe0f4
1 geänderte Dateien mit 5 neuen und 2 gelöschten Zeilen
  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) {
       observe(t);
     } 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);
         time += _step;
+        time = std::floor((time + epsilon) / _step) * _step;
       }
     }
   }
@@ -99,6 +100,8 @@ private:
     }
   }
 
+  const double epsilon = 1e-6;
+
   double _step;
   const common::Model<Time> *_model;
   Views _views;