Class: Sevgi::Geometry::Equation::Linear::Vertical
- Inherits:
-
Linear
- Object
- Linear
- Sevgi::Geometry::Equation::Linear::Vertical
- Defined in:
- lib/sevgi/geometry/equation/linear.rb
Overview
Vertical linear equation in x = c form.
Instance Method Summary collapse
-
#approx(precision = nil) ⇒ Sevgi::Geometry::Equation::Linear::Vertical
Returns an equation rounded to precision.
-
#eql?(other) ⇒ Boolean
(also: #==)
Reports strict equation equality.
-
#hash ⇒ Integer
Returns a hash compatible with strict equality.
-
#initialize(c) ⇒ void
constructor
Creates a vertical equation.
-
#on?(point) ⇒ Boolean
Reports whether a point is on the line.
-
#shift(distance = nil, dx: nil, dy: nil) ⇒ Sevgi::Geometry::Equation::Linear::Vertical
Returns a parallel vertical equation shifted by offsets.
-
#to_s ⇒ String
Formats the equation for display.
-
#x(y = nil) ⇒ Float
Evaluates x for a y coordinate.
-
#y(_x) ⇒ void
Evaluates y for an x coordinate.
Constructor Details
#initialize(c) ⇒ void
Creates a vertical equation.
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.
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.
244 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 244 def eql?(other) = self.class == other.class && x == other.x |
#hash ⇒ Integer
Returns a hash compatible with strict equality.
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.
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.
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_s ⇒ String
Formats the equation for display.
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.
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.
291 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 291 def y(_x) = Error.("y is indeterminate for a vertical equation") |