math: revised timestamp calculations around epsilon

This commit is contained in:
itsmattkc
2022-05-29 11:13:05 -07:00
parent bbf6f8f9f9
commit 29908f2d8b
3 changed files with 33 additions and 3 deletions
+12 -2
View File
@@ -304,14 +304,24 @@ int64_t Timecode::time_to_timestamp(const double &time, const rational &timebase
return 0;
}
const double eps = 0.000000000001;
switch (floor) {
case kRound:
default:
return qRound64(d);
case kFloor:
return qFloor(d);
if (d > qCeil(d)-eps) {
return qCeil(d);
} else {
return qFloor(d);
}
case kCeil:
return qCeil(d);
if (d < qFloor(d)+eps) {
return qFloor(d);
} else {
return qCeil(d);
}
}
}
+1 -1
View File
@@ -368,7 +368,7 @@ void TimeRangeListFrameIterator::UpdateIndexIfNecessary()
range_index_++;
if (range_index_ < list_.size()) {
current_ = Timecode::snap_time_to_timebase(list_.at(range_index_).in(), timebase_, Timecode::kRound);
current_ = Timecode::snap_time_to_timebase(list_.at(range_index_).in(), timebase_, Timecode::kCeil);
}
}
}
+20
View File
@@ -105,4 +105,24 @@ OLIVE_ADD_TEST(TimeRangeListFrameIteratorSize)
OLIVE_TEST_END;
}
OLIVE_ADD_TEST(TimeRangeListFrameIteratorSize2)
{
const rational timebase(1001, 30000);
TimeRangeList ranges;
ranges.insert(TimeRange(rational(247247, 30000), rational(31031, 3750))); // 1
TimeRange tr(rational(247247, 30000), rational(31031, 3750));
TimeRangeListFrameIterator iterator(ranges, timebase);
QVector<rational> vec = iterator.ToVector();
OLIVE_ASSERT_EQUAL(vec.size(), 1);
OLIVE_ASSERT_EQUAL(iterator.size(), vec.size());
OLIVE_TEST_END;
}
}