summaryrefslogtreecommitdiff
path: root/osframework/source/SexyAppFramework/Ratio.h
diff options
context:
space:
mode:
Diffstat (limited to 'osframework/source/SexyAppFramework/Ratio.h')
-rw-r--r--osframework/source/SexyAppFramework/Ratio.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/osframework/source/SexyAppFramework/Ratio.h b/osframework/source/SexyAppFramework/Ratio.h
new file mode 100644
index 0000000..c5b77dc
--- /dev/null
+++ b/osframework/source/SexyAppFramework/Ratio.h
@@ -0,0 +1,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