Class: SciYAG::Backends::TrimFilter

Inherits:
Filter
  • Object
show all
Includes:
Dobjects
Defined in:
lib/SciYAG/Backends/filters/trim.rb

Overview

Removes a given ratio of points

Instance Method Summary collapse

Methods inherited from Filter

describe

Methods included from Descriptions::DescriptionExtend

#base_ancestor?, #description, #description_hash, #description_hash_base, #description_list, #description_list_base, extend_object, #inherit, #init_param, #init_params, #lookup_description_extend_ancestor, #param, #param_noaccess, #register_description, #set_description, #set_description_hash_base, #set_description_list_base

Methods included from Descriptions::DescriptionInclude

#description, #fill_parser, #long_name, #parser_banner, #parser_options

Constructor Details

#initialize(nb) ⇒ TrimFilter

Returns a new instance of TrimFilter.



31
32
33
34
35
36
37
# File 'lib/SciYAG/Backends/filters/trim.rb', line 31

def initialize(nb) 
  @nb = Float(nb)
  if @nb <= 1
    warn "Invalid parameter nb #{nb}, using 3"
    @nb = 3
  end
end

Instance Method Details

#apply(f) ⇒ Object

There you go: a simple averageing filter.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/SciYAG/Backends/filters/trim.rb', line 40

def apply(f)
  new_x = Dvector.new
  new_y = Dvector.new
  nb = 0.0
  for x,y in f
    if nb < 1
      new_x << x
      new_y << y
    end
    nb += 1
    if nb  >= @nb
      nb -= @nb
    end
  end
  return Function.new(new_x, new_y)
end

#apply!(f) ⇒ Object



57
58
59
60
61
# File 'lib/SciYAG/Backends/filters/trim.rb', line 57

def apply!(f)
  new_f = apply(f)
  f.x.replace(new_f.x)
  f.y.replace(new_f.y)
end