From 9567a93fbaee49942e0b9ff149b33aeb9955439a Mon Sep 17 00:00:00 2001 From: ser1zw Date: Sat, 21 May 2011 20:12:06 +0900 Subject: [PATCH] tested Curve --- ext/opencv/curve.cpp | 6 ++++-- test/test_curve.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100755 test/test_curve.rb diff --git a/ext/opencv/curve.cpp b/ext/opencv/curve.cpp index 2bf2d87..024a3e5 100644 --- a/ext/opencv/curve.cpp +++ b/ext/opencv/curve.cpp @@ -36,7 +36,7 @@ define_ruby_module() */ VALUE opencv = rb_module_opencv(); module = rb_define_module_under(opencv, "Curve"); - rb_define_method(module, "close?", RUBY_METHOD_FUNC(rb_closed_q), 0); + rb_define_method(module, "closed?", RUBY_METHOD_FUNC(rb_closed_q), 0); rb_define_method(module, "convex?", RUBY_METHOD_FUNC(rb_convex_q), 0); rb_define_method(module, "hole?", RUBY_METHOD_FUNC(rb_hole_q), 0); rb_define_method(module, "simple?", RUBY_METHOD_FUNC(rb_simple_q), 0); @@ -95,7 +95,9 @@ rb_arc_length(int argc, VALUE *argv, VALUE self) { VALUE slice, is_closed; rb_scan_args(argc, argv, "02", &slice, &is_closed); - return rb_float_new(cvArcLength(CVARR(self), NIL_P(slice) ? CV_WHOLE_SEQ : VALUE_TO_CVSLICE(slice), TRUE_OR_FALSE(is_closed, -1))); + return rb_float_new(cvArcLength(CVARR(self), + NIL_P(slice) ? CV_WHOLE_SEQ : VALUE_TO_CVSLICE(slice), + TRUE_OR_FALSE(is_closed, -1))); } __NAMESPACE_END_CURVE diff --git a/test/test_curve.rb b/test/test_curve.rb new file mode 100755 index 0000000..0da1c6d --- /dev/null +++ b/test/test_curve.rb @@ -0,0 +1,42 @@ +#!/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::Curve +class TestCurve < OpenCVTestCase + def setup + @contour1 = CvContour.new + + mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i| + (j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black + } + @contour2 = mat0.find_contours + end + + def test_closed + assert_false(@contour1.closed?) + assert(@contour2.closed?) + end + + def test_convex + assert_false(@contour1.convex?) + end + + def test_hole + assert_false(@contour1.hole?) + end + + def test_simple + assert(@contour1.simple?) + end + + def test_arc_length + assert_in_delta(211.480, @contour2.arc_length, 0.001) + assert_in_delta(18.071, @contour2.arc_length(0..10, true), 0.001) + end +end +