Class: Cartesius::Angle
- Inherits:
-
Object
- Object
- Cartesius::Angle
- Defined in:
- lib/cartesius/angle.rb
Class Method Summary collapse
- .by_degrees(degrees) ⇒ Object
- .by_lines(line1:, line2:) ⇒ Object
- .by_radiants(radiants) ⇒ Object
- .flat ⇒ Object
- .full ⇒ Object
- .null ⇒ Object
- .right ⇒ Object
Instance Method Summary collapse
- #acute? ⇒ Boolean
- #congruent?(angle) ⇒ Boolean (also: #eql?)
- #degrees(precision = 3) ⇒ Object
- #flat? ⇒ Boolean
- #full? ⇒ Boolean
-
#initialize(angle) ⇒ Angle
constructor
A new instance of Angle.
- #null? ⇒ Boolean
- #obtuse? ⇒ Boolean
- #radiants(precision = 3) ⇒ Object
- #right? ⇒ Boolean
Constructor Details
#initialize(angle) ⇒ Angle
Returns a new instance of Angle.
9 10 11 |
# File 'lib/cartesius/angle.rb', line 9 def initialize(angle) @angle = angle end |
Class Method Details
.by_degrees(degrees) ⇒ Object
15 16 17 |
# File 'lib/cartesius/angle.rb', line 15 def self.by_degrees(degrees) new(degrees) end |
.by_lines(line1:, line2:) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/cartesius/angle.rb', line 23 def self.by_lines(line1:, line2:) raise ArgumentError.new('Lines must not be parallel!') if line1.parallel?(line2) if line1.perpendicular?(line2) [right, right] else acute = by_radiants(Math.atan(line1.slope - line2.slope / 1 + line1.slope * line2.slope).abs) [acute, new(FLAT - acute.degrees)] end end |
.by_radiants(radiants) ⇒ Object
19 20 21 |
# File 'lib/cartesius/angle.rb', line 19 def self.by_radiants(radiants) by_degrees(radiants * FLAT / Math::PI) end |
.flat ⇒ Object
41 42 43 |
# File 'lib/cartesius/angle.rb', line 41 def self.flat by_degrees(FLAT) end |
.full ⇒ Object
45 46 47 |
# File 'lib/cartesius/angle.rb', line 45 def self.full by_degrees(FULL) end |
.null ⇒ Object
33 34 35 |
# File 'lib/cartesius/angle.rb', line 33 def self.null by_degrees(NULL) end |
.right ⇒ Object
37 38 39 |
# File 'lib/cartesius/angle.rb', line 37 def self.right by_degrees(RIGHT) end |
Instance Method Details
#acute? ⇒ Boolean
61 62 63 |
# File 'lib/cartesius/angle.rb', line 61 def acute? degrees > NULL and degrees < RIGHT end |
#congruent?(angle) ⇒ Boolean Also known as: eql?
81 82 83 84 |
# File 'lib/cartesius/angle.rb', line 81 def congruent?(angle) angle.instance_of?(self.class) and angle.degrees == degrees end |
#degrees(precision = 3) ⇒ Object
49 50 51 |
# File 'lib/cartesius/angle.rb', line 49 def degrees(precision = 3) @angle.round(precision) end |
#flat? ⇒ Boolean
73 74 75 |
# File 'lib/cartesius/angle.rb', line 73 def flat? degrees == FLAT end |
#full? ⇒ Boolean
77 78 79 |
# File 'lib/cartesius/angle.rb', line 77 def full? degrees == FULL end |
#null? ⇒ Boolean
57 58 59 |
# File 'lib/cartesius/angle.rb', line 57 def null? degrees == NULL end |
#obtuse? ⇒ Boolean
69 70 71 |
# File 'lib/cartesius/angle.rb', line 69 def obtuse? degrees > RIGHT and degrees < FLAT end |
#radiants(precision = 3) ⇒ Object
53 54 55 |
# File 'lib/cartesius/angle.rb', line 53 def radiants(precision = 3) (@angle * Math::PI / FLAT).round(precision) end |
#right? ⇒ Boolean
65 66 67 |
# File 'lib/cartesius/angle.rb', line 65 def right? degrees == RIGHT end |