<commit_before>/************************************************************

   cvpoint.cpp -

   $Author: lsxi $

   Copyright (C) 2005-2006 <NAME>

************************************************************/
#include "cvpoint.h"
/*
 * Document-class: OpenCV::CvPoint
 *
 * This class means one point on X axis Y axis. 
 * X and Y takes the value of the Fixnum. see also CvPoint2D32F
 * 
 * C structure is here, very simple.
 *   typdef struct CvPoint {
 *     int x;
 *     int y;
 *   }
 */
__NAMESPACE_BEGIN_OPENCV
__NAMESPACE_BEGIN_CVPOINT

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, "CvPoint", rb_cObject);
  rb_define_alloc_func(rb_klass, rb_allocate);
  rb_define_singleton_method(rb_klass, "compatible?", RUBY_METHOD_FUNC(rb_compatible_q), 1);
  rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
  rb_define_method(rb_klass, "x", RUBY_METHOD_FUNC(rb_x), 0);
  rb_define_method(rb_klass, "x=", RUBY_METHOD_FUNC(rb_set_x), 1);
  rb_define_method(rb_klass, "y", RUBY_METHOD_FUNC(rb_y), 0);
  rb_define_method(rb_klass, "y=", RUBY_METHOD_FUNC(rb_set_y), 1);

  rb_define_method(rb_klass, "to_s", RUBY_METHOD_FUNC(rb_to_s), 0);
  rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
  rb_define_alias(rb_klass, "to_a", "to_ary");
}

/*
 * call-seq:
 *   combatible?(obj)
 *
 * 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)
 */
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;
}

VALUE
rb_allocate(VALUE klass)
{
  CvPoint *ptr;
  return Data_Make_Struct(klass, CvPoint, 0, -1, ptr);
}

/*
 * call-seq:
 *   new -> CvPoint.new(0, 0)
 *   new(obj) -> CvPoint.new(obj.x.to_i, obj.y.to_i)
 *   new(x, y)
 *
 * 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)
 */
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;
}

/*
 * Return parameter on x-axis.
 */
VALUE
rb_x(VALUE self)
{
  return INT2FIX(CVPOINT(self)->x);
}

/*
 * call-seq:
 *   x = val
 *
 * 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
 */
VALUE
rb_set_x(VALUE self, VALUE x)
{
  CVPOINT(self)->x = NUM2INT(x);
  return self;
}

/*
 * Return parameter on y-axis.
 */
VALUE
rb_y(VALUE self)
{
  return INT2FIX(CVPOINT(self)->y);
}

/*
 * call-seq:
 *   y = val
 *
 * Set y-axis parameter, return self.
 * It is dropped below the decimal point.
 */
VALUE
rb_set_y(VALUE self, VALUE y)
{
  CVPOINT(self)->y = NUM2INT(y);
  return self;
}
<commit_msg>replace INT2FIX to INT2NUM in CvPoint<commit_after>/************************************************************

   cvpoint.cpp -

   $Author: lsxi $

   Copyright (C) 2005-2006 <NAME>

************************************************************/
#include "cvpoint.h"
/*
 * Document-class: OpenCV::CvPoint
 *
 * This class means one point on X axis Y axis. 
 * X and Y takes the value of the Fixnum. see also CvPoint2D32F
 * 
 * C structure is here, very simple.
 *   typdef struct CvPoint {
 *     int x;
 *     int y;
 *   }
 */
__NAMESPACE_BEGIN_OPENCV
__NAMESPACE_BEGIN_CVPOINT

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, "CvPoint", rb_cObject);
  rb_define_alloc_func(rb_klass, rb_allocate);
  rb_define_singleton_method(rb_klass, "compatible?", RUBY_METHOD_FUNC(rb_compatible_q), 1);
  rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
  rb_define_method(rb_klass, "x", RUBY_METHOD_FUNC(rb_x), 0);
  rb_define_method(rb_klass, "x=", RUBY_METHOD_FUNC(rb_set_x), 1);
  rb_define_method(rb_klass, "y", RUBY_METHOD_FUNC(rb_y), 0);
  rb_define_method(rb_klass, "y=", RUBY_METHOD_FUNC(rb_set_y), 1);

  rb_define_method(rb_klass, "to_s", RUBY_METHOD_FUNC(rb_to_s), 0);
  rb_define_method(rb_klass, "to_ary", RUBY_METHOD_FUNC(rb_to_ary), 0);
  rb_define_alias(rb_klass, "to_a", "to_ary");
}

/*
 * call-seq:
 *   combatible?(obj)
 *
 * 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)
 */
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;
}

VALUE
rb_allocate(VALUE klass)
{
  CvPoint *ptr;
  return Data_Make_Struct(klass, CvPoint, 0, -1, ptr);
}

/*
 * call-seq:
 *   new -> CvPoint.new(0, 0)
 *   new(obj) -> CvPoint.new(obj.x.to_i, obj.y.to_i)
 *   new(x, y)
 *
 * 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)
 */
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;
}

/*
 * Return parameter on x-axis.
 */
VALUE
rb_x(VALUE self)
{
  return INT2NUM(CVPOINT(self)->x);
}

/*
 * call-seq:
 *   x = val
 *
 * 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
 */
VALUE
rb_set_x(VALUE self, VALUE x)
{
  CVPOINT(self)->x = NUM2INT(x);
  return self;
}

/*
 * Return parameter on y-axis.
 */
VALUE
rb_y(VALUE self)
{
  return INT2NUM(CVPOINT(self)->y);
}

/*
 * call-seq:
 *   y = val
 *
 * Set y-axis parameter, return self.
 * It is dropped below the decimal point.
 */
VALUE
rb_set_y(VALUE self, VALUE y)
{
  CVPOINT(self)->y = NUM2INT(y);
  return self;
}

{'fraction_non_alphanumeric': 0.17295682867227805, 'fraction_numerical': 0.014933478142818354, 'mean_word_length': 3.308187134502924, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2811953', 'n_tokens_mistral': 3026, 'n_tokens_neox': 2939, 'n_words': 659}