Ver código fonte

Observe: fix rounded time

Eric Ramat 1 ano atrás
pai
commit
4cc7ffe0f4
1 arquivos alterados com 5 adições e 2 exclusões
  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;