Class: Cartesius::Angle

Inherits:
Object
  • Object
show all
Defined in:
lib/cartesius/angle.rb

Class Method Summary collapse

Instance Method Summary collapse

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

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
# File 'lib/cartesius/angle.rb', line 23

def self.(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

.flatObject



41
42
43
# File 'lib/cartesius/angle.rb', line 41

def self.flat
  by_degrees(FLAT)
end

.fullObject



45
46
47
# File 'lib/cartesius/angle.rb', line 45

def self.full
  by_degrees(FULL)
end

.nullObject



33
34
35
# File 'lib/cartesius/angle.rb', line 33

def self.null
  by_degrees(NULL)
end

.rightObject



37
38
39
# File 'lib/cartesius/angle.rb', line 37

def self.right
  by_degrees(RIGHT)
end

Instance Method Details

#acute?Boolean

Returns:

  • (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?

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


73
74
75
# File 'lib/cartesius/angle.rb', line 73

def flat?
  degrees == FLAT
end

#full?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/cartesius/angle.rb', line 77

def full?
  degrees == FULL
end

#null?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/cartesius/angle.rb', line 57

def null?
  degrees == NULL
end

#obtuse?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


65
66
67
# File 'lib/cartesius/angle.rb', line 65

def right?
  degrees == RIGHT
end