abstract struct Geode::Angle(T)
- Geode::Angle(T)
- Struct
- Value
- Object
Overview
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
.
Included Modules
- Comparable(Geode::Angle(T))
- Steppable
Direct Known Subclasses
Defined in:
geode/angles/angle.crgeode/angles/comparison.cr
geode/angles/operations.cr
Constructors
-
.new(value : T)
Creates an angle from the specified value.
-
.zero : self
Creates an angle initialized at zero.
Instance Method Summary
-
#%(amount : Number) : Angle
Computes the remainder after dividing the angle by the specified amount.
-
#%(other : self) : Number
Computes the remainder after dividing the angle by another.
-
#%(other : Angle) : Number
Computes the remainder after dividing the angle by another of a different type.
-
#&*(amount : Number) : Angle
Multiplies the angle by the specified amount.
-
#&+(other : self) : self
Adds two angles together.
-
#&-(other : self) : self
Subtracts another angle from this one.
-
#*(amount : Number) : Angle
Multiplies the angle by the specified amount.
-
#+(other : self) : self
Adds two angles together.
-
#+(other : Angle) : Angle
Adds two angles of different types together.
-
#-(other : self) : self
Subtracts another angle from this one.
-
#-(other : Angle) : Angle
Subtracts another angle of a different type from this one.
-
#- : self
Returns a negated angle.
-
#/(amount : Number) : Angle
Divides the angle by the specified amount.
-
#/(other : self) : Number
Divides the angle by another.
-
#/(other : Angle) : Number
Divides the angle by another of a different type.
-
#//(amount : Number) : Angle
Divides the angle by the specified amount.
-
#//(other : self) : Number
Divides the angle by another.
-
#//(other : Angle) : Number
Divides the angle by another of a different type.
-
#<=>(other : self)
Compares this angle to another.
-
#<=>(other : Angle)
Compares this angle to another of a different type.
-
#abs : self
Returns the absolute value of the angle.
-
#abs2 : self
Returns the angle squared.
-
#acute?
Returns true if the angle is greater than zero and less than a right-angle (quarter revolution).
-
#ceil : self
Returns an angle rounded up to the nearest integer.
-
#floor : self
Returns an angle rounded down to the nearest integer.
-
#fraction : self
Returns the fraction portion of the angle's value.
-
#full?
Returns true if the angle is a full angle (one revolution).
-
#lerp(other : self, t : Number) : self
Calculates the linear interpolation between two angles.
-
#near_zero?(tolerance : self)
Checks if the angle is close to zero.
-
#near_zero?(tolerance : Angle)
Checks if the angle is close to zero.
-
#near_zero?(tolerance : Number)
Checks if the angle is close to zero.
-
#negative?
Checks if the angle is negative.
-
#normalize : self
Returns an angle corrected to be between zero and one revolution.
-
#oblique?
Returns true if the angle isn't a multiple of a right angle.
-
#obtuse?
Returns true if the angle is greater than a right angle and less than a straight angle.
-
#positive?
Checks if the angle is positive.
-
#reflex?
Returns true if the angle is greater than a straight angle and less than a full angle.
-
#right?
Returns true if the angle is a right angle (quarter revolution).
-
#round(mode : Number::RoundingMode = :ties_even) : self
Returns a rounded angle.
-
#round(digits : Number, base = 10, *, mode : Number::RoundingMode = :ties_even) : self
Returns a rounded angle.
-
#sign
Returns a value equal to its original sign.
-
#signed_normalize : self
Returns an angle corrected to be between negative half a revolution to positive half a revolution.
-
#straight?
Returns true if the angle is a straight angle (half revolution).
-
#to_f : Float
Converts the angle to radians and returns it as a floating-point value.
-
#to_unsafe
Converts the angle to radians and returns it as a floating-point value.
-
#value : T
Underlying value.
-
#zero?
Checks if the angle is zero.
Constructor Detail
Instance Method Detail
Computes the remainder after dividing the angle by the specified amount.
25.degrees % 10 # => 5°
Computes the remainder after dividing the angle by another.
30.degrees % 4.degrees # => 2
Computes the remainder after dividing the angle by another of a different type.
200.degrees % (Math::PI.radians / 3) # => 20
Multiplies the angle by the specified amount.
Values will wrap instead of overflowing and raising an error.
15.degrees &* 5 # => 75°
Adds two angles together.
Values will wrap instead of overflowing and raising an error.
30.degrees &+ 45.degrees # => 75°
Subtracts another angle from this one.
Values will wrap instead of overflowing and raising an error.
90.degrees &- 30.degrees # => 60°
Multiplies the angle by the specified amount.
15.degrees * 5 # => 75°
Adds two angles together.
30.degrees + 45.degrees # => 75°
Adds two angles of different types together.
30.degrees + Math::PI.radians / 2 # => 120.0°
Subtracts another angle from this one.
90.degrees - 30.degrees # => 60°
Subtracts another angle of a different type from this one.
180.degrees - Math::PI.radians / 2 # => 90.0°
Divides the angle by the specified amount.
90.degrees / 4 # => 22.5°
Divides the angle by another.
180.degrees / 45.degrees # => 4.0
Divides the angle by another of a different type.
180.degrees / (Math::PI.radians / 3) # => 3.0
Divides the angle by the specified amount.
Uses integer division.
25.degrees // 10 # => 2°
Divides the angle by another.
Uses integer division.
30.degrees // 4.degrees # => 7
Divides the angle by another of a different type.
Uses integer division.
200.degrees // (Math::PI.radians / 3) # => 3
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
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
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
Returns an angle rounded down to the nearest integer.
5.7.degrees.floor # => 5.0°
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°
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
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.
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
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
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
Checks if the angle is negative.
-5.degrees.negative? # => true
5.degrees.negative? # => false
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°
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
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
Checks if the angle is positive.
5.degrees.positive? # => true
-5.degrees.positive? # => false
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
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
Returns a rounded angle.
See Number#round
for details.
90.1.degrees.round # => 90.0°
Returns a rounded angle.
See Number#round
for details.
12.34.degrees.round(1) # => 12.3°
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
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°
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