Class: OpenCV::CvSize

Inherits:
Object
  • Object
show all
Defined in:
ext/opencv/cvsize.cpp,
ext/opencv/cvsize.cpp

Overview

This class means one size on X axis Y axis. X and Y takes the value of the Fixnum.

C structure is here, very simple.

typdef struct CvSize {
  int width;
  int height;
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#newObject #new(obj) ⇒ Object #new(width, height) ⇒ Object

Create new size of 2D, (width, height). It is dropped below the decimal point.

new() is same as new(0, 0)

new(obj) is same as new(obj.x.to_i, obj.y.to_i)



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'ext/opencv/cvsize.cpp', line 78

VALUE
rb_initialize(int argc, VALUE *argv, VALUE self)
{
  CvSize *self_ptr = CVSIZE(self);
  switch (argc) {
  case 0:
    break;
  case 1: {
    CvSize size = VALUE_TO_CVSIZE(argv[0]);
    self_ptr->width = size.width;
    self_ptr->height = size.height;
    break;
  }
  case 2:
    self_ptr->width = NUM2INT(argv[0]);
    self_ptr->height = NUM2INT(argv[1]);
    break;
  default:
    rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
    break;
  }
  return self;
}

Class Method Details

.compatible?(obj) ⇒ Boolean

Return compatibility to CvSize. Return true if object have method #width and #height.

For example.

class MySize
  def width
    10
  end
  def height
    20
  end
end
mp = MySize.new
CvSize.compatible?(mp)  #=> true
CvSize.new(mp)          #=> same as CvSize(10, 20)

Returns:

  • (Boolean)


53
54
55
56
57
# File 'ext/opencv/cvsize.cpp', line 53

VALUE
rb_compatible_q(VALUE klass, VALUE object)
{
  return (rb_respond_to(object, rb_intern("width")) && rb_respond_to(object, rb_intern("height"))) ? Qtrue : Qfalse;
}

Instance Method Details

#heightObject

Return size of yaxis.



128
129
130
131
132
# File 'ext/opencv/cvsize.cpp', line 128

VALUE
rb_height(VALUE self)
{
  return INT2NUM(CVSIZE(self)->height);
}

#height=(val) ⇒ Object

Set y-axis size, return self. It is dropped below the decimal point.



141
142
143
144
145
146
# File 'ext/opencv/cvsize.cpp', line 141

VALUE
rb_set_height(VALUE self, VALUE y)
{
  CVSIZE(self)->height = NUM2INT(y);
  return self;
}

#to_aryArray Also known as: to_a

Return width and height by Array.

Returns:

  • (Array)


172
173
174
175
176
# File 'ext/opencv/cvsize.cpp', line 172

VALUE
rb_to_ary(VALUE self)
{
  return rb_ary_new3(2, rb_width(self), rb_height(self));
}

#to_s"<OpenCV::CvSize:widthxheight>"

Return width and height by String.

Returns:

  • ("<OpenCV::CvSize:widthxheight>")


154
155
156
157
158
159
160
161
162
163
164
# File 'ext/opencv/cvsize.cpp', line 154

VALUE
rb_to_s(VALUE self)
{
  const int i = 4;
  VALUE str[i];
  str[0] = rb_str_new2("<%s:%dx%d>");
  str[1] = rb_str_new2(rb_class2name(CLASS_OF(self)));
  str[2] = rb_width(self);
  str[3] = rb_height(self);
  return rb_f_sprintf(i, str);
}

#widthObject

Return size of x-axis.



105
106
107
108
109
# File 'ext/opencv/cvsize.cpp', line 105

VALUE
rb_width(VALUE self)
{
  return INT2NUM(CVSIZE(self)->width);
}

#width=(val) ⇒ Object

Set x-axis size, return self. It is dropped below the decimal point.



118
119
120
121
122
123
# File 'ext/opencv/cvsize.cpp', line 118

VALUE
rb_set_width(VALUE self, VALUE x)
{
  CVSIZE(self)->width = NUM2INT(x);
  return self;
}