Loading...
Searching...
No Matches
sf::Angle Class Reference

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 Angleoperator+= (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 Angleoperator-= (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 Angleoperator*= (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 Angleoperator/= (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 Angleoperator%= (Angle &left, Angle right)
 Overload of binary operator%= to compute/assign remainder of an angle value.
 

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:

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
Represents an angle value.
Definition Angle.hpp:35
constexpr float asRadians() const
Return the angle's value in radians.
friend constexpr Angle radians(float angle)
Construct an angle value from a number of radians.
friend constexpr Angle degrees(float angle)
Construct an angle value from a number of degrees.
constexpr float asDegrees() const
Return the angle's value in degrees.
constexpr Angle radians(float angle)
Construct an angle value from a number of radians.
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()

constexpr sf::Angle::Angle ( )
constexprdefault

Default constructor.

Sets the angle value to zero.

Member Function Documentation

◆ asDegrees()

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

Return the angle's value in degrees.

Returns
Angle in degrees
See also
asRadians

◆ asRadians()

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

Return the angle's value in radians.

Returns
Angle in radians
See also
asDegrees

◆ wrapSigned()

constexpr Angle sf::Angle::wrapSigned ( ) const
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()

constexpr Angle sf::Angle::wrapUnsigned ( ) const
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

constexpr Angle degrees ( float  angle)
friend

Construct an angle value from a number of degrees.

Parameters
angleNumber of degrees
Returns
Angle value constructed from the number of degrees
See also
radians

◆ operator!=()

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

Overload of operator!= to compare two angle values.

Note
Does not automatically wrap the angle value
Parameters
leftLeft operand (an angle)
rightRight operand (an angle)
Returns
true if both angle values are different

◆ operator%()

constexpr 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)
Parameters
leftLeft operand (an angle)
rightRight operand (an angle)
Returns
left modulo right

◆ operator%=()

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

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

Parameters
leftLeft operand (an angle)
rightRight operand (an angle)
Returns
left modulo right

◆ operator*() [1/2]

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

Overload of binary operator* to scale an angle value.

Parameters
leftLeft operand (an angle)
rightRight operand (a number)
Returns
left multiplied by right

◆ operator*() [2/2]

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

Overload of binary operator* to scale an angle value.

Parameters
leftLeft operand (a number)
rightRight operand (an angle)
Returns
left multiplied by right

◆ operator*=()

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

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

Parameters
leftLeft operand (an angle)
rightRight operand (a number)
Returns
left multiplied by right

◆ operator+()

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

Overload of binary operator+ to add two angle values.

Parameters
leftLeft operand (an angle)
rightRight operand (an angle)
Returns
Sum of the two angle values

◆ operator+=()

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

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

Parameters
leftLeft operand (an angle)
rightRight operand (an angle)
Returns
Sum of the two angle values

◆ operator-() [1/2]

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

Overload of binary operator- to subtract two angle values.

Parameters
leftLeft operand (an angle)
rightRight operand (an angle)
Returns
Difference of the two angle values

◆ operator-() [2/2]

constexpr Angle operator- ( Angle  right)
related

Overload of unary operator- to negate an angle value.

Represents a rotation in the opposite direction.

Parameters
rightRight operand (an angle)
Returns
Negative of the angle value

◆ operator-=()

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

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

Parameters
leftLeft operand (an angle)
rightRight operand (an angle)
Returns
Difference of the two angle values

◆ operator/() [1/2]

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

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

Parameters
leftLeft operand (an angle)
rightRight operand (an angle)
Returns
left divided by right

◆ operator/() [2/2]

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

Overload of binary operator/ to scale an angle value.

Parameters
leftLeft operand (an angle)
rightRight operand (a number)
Returns
left divided by right

◆ operator/=()

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

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

Parameters
leftLeft operand (an angle)
rightRight operand (a number)
Returns
left divided by right

◆ operator<()

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

Overload of operator< to compare two angle values.

Note
Does not automatically wrap the angle value
Parameters
leftLeft operand (an angle)
rightRight operand (an angle)
Returns
true if left is less than right

◆ operator<=()

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

Overload of operator<= to compare two angle values.

Note
Does not automatically wrap the angle value
Parameters
leftLeft operand (an angle)
rightRight operand (an angle)
Returns
true if left is less than or equal to right

◆ operator==()

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

Overload of operator== to compare two angle values.

Note
Does not automatically wrap the angle value
Parameters
leftLeft operand (an angle)
rightRight operand (an angle)
Returns
true if both angle values are equal

◆ operator>()

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

Overload of operator> to compare two angle values.

Note
Does not automatically wrap the angle value
Parameters
leftLeft operand (an angle)
rightRight operand (an angle)
Returns
true if left is greater than right

◆ operator>=()

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

Overload of operator>= to compare two angle values.

Note
Does not automatically wrap the angle value
Parameters
leftLeft operand (an angle)
rightRight operand (an angle)
Returns
true if left is greater than or equal to right

◆ radians

constexpr Angle radians ( float  angle)
friend

Construct an angle value from a number of radians.

Parameters
angleNumber 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: