Class: CVFFI::VectorMath::NativeVectors::ScalarVector

Inherits:
Object
  • Object
show all
Defined in:
lib/opencv-ffi-ext/vector_math.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, length) ⇒ ScalarVector

Returns a new instance of ScalarVector.



46
47
48
49
# File 'lib/opencv-ffi-ext/vector_math.rb', line 46

def initialize( type, length )
  name = define_vector( type, length )
  instance_eval "@data = #{name}.new '\0'"
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



45
46
47
# File 'lib/opencv-ffi-ext/vector_math.rb', line 45

def data
  @data
end

Instance Method Details

#[](i) ⇒ Object



51
52
53
# File 'lib/opencv-ffi-ext/vector_math.rb', line 51

def [](i)
  @data.d[i]
end

#[]=(i, b) ⇒ Object



55
56
57
# File 'lib/opencv-ffi-ext/vector_math.rb', line 55

def []=(i,b)
  @data.d[i] = b
end

#as_ScalarArrayObject Also known as: to_c



59
60
61
62
# File 'lib/opencv-ffi-ext/vector_math.rb', line 59

def as_ScalarArray
  ScalarArray.new( len: @data.length,
                   data: @data )
end

#define_vector(type, length, name = nil) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/opencv-ffi-ext/vector_math.rb', line 34

def define_vector( type, length, name = nil )
  name = name || "Auto_#{type}_#{length}_vector"
  instance_eval <<-eos
  class #{name} < NiceFFI::Struct
      layout :d, [:#{type}, #{length}]
      def length; #{length}; end
  end
  eos
  name
end