Class: Sevgi::Geometry::Equation::Linear::Horizontal

Inherits:
Diagonal
  • Object
show all
Defined in:
lib/sevgi/geometry/equation/linear.rb

Overview

Horizontal linear equation in y = c form.

Instance Attribute Summary

Attributes inherited from Diagonal

#intercept, #slope

Instance Method Summary collapse

Methods inherited from Diagonal

#eql?, #hash, #left?, #on?, #right?, #x, #y

Constructor Details

#initialize(c) ⇒ void

Creates a horizontal equation.

Parameters:

  • c (Numeric)

    y coordinate



119
# File 'lib/sevgi/geometry/equation/linear.rb', line 119

def initialize(c) = super(slope: 0.0, intercept: c)

Instance Method Details

#approx(precision = nil) ⇒ Sevgi::Geometry::Equation::Linear::Horizontal

Returns an equation rounded to precision.

Parameters:

  • precision (Integer, nil) (defaults to: nil)

    decimal precision, or nil for the current function default

Returns:



124
# File 'lib/sevgi/geometry/equation/linear.rb', line 124

def approx(precision = nil) = self.class.new(F.approx(intercept, precision))

#shift(distance = nil, dx: nil, dy: nil) ⇒ Sevgi::Geometry::Equation::Linear::Horizontal

Returns a parallel horizontal equation shifted by offsets.

A positive signed distance shifts upward in screen coordinates.

Parameters:

  • distance (Numeric, nil) (defaults to: nil)

    signed perpendicular offset

  • dx (Numeric, nil) (defaults to: nil)

    accepted for signature compatibility and ignored

  • dy (Numeric, nil) (defaults to: nil)

    explicit y translation

Returns:



133
134
135
136
137
# File 'lib/sevgi/geometry/equation/linear.rb', line 133

def shift(distance = nil, dx: nil, dy: nil)
  _dx = dx

  self.class.new(intercept + (dy || 0.0) - (distance || 0.0))
end

#to_sString

Formats the equation for display.

Returns:

  • (String)


141
# File 'lib/sevgi/geometry/equation/linear.rb', line 141

def to_s = "Linear<y = #{F.approx(intercept)}>"