.doc/ext/rays/matrix.cpp in rays-0.1.6 vs .doc/ext/rays/matrix.cpp in rays-0.1.7

- old
+ new

@@ -8,64 +8,29 @@ using namespace Rucy; static Class cMatrix; +RUCY_DEFINE_VALUE_FROM_TO(Rays::Matrix, cMatrix) -namespace Rays -{ +#define THIS to<Rays::Matrix*>(self) +#define CHECK RUCY_CHECK_OBJ(Rays::Matrix, cMatrix, self) - Class - matrix_class () - { - return cMatrix; - } - -}// Rays - - -namespace Rucy -{ - - - Value - value (const Rays::Matrix& obj) - { - return new_type(cMatrix, new Rays::Matrix(obj)); - } - - Value - value (const Rays::Matrix* obj) - { - return obj ? value(*obj) : nil(); - } - - -}// Rucy - - -#define THIS to<Rays::Matrix*>(self) - -#define CHECK RUCY_CHECK_OBJ(self, Rays::Matrix, cMatrix) - - static VALUE alloc(VALUE klass) { return new_type<Rays::Matrix>(klass); } static VALUE initialize(VALUE self) { - RUCY_CHECK_OBJ(self, Rays::Matrix, cMatrix); + CHECK; + check_arg_count(__FILE__, __LINE__, "Matrix#initialize", argc, 0, 1, 16); - if (argc != 0 && argc != 1 && argc != 16) - arg_count_error("Matrix#initialize", argc, 0, 1, 16); - if (argc == 0) return self; switch (argc) { case 1: @@ -85,27 +50,21 @@ } static VALUE initialize_copy(VALUE self, VALUE obj) { - RUCY_CHECK_OBJ(self, Rays::Matrix, cMatrix); - - Rays::Matrix* matrix = to<Rays::Matrix*>(obj); - if (!matrix) argument_error(); - - *THIS = *matrix; + CHECK; + *THIS = to<Rays::Matrix&>(obj); return self; } static VALUE set(VALUE self) { CHECK; + check_arg_count(__FILE__, __LINE__, "Matrix#initialize", argc, 0, 1, 16); - if (argc != 0 && argc != 1 && argc != 16) - arg_count_error("Matrix#initialize", argc, 0, 1, 16); - switch (argc) { case 0: *THIS = Rays::Matrix(); break; @@ -128,11 +87,10 @@ static VALUE at(VALUE self, VALUE row, VALUE column) { CHECK; - return value(THIS->at(row.as_i(), column.as_i())); } void @@ -145,5 +103,19 @@ rb_define_private_method(cMatrix, "initialize", RUBY_METHOD_FUNC(initialize), -1); rb_define_private_method(cMatrix, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1); rb_define_method(cMatrix, "set", RUBY_METHOD_FUNC(set), -1); rb_define_method(cMatrix, "at", RUBY_METHOD_FUNC(at), 2); } + + +namespace Rays +{ + + + Class + matrix_class () + { + return cMatrix; + } + + +}// Rays