浏览代码

Observe: fix rounded time

Eric Ramat 1 年之前
父节点
当前提交
4cc7ffe0f4
共有 1 个文件被更改,包括 5 次插入2 次删除
  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;