bn::fixed_point class

Defines a two-dimensional point using fixed point precision.

Constructors, destructors, conversion operators

fixed_point() defaulted constexpr
Default constructor.
fixed_point(fixed x, fixed y) constexpr
Constructor.
fixed_point(const point& point) constexpr
Constructor.

Public functions

auto x() const -> fixed constexpr
Returns the horizontal coordinate.
void set_x(fixed x) constexpr
Sets the horizontal coordinate.
auto y() const -> fixed constexpr
Returns the vertical coordinate.
void set_y(fixed y) constexpr
Sets the vertical coordinate.
auto multiplication(int value) const -> fixed_point constexpr
Returns the multiplication of this point by the given integer value.
auto multiplication(fixed value) const -> fixed_point constexpr
Returns the multiplication of this point by the given fixed point value, using half precision to try to avoid overflow.
auto safe_multiplication(int value) const -> fixed_point constexpr
Returns the multiplication of this point by the given integer value.
auto safe_multiplication(fixed value) const -> fixed_point constexpr
Returns the multiplication of this point by the given fixed point value, casting them to int64_t to try to avoid overflow.
auto unsafe_multiplication(int value) const -> fixed_point constexpr
Returns the multiplication of this point by the given integer value.
auto unsafe_multiplication(fixed value) const -> fixed_point constexpr
Returns the multiplication of this point by the given fixed point value without trying to avoid overflow.
auto division(int value) const -> fixed_point constexpr
Returns the division of this point by the given integer value.
auto division(fixed value) const -> fixed_point constexpr
Returns the division of this point by the given fixed point value, using half precision to try to avoid overflow.
auto safe_division(int value) const -> fixed_point constexpr
Returns the division of this value by the given integer value.
auto safe_division(fixed value) const -> fixed_point constexpr
Returns the division of this point by the given fixed point value, casting them to int64_t to try to avoid overflow.
auto unsafe_division(int value) const -> fixed_point constexpr
Returns the division of this value by the given integer value.
auto unsafe_division(fixed value) const -> fixed_point constexpr
Returns the division of this point by the given fixed point value without trying to avoid overflow.
auto operator-() const -> fixed_point constexpr
Returns a fixed_point that is formed by changing the sign of both coordinates.
auto operator+=(const fixed_point& other) -> fixed_point& constexpr
Adds the given fixed_point to this one.
auto operator-=(const fixed_point& other) -> fixed_point& constexpr
Subtracts the given fixed_point to this one.
auto operator*=(int value) -> fixed_point& constexpr
Multiplies both coordinates by the given factor.
auto operator*=(fixed value) -> fixed_point& constexpr
Multiplies both coordinates by the given factor.
auto operator/=(int value) -> fixed_point& constexpr
Divides both coordinates by the given divisor.
auto operator/=(fixed value) -> fixed_point& constexpr
Divides both coordinates by the given divisor.

Friends

auto operator+(const fixed_point& a, const fixed_point& b) -> fixed_point constexpr
Returns the sum of a and b.
auto operator-(const fixed_point& a, const fixed_point& b) -> fixed_point constexpr
Returns b subtracted from a.
auto operator*(const fixed_point& a, int b) -> fixed_point constexpr
Returns a multiplied by b.
auto operator*(const fixed_point& a, fixed b) -> fixed_point constexpr
Returns a multiplied by b.
auto operator/(const fixed_point& a, int b) -> fixed_point constexpr
Returns a divided by b.
auto operator/(const fixed_point& a, fixed b) -> fixed_point constexpr
Returns a divided by b.
auto operator==(const fixed_point& a, const fixed_point& b) -> bool defaulted constexpr
Default equal operator.

Function documentation

bn::fixed_point::fixed_point(fixed x, fixed y) constexpr

Constructor.

Parameters
x Horizontal coordinate.
y Vertical coordinate.

bn::fixed_point::fixed_point(const point& point) constexpr

Constructor.

Parameters
point Integer point.

fixed_point& bn::fixed_point::operator+=(const fixed_point& other) constexpr

Adds the given fixed_point to this one.

Parameters
other fixed_point to add.
Returns Reference to this.

fixed_point& bn::fixed_point::operator-=(const fixed_point& other) constexpr

Subtracts the given fixed_point to this one.

Parameters
other fixed_point to subtract.
Returns Reference to this.

fixed_point& bn::fixed_point::operator*=(int value) constexpr

Multiplies both coordinates by the given factor.

Parameters
value Integer multiplication factor.
Returns Reference to this.

fixed_point& bn::fixed_point::operator*=(fixed value) constexpr

Multiplies both coordinates by the given factor.

Parameters
value Fixed point multiplication factor.
Returns Reference to this.

fixed_point& bn::fixed_point::operator/=(int value) constexpr

Divides both coordinates by the given divisor.

Parameters
value Valid integer divisor (!= 0).
Returns Reference to this.

fixed_point& bn::fixed_point::operator/=(fixed value) constexpr

Divides both coordinates by the given divisor.

Parameters
value Valid fixed point divisor (!= 0).
Returns Reference to this.