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:



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

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:



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

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)


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

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

#hashInteger

Returns a hash compatible with strict equality.

Returns:

  • (Integer)


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

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

#left?(point) ⇒ Boolean

Reports whether a point is on the left side of the line.

Parameters:

Returns:

  • (Boolean)

Raises:



178
179
180
181
182
# File 'lib/sevgi/geometry/equation/linear.rb', line 178

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

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

#on?(point) ⇒ Boolean

Reports whether a point is on the line.

Parameters:

Returns:

  • (Boolean)

Raises:



188
189
190
191
192
# File 'lib/sevgi/geometry/equation/linear.rb', line 188

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

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

#right?(point) ⇒ Boolean

Reports whether a point is on the right side of the line.

Parameters:

Returns:

  • (Boolean)

Raises:



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

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

  F.gt?(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:



211
212
213
214
215
# File 'lib/sevgi/geometry/equation/linear.rb', line 211

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

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

#to_sString

Formats the equation for display.

Returns:

  • (String)


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

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

#x(_ = nil) ⇒ Float

Evaluates x for a y coordinate.

Parameters:

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

    ignored y coordinate

Returns:

  • (Float)


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

def x(_ = nil) = @x

#y(_ = nil) ⇒ Float

Evaluates y for an x coordinate.

Parameters:

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

    ignored x coordinate

Returns:

  • (Float)

    positive infinity because a vertical line has no single y



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

def y(_ = nil) = ::Float::INFINITY