-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bump Ratio to 3.0 #438
Bump Ratio to 3.0 #438
Conversation
Closing since Ratio 4.0 has been released ;) |
Reopening since Ratio v4.0.0 is only a release candidate ;) |
lib/membrane/clock.ex
Outdated
use Numbers, overload_operators: true | ||
|
||
if till_next < 0 do | ||
if Ratio.lt?(till_next, 0) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we overload operators if we don't use them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we are using them - the overloaded operators are not only comparison operators, but also arithmetic operators
lib/membrane/clock.ex
Outdated
use Numbers, overload_operators: true | ||
%{till_next: from_previous, clock_time: clock_time} = state | ||
clock_time = clock_time + from_previous | ||
ratio = clock_time / (state.time_provider.() - state.init_time) | ||
ratio = Ratio.div(Ratio.new(clock_time), Ratio.new(state.time_provider.() - state.init_time)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as above
…move unnecessary use Number clauses
lib/membrane/clock.ex
Outdated
@typedoc """ | ||
Ratio of the Clock time to the reference time. | ||
""" | ||
@type ratio_t :: Ratio.t() | non_neg_integer | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd leave this type
@typedoc """ | |
Ratio of the Clock time to the reference time. | |
""" | |
@type ratio_t :: Ratio.t() | non_neg_integer | |
@typedoc """ | |
Ratio of the Clock time to the reference time. | |
""" | |
@type ratio_t :: Ratio.t() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
lib/membrane/clock.ex
Outdated
clock_time = clock_time + from_previous | ||
ratio = clock_time / (state.time_provider.() - state.init_time) | ||
clock_time = Ratio.add(clock_time, from_previous) | ||
ratio = Ratio.new(clock_time, state.time_provider.() - state.init_time) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
div
is less confusing in this case IMO
ratio = Ratio.new(clock_time, state.time_provider.() - state.init_time) | |
ratio = Ratio.div(clock_time, state.time_provider.() - state.init_time) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
The reason why Ratio.new
was used there previously is because Ratio.new accepts both integers and Ratios as arguments, while Ratio.div
enforces usage of Ratio - I need to convert state.time_provider.() - state.init_time
into a Ratio by using Ratio.new
anyway :D
lib/membrane/core/timer.ex
Outdated
@@ -48,7 +48,7 @@ defmodule Membrane.Core.Timer do | |||
end | |||
|
|||
def tick(timer) do | |||
use Ratio | |||
use Numbers, overload_operators: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's be consistent and not use that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
lib/membrane/time.ex
Outdated
raise "Only integers and rationals can be converted with Membrane.Time.#{unquote(unit.plural)}" | ||
end | ||
def unquote(unit.plural)(number) when Ratio.is_rational(number) do | ||
use Numbers, overload_operators: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done here and also in clock_test.exs
This reverts commit d05b7fd.
This reverts commit d05b7fd.
This PR updates the Ratio dependency do 3.0 and updates the code accordingly to the changes in API. This PR should be merged once we decide to update Ratio dependency in all the plugins in organization.