mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
implemented CvTwoPoints#[] and tested CvTwoPoints
This commit is contained in:
parent
7eb93ccde3
commit
2648fc580d
3 changed files with 65 additions and 0 deletions
|
@ -47,6 +47,7 @@ define_ruby_class()
|
||||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||||
rb_define_method(rb_klass, "point1", RUBY_METHOD_FUNC(rb_point1), 0);
|
rb_define_method(rb_klass, "point1", RUBY_METHOD_FUNC(rb_point1), 0);
|
||||||
rb_define_method(rb_klass, "point2", RUBY_METHOD_FUNC(rb_point2), 0);
|
rb_define_method(rb_klass, "point2", RUBY_METHOD_FUNC(rb_point2), 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_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
|
||||||
rb_define_alias(rb_klass, "to_a", "to_ary");
|
rb_define_alias(rb_klass, "to_a", "to_ary");
|
||||||
}
|
}
|
||||||
|
@ -83,6 +84,29 @@ rb_point2(VALUE self)
|
||||||
return cCvPoint::new_object(CVTWOPOINTS(self)->p2);
|
return cCvPoint::new_object(CVTWOPOINTS(self)->p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 cCvPoint::new_object(CVTWOPOINTS(self)->p1);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
return cCvPoint::new_object(CVTWOPOINTS(self)->p2);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
rb_raise(rb_eIndexError, "index should be 0...2");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* to_ary -> [self.point1, self.point2]
|
* to_ary -> [self.point1, self.point2]
|
||||||
|
|
|
@ -32,6 +32,7 @@ VALUE rb_allocate(VALUE klass);
|
||||||
|
|
||||||
VALUE rb_point1(VALUE self);
|
VALUE rb_point1(VALUE self);
|
||||||
VALUE rb_point2(VALUE self);
|
VALUE rb_point2(VALUE self);
|
||||||
|
VALUE rb_aref(VALUE self, VALUE index);
|
||||||
VALUE rb_to_ary(VALUE self);
|
VALUE rb_to_ary(VALUE self);
|
||||||
|
|
||||||
VALUE new_object(CvTwoPoints twopoints);
|
VALUE new_object(CvTwoPoints twopoints);
|
||||||
|
|
40
test/test_cvtwopoints.rb
Executable file
40
test/test_cvtwopoints.rb
Executable file
|
@ -0,0 +1,40 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
# -*- mode: ruby; coding: utf-8-unix -*-
|
||||||
|
require 'test/unit'
|
||||||
|
require 'opencv'
|
||||||
|
require File.expand_path(File.dirname(__FILE__)) + '/helper'
|
||||||
|
|
||||||
|
include OpenCV
|
||||||
|
|
||||||
|
# Tests for OpenCV::CvTwoPoints
|
||||||
|
class TestCvTwoPoints < OpenCVTestCase
|
||||||
|
def setup
|
||||||
|
@twopoints = CvTwoPoints.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_initialize
|
||||||
|
assert_not_nil(@twopoints)
|
||||||
|
assert_equal(CvTwoPoints, @twopoints.class)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_point
|
||||||
|
assert_not_nil(@twopoints.point1)
|
||||||
|
assert_not_nil(@twopoints.point2)
|
||||||
|
assert_equal(CvPoint, @twopoints.point1.class)
|
||||||
|
assert_equal(CvPoint, @twopoints.point2.class)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_aref
|
||||||
|
assert_not_nil(@twopoints[0])
|
||||||
|
assert_not_nil(@twopoints[1])
|
||||||
|
assert_equal(CvPoint, @twopoints[0].class)
|
||||||
|
assert_equal(CvPoint, @twopoints[1].class)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_to_ary
|
||||||
|
assert_equal(Array, @twopoints.to_ary.class)
|
||||||
|
assert_equal(2, @twopoints.to_ary.size)
|
||||||
|
assert_equal(2, @twopoints.to_a.size)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue