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



149
150
151
152
153
# File 'lib/sevgi/geometry/equation/linear.rb', line 149

def initialize(c)
  super()

  @x = c.to_f
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:



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

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)


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

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

#hashInteger

Returns a hash compatible with strict equality.

Returns:

  • (Integer)


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

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:



173
174
175
176
177
# File 'lib/sevgi/geometry/equation/linear.rb', line 173

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:



183
184
185
186
187
# File 'lib/sevgi/geometry/equation/linear.rb', line 183

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:



193
194
195
196
197
# File 'lib/sevgi/geometry/equation/linear.rb', line 193

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:



206
207
208
209
210
# File 'lib/sevgi/geometry/equation/linear.rb', line 206

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)


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

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)


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

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



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

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