math: revised timestamp calculations around epsilon
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user