Class: Sevgi::Geometry::Equation
- Inherits:
-
Object
- Object
- Sevgi::Geometry::Equation
- Defined in:
- lib/sevgi/geometry/equation.rb,
lib/sevgi/geometry/equation/linear.rb,
lib/sevgi/geometry/equation/quadratic.rb
Overview
Abstract base class for geometry equations used in boundary intersections.
The supported public factories build horizontal, vertical, and diagonal
linear equations. #intersect always returns an Array: no intersection is
[], while one crossing is a one-item Array. Coincident parallel lines do
not represent a finite intersection and also return an empty Array.
Defined Under Namespace
Classes: Linear
Class Method Summary collapse
-
.diagonal(slope:, intercept:) ⇒ Sevgi::Geometry::Equation::Linear::Diagonal
Builds a non-axis-aligned linear equation.
-
.horizontal(const) ⇒ Sevgi::Geometry::Equation::Linear::Horizontal
Builds a horizontal linear equation.
-
.vertical(const) ⇒ Sevgi::Geometry::Equation::Linear::Vertical
Builds a vertical linear equation.
Instance Method Summary collapse
-
#intersect(other) ⇒ Array<Sevgi::Geometry::Point>
Intersects this equation with another equation.
-
#y(_x) ⇒ Float
abstract
Evaluates y for an x coordinate.
Class Method Details
.diagonal(slope:, intercept:) ⇒ Sevgi::Geometry::Equation::Linear::Diagonal
Builds a non-axis-aligned linear equation.
24 |
# File 'lib/sevgi/geometry/equation.rb', line 24 def self.diagonal(slope:, intercept:) = Linear::Diagonal.new(slope:, intercept:) |
.horizontal(const) ⇒ Sevgi::Geometry::Equation::Linear::Horizontal
Builds a horizontal linear equation.
30 |
# File 'lib/sevgi/geometry/equation.rb', line 30 def self.horizontal(const) = Linear::Horizontal.new(const) |
.vertical(const) ⇒ Sevgi::Geometry::Equation::Linear::Vertical
Builds a vertical linear equation.
36 |
# File 'lib/sevgi/geometry/equation.rb', line 36 def self.vertical(const) = Linear::Vertical.new(const) |
Instance Method Details
#intersect(other) ⇒ Array<Sevgi::Geometry::Point>
Intersects this equation with another equation.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sevgi/geometry/equation.rb', line 43 def intersect(other) Error.("Must be an equation: #{other}") unless other.is_a?(Equation) points = case [self, other] in [Linear, Linear] linear_vs_linear(other) in [Linear, Quadratic] linear_vs_quadratic(other) in [Quadratic, Quadratic] quadratic_vs_quadratic(other) else PanicError.("Intersection not implemented: #{self.class} / #{other.class}") end Array(points) end |
#y(_x) ⇒ Float
Subclasses implement equation-specific mapping.
Evaluates y for an x coordinate.
65 |
# File 'lib/sevgi/geometry/equation.rb', line 65 def y(_x, ...) = PanicError.("#{self.class}#y must be implemented") |