#include "rays/ruby/matrix.h" #include #include "defs.h" using namespace Rucy; RUCY_DEFINE_VALUE_FROM_TO(Rays::Matrix) #define THIS to(self) #define CHECK RUCY_CHECK_OBJ(Rays::Matrix, self) static VALUE alloc(VALUE klass) { return new_type(klass); } static VALUE initialize(VALUE self) { CHECK; check_arg_count(__FILE__, __LINE__, "Matrix#initialize", argc, 0, 1, 16); if (argc == 0) return self; switch (argc) { case 1: *THIS = Rays::Matrix(to(argv[0])); break; case 16: *THIS = Rays::Matrix( to(argv[0]), to(argv[1]), to(argv[2]), to(argv[3]), to(argv[4]), to(argv[5]), to(argv[6]), to(argv[7]), to(argv[8]), to(argv[9]), to(argv[10]), to(argv[11]), to(argv[12]), to(argv[13]), to(argv[14]), to(argv[15])); break; } return self; } static VALUE initialize_copy(VALUE self, VALUE obj) { CHECK; *THIS = to(obj); return self; } static VALUE set(VALUE self) { CHECK; check_arg_count(__FILE__, __LINE__, "Matrix#initialize", argc, 0, 1, 16); switch (argc) { case 0: *THIS = Rays::Matrix(); break; case 1: *THIS = Rays::Matrix(to(argv[0])); break; case 16: *THIS = Rays::Matrix( to(argv[0]), to(argv[1]), to(argv[2]), to(argv[3]), to(argv[4]), to(argv[5]), to(argv[6]), to(argv[7]), to(argv[8]), to(argv[9]), to(argv[10]), to(argv[11]), to(argv[12]), to(argv[13]), to(argv[14]), to(argv[15])); break; } return self; } static VALUE at(VALUE self, VALUE row, VALUE column) { CHECK; return value(THIS->at(row.as_i(), column.as_i())); } static Class cMatrix; void Init_matrix () { Module mRays = rb_define_module("Rays"); cMatrix = rb_define_class_under(mRays, "Matrix", rb_cObject); rb_define_alloc_func(cMatrix, alloc); 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