Class: OpenCV::CvPoint

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

Overview

This class means one point on X axis Y axis. X and Y takes the value of the Integer. see also CvPoint2D32F

C structure is here, very simple.

typdef struct CvPoint {
  int x;
  int y;
}

Direct Known Subclasses

GUI::MouseEvent

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#newCvPoint.new(0, 0) #new(obj) ⇒ CvPoint.new(obj.x.to_i] #new(x, y) ⇒ Object

Create new 2D-coordinate, (x, y). 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)

Overloads:

  • #newCvPoint.new(0, 0)
  • #new(obj) ⇒ CvPoint.new(obj.x.to_i]

    Returns CvPoint.new(obj.x.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/cvpoint.cpp', line 78

VALUE
rb_initialize(int argc, VALUE *argv, VALUE self)
{
  CvPoint* self_ptr = CVPOINT(self);
  switch (argc) {
  case 0:
    break;
  case 1: {
    CvPoint point = VALUE_TO_CVPOINT(argv[0]);
    self_ptr->x = point.x;
    self_ptr->y = point.y;
    break;
  }
  case 2:
    self_ptr->x = NUM2INT(argv[0]);
    self_ptr->y = NUM2INT(argv[1]);
    break;
  default:
    rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
    break;
  }
  return self;
}

Class Method Details

.combatible?(obj) ⇒ Boolean

Return compatibility to CvPoint. Return true if object have method #x and #y.

For example.

class MyPoint
  def x
    1
  end
  def y
    2
  end
end
mp = MyPoint.new
CvPoint.compatible?(mp)  #=> true
CvPoint.new(mp)          #=> same as CvPoint(1, 2)

Returns:

  • (Boolean)


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

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

Instance Method Details

#to_aryArray Also known as: to_a

Return x and y by Array.

Returns:

  • (Array)


177
178
179
180
181
182
# File 'ext/opencv/cvpoint.cpp', line 177

VALUE
rb_to_ary(VALUE self)
{
  CvPoint* self_ptr = CVPOINT(self);
  return rb_ary_new3(2, INT2NUM(self_ptr->x), INT2NUM(self_ptr->y));
}

#to_s"<OpenCV::CvPoint:(self.x]

Return x and y by String.

Returns “<OpenCV::CvPoint:(self.x].

Returns:

  • ("<OpenCV::CvPoint:(self.x])

    “<OpenCV::CvPoint:(self.x]



159
160
161
162
163
164
165
166
167
168
169
# File 'ext/opencv/cvpoint.cpp', line 159

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

#xObject

Return parameter on x-axis.



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

VALUE
rb_x(VALUE self)
{
  return INT2NUM(CVPOINT(self)->x);
}

#x=(val) ⇒ Object

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

pt = CvPoint.new
pt.x = 1.1
pt.x           #=> 1
pt.x = 100.9
pt.x           #=> 100


123
124
125
126
127
128
# File 'ext/opencv/cvpoint.cpp', line 123

VALUE
rb_set_x(VALUE self, VALUE x)
{
  CVPOINT(self)->x = NUM2INT(x);
  return self;
}

#yObject

Return parameter on y-axis.



133
134
135
136
137
# File 'ext/opencv/cvpoint.cpp', line 133

VALUE
rb_y(VALUE self)
{
  return INT2NUM(CVPOINT(self)->y);
}

#y=(val) ⇒ Object

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



146
147
148
149
150
151
# File 'ext/opencv/cvpoint.cpp', line 146

VALUE
rb_set_y(VALUE self, VALUE y)
{
  CVPOINT(self)->y = NUM2INT(y);
  return self;
}