Class: Sumi::Geometry::Equation::Linear::Horizontal
- Inherits:
-
Linear
- Object
- Linear
- Sumi::Geometry::Equation::Linear::Horizontal
- Defined in:
- geometry/lib/sumi/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) ⇒ Sumi::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) ⇒ Sumi::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.
182 183 184 185 186 187 |
# File 'geometry/lib/sumi/geometry/equation/linear.rb', line 182 def initialize(c) super() @slope = 0.0 @intercept = Real[:y, c] end |
Instance Attribute Details
#intercept ⇒ Float (readonly)
Returns the y coordinate.
176 177 178 |
# File 'geometry/lib/sumi/geometry/equation/linear.rb', line 176 def intercept @intercept end |
#slope ⇒ Float (readonly)
Returns the zero line slope.
172 173 174 |
# File 'geometry/lib/sumi/geometry/equation/linear.rb', line 172 def slope @slope end |
Instance Method Details
#approx(precision = nil) ⇒ Sumi::Geometry::Equation::Linear::Horizontal
Returns an equation rounded to precision.
192 |
# File 'geometry/lib/sumi/geometry/equation/linear.rb', line 192 def approx(precision = nil) = self.class.new(F.approx(intercept, precision)) |
#eql?(other) ⇒ Boolean Also known as: ==
Reports strict equation equality.
197 |
# File 'geometry/lib/sumi/geometry/equation/linear.rb', line 197 def eql?(other) = Nonvertical.equal?(self, other) |
#hash ⇒ Integer
Returns a hash compatible with strict equality.
201 |
# File 'geometry/lib/sumi/geometry/equation/linear.rb', line 201 def hash = Nonvertical.hash(self) |
#on?(point) ⇒ Boolean
Reports whether a point is on the line.
207 |
# File 'geometry/lib/sumi/geometry/equation/linear.rb', line 207 def on?(point) = Nonvertical.on?(self, point) |
#shift(distance = nil, dx: nil, dy: nil) ⇒ Sumi::Geometry::Equation::Linear::Horizontal
Returns a parallel horizontal equation shifted by offsets.
A positive signed distance shifts upward in screen coordinates.
217 218 219 220 221 |
# File 'geometry/lib/sumi/geometry/equation/linear.rb', line 217 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.
231 |
# File 'geometry/lib/sumi/geometry/equation/linear.rb', line 231 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.
227 |
# File 'geometry/lib/sumi/geometry/equation/linear.rb', line 227 def x(_y) = Error.("x is indeterminate for a horizontal equation") |
#y(x) ⇒ Float
Evaluates y for an x coordinate.
237 |
# File 'geometry/lib/sumi/geometry/equation/linear.rb', line 237 def y(x) = Nonvertical.y(self, x) |