Class: Sumi::Geometry::Equation::Linear::Vertical
- Inherits:
-
Linear
- Object
- Linear
- Sumi::Geometry::Equation::Linear::Vertical
- Defined in:
- geometry/lib/sumi/geometry/equation/linear.rb
Overview
Vertical linear equation in x = c form.
Instance Method Summary collapse
-
#approx(precision = nil) ⇒ Sumi::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) ⇒ Sumi::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.
250 251 252 253 254 |
# File 'geometry/lib/sumi/geometry/equation/linear.rb', line 250 def initialize(c) super() @x = Real[:x, c] end |
Instance Method Details
#approx(precision = nil) ⇒ Sumi::Geometry::Equation::Linear::Vertical
Returns an equation rounded to precision.
259 |
# File 'geometry/lib/sumi/geometry/equation/linear.rb', line 259 def approx(precision = nil) = self.class.new(F.approx(x, precision)) |
#eql?(other) ⇒ Boolean Also known as: ==
Reports strict equation equality.
264 |
# File 'geometry/lib/sumi/geometry/equation/linear.rb', line 264 def eql?(other) = self.class == other.class && x == other.x |
#hash ⇒ Integer
Returns a hash compatible with strict equality.
268 |
# File 'geometry/lib/sumi/geometry/equation/linear.rb', line 268 def hash = [self.class, x].hash |
#on?(point) ⇒ Boolean
Reports whether a point is on the line.
274 275 276 277 278 |
# File 'geometry/lib/sumi/geometry/equation/linear.rb', line 274 def on?(point) point = Tuple[Point, point] F.eq?(point.x, x(point.y)) end |
#shift(distance = nil, dx: nil, dy: nil) ⇒ Sumi::Geometry::Equation::Linear::Vertical
Returns a parallel vertical equation shifted by offsets.
A positive signed distance shifts right in screen coordinates.
288 289 290 291 292 |
# File 'geometry/lib/sumi/geometry/equation/linear.rb', line 288 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.
296 |
# File 'geometry/lib/sumi/geometry/equation/linear.rb', line 296 def to_s = "Linear<x = #{F.approx(x)}>" |
#x(y = nil) ⇒ Float
Evaluates x for a y coordinate.
302 303 304 305 |
# File 'geometry/lib/sumi/geometry/equation/linear.rb', line 302 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.
311 |
# File 'geometry/lib/sumi/geometry/equation/linear.rb', line 311 def y(_x) = Error.("y is indeterminate for a vertical equation") |