struct

Geode::Angle(T)

Inherits Comparable < Steppable < Struct < Value < Object

Base unit class for all rotation measurements.

The T type parameter is the type used to store the angle's value. It should be a numerical type, preferably Float32 or Float64.

Constructors

new(value : T)

Creates an angle from the specified value.

Source
zero

Creates an angle initialized at zero.

Source

Instance methods

%(amount : Number) : Angle

Computes the remainder after dividing the angle by the specified amount.

25.degrees % 10 # => 5°
Source
%(other : self) : Number

Computes the remainder after dividing the angle by another.

30.degrees % 4.degrees # => 2
Source
%(other : Angle) : Number

Computes the remainder after dividing the angle by another of a different type.

200.degrees % (Math::PI.radians / 3) # => 20
Source
&*(amount : Number) : Angle

Multiplies the angle by the specified amount.

Values will wrap instead of overflowing and raising an error.

15.degrees &* 5 # => 75°
Source
&+(other : self) : self

Adds two angles together.

Values will wrap instead of overflowing and raising an error.

30.degrees &+ 45.degrees # => 75°
Source
&-(other : self) : self

Subtracts another angle from this one.

Values will wrap instead of overflowing and raising an error.

90.degrees &- 30.degrees # => 60°
Source
*(amount : Number) : Angle

Multiplies the angle by the specified amount.

15.degrees * 5 # => 75°
Source
+(other : self) : self

Adds two angles together.

30.degrees + 45.degrees # => 75°
Source
+(other : Angle) : Angle

Adds two angles of different types together.

30.degrees + Math::PI.radians / 2 # => 120.0°
Source
-(other : self) : self

Subtracts another angle from this one.

90.degrees - 30.degrees # => 60°
Source
-(other : Angle) : Angle

Subtracts another angle of a different type from this one.

180.degrees - Math::PI.radians / 2 # => 90.0°
Source
-

Returns a negated angle.

-(45.degrees) # => -45°
Source
/(amount : Number) : Angle

Divides the angle by the specified amount.

90.degrees / 4 # => 22.5°
Source
/(other : self) : Number

Divides the angle by another.

180.degrees / 45.degrees # => 4.0
Source
/(other : Angle) : Number

Divides the angle by another of a different type.

180.degrees / (Math::PI.radians / 3) # => 3.0
Source
//(amount : Number) : Angle

Divides the angle by the specified amount.

Uses integer division.

25.degrees // 10 # => 2°
Source
//(other : self) : Number

Divides the angle by another.

Uses integer division.

30.degrees // 4.degrees # => 7
Source
//(other : Angle) : Number

Divides the angle by another of a different type.

Uses integer division.

200.degrees // (Math::PI.radians / 3) # => 3
Source
<=>(other : self)

Compares this angle to another.

The return value will be:

  • -1 if this angle is less than other.
  • 0 if the angles are equal.
  • 1 if this angle is greater than other.
45.degrees <=> 90.degrees # => -1
60.degrees <=> 60.degrees # => 0
90.degrees <=> 45.degrees # => 1
Source
<=>(other : Angle)

Compares this angle to another of a different type.

The return value will be:

  • -1 if this angle is less than other.
  • 0 if the angles are equal.
  • 1 if this angle is greater than other.
45.degrees <=> (Math::PI).radians     # => -1
180.degrees <=> (Math::PI).radians    # => 0
90.degrees <=> (Math::PI / 4).radians # => 1
Source
abs

Returns the absolute value of the angle.

-45.degrees.abs # => 45°
Source
abs2

Returns the angle squared.

5.degrees.abs2 # => 25°
Source
acute?

Returns true if the angle is greater than zero and less than a right-angle (quarter revolution).

0.degrees.acute?  # => false
45.degrees.acute? # => true
90.degrees.acute? # => false
Source
ceil

Returns an angle rounded up to the nearest integer.

25.3.degrees.ceil # => 26.0°
Source
floor

Returns an angle rounded down to the nearest integer.

5.7.degrees.floor # => 5.0°
Source
fraction

Returns the fraction portion of the angle's value.

This is effectively equal to:

fraction(v) = v - floor(v)
1.2.degrees.fraction # => 0.2°
Source
full?

Returns true if the angle is a full angle (one revolution).

Multiples of full revolutions are not considered full angles.

0.degrees.full?   # => false
360.degrees.full? # => true
720.degrees.full? # => false
Source
lerp(other : self, t : Number) : self

Calculates the linear interpolation between two angles.

t is a value from 0 to 1, where 0 represents this angle and 1 represents other. Any value between 0 and 1 will result in a proportional amount of this angle and other.

This method uses the precise calculation that does not suffer precision loss from high exponential differences.

Source
near_zero?(tolerance : self)

Checks if the angle is close to zero.

The value must be within tolerance of zero.

0.degrees.near_zero?(1.degrees)  # => true
1.degrees.near_zero?(1.degrees)  # => true
30.degrees.near_zero?(1.degrees) # => false
Source
near_zero?(tolerance : Angle)

Checks if the angle is close to zero.

The value must be within tolerance of zero.

0.radians.near_zero?(1.degrees)        # => true
0.01.radians.near_zero?(1.degrees)     # => true
Math::PI.radians.near_zero?(1.degrees) # => false
Source
near_zero?(tolerance : Number)

Checks if the angle is close to zero.

The value must be within tolerance of zero.

0.degrees.near_zero?(1)  # => true
1.degrees.near_zero?(1)  # => true
30.degrees.near_zero?(1) # => false
Source
negative?

Checks if the angle is negative.

-5.degrees.negative? # => true
5.degrees.negative?  # => false
Source
normalize

Returns an angle corrected to be between zero and one revolution.

30.degrees.normalize  # => 30°
-90.degrees.normalize # => 270°
360.degrees.normalize # => 0°
540.degrees.normalize # => 180°
Source
oblique?

Returns true if the angle isn't a multiple of a right angle.

45.degrees.oblique?  # => true
90.degrees.oblique?  # => false
180.degrees.oblique? # => false
360.degrees.oblique? # => false
Source
obtuse?

Returns true if the angle is greater than a right angle and less than a straight angle.

90.degrees.obtuse?  # => false
135.degrees.obtuse? # => true
180.degrees.obtuse? # => false
Source
positive?

Checks if the angle is positive.

5.degrees.positive?  # => true
-5.degrees.positive? # => false
Source
reflex?

Returns true if the angle is greater than a straight angle and less than a full angle.

180.degrees.reflex? # => false
270.degrees.reflex? # => true
360.degrees.reflex? # => false
Source
right?

Returns true if the angle is a right angle (quarter revolution).

Multiples of quarter revolutions are not considered right angles.

0.degrees.right?   # => false
90.degrees.right?  # => true
180.degrees.right? # => false
270.degrees.right? # => false
Source
round(mode : Number::RoundingMode = :ties_even) : self

Returns a rounded angle.

See Number#round for details.

90.1.degrees.round # => 90.0°
Source
round(digits : Number, base = 10, *, mode : Number::RoundingMode = :ties_even) : self

Returns a rounded angle.

See Number#round for details.

12.34.degrees.round(1) # => 12.3°
Source
sign

Returns a value equal to its original sign.

1 is used for positive values, -1 for negative values, and 0 for zero.

-5.degrees.sign # => -1
Source
signed_normalize

Returns an angle corrected to be between negative half a revolution to positive half a revolution.

30.degrees.normalize   # => 30°
-45.degrees.normalize  # => -45°
360.degrees.normalize  # => 0°
270.degrees.normalize  # => -90°
-225.degrees.normalize # => 135°
Source
straight?

Returns true if the angle is a straight angle (half revolution).

Multiples of half revolutions are not considered straight angles.

0.degrees.straight?   # => false
180.degrees.straight? # => true
360.degrees.straight? # => false
Source
to_f

Converts the angle to radians and returns it as a floating-point value.

Source
to_unsafe

Converts the angle to radians and returns it as a floating-point value.

Source
value

Underlying value.

Source
zero?

Checks if the angle is zero.

0.degrees.zero?  # => true
90.degrees.zero? # => false
Source