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
Base class for geometric equations that can intersect with each other.
Defined Under Namespace
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.
11 |
# File 'lib/sevgi/geometry/equation.rb', line 11 def self.diagonal(slope:, intercept:) = Linear::Diagonal.new(slope:, intercept:) |
.horizontal(const) ⇒ Sevgi::Geometry::Equation::Linear::Horizontal
Builds a horizontal linear equation.
16 |
# File 'lib/sevgi/geometry/equation.rb', line 16 def self.horizontal(const) = Linear::Horizontal.new(const) |
.vertical(const) ⇒ Sevgi::Geometry::Equation::Linear::Vertical
Builds a vertical linear equation.
21 |
# File 'lib/sevgi/geometry/equation.rb', line 21 def self.vertical(const) = Linear::Vertical.new(const) |
Instance Method Details
#intersect(other) ⇒ Array<Sevgi::Geometry::Point>
Intersects this equation with another equation.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sevgi/geometry/equation.rb', line 28 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
This method is abstract.
Subclasses implement equation-specific mapping.
Evaluates y for an x coordinate.
50 |
# File 'lib/sevgi/geometry/equation.rb', line 50 def y(_x, ...) = PanicError.("#{self.class}#y must be implemented") |