OpenShot Library | libopenshot  0.2.5
Fraction.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Header file for Fraction class
4  * @author Jonathan Thomas <jonathan@openshot.org>
5  *
6  * @ref License
7  */
8 
9 /* LICENSE
10  *
11  * Copyright (c) 2008-2019 OpenShot Studios, LLC
12  * <http://www.openshotstudios.com/>. This file is part of
13  * OpenShot Library (libopenshot), an open-source project dedicated to
14  * delivering high quality video editing and animation solutions to the
15  * world. For more information visit <http://www.openshot.org/>.
16  *
17  * OpenShot Library (libopenshot) is free software: you can redistribute it
18  * and/or modify it under the terms of the GNU Lesser General Public License
19  * as published by the Free Software Foundation, either version 3 of the
20  * License, or (at your option) any later version.
21  *
22  * OpenShot Library (libopenshot) is distributed in the hope that it will be
23  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU Lesser General Public License for more details.
26  *
27  * You should have received a copy of the GNU Lesser General Public License
28  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
29  */
30 
31 #ifndef OPENSHOT_FRACTION_H
32 #define OPENSHOT_FRACTION_H
33 
34 #include <math.h>
35 
36 namespace openshot {
37 
38  /**
39  * @brief This class represents a fraction
40  *
41  * Fractions are often used in video editing to represent ratios and rates, for example:
42  * pixel ratios, frames per second, timebase, and other common ratios. Fractions are preferred
43  * over decimals due to their increased precision.
44  */
45  class Fraction {
46  public:
47  int num; ///<Numerator for the fraction
48  int den; ///<Denominator for the fraction
49 
50  /// Default Constructor
51  Fraction();
52  /// Constructor with numerator and denominator
53  Fraction(int num, int den);
54 
55  /// Calculate the greatest common denominator
57 
58  /// Reduce this fraction (i.e. 640/480 = 4/3)
59  void Reduce();
60 
61  /// Return this fraction as a float (i.e. 1/2 = 0.5)
62  float ToFloat();
63 
64  /// Return this fraction as a double (i.e. 1/2 = 0.5)
65  double ToDouble();
66 
67  /// Return a rounded integer of the fraction (for example 30000/1001 returns 30)
68  int ToInt();
69 
70  /// Return the reciprocal as a Fraction
72  };
73 
74 
75 }
76 
77 #endif
openshot::Fraction::ToFloat
float ToFloat()
Return this fraction as a float (i.e. 1/2 = 0.5)
Definition: Fraction.cpp:44
openshot::Fraction::ToInt
int ToInt()
Return a rounded integer of the fraction (for example 30000/1001 returns 30)
Definition: Fraction.cpp:54
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: AudioBufferSource.h:39
openshot::Fraction
This class represents a fraction.
Definition: Fraction.h:45
openshot::Fraction::Reciprocal
Fraction Reciprocal()
Return the reciprocal as a Fraction.
Definition: Fraction.cpp:84
openshot::Fraction::GreatestCommonDenominator
int GreatestCommonDenominator()
Calculate the greatest common denominator.
Definition: Fraction.cpp:59
openshot::Fraction::Fraction
Fraction()
Default Constructor.
Definition: Fraction.cpp:36
openshot::Fraction::num
int num
Numerator for the fraction.
Definition: Fraction.h:47
openshot::Fraction::den
int den
Denominator for the fraction.
Definition: Fraction.h:48
openshot::Fraction::Reduce
void Reduce()
Reduce this fraction (i.e. 640/480 = 4/3)
Definition: Fraction.cpp:74
openshot::Fraction::ToDouble
double ToDouble()
Return this fraction as a double (i.e. 1/2 = 0.5)
Definition: Fraction.cpp:49