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 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::Frame::Display(), openshot::TrackedObjectBBox::FrameNToTime(), openshot::Frame::GetSamplesPerFrame(), openshot::ImageReader::Open(), operator/(), openshot::Frame::Save(), openshot::ImageWriter::SetVideoOptions(), openshot::Frame::Thumbnail(), openshot::Timeline::Timeline(), 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::TextReader::Open(), openshot::FFmpegWriter::SetVideoOptions(), openshot::ImageWriter::SetVideoOptions(), and openshot::Timeline::Timeline().

## 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::Timeline::apply_effects(), openshot::FrameMapper::ChangeMapping(), openshot::Frame::Display(), openshot::ReaderBase::DisplayInfo(), openshot::WriterBase::DisplayInfo(), openshot::FFmpegReader::FFmpegReader(), openshot::FrameMapper::FrameMapper(), openshot::TrackedObjectBBox::FrameNToTime(), openshot::Timeline::GetFrame(), openshot::Caption::GetFrame(), openshot::Timeline::GetMaxFrame(), openshot::Frame::GetSamplesPerFrame(), openshot::FFmpegReader::Open(), openshot::ImageReader::Open(), openshot::QtHtmlReader::Open(), openshot::QtImageReader::Open(), openshot::QtTextReader::Open(), openshot::TextReader::Open(), openshot::operator*(), operator*(), openshot::operator/(), operator/(), openshot::Clip::PropertiesJSON(), openshot::VideoCacheThread::run(), openshot::Frame::Save(), and openshot::Frame::Thumbnail().

## 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(), openshot::Clip::End(), openshot::Timeline::GetFrame(), openshot::Caption::GetFrame(), openshot::FFmpegReader::Open(), openshot::VideoCacheThread::run(), openshot::Timeline::SetJsonValue(), openshot::Timeline::Timeline(), openshot::Timeline::Timeline(), and openshot::ImageWriter::WriteFrame().

## 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(), openshot::Frame::Display(), openshot::ReaderBase::DisplayInfo(), openshot::WriterBase::DisplayInfo(), openshot::FrameMapper::FrameMapper(), openshot::FrameMapper::GetFrame(), GreatestCommonDenominator(), openshot::Profile::JsonValue(), openshot::WriterBase::JsonValue(), openshot::ReaderBase::JsonValue(), openshot::Tracker::JsonValue(), openshot::TrackedObjectBBox::JsonValue(), openshot::Profile::Key(), openshot::Profile::LongName(), openshot::Profile::LongNameWithDesc(), openshot::FFmpegReader::Open(), openshot::ImageReader::Open(), openshot::QtHtmlReader::Open(), openshot::QtImageReader::Open(), openshot::QtTextReader::Open(), openshot::TextReader::Open(), operator*(), openshot::Profile::Profile(), openshot::Profile::Profile(), Reciprocal(), Reduce(), openshot::Frame::Save(), openshot::Profile::SetJsonValue(), openshot::WriterBase::SetJsonValue(), openshot::Tracker::SetJsonValue(), openshot::TrackedObjectBBox::SetJsonValue(), openshot::ReaderBase::SetJsonValue(), openshot::Frame::SetPixelRatio(), openshot::FFmpegWriter::SetVideoOptions(), openshot::ImageWriter::SetVideoOptions(), openshot::Frame::Thumbnail(), ToDouble(), ToFloat(), ToInt(), and VideoRenderWidget::VideoRenderWidget().

## 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(), openshot::Frame::Display(), openshot::ReaderBase::DisplayInfo(), openshot::WriterBase::DisplayInfo(), openshot::FrameMapper::FrameMapper(), openshot::FrameMapper::GetFrame(), GreatestCommonDenominator(), openshot::Profile::JsonValue(), openshot::WriterBase::JsonValue(), openshot::ReaderBase::JsonValue(), openshot::Tracker::JsonValue(), openshot::TrackedObjectBBox::JsonValue(), openshot::Profile::Key(), openshot::Profile::LongName(), openshot::Profile::LongNameWithDesc(), openshot::FFmpegReader::Open(), openshot::ImageReader::Open(), openshot::QtHtmlReader::Open(), openshot::QtImageReader::Open(), openshot::QtTextReader::Open(), openshot::TextReader::Open(), operator*(), openshot::Profile::Profile(), openshot::Profile::Profile(), Reciprocal(), Reduce(), openshot::Frame::Save(), openshot::Profile::SetJsonValue(), openshot::WriterBase::SetJsonValue(), openshot::Tracker::SetJsonValue(), openshot::TrackedObjectBBox::SetJsonValue(), openshot::ReaderBase::SetJsonValue(), openshot::Frame::SetPixelRatio(), openshot::FFmpegWriter::SetVideoOptions(), openshot::ImageWriter::SetVideoOptions(), openshot::Frame::Thumbnail(), ToDouble(), ToFloat(), ToInt(), and VideoRenderWidget::VideoRenderWidget().

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

- Fraction.h
- Fraction.cpp