diff options
author | Colin Snover | 2016-02-11 16:25:33 -0600 |
---|---|---|
committer | Colin Snover | 2016-02-18 13:18:02 -0600 |
commit | 4ba0ff8deb57aba3b034462c6c00ecf13ee281c9 (patch) | |
tree | 82822210546cb4839acc077c5fb3fc69cefae586 | |
parent | 7d54f0aaaf1854e421ee0e8eac3292c7bc0db284 (diff) | |
download | scummvm-rg350-4ba0ff8deb57aba3b034462c6c00ecf13ee281c9.tar.gz scummvm-rg350-4ba0ff8deb57aba3b034462c6c00ecf13ee281c9.tar.bz2 scummvm-rg350-4ba0ff8deb57aba3b034462c6c00ecf13ee281c9.zip |
COMMON: Add convenience method to Common::Rational for 1:1 ratios
For SCI engine games, ratios may not be normalised and so to avoid
extra scaling, there needs to be a way to simply check whether a
ratio is 1:1.
-rw-r--r-- | common/rational.h | 2 | ||||
-rw-r--r-- | test/common/rational.h | 11 |
2 files changed, 13 insertions, 0 deletions
diff --git a/common/rational.h b/common/rational.h index 55fb361774..89caaf25b4 100644 --- a/common/rational.h +++ b/common/rational.h @@ -84,6 +84,8 @@ public: int getNumerator() const { return _num; } int getDenominator() const { return _denom; } + bool isOne() const { return _num == _denom; } + void debugPrint(int debuglevel = 0, const char *caption = "Rational:") const; private: diff --git a/test/common/rational.h b/test/common/rational.h index 46dfc278c7..23d0c10acd 100644 --- a/test/common/rational.h +++ b/test/common/rational.h @@ -130,4 +130,15 @@ public: TS_ASSERT_EQUALS(r1 / 2, Common::Rational(1, 4)); TS_ASSERT_EQUALS(2 / r1, Common::Rational(4, 1)); } + + void test_isOne() { + Common::Rational r0(5, 5); + Common::Rational r1(1, 2); + Common::Rational r2(2, 1); + Common::Rational r3(1, 1); + TS_ASSERT(r0.isOne()); + TS_ASSERT(!r1.isOne()); + TS_ASSERT(!r2.isOne()); + TS_ASSERT(r3.isOne()); + } }; |