diff --git a/src/Fraction.h b/src/Fraction.h index a09db625..32064969 100644 --- a/src/Fraction.h +++ b/src/Fraction.h @@ -38,62 +38,63 @@ namespace openshot { - /** - * @brief This class represents a fraction - * - * Fractions are often used in video editing to represent ratios and rates, for example: - * pixel ratios, frames per second, timebase, and other common ratios. Fractions are preferred - * over decimals due to their increased precision. - */ - class Fraction { - public: - int num; /// pair); + /// Constructor that accepts a (num, den) pair + Fraction(std::pair pair); - /// Constructor that takes a vector of length 2 (containing {num, den}) - Fraction(std::vector vector); + /// Constructor that takes a vector of length 2 (containing {num, den}) + Fraction(std::vector vector); - /// Constructor that takes a key-value mapping (keys: 'num'. 'den') - Fraction(std::map mapping); + /// Constructor that takes a key-value mapping (keys: 'num'. 'den') + Fraction(std::map mapping); - /// Calculate the greatest common denominator - int GreatestCommonDenominator(); + /// Calculate the greatest common denominator + int GreatestCommonDenominator(); - /// Reduce this fraction (i.e. 640/480 = 4/3) - void Reduce(); + /// Reduce this fraction (i.e. 640/480 = 4/3) + void Reduce(); - /// Return this fraction as a float (i.e. 1/2 = 0.5) - float ToFloat(); + /// Return this fraction as a float (i.e. 1/2 = 0.5) + float ToFloat(); - /// Return this fraction as a double (i.e. 1/2 = 0.5) - double ToDouble() const; + /// Return this fraction as a double (i.e. 1/2 = 0.5) + double ToDouble() const; - /// Return a rounded integer of the fraction (for example 30000/1001 returns 30) - int ToInt(); + /// Return a rounded integer of the fraction (for example 30000/1001 returns 30) + int ToInt(); - /// Return the reciprocal as a Fraction - Fraction Reciprocal() const; - }; + /// Return the reciprocal as a Fraction + Fraction Reciprocal() const; +}; - // Stream output operator for openshot::Fraction - template - std::basic_ostream& - operator<<(std::basic_ostream& o, const openshot::Fraction& frac) { - std::basic_ostringstream s; - s.flags(o.flags()); - s.imbue(o.getloc()); - s.precision(o.precision()); - s << "Fraction(" << frac.num << ", " << frac.den << ")"; - return o << s.str(); - }; -} +// Stream output operator for openshot::Fraction +template +std::basic_ostream& +operator<<(std::basic_ostream& o, const openshot::Fraction& frac) { + std::basic_ostringstream s; + s.flags(o.flags()); + s.imbue(o.getloc()); + s.precision(o.precision()); + s << "Fraction(" << frac.num << ", " << frac.den << ")"; + return o << s.str(); +}; + +} // namespace openshot #endif