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