Class: Sevgi::Geometry::Equation::Linear::Vertical

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

Overview

Vertical linear equation in x = c form.

Instance Method Summary collapse

Constructor Details

#initialize(c) ⇒ void

Creates a vertical equation.

Parameters:

  • c (Numeric)

    x coordinate

Raises:



230
231
232
233
234
# File 'lib/sevgi/geometry/equation/linear.rb', line 230

def initialize(c)
  super()

  @x = Real[:x, c]
end

Instance Method Details

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

Returns an equation rounded to precision.

Parameters:

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

    decimal precision, or nil for the current function default

Returns:



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

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

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

Reports strict equation equality.

Parameters:

  • other (Object)

    object to compare

Returns:

  • (Boolean)


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

def eql?(other) = self.class == other.class && x == other.x

#hashInteger

Returns a hash compatible with strict equality.

Returns:

  • (Integer)


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

def hash = [self.class, x].hash

#on?(point) ⇒ Boolean

Reports whether a point is on the line.

Parameters:

Returns:

  • (Boolean)

Raises:



254
255
256
257
258
# File 'lib/sevgi/geometry/equation/linear.rb', line 254

def on?(point)
  point = Tuple[Point, point]

  F.eq?(point.x, x(point.y))
end

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

Returns a parallel vertical equation shifted by offsets.

A positive signed distance shifts right in screen coordinates.

Parameters:

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

    signed perpendicular offset

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

    explicit x translation

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

    accepted for signature compatibility and ignored

Returns:

Raises:



268
269
270
271
272
# File 'lib/sevgi/geometry/equation/linear.rb', line 268

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

  self.class.new(x + distance + dx)
end

#to_sString

Formats the equation for display.

Returns:

  • (String)


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

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

#x(y = nil) ⇒ Float

Evaluates x for a y coordinate.

Parameters:

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

    ignored finite y coordinate

Returns:

  • (Float)

Raises:



282
283
284
285
# File 'lib/sevgi/geometry/equation/linear.rb', line 282

def x(y = nil)
  Real[:y, y] unless y.nil?
  @x
end

#y(_x) ⇒ void

This method returns an undefined value.

Evaluates y for an x coordinate.

Parameters:

  • _x (Numeric)

    x coordinate

Raises:



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

def y(_x) = Error.("y is indeterminate for a vertical equation")