OpenShot Library | libopenshot  0.2.6
Public Member Functions | Public Attributes | List of all members
openshot::Fraction Class Reference

This class represents a fraction. More...

#include <Fraction.h>

Public Member Functions

 Fraction ()
 Default Constructor. More...
 
 Fraction (int num, int den)
 Constructor with numerator and denominator. More...
 
 Fraction (std::pair< int, int > pair)
 Constructor that accepts a (num, den) pair. More...
 
 Fraction (std::vector< int > vector)
 Constructor that takes a vector of length 2 (containing {num, den}) More...
 
 Fraction (std::map< std::string, int > mapping)
 Constructor that takes a key-value mapping (keys: 'num'. 'den') More...
 
int GreatestCommonDenominator ()
 Calculate the greatest common denominator. More...
 
Fraction Reciprocal () const
 Return the reciprocal as a Fraction. More...
 
void Reduce ()
 Reduce this fraction (i.e. 640/480 = 4/3) More...
 
double ToDouble () const
 Return this fraction as a double (i.e. 1/2 = 0.5) More...
 
float ToFloat ()
 Return this fraction as a float (i.e. 1/2 = 0.5) More...
 
int ToInt ()
 Return a rounded integer of the fraction (for example 30000/1001 returns 30) More...
 

Public Attributes

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

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 48 of file Fraction.h.

Constructor & Destructor Documentation

◆ Fraction() [1/5]

Fraction::Fraction ( )

Default Constructor.

Definition at line 37 of file Fraction.cpp.

Referenced by Reciprocal().

◆ Fraction() [2/5]

Fraction::Fraction ( int  num,
int  den 
)

Constructor with numerator and denominator.

Definition at line 49 of file Fraction.cpp.

◆ Fraction() [3/5]

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

Constructor that accepts a (num, den) pair.

Definition at line 39 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 45 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 42 of file Fraction.cpp.

Member Function Documentation

◆ GreatestCommonDenominator()

int Fraction::GreatestCommonDenominator ( )

Calculate the greatest common denominator.

Definition at line 69 of file Fraction.cpp.

Referenced by Reduce().

◆ Reciprocal()

Fraction Fraction::Reciprocal ( ) const

◆ Reduce()

void Fraction::Reduce ( )

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

Definition at line 84 of file Fraction.cpp.

Referenced by openshot::ImageWriter::SetVideoOptions(), openshot::FFmpegWriter::SetVideoOptions(), and openshot::Timeline::Timeline().

◆ ToDouble()

double Fraction::ToDouble ( ) const

◆ ToFloat()

float Fraction::ToFloat ( )

◆ ToInt()

int Fraction::ToInt ( )

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

Definition at line 64 of file Fraction.cpp.

Referenced by openshot::FrameMapper::Reader().

Member Data Documentation

◆ den

int openshot::Fraction::den

Denominator for the fraction.

Definition at line 51 of file Fraction.h.

Referenced by openshot::Timeline::ApplyJsonDiff(), openshot::FrameMapper::ChangeMapping(), openshot::ChunkReader::ChunkReader(), openshot::FFmpegWriter::Close(), openshot::WriterBase::CopyReaderInfo(), openshot::Frame::DeepCopy(), openshot::Frame::Display(), openshot::WriterBase::DisplayInfo(), openshot::ReaderBase::DisplayInfo(), openshot::FrameMapper::FrameMapper(), openshot::Clip::GetEffect(), openshot::Caption::GetFrame(), openshot::FrameMapper::GetFrame(), GreatestCommonDenominator(), openshot::Profile::JsonValue(), openshot::WriterBase::JsonValue(), openshot::ReaderBase::JsonValue(), openshot::TrackedObjectBBox::JsonValue(), openshot::DecklinkWriter::Open(), openshot::ImageReader::Open(), openshot::QtImageReader::Open(), openshot::DecklinkReader::Open(), openshot::QtHtmlReader::Open(), openshot::TextReader::Open(), openshot::QtTextReader::Open(), openshot::Keyframe::PrintValues(), openshot::Profile::Profile(), Reciprocal(), Reduce(), openshot::Frame::Save(), openshot::Profile::SetJsonValue(), openshot::WriterBase::SetJsonValue(), openshot::ReaderBase::SetJsonValue(), openshot::TrackedObjectBBox::SetJsonValue(), openshot::Timeline::SetMaxSize(), openshot::Frame::SetPixelRatio(), openshot::ImageWriter::SetVideoOptions(), openshot::FFmpegWriter::SetVideoOptions(), openshot::Frame::Thumbnail(), ToDouble(), ToFloat(), ToInt(), VideoRenderWidget::VideoRenderWidget(), and openshot::FFmpegWriter::WriteTrailer().

◆ num

int openshot::Fraction::num

Numerator for the fraction.

Definition at line 50 of file Fraction.h.

Referenced by openshot::Timeline::ApplyJsonDiff(), openshot::FrameMapper::ChangeMapping(), openshot::ChunkReader::ChunkReader(), openshot::FFmpegWriter::Close(), openshot::WriterBase::CopyReaderInfo(), openshot::Frame::DeepCopy(), openshot::Frame::Display(), openshot::WriterBase::DisplayInfo(), openshot::ReaderBase::DisplayInfo(), openshot::FrameMapper::FrameMapper(), openshot::Clip::GetEffect(), openshot::Caption::GetFrame(), openshot::FrameMapper::GetFrame(), GreatestCommonDenominator(), openshot::Profile::JsonValue(), openshot::WriterBase::JsonValue(), openshot::ReaderBase::JsonValue(), openshot::TrackedObjectBBox::JsonValue(), openshot::DecklinkWriter::Open(), openshot::ImageReader::Open(), openshot::QtImageReader::Open(), openshot::DecklinkReader::Open(), openshot::QtHtmlReader::Open(), openshot::TextReader::Open(), openshot::QtTextReader::Open(), openshot::Keyframe::PrintValues(), openshot::Profile::Profile(), Reciprocal(), Reduce(), openshot::Frame::Save(), openshot::Profile::SetJsonValue(), openshot::WriterBase::SetJsonValue(), openshot::ReaderBase::SetJsonValue(), openshot::TrackedObjectBBox::SetJsonValue(), openshot::Timeline::SetMaxSize(), openshot::Frame::SetPixelRatio(), openshot::ImageWriter::SetVideoOptions(), openshot::FFmpegWriter::SetVideoOptions(), openshot::Frame::Thumbnail(), ToDouble(), ToFloat(), ToInt(), VideoRenderWidget::VideoRenderWidget(), and openshot::FFmpegWriter::WriteTrailer().


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