| Flutter Impeller |

Public Member Functions | List of all members
impeller::Rational Class Reference

`#include <rational.h>`

## Public Member Functions
constexpr | Rational (int32_t num)
constexpr | Rational (int32_t num, uint32_t den)
int32_t | GetNumerator () const
uint32_t | GetDenominator () const
bool | operator== (const Rational &that) const
bool | operator< (const Rational &that) const
uint64_t | GetHash () const
| operator Scalar () const
Rational | Invert () const

## Detailed Description

Definition at line 13 of file rational.h.

## Constructor & Destructor Documentation

## ◆ Rational() [1/2]

constexpr impeller::Rational::Rational | ( | int32_t | num | ) |
| inlineexplicitconstexpr

Definition at line 15 of file rational.h.

15 : num_(num), den_(1) {}

Referenced by Invert().

## ◆ Rational() [2/2]

constexpr impeller::Rational::Rational | ( | int32_t | num,
|  | uint32_t | den
| ) |  |
| inlineconstexpr

Definition at line 17 of file rational.h.

17 : num_(num), den_(den) {}

## Member Function Documentation

## ◆ GetDenominator()

uint32_t impeller::Rational::GetDenominator | ( |  | ) | const
| inline

Definition at line 21 of file rational.h.

21 { return den_; }

Referenced by impeller::TextFrame::RoundScaledFontSize().

## ◆ GetHash()

uint64_t impeller::Rational::GetHash | ( |  | ) | const

Definition at line 38 of file rational.cc.

38 {
39 if (num_ == 0) {
40 return 0;
41 }
42 uint64_t gcd = std::gcd(num_, den_);
43 return ((num_ / gcd) << 32) | (den_ / gcd);
44 }

Referenced by impeller::TextShadowCache::TextShadowCacheKey::Hash::operator()().

## ◆ GetNumerator()

int32_t impeller::Rational::GetNumerator | ( |  | ) | const
| inline

Definition at line 19 of file rational.h.

19 { return num_; }

Referenced by impeller::TextFrame::RoundScaledFontSize().

## ◆ Invert()

Rational impeller::Rational::Invert | ( |  | ) | const

Definition at line 46 of file rational.cc.

46 {
47 if (num_ >= 0) {
48 return Rational(den_, num_);
49 } else {
50 return Rational(-1 * static_cast<int32_t>(den_), std::abs(num_));
51 }
52 }
impeller::Rational::Rational
constexpr Rational(int32_t num)
Definition: rational.h:15

References Rational().

Referenced by impeller::TextContents::ComputeVertexData().

## ◆ operator Scalar()

impeller::Rational::operator Scalar | ( |  | ) | const
| inlineexplicit

Definition at line 29 of file rational.h.

29 { return static_cast<float>(num_) / den_; }

## ◆ operator<()

bool impeller::Rational::operator< | ( | const Rational & | that | ) | const

Definition at line 28 of file rational.cc.

28 {
29 if (den_ == that.den_) {
30 return num_ < that.num_;
31 } else if ((num_ >= 0) != (that.num_ >= 0)) {
32 return num_ < that.num_;
33 } else {
34 return AbsToUnsigned(num_) * that.den_ < AbsToUnsigned(that.num_) * den_;
35 }
36 }

## ◆ operator==()

bool impeller::Rational::operator== | ( | const Rational & | that | ) | const

Definition at line 18 of file rational.cc.

18 {
19 if (den_ == that.den_) {
20 return num_ == that.num_;
21 } else if ((num_ >= 0) != (that.num_ >= 0)) {
22 return false;
23 } else {
24 return AbsToUnsigned(num_) * that.den_ == AbsToUnsigned(that.num_) * den_;
25 }
26 }

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

- impeller/geometry/rational.h
- impeller/geometry/rational.cc