summaryrefslogtreecommitdiff
path: root/osframework/source/SexyAppFramework/Ratio.h
blob: c5b77dc52fb09ed0763f42a0e92ea008d66a0b71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef __RATIO_H__
#define __RATIO_H__

namespace Sexy
{
	struct Ratio
	{
		Ratio();
		Ratio(int theNumerator, int theDenominator);
		void Set(int theNumerator, int theDenominator);
		bool operator==(const Ratio& theRatio) const;
		bool operator!=(const Ratio& theRatio) const;
		bool operator<(const Ratio& theRatio) const;
		int operator*(int theInt) const;
		int operator/(int theInt) const;
		int mNumerator;
		int mDenominator;
	};

	inline bool Ratio::operator==(const Ratio& theRatio) const
	{
		return mNumerator == theRatio.mNumerator && mDenominator == theRatio.mDenominator;
	}

	inline bool Ratio::operator!=(const Ratio& theRatio) const
	{
		return ! (*this == theRatio);
	}

	inline bool Ratio::operator<(const Ratio& theRatio) const
	{
		return (mNumerator*theRatio.mDenominator/mDenominator < theRatio.mNumerator)
			|| (mNumerator < theRatio.mNumerator*mDenominator/theRatio.mDenominator);
	}

	inline int Ratio::operator*(int theInt) const
	{
		return theInt * mNumerator / mDenominator;
	}

	inline int Ratio::operator/(int theInt) const
	{
		return theInt * mDenominator / mNumerator;
	}

	inline int operator*(int theInt, const Ratio& theRatio)
	{
		return theInt * theRatio.mNumerator / theRatio.mDenominator;
	}

	inline int operator/(int theInt, const Ratio& theRatio)
	{
		return theInt * theRatio.mDenominator / theRatio.mNumerator;
	}

}

#endif