Module: Dieses::Geometry::Equation

Defined in:
lib/dieses/geometry/equation.rb,
lib/dieses/geometry/equation/slant.rb,
lib/dieses/geometry/equation/steep.rb

Defined Under Namespace

Classes: Slant, Steep

Class Method Summary collapse

Class Method Details

.from_line(line) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dieses/geometry/equation.rb', line 11

def from_line(line)
  starting, ending = line.starting, line.ending

  if (c = starting.x) == ending.x
    vertical(c)
  elsif (c = starting.y) == ending.y
    horizontal(c)
  else
    slope     = (ending.y - starting.y) / (ending.x - starting.x)
    intercept = starting.y - slope * starting.x

    slant(slope: slope, intercept: intercept)
  end
end

.horizontal(c) ⇒ Object



48
49
50
# File 'lib/dieses/geometry/equation.rb', line 48

def horizontal(c)
  slant(slope: 0.0, intercept: c)
end

.intersect(u, v) ⇒ Object



52
53
54
# File 'lib/dieses/geometry/equation.rb', line 52

def intersect(u, v)
  u.intersect(v)
end

.slant(slope:, intercept:) ⇒ Object



26
27
28
# File 'lib/dieses/geometry/equation.rb', line 26

def slant(slope:, intercept:)
  Slant.new slope: slope, intercept: intercept
end

.slant_from_direction(point:, angle:) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/dieses/geometry/equation.rb', line 30

def slant_from_direction(point:, angle:)
  return horizontal(point.y) if (angle % 180).zero?
  return vertical(point.x)   if (angle % 90).zero?

  slope     = Math.tan(Support.to_radian(angle.to_f))
  intercept = point.y - slope * point.x

  slant(slope: slope, intercept: intercept)
end

.steep(c) ⇒ Object Also known as: vertical



40
41
42
# File 'lib/dieses/geometry/equation.rb', line 40

def steep(c)
  Steep.new c
end