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.
149 150 151 152 153 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 149 def initialize(c) super() @x = c.to_f end |
Instance Method Details
#approx(precision = nil) ⇒ Sevgi::Geometry::Equation::Linear::Vertical
Returns an equation rounded to precision.
158 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 158 def approx(precision = nil) = self.class.new(F.approx(x, precision)) |
#eql?(other) ⇒ Boolean Also known as: ==
Reports strict equation equality.
163 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 163 def eql?(other) = self.class == other.class && x == other.x |
#hash ⇒ Integer
Returns a hash compatible with strict equality.
167 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 167 def hash = [self.class, x].hash |
#left?(point) ⇒ Boolean
Reports whether a point is on the left side of the line.
173 174 175 176 177 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 173 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.
183 184 185 186 187 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 183 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.
193 194 195 196 197 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 193 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.
206 207 208 209 210 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 206 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.
214 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 214 def to_s = "Linear<x = #{F.approx(x)}>" |
#x(_ = nil) ⇒ Float
Evaluates x for a y coordinate.
219 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 219 def x(_ = nil) = @x |
#y(_ = nil) ⇒ Float
Evaluates y for an x coordinate.
224 |
# File 'lib/sevgi/geometry/equation/linear.rb', line 224 def y(_ = nil) = ::Float::INFINITY |