Loading...
Searching...
No Matches
openshot::Fraction Class Reference

This class represents a fraction. More...

`#include <Fraction.h>`

## Public Member Functions

| Fraction ()
| Default Constructor.
| Fraction (int num, int den)
| Constructor with numerator and denominator.
| Fraction (std::map< std::string, int > mapping)
| Constructor that takes a key-value mapping (keys: 'num'. 'den').
| Fraction (std::pair< int, int > pair)
| Constructor that accepts a (num, den) pair.
| Fraction (std::vector< int > vector)
| Constructor that takes a vector of length 2 (containing {num, den}).
int | GreatestCommonDenominator ()
| Calculate the greatest common denominator.
template<class numT>
numT | operator* (const numT &other) const
| Multiplication in the form (openshot_Fraction * numeric_value).
openshot::Fraction | operator* (openshot::Fraction other)
| Multiply two Fraction objects together.
template<class numT>
numT | operator/ (const numT &other) const
| Division in the form (openshot_Fraction / numeric_value).
openshot::Fraction | operator/ (openshot::Fraction other)
| Divide a Fraction by another Fraction.
Fraction | Reciprocal () const
| Return the reciprocal as a Fraction.
void | Reduce ()
| Reduce this fraction (i.e. 640/480 = 4/3).
double | ToDouble () const
| Return this fraction as a double (i.e. 1/2 = 0.5).
float | ToFloat ()
| Return this fraction as a float (i.e. 1/2 = 0.5).
int | ToInt ()
| Return a rounded integer of the fraction (for example 30000/1001 returns 30).

## Public Attributes

int | den
| Denominator for the fraction.
int | num
| Numerator for the fraction.

## Detailed Description

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.

Definition at line 30 of file Fraction.h.

## Constructor & Destructor Documentation

## Fraction() [1/5]

Fraction::Fraction | ( |  | ) |

Default Constructor.

Definition at line 19 of file Fraction.cpp.

Referenced by Fraction(), Fraction(), Fraction(), Fraction(), and Reciprocal().

## Fraction() [2/5]

Fraction::Fraction | ( | int | num,
|  | int | den )

Constructor with numerator and denominator.

Definition at line 31 of file Fraction.cpp.

## Fraction() [3/5]

Fraction::Fraction | ( | std::pair< int, int > | pair | ) |

Constructor that accepts a (num, den) pair.

Definition at line 21 of file Fraction.cpp.

## Fraction() [4/5]

Fraction::Fraction | ( | std::vector< int > | vector | ) |

Constructor that takes a vector of length 2 (containing {num, den}).

Definition at line 27 of file Fraction.cpp.

## Fraction() [5/5]

Fraction::Fraction | ( | std::map< std::string, int > | mapping | ) |

Constructor that takes a key-value mapping (keys: 'num'. 'den').

Definition at line 24 of file Fraction.cpp.

## Member Function Documentation

## GreatestCommonDenominator()

int Fraction::GreatestCommonDenominator | ( |  | ) |

Calculate the greatest common denominator.

Definition at line 50 of file Fraction.cpp.

Referenced by Reduce().

## operator*() [1/2]

template<class numT>

numT openshot::Fraction::operator* | ( | const numT & | other | ) | const

inline

Multiplication in the form (openshot_Fraction * numeric_value).

Definition at line 82 of file Fraction.h.

## operator*() [2/2]

openshot::Fraction openshot::Fraction::operator* | ( | openshot::Fraction | other | ) |

inline

Multiply two Fraction objects together.

Definition at line 71 of file Fraction.h.

## operator/() [1/2]

template<class numT>

numT openshot::Fraction::operator/ | ( | const numT & | other | ) | const

inline

Division in the form (openshot_Fraction / numeric_value).

Definition at line 88 of file Fraction.h.

## operator/() [2/2]

openshot::Fraction openshot::Fraction::operator/ | ( | openshot::Fraction | other | ) |

inline

Divide a Fraction by another Fraction.

Definition at line 76 of file Fraction.h.

## Reciprocal()

Fraction Fraction::Reciprocal | ( |  | ) | const

Return the reciprocal as a Fraction.

Definition at line 78 of file Fraction.cpp.

Referenced by openshot::TrackedObjectBBox::FrameNToTime(), openshot::Frame::GetSamplesPerFrame(), operator/(), openshot::ImageWriter::SetVideoOptions(), and openshot::Timeline::Timeline().

## Reduce()

void Fraction::Reduce | ( |  | ) |

Reduce this fraction (i.e. 640/480 = 4/3).

Definition at line 65 of file Fraction.cpp.

Referenced by openshot::ImageReader::Open(), openshot::QtHtmlReader::Open(), openshot::QtImageReader::Open(), openshot::QtTextReader::Open(), openshot::FFmpegWriter::SetVideoOptions(), and openshot::ImageWriter::SetVideoOptions().

## ToDouble()

double Fraction::ToDouble | ( |  | ) | const

Return this fraction as a double (i.e. 1/2 = 0.5).

Definition at line 40 of file Fraction.cpp.

Referenced by openshot::AudioWaveformer::ApplyKeyframes(), openshot::TrackedObjectBBox::FrameNToTime(), openshot::Caption::GetFrame(), openshot::Frame::GetSamplesPerFrame(), operator*(), openshot::operator*(), operator/(), openshot::operator/(), openshot::Profile::operator<, and openshot::Profile::operator>.

## ToFloat()

float Fraction::ToFloat | ( |  | ) |

Return this fraction as a float (i.e. 1/2 = 0.5).

Definition at line 35 of file Fraction.cpp.

Referenced by VideoRenderWidget::centeredViewport(), and openshot::Caption::GetFrame().

## ToInt()

int Fraction::ToInt | ( |  | ) |

Return a rounded integer of the fraction (for example 30000/1001 returns 30).

Definition at line 45 of file Fraction.cpp.

## Member Data Documentation

## den

int openshot::Fraction::den

Denominator for the fraction.

Definition at line 33 of file Fraction.h.

Referenced by openshot::FrameMapper::ChangeMapping(), openshot::WriterBase::CopyReaderInfo(), openshot::Frame::DeepCopy(), Fraction(), GreatestCommonDenominator(), openshot::QtHtmlReader::Open(), openshot::QtImageReader::Open(), openshot::QtTextReader::Open(), operator*(), openshot::Profile::operator==, Reciprocal(), Reduce(), openshot::FFmpegWriter::SetVideoOptions(), openshot::ImageWriter::SetVideoOptions(), ToDouble(), ToFloat(), and ToInt().

## num

int openshot::Fraction::num

Numerator for the fraction.

Definition at line 32 of file Fraction.h.

Referenced by openshot::FrameMapper::ChangeMapping(), openshot::WriterBase::CopyReaderInfo(), openshot::Frame::DeepCopy(), Fraction(), GreatestCommonDenominator(), openshot::QtHtmlReader::Open(), openshot::QtImageReader::Open(), openshot::QtTextReader::Open(), operator*(), openshot::Profile::operator==, Reciprocal(), Reduce(), openshot::FFmpegWriter::SetVideoOptions(), openshot::ImageWriter::SetVideoOptions(), ToDouble(), ToFloat(), and ToInt().

The documentation for this class was generated from the following files:

- Fraction.h
- Fraction.cpp