Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/opentime/rationalTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ class OPENTIME_API_TYPE RationalTime
/// @brief Returns the time value converted to a new rate.
constexpr double value_rescaled_to(double new_rate) const noexcept
{
return new_rate == _rate ? _value : (_value * new_rate) / _rate;
return new_rate == _rate
? _value
: (_rate > 0 ? (_value * new_rate) / _rate : 0);
}

/// @brief Returns the time value converted to a new rate.
Expand Down
12 changes: 12 additions & 0 deletions tests/test_opentime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ main(int argc, char** argv)
assertFalse(t2.is_invalid_time());
});

tests.add_test("test_rescale", [] {
RationalTime t1(1.0, 1.0);
RationalTime t2 = t1.rescaled_to(24);
assertEqual(t2.value(), 24);
assertEqual(t2.rate(), 24);

// Try rescaling an invalid time:
t2 = RationalTime(1.0, 0.0).rescaled_to(24);
assertEqual(t2.value(), 0);
assertEqual(t2.rate(), 24);
});

tests.add_test("test_equality", [] {
RationalTime t1(30.2);
assertEqual(t1, t1);
Expand Down
Loading