You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Fraction: Templated / and * operators
This commit is contained in:
@@ -64,8 +64,44 @@ public:
|
||||
|
||||
/// Return the reciprocal as a Fraction
|
||||
Fraction Reciprocal() const;
|
||||
|
||||
// Multiplication and division
|
||||
|
||||
/// Multiply two Fraction objects together
|
||||
openshot::Fraction operator*(openshot::Fraction other) {
|
||||
return openshot::Fraction(num * other.num, den * other.den);
|
||||
}
|
||||
|
||||
/// Divide a Fraction by another Fraction
|
||||
openshot::Fraction operator/(openshot::Fraction other) {
|
||||
return *this * other.Reciprocal();
|
||||
}
|
||||
|
||||
/// Multiplication in the form (openshot_Fraction * numeric_value)
|
||||
template<class numT>
|
||||
numT operator*(const numT& other) const {
|
||||
return static_cast<numT>(ToDouble() * other);
|
||||
}
|
||||
|
||||
/// Division in the form (openshot_Fraction / numeric_value)
|
||||
template<class numT>
|
||||
numT operator/(const numT& other) const {
|
||||
return static_cast<numT>(ToDouble() / other);
|
||||
}
|
||||
};
|
||||
|
||||
/// Multiplication in the form (numeric_value * openshot_Fraction)
|
||||
template<class numT>
|
||||
numT operator*(const numT& left, const openshot::Fraction& right) {
|
||||
return static_cast<numT>(left * right.ToDouble());
|
||||
}
|
||||
|
||||
/// Division in the form (numeric_value / openshot_Fraction)
|
||||
template<class numT>
|
||||
numT operator/(const numT& left, const openshot::Fraction& right) {
|
||||
return static_cast<numT>(left / right.ToDouble());
|
||||
}
|
||||
|
||||
// Stream output operator for openshot::Fraction
|
||||
template<class charT, class traits>
|
||||
std::basic_ostream<charT, traits>&
|
||||
|
||||
Reference in New Issue
Block a user