mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-10-31 22:59:14 +00:00
value: Provide MulDiv extensions for fractions
This commit is contained in:
parent
0d872ae6f8
commit
5a553a1ff6
2 changed files with 29 additions and 1 deletions
|
@ -353,7 +353,7 @@ pub mod prelude {
|
||||||
task_pool::{TaskHandle, TaskPoolExtManual},
|
task_pool::{TaskHandle, TaskPoolExtManual},
|
||||||
typefind::TypeFindImpl,
|
typefind::TypeFindImpl,
|
||||||
utils::Displayable,
|
utils::Displayable,
|
||||||
value::GstValueExt,
|
value::{GstValueExt, MulDivExtFraction},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
use std::{cmp, fmt, ops, slice};
|
use std::{cmp, fmt, ops, slice};
|
||||||
|
|
||||||
use glib::{prelude::*, translate::*};
|
use glib::{prelude::*, translate::*};
|
||||||
|
use muldiv::MulDiv;
|
||||||
use num_rational::Rational32;
|
use num_rational::Rational32;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
|
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
|
||||||
|
@ -307,6 +308,33 @@ impl From<Fraction> for Rational32 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait MulDivExtFraction {
|
||||||
|
type Output;
|
||||||
|
|
||||||
|
fn mul_frac_floor(self, frac: Fraction) -> Option<Self::Output>;
|
||||||
|
fn mul_frac_round(self, frac: Fraction) -> Option<Self::Output>;
|
||||||
|
fn mul_frac_ceil(self, frac: Fraction) -> Option<Self::Output>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> MulDivExtFraction for T
|
||||||
|
where
|
||||||
|
T: MulDiv<i32>,
|
||||||
|
{
|
||||||
|
type Output = <Self as MulDiv<i32>>::Output;
|
||||||
|
|
||||||
|
fn mul_frac_floor(self, frac: Fraction) -> Option<Self::Output> {
|
||||||
|
self.mul_div_floor(frac.numer(), frac.denom())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn mul_frac_round(self, frac: Fraction) -> Option<Self::Output> {
|
||||||
|
self.mul_div_round(frac.numer(), frac.denom())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn mul_frac_ceil(self, frac: Fraction) -> Option<Self::Output> {
|
||||||
|
self.mul_div_ceil(frac.numer(), frac.denom())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl glib::types::StaticType for Fraction {
|
impl glib::types::StaticType for Fraction {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn static_type() -> glib::types::Type {
|
fn static_type() -> glib::types::Type {
|
||||||
|
|
Loading…
Reference in a new issue