Class: Sevgi::Geometry::Equation::Linear::Horizontal
- Inherits:
-
Linear
- Object
- Linear
- Sevgi::Geometry::Equation::Linear::Horizontal
- Defined in:
- lib/sevgi/geometry/equation/linear.rb
Overview
Horizontal linear equation in y = c form.
Instance Attribute Summary collapse
-
#intercept ⇒ Float
readonly
Returns the y coordinate.
-
#slope ⇒ Float
readonly
Returns the zero line slope.
Instance Method Summary collapse
-
#approx(precision = nil) ⇒ Sevgi::Geometry::Equation::Linear::Horizontal
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 horizontal equation.
-
#on?(point) ⇒ Boolean
Reports whether a point is on the line.
-
#shift(distance = nil, dx: nil, dy: nil) ⇒ Sevgi::Geometry::Equation::Linear::Horizontal
Returns a parallel horizontal equation shifted by offsets.
-
#to_s ⇒ String
Formats the equation for display.
-
#x(_y) ⇒ void
Rejects x lookup because a horizontal equation does not determine one x coordinate.
-
#y(x) ⇒ Float
Evaluates y for an x coordinate.
Constructor Details
#initialize(c) ⇒ void
Creates a horizontal equation.
162 163 164 165 166 167 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 162 def initialize(c) super() @slope = 0.0 @intercept = Real[:y, c] end |
Instance Attribute Details
#intercept ⇒ Float (readonly)
Returns the y coordinate.
156 157 158 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 156 def intercept @intercept end |
#slope ⇒ Float (readonly)
Returns the zero line slope.
152 153 154 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 152 def slope @slope end |
Instance Method Details
#approx(precision = nil) ⇒ Sevgi::Geometry::Equation::Linear::Horizontal
Returns an equation rounded to precision.
172 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 172 def approx(precision = nil) = self.class.new(F.approx(intercept, precision)) |
#eql?(other) ⇒ Boolean Also known as: ==
Reports strict equation equality.
177 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 177 def eql?(other) = Nonvertical.equal?(self, other) |
#hash ⇒ Integer
Returns a hash compatible with strict equality.
181 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 181 def hash = Nonvertical.hash(self) |
#on?(point) ⇒ Boolean
Reports whether a point is on the line.
187 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 187 def on?(point) = Nonvertical.on?(self, point) |
#shift(distance = nil, dx: nil, dy: nil) ⇒ Sevgi::Geometry::Equation::Linear::Horizontal
Returns a parallel horizontal equation shifted by offsets.
A positive signed distance shifts upward in screen coordinates.
197 198 199 200 201 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 197 def shift(distance = nil, dx: nil, dy: nil) distance, _dx, dy = shift_values(distance, dx, dy) self.class.new(intercept + dy - distance) end |
#to_s ⇒ String
Formats the equation for display.
211 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 211 def to_s = "Linear<y = #{F.approx(intercept)}>" |
#x(_y) ⇒ void
This method returns an undefined value.
Rejects x lookup because a horizontal equation does not determine one x coordinate.
207 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 207 def x(_y) = Error.("x is indeterminate for a horizontal equation") |
#y(x) ⇒ Float
Evaluates y for an x coordinate.
217 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 217 def y(x) = Nonvertical.y(self, x) |