Class: TerminalVis::Interpolation::RegionInterpolation
- Inherits:
-
Object
- Object
- TerminalVis::Interpolation::RegionInterpolation
- Defined in:
- lib/math/region_interpolation.rb
Overview
class to interpolate a given section of the possible data space
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
A hash with the values of the interpolated section.
-
#delta_x ⇒ Float
readonly
private
The step size in x between to interpolation points.
-
#delta_y ⇒ Float
readonly
private
The step size in y between to interpolation points.
-
#interval_x ⇒ Float
readonly
private
The half portion of the x-dimension that should be interpolated.
-
#interval_y ⇒ Float
readonly
private
The half portion of the y-dimension that should be interpolated.
Instance Method Summary collapse
-
#check_value(value) ⇒ Object
private
method to check for positive values.
-
#create_values_for_line(x, y_run, meta_data, data_set) ⇒ Object
private
method to create the interpolated values for a given y value.
-
#initialize(interval_x, delta_x, interval_y, delta_y) ⇒ RegionInterpolation
constructor
initialization.
-
#interpolate_region(x, y, meta_data, data_set) ⇒ DataSet
method to start the interpolation for the given centroid (x,y).
Constructor Details
#initialize(interval_x, delta_x, interval_y, delta_y) ⇒ RegionInterpolation
initialization
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/math/region_interpolation.rb', line 25 def initialize(interval_x, delta_x, interval_y, delta_y) @interval_x = interval_x @delta_x = delta_x @interval_y = interval_y @delta_y = delta_y @data = Array.new() check_value(@interval_x) check_value(@interval_y) check_value(@delta_x) check_value(@delta_y) end |
Instance Attribute Details
#data ⇒ Hash (readonly)
Returns a hash with the values of the interpolated section.
14 15 16 |
# File 'lib/math/region_interpolation.rb', line 14 def data @data end |
#delta_x ⇒ Float (readonly, private)
Returns the step size in x between to interpolation points.
63 64 65 |
# File 'lib/math/region_interpolation.rb', line 63 def delta_x @delta_x end |
#delta_y ⇒ Float (readonly, private)
Returns the step size in y between to interpolation points.
68 69 70 |
# File 'lib/math/region_interpolation.rb', line 68 def delta_y @delta_y end |
#interval_x ⇒ Float (readonly, private)
Returns the half portion of the x-dimension that should be interpolated.
61 62 63 |
# File 'lib/math/region_interpolation.rb', line 61 def interval_x @interval_x end |
#interval_y ⇒ Float (readonly, private)
Returns the half portion of the y-dimension that should be interpolated.
66 67 68 |
# File 'lib/math/region_interpolation.rb', line 66 def interval_y @interval_y end |
Instance Method Details
#check_value(value) ⇒ Object (private)
method to check for positive values
90 91 92 93 94 95 |
# File 'lib/math/region_interpolation.rb', line 90 def check_value(value) if (value <= 0) raise ArgumentError, " Error in RegionInterpolation: #{value} <= 0.".red end end |
#create_values_for_line(x, y_run, meta_data, data_set) ⇒ Object (private)
method to create the interpolated values for a given y value
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/math/region_interpolation.rb', line 76 def create_values_for_line(x, y_run, , data_set) row = Array.new() x_run = x - @interval_x while (x_run <= (x + @interval_x).round(3)) row << BilinearInterpolation.bilinear_interpolation(, data_set, x_run, y_run).round(5) x_run = (x_run + @delta_x).round(3) end return row end |
#interpolate_region(x, y, meta_data, data_set) ⇒ DataSet
method to start the interpolation for the given centroid (x,y)
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/math/region_interpolation.rb', line 45 def interpolate_region(x, y, , data_set) y_run = y - @interval_y index = 2 * @interval_y / @delta_y while (y_run <= (y + @interval_y).round(3)) @data << create_values_for_line(x, y_run, , data_set) index -= 1 y_run = (y_run + @delta_y).round(3) end return DataInput::DataSet.new(data) end |