SFML 3.0.0

- Main Page
- Topics
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Friends | Related Symbols | List of all members
sf::Angle Class Reference
System module

Represents an angle value. More...

`#include <SFML/System/Angle.hpp>`

## Public Member Functions
constexpr | Angle ()=default
| Default constructor.
constexpr float | asDegrees () const
| Return the angle's value in degrees.
constexpr float | asRadians () const
| Return the angle's value in radians.
constexpr Angle | wrapSigned () const
| Wrap to a range such that -180° <= angle < 180°
constexpr Angle | wrapUnsigned () const
| Wrap to a range such that 0° <= angle < 360°

## Static Public Attributes
static const Angle | Zero
| Predefined 0 degree angle value.

## Friends
constexpr Angle | degrees (float angle)
| Construct an angle value from a number of degrees.
constexpr Angle | radians (float angle)
| Construct an angle value from a number of radians.

## Related Symbols
(Note that these are not member symbols.)
constexpr bool | operator== (Angle left, Angle right)
| Overload of `operator==` to compare two angle values.
constexpr bool | operator!= (Angle left, Angle right)
| Overload of `operator!=` to compare two angle values.
constexpr bool | operator< (Angle left, Angle right)
| Overload of `operator<` to compare two angle values.
constexpr bool | operator> (Angle left, Angle right)
| Overload of `operator>` to compare two angle values.
constexpr bool | operator<= (Angle left, Angle right)
| Overload of `operator<=` to compare two angle values.
constexpr bool | operator>= (Angle left, Angle right)
| Overload of `operator>=` to compare two angle values.
constexpr Angle | operator- (Angle right)
| Overload of unary `operator-` to negate an angle value.
constexpr Angle | operator+ (Angle left, Angle right)
| Overload of binary `operator+` to add two angle values.
constexpr Angle & | operator+= (Angle &left, Angle right)
| Overload of binary `operator+=` to add/assign two angle values.
constexpr Angle | operator- (Angle left, Angle right)
| Overload of binary `operator-` to subtract two angle values.
constexpr Angle & | operator-= (Angle &left, Angle right)
| Overload of binary `operator-=` to subtract/assign two angle values.
constexpr Angle | operator* (Angle left, float right)
| Overload of binary `operator*` to scale an angle value.
constexpr Angle | operator* (float left, Angle right)
| Overload of binary `operator*` to scale an angle value.
constexpr Angle & | operator*= (Angle &left, float right)
| Overload of binary `operator*=` to scale/assign an angle value.
constexpr Angle | operator/ (Angle left, float right)
| Overload of binary `operator/` to scale an angle value.
constexpr Angle & | operator/= (Angle &left, float right)
| Overload of binary `operator/=` to scale/assign an angle value.
constexpr float | operator/ (Angle left, Angle right)
| Overload of binary `operator/` to compute the ratio of two angle values.
constexpr Angle | operator% (Angle left, Angle right)
| Overload of binary `operator%` to compute modulo of an angle value.
constexpr Angle & | operator%= (Angle &left, Angle right)
| Overload of binary `operator%=` to compute/assign remainder of an angle value.
constexpr Angle | operator""_deg (long double angle)
| User defined literal for angles in degrees, e.g. `10.5_deg`
constexpr Angle | operator""_deg (unsigned long long int angle)
| User defined literal for angles in degrees, e.g. `90_deg`
constexpr Angle | operator""_rad (long double angle)
| User defined literal for angles in radians, e.g. `0.1_rad`
constexpr Angle | operator""_rad (unsigned long long int angle)
| User defined literal for angles in radians, e.g. `2_rad`

## Detailed Description

Represents an angle value.

`sf::Angle` encapsulates an angle value in a flexible way.

It allows for defining an angle value either as a number of degrees or radians. It also works the other way around. You can read an angle value as either a number of degrees or radians.

By using such a flexible interface, the API doesn't impose any fixed type or unit for angle values and lets the user choose their own preferred representation.

Angle values support the usual mathematical operations. You can add or subtract two angles, multiply or divide an angle by a number, compare two angles, etc.

Usage example:

sf::Angle a1 = sf::degrees(90);
float radians = a1.asRadians(); // 1.5708f
sf::Angle a2 = sf::radians(3.141592654f);
float degrees = a2.asDegrees(); // 180.0f
using namespace sf::Literals;
sf::Angle a3 = 10_deg; // 10 degrees
sf::Angle a4 = 1.5_deg; // 1.5 degrees
sf::Angle a5 = 1_rad; // 1 radians
sf::Angle a6 = 3.14_rad; // 3.14 radians
sf::Angle
Represents an angle value.
Definition Angle.hpp:35
sf::Angle::asRadians
constexpr float asRadians() const
Return the angle's value in radians.
sf::Angle::radians
friend constexpr Angle radians(float angle)
Construct an angle value from a number of radians.
sf::Angle::degrees
friend constexpr Angle degrees(float angle)
Construct an angle value from a number of degrees.
sf::Angle::asDegrees
constexpr float asDegrees() const
Return the angle's value in degrees.
sf::Literals
Definition Angle.hpp:426
sf::radians
constexpr Angle radians(float angle)
Construct an angle value from a number of radians.
sf::degrees
constexpr Angle degrees(float angle)
Construct an angle value from a number of degrees.

Definition at line 34 of file Angle.hpp.

## Constructor & Destructor Documentation

## ◆ Angle()

sf::Angle::Angle | ( |  | ) |
| constexpr default

Default constructor.

Sets the angle value to zero.

## Member Function Documentation

## ◆ asDegrees()

float sf::Angle::asDegrees | ( |  | ) | const
| nodiscard constexpr

Return the angle's value in degrees.

Returns
  Angle in degrees

See also
  `asRadians`

## ◆ asRadians()

float sf::Angle::asRadians | ( |  | ) | const
| nodiscard constexpr

Return the angle's value in radians.

Returns
  Angle in radians

See also
  `asDegrees`

## ◆ wrapSigned()

Angle sf::Angle::wrapSigned | ( |  | ) | const
| nodiscard constexpr

Wrap to a range such that -180° <= angle < 180°

Similar to a modulo operation, this returns a copy of the angle constrained to the range [-180°, 180°) == [-Pi, Pi). The resulting angle represents a rotation which is equivalent to `*this`.

The name "signed" originates from the similarity to signed integers:

| signed | unsigned
--- | --- | ---
char | [-128, 128) | [0, 256)
Angle | [-180°, 180°) | [0°, 360°)

Returns
  Signed angle, wrapped to [-180°, 180°)

See also
  `wrapUnsigned`

## ◆ wrapUnsigned()

Angle sf::Angle::wrapUnsigned | ( |  | ) | const
| nodiscard constexpr

Wrap to a range such that 0° <= angle < 360°

Similar to a modulo operation, this returns a copy of the angle constrained to the range [0°, 360°) == [0, Tau) == [0, 2*Pi). The resulting angle represents a rotation which is equivalent to `*this`.

The name "unsigned" originates from the similarity to unsigned integers:

| signed | unsigned
--- | --- | ---
char | [-128, 128) | [0, 256)
Angle | [-180°, 180°) | [0°, 360°)

Returns
  Unsigned angle, wrapped to [0°, 360°)

See also
  `wrapSigned`

## Friends And Related Symbol Documentation

## ◆ degrees

Angle degrees | ( | float | angle | ) |
| friend

Construct an angle value from a number of degrees.

Parameters

  angle | Number of degrees

Returns
  Angle value constructed from the number of degrees

See also
  `radians`

## ◆ operator!=()

bool operator!= | ( | Angle | left,
|  | Angle | right )
| related

Overload of `operator!=` to compare two angle values.

Note
  Does not automatically wrap the angle value

Parameters

  left | Left operand (an angle)
  right | Right operand (an angle)

Returns
  `true` if both angle values are different

## ◆ operator""_deg() [1/2]

Angle operator""_deg | ( | long double | angle | ) |
| related

User defined literal for angles in degrees, e.g. `10.5_deg`

Parameters

  angle | Angle in degrees

Returns
  Angle

## ◆ operator""_deg() [2/2]

Angle operator""_deg | ( | unsigned long long int | angle | ) |
| related

User defined literal for angles in degrees, e.g. `90_deg`

Parameters

  angle | Angle in degrees

Returns
  Angle

## ◆ operator""_rad() [1/2]

Angle operator""_rad | ( | long double | angle | ) |
| related

User defined literal for angles in radians, e.g. `0.1_rad`

Parameters

  angle | Angle in radians

Returns
  Angle

## ◆ operator""_rad() [2/2]

Angle operator""_rad | ( | unsigned long long int | angle | ) |
| related

User defined literal for angles in radians, e.g. `2_rad`

Parameters

  angle | Angle in radians

Returns
  Angle

## ◆ operator%()

Angle operator% | ( | Angle | left,
|  | Angle | right )
| related

Overload of binary `operator%` to compute modulo of an angle value.

Right hand angle must be greater than zero.

Examples:

sf::degrees(90) % sf::degrees(40) // 10 degrees
sf::degrees(-90) % sf::degrees(40) // 30 degrees (not -10)
sf
Definition AudioResource.hpp:36

Parameters

  left | Left operand (an angle)
  right | Right operand (an angle)

Returns
  `left` modulo `right`

## ◆ operator%=()

Angle & operator%= | ( | Angle & | left,
|  | Angle | right )
| related

Overload of binary `operator%=` to compute/assign remainder of an angle value.

Parameters

  left | Left operand (an angle)
  right | Right operand (an angle)

Returns
  `left` modulo `right`

## ◆ operator*() [1/2]

Angle operator* | ( | Angle | left,
|  | float | right )
| related

Overload of binary `operator*` to scale an angle value.

Parameters

  left | Left operand (an angle)
  right | Right operand (a number)

Returns
  `left` multiplied by `right`

## ◆ operator*() [2/2]

Angle operator* | ( | float | left,
|  | Angle | right )
| related

Overload of binary `operator*` to scale an angle value.

Parameters

  left | Left operand (a number)
  right | Right operand (an angle)

Returns
  `left` multiplied by `right`

## ◆ operator*=()

Angle & operator*= | ( | Angle & | left,
|  | float | right )
| related

Overload of binary `operator*=` to scale/assign an angle value.

Parameters

  left | Left operand (an angle)
  right | Right operand (a number)

Returns
  `left` multiplied by `right`

## ◆ operator+()

Angle operator+ | ( | Angle | left,
|  | Angle | right )
| related

Overload of binary `operator+` to add two angle values.

Parameters

  left | Left operand (an angle)
  right | Right operand (an angle)

Returns
  Sum of the two angle values

## ◆ operator+=()

Angle & operator+= | ( | Angle & | left,
|  | Angle | right )
| related

Overload of binary `operator+=` to add/assign two angle values.

Parameters

  left | Left operand (an angle)
  right | Right operand (an angle)

Returns
  Sum of the two angle values

## ◆ operator-() [1/2]

Angle operator- | ( | Angle | left,
|  | Angle | right )
| related

Overload of binary `operator-` to subtract two angle values.

Parameters

  left | Left operand (an angle)
  right | Right operand (an angle)

Returns
  Difference of the two angle values

## ◆ operator-() [2/2]

Angle operator- | ( | Angle | right | ) |
| related

Overload of unary `operator-` to negate an angle value.

Represents a rotation in the opposite direction.

Parameters

  right | Right operand (an angle)

Returns
  Negative of the angle value

## ◆ operator-=()

Angle & operator-= | ( | Angle & | left,
|  | Angle | right )
| related

Overload of binary `operator-=` to subtract/assign two angle values.

Parameters

  left | Left operand (an angle)
  right | Right operand (an angle)

Returns
  Difference of the two angle values

## ◆ operator/() [1/2]

float operator/ | ( | Angle | left,
|  | Angle | right )
| related

Overload of binary `operator/` to compute the ratio of two angle values.

Parameters

  left | Left operand (an angle)
  right | Right operand (an angle)

Returns
  `left` divided by `right`

## ◆ operator/() [2/2]

Angle operator/ | ( | Angle | left,
|  | float | right )
| related

Overload of binary `operator/` to scale an angle value.

Parameters

  left | Left operand (an angle)
  right | Right operand (a number)

Returns
  `left` divided by `right`

## ◆ operator/=()

Angle & operator/= | ( | Angle & | left,
|  | float | right )
| related

Overload of binary `operator/=` to scale/assign an angle value.

Parameters

  left | Left operand (an angle)
  right | Right operand (a number)

Returns
  `left` divided by `right`

## ◆ operator<()

bool operator< | ( | Angle | left,
|  | Angle | right )
| related

Overload of `operator<` to compare two angle values.

Note
  Does not automatically wrap the angle value

Parameters

  left | Left operand (an angle)
  right | Right operand (an angle)

Returns
  `true` if left is less than right

## ◆ operator<=()

bool operator<= | ( | Angle | left,
|  | Angle | right )
| related

Overload of `operator<=` to compare two angle values.

Note
  Does not automatically wrap the angle value

Parameters

  left | Left operand (an angle)
  right | Right operand (an angle)

Returns
  `true` if left is less than or equal to right

## ◆ operator==()

bool operator== | ( | Angle | left,
|  | Angle | right )
| related

Overload of `operator==` to compare two angle values.

Note
  Does not automatically wrap the angle value

Parameters

  left | Left operand (an angle)
  right | Right operand (an angle)

Returns
  `true` if both angle values are equal

## ◆ operator>()

bool operator> | ( | Angle | left,
|  | Angle | right )
| related

Overload of `operator>` to compare two angle values.

Note
  Does not automatically wrap the angle value

Parameters

  left | Left operand (an angle)
  right | Right operand (an angle)

Returns
  `true` if left is greater than right

## ◆ operator>=()

bool operator>= | ( | Angle | left,
|  | Angle | right )
| related

Overload of `operator>=` to compare two angle values.

Note
  Does not automatically wrap the angle value

Parameters

  left | Left operand (an angle)
  right | Right operand (an angle)

Returns
  `true` if left is greater than or equal to right

## ◆ radians

Angle radians | ( | float | angle | ) |
| friend

Construct an angle value from a number of radians.

Parameters

  angle | Number of radians

Returns
  Angle value constructed from the number of radians

See also
  `degrees`

## Member Data Documentation

## ◆ Zero

const Angle sf::Angle::Zero
| static

Predefined 0 degree angle value.

Definition at line 135 of file Angle.hpp.

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

- Angle.hpp