Class: TerminalVis::Interpolation::RegionInterpolation

Inherits:
Object
  • Object
show all
Defined in:
lib/math/region_interpolation.rb

Overview

class to interpolate a given section of the possible data space

Raises:

  • (ArgumentError)

    if one of the required parameter is <= 0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interval_x, delta_x, interval_y, delta_y) ⇒ RegionInterpolation

initialization

Parameters:

  • interval_x (Float)

    the half portion of the x-dimension that should be interpolated

  • delta_x (Float)

    the step size in x between to interpolation points

  • interval_y (Float)

    the half portion of the y-dimension that should be interpolated

  • delta_y (Float)

    the step size in y between to interpolation points



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

#dataHash (readonly)

Returns a hash with the values of the interpolated section.

Returns:

  • (Hash)

    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_xFloat (readonly, private)

Returns the step size in x between to interpolation points.

Returns:

  • (Float)

    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_yFloat (readonly, private)

Returns the step size in y between to interpolation points.

Returns:

  • (Float)

    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_xFloat (readonly, private)

Returns the half portion of the x-dimension that should be interpolated.

Returns:

  • (Float)

    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_yFloat (readonly, private)

Returns the half portion of the y-dimension that should be interpolated.

Returns:

  • (Float)

    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

Parameters:

  • value (Float)

    the given value

Raises:

  • (ArgumentError)

    if one of the required parameter is <= 0



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

Parameters:

  • x (Float)

    the x-coordinate of the starting point

  • y_run (Float)

    the y-coordinate of the actual row

  • meta_data (VisMetaData)

    the required meta data

  • data_set (DataSet)

    the dataset which values are used for the interpolation



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)

Parameters:

  • x (Float)

    the x-coordinate of the centroid

  • y (Float)

    the y-coordinate of the centroid

  • meta_data (VisMetaData)

    the required meta data

  • data_set (DataSet)

    the dataset which values are used for the interpolation

Returns:

  • (DataSet)

    the interpolated data



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