1
0
Fork 0
mirror of https://github.com/ruby-opencv/ruby-opencv synced 2023-03-27 23:22:12 -04:00
ruby-opencv/ext/opencv/cvcircle32f.cpp
Patrick Ting 08a9655dc1 Added gemspec to be able to bundle install from git.
Added IplImage#smoothness that returns :smooth, :messy, or :blank.
Rake compile will now compile the C extension code.
2011-04-14 12:26:41 -07:00

116 lines
2.2 KiB
C++

/************************************************************
cvcircle32f.cpp -
$Author: lsxi $
Copyright (C) 2005-2006 Masakazu Yonekura
************************************************************/
#include "cvcircle32f.h"
/*
* Document-class: OpenCV::CvCircle32f
*
* Combination of center and radius.
*
* see CvMat#hough_circles
*/
__NAMESPACE_BEGIN_OPENCV
__NAMESPACE_BEGIN_CVCIRCLE32F
VALUE rb_klass;
VALUE
rb_class()
{
return rb_klass;
}
void
define_ruby_class()
{
if (rb_klass)
return;
/*
* opencv = rb_define_module("OpenCV");
*
* note: this comment is used by rdoc.
*/
VALUE opencv = rb_module_opencv();
rb_klass = rb_define_class_under(opencv, "CvCircle32f", rb_cObject);
rb_define_alloc_func(rb_klass, rb_allocate);
rb_define_method(rb_klass, "center", RUBY_METHOD_FUNC(rb_center), 0);
rb_define_method(rb_klass, "radius", RUBY_METHOD_FUNC(rb_radius), 0);
rb_define_method(rb_klass, "[]", RUBY_METHOD_FUNC(rb_aref), 1);
rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
rb_define_alias(rb_klass, "to_a", "to_ary");
}
VALUE
rb_allocate(VALUE klass)
{
CvCircle32f *ptr;
return Data_Make_Struct(klass, CvCircle32f, 0, -1, ptr);
}
/*
* Return parameter on center.
*/
VALUE
rb_center(VALUE self)
{
return cCvPoint2D32f::new_object(CVCIRCLE32F(self)->center);
}
/*
* Return parameter on radius.
*/
VALUE
rb_radius(VALUE self)
{
return rb_float_new(CVCIRCLE32F(self)->radius);
}
/*
* call-seq:
* [<i>index</i>]
*
* Return value of <i>index</i> dimension.
*/
VALUE
rb_aref(VALUE self, VALUE index)
{
switch (NUM2INT(index)) {
case 0:
return DBL2NUM(CVCIRCLE32F(self)->center.x);
break;
case 1:
return DBL2NUM(CVCIRCLE32F(self)->center.y);
break;
case 2:
return DBL2NUM(CVCIRCLE32F(self)->radius);
break;
default:
rb_raise(rb_eIndexError, "index should be 0...3");
break;
}
return Qnil;
}
VALUE
rb_to_ary(VALUE self)
{
return rb_ary_new3(2, rb_center(self), rb_radius(self));
}
VALUE
new_object(CvCircle32f circle32f)
{
VALUE object = rb_allocate(rb_klass);
*CVCIRCLE32F(object) = circle32f;
return object;
}
__NAMESPACE_END_CVCIRCLE32F
__NAMESPACE_END_OPENCV