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

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

Overview

Horizontal linear equation in y = c form.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(c) ⇒ void

Creates a horizontal equation.

Parameters:

  • c (Numeric)

    y coordinate

Raises:



162
163
164
165
166
167
# File 'lib/sevgi/geometry/equation/linear.rb', line 162

def initialize(c)
  super()

  @slope = 0.0
  @intercept = Real[:y, c]
end

Instance Attribute Details

#interceptFloat (readonly)

Returns the y coordinate.

Returns:

  • (Float)


156
157
158
# File 'lib/sevgi/geometry/equation/linear.rb', line 156

def intercept
  @intercept
end

#slopeFloat (readonly)

Returns the zero line slope.

Returns:

  • (Float)


152
153
154
# File 'lib/sevgi/geometry/equation/linear.rb', line 152

def slope
  @slope
end

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:



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

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

#eql?(other) ⇒ Boolean Also known as: ==

Reports strict equation equality.

Parameters:

  • other (Object)

    object to compare

Returns:

  • (Boolean)


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

def eql?(other) = Nonvertical.equal?(self, other)

#hashInteger

Returns a hash compatible with strict equality.

Returns:

  • (Integer)


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

def hash = Nonvertical.hash(self)

#on?(point) ⇒ Boolean

Reports whether a point is on the line.

Parameters:

Returns:

  • (Boolean)

Raises:



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

def on?(point) = Nonvertical.on?(self, point)

#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:

Raises:



197
198
199
200
201
# File 'lib/sevgi/geometry/equation/linear.rb', line 197

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

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

#to_sString

Formats the equation for display.

Returns:

  • (String)


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

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

#x(_y) ⇒ void

This method returns an undefined value.

Rejects x lookup because a horizontal equation does not determine one x coordinate.

Parameters:

  • _y (Numeric)

    y coordinate

Raises:



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

def x(_y) = Error.("x is indeterminate for a horizontal equation")

#y(x) ⇒ Float

Evaluates y for an x coordinate.

Parameters:

  • x (Numeric)

    x coordinate

Returns:

  • (Float)

Raises:



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

def y(x) = Nonvertical.y(self, x)