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.
This commit is contained in:
Colin Snover 2016-02-11 16:25:33 -06:00
parent 7d54f0aaaf
commit 4ba0ff8deb
2 changed files with 13 additions and 0 deletions

View file

@ -84,6 +84,8 @@ public:
int getNumerator() const { return _num; } int getNumerator() const { return _num; }
int getDenominator() const { return _denom; } int getDenominator() const { return _denom; }
bool isOne() const { return _num == _denom; }
void debugPrint(int debuglevel = 0, const char *caption = "Rational:") const; void debugPrint(int debuglevel = 0, const char *caption = "Rational:") const;
private: private:

View file

@ -130,4 +130,15 @@ public:
TS_ASSERT_EQUALS(r1 / 2, Common::Rational(1, 4)); TS_ASSERT_EQUALS(r1 / 2, Common::Rational(1, 4));
TS_ASSERT_EQUALS(2 / r1, Common::Rational(4, 1)); 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());
}
}; };