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.
-
#left?(point) ⇒ Boolean
Reports whether a point is on the left side of the line.
-
#on?(point) ⇒ Boolean
Reports whether a point is on the line.
-
#right?(point) ⇒ Boolean
Reports whether a point is on the right side of 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(_ = nil) ⇒ Float
Evaluates x for a y coordinate.
-
#y(_ = nil) ⇒ Float
Evaluates y for an x coordinate.
Constructor Details
#initialize(c) ⇒ void
Creates a vertical equation.
152 153 154 155 156 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 152 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.
161 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 161 def approx(precision = nil) = self.class.new(F.approx(x, precision)) |
#eql?(other) ⇒ Boolean Also known as: ==
Reports strict equation equality.
166 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 166 def eql?(other) = self.class == other.class && x == other.x |
#hash ⇒ Integer
Returns a hash compatible with strict equality.
170 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 170 def hash = [self.class, x].hash |
#left?(point) ⇒ Boolean
Reports whether a point is on the left side of the line.
176 177 178 179 180 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 176 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.
186 187 188 189 190 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 186 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.
196 197 198 199 200 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 196 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.
209 210 211 212 213 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 209 def shift(distance = nil, dx: nil, dy: nil) _dy = dy self.class.new(x + (distance || 0.0) + (dx || 0.0)) end |
#to_s ⇒ String
Formats the equation for display.
217 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 217 def to_s = "Linear<x = #{F.approx(x)}>" |
#x(_ = nil) ⇒ Float
Evaluates x for a y coordinate.
222 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 222 def x(_ = nil) = @x |
#y(_ = nil) ⇒ Float
Evaluates y for an x coordinate.
227 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 227 def y(_ = nil) = ::Float::INFINITY |