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?(other) ⇒ Boolean (also: #eql?)
- #degrees ⇒ 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.
12 13 14 15 |
# File 'lib/cartesius/angle.rb', line 12 def initialize(angle) validation(angle) @angle = angle end |
Class Method Details
.by_degrees(degrees) ⇒ Object
19 20 21 |
# File 'lib/cartesius/angle.rb', line 19 def self.by_degrees(degrees) new(degrees) end |
.by_lines(line1:, line2:) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/cartesius/angle.rb', line 27 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
23 24 25 |
# File 'lib/cartesius/angle.rb', line 23 def self.by_radiants(radiants) by_degrees(radiants * FLAT / Math::PI) end |
.flat ⇒ Object
45 46 47 |
# File 'lib/cartesius/angle.rb', line 45 def self.flat by_degrees(FLAT) end |
.full ⇒ Object
49 50 51 |
# File 'lib/cartesius/angle.rb', line 49 def self.full by_degrees(FULL) end |
.null ⇒ Object
37 38 39 |
# File 'lib/cartesius/angle.rb', line 37 def self.null by_degrees(NULL) end |
.right ⇒ Object
41 42 43 |
# File 'lib/cartesius/angle.rb', line 41 def self.right by_degrees(RIGHT) end |
Instance Method Details
#acute? ⇒ Boolean
65 66 67 |
# File 'lib/cartesius/angle.rb', line 65 def acute? CloseNeighbourhood.new(45, 45 - Tolerance::TOLERANCE).include?(degrees) end |
#congruent?(other) ⇒ Boolean Also known as: eql?
85 86 87 88 |
# File 'lib/cartesius/angle.rb', line 85 def congruent?(other) other.instance_of?(self.class) && OpenNeighbourhood.new(NULL, Tolerance::TOLERANCE).include?((other.degrees - degrees).abs) end |
#degrees ⇒ Object
53 54 55 |
# File 'lib/cartesius/angle.rb', line 53 def degrees @angle end |
#flat? ⇒ Boolean
77 78 79 |
# File 'lib/cartesius/angle.rb', line 77 def flat? OpenNeighbourhood.new(FLAT, Tolerance::TOLERANCE).include?(degrees) end |
#full? ⇒ Boolean
81 82 83 |
# File 'lib/cartesius/angle.rb', line 81 def full? OpenNeighbourhood.new(FULL, Tolerance::TOLERANCE).include?(degrees) end |
#null? ⇒ Boolean
61 62 63 |
# File 'lib/cartesius/angle.rb', line 61 def null? OpenNeighbourhood.new(NULL, Tolerance::TOLERANCE).include?(degrees) end |
#obtuse? ⇒ Boolean
73 74 75 |
# File 'lib/cartesius/angle.rb', line 73 def obtuse? CloseNeighbourhood.new(135, 45 - Tolerance::TOLERANCE).include?(degrees) end |
#radiants(precision = 3) ⇒ Object
57 58 59 |
# File 'lib/cartesius/angle.rb', line 57 def radiants(precision = 3) (@angle * Math::PI / FLAT).round(precision) end |
#right? ⇒ Boolean
69 70 71 |
# File 'lib/cartesius/angle.rb', line 69 def right? OpenNeighbourhood.new(RIGHT, Tolerance::TOLERANCE).include?(degrees) end |