rays 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/.doc/ext/rays/bitmap.cpp +70 -233
  3. data/.doc/ext/rays/bounds.cpp +339 -57
  4. data/.doc/ext/rays/color.cpp +58 -48
  5. data/.doc/ext/rays/color_space.cpp +174 -0
  6. data/.doc/ext/rays/font.cpp +31 -53
  7. data/.doc/ext/rays/image.cpp +64 -67
  8. data/.doc/ext/rays/matrix.cpp +22 -50
  9. data/.doc/ext/rays/native.cpp +9 -2
  10. data/.doc/ext/rays/painter.cpp +276 -259
  11. data/.doc/ext/rays/point.cpp +186 -52
  12. data/.doc/ext/rays/rays.cpp +25 -20
  13. data/.doc/ext/rays/shader.cpp +61 -0
  14. data/.doc/ext/rays/texture.cpp +47 -59
  15. data/{README → README.md} +0 -0
  16. data/Rakefile +6 -5
  17. data/VERSION +1 -1
  18. data/ext/rays/bitmap.cpp +88 -248
  19. data/ext/rays/bounds.cpp +437 -141
  20. data/ext/rays/color.cpp +79 -69
  21. data/ext/rays/color_space.cpp +185 -0
  22. data/ext/rays/extconf.rb +14 -63
  23. data/ext/rays/font.cpp +44 -65
  24. data/ext/rays/image.cpp +82 -81
  25. data/ext/rays/matrix.cpp +32 -60
  26. data/ext/rays/native.cpp +9 -2
  27. data/ext/rays/painter.cpp +345 -321
  28. data/ext/rays/point.cpp +212 -69
  29. data/ext/rays/rays.cpp +29 -23
  30. data/ext/rays/shader.cpp +63 -0
  31. data/ext/rays/texture.cpp +64 -74
  32. data/include/rays/bitmap.h +21 -12
  33. data/include/rays/bounds.h +67 -9
  34. data/include/rays/color.h +23 -7
  35. data/include/rays/{colorspace.h → color_space.h} +6 -3
  36. data/include/rays/exception.h +17 -11
  37. data/include/rays/font.h +4 -3
  38. data/include/rays/image.h +11 -6
  39. data/include/rays/matrix.h +15 -12
  40. data/include/rays/opengl.h +54 -1
  41. data/include/rays/painter.h +98 -108
  42. data/include/rays/point.h +45 -5
  43. data/include/rays/rays.h +2 -2
  44. data/include/rays/ruby/bitmap.h +2 -16
  45. data/include/rays/ruby/bounds.h +4 -16
  46. data/include/rays/ruby/color.h +3 -16
  47. data/include/rays/ruby/color_space.h +27 -0
  48. data/include/rays/ruby/font.h +2 -16
  49. data/include/rays/ruby/image.h +2 -16
  50. data/include/rays/ruby/matrix.h +2 -16
  51. data/include/rays/ruby/painter.h +2 -16
  52. data/include/rays/ruby/point.h +3 -16
  53. data/include/rays/ruby/shader.h +27 -0
  54. data/include/rays/ruby/texture.h +2 -16
  55. data/include/rays/ruby.h +1 -0
  56. data/include/rays/shader.h +48 -0
  57. data/include/rays/texture.h +13 -2
  58. data/include/rays.h +2 -1
  59. data/lib/rays/bitmap.rb +20 -11
  60. data/lib/rays/bounds.rb +29 -68
  61. data/lib/rays/color.rb +39 -0
  62. data/lib/rays/color_space.rb +33 -0
  63. data/lib/rays/font.rb +29 -0
  64. data/lib/rays/image.rb +22 -0
  65. data/lib/rays/module.rb +11 -7
  66. data/lib/rays/painter.rb +103 -40
  67. data/lib/rays/point.rb +19 -36
  68. data/lib/rays/shader.rb +13 -0
  69. data/lib/rays/texture.rb +9 -0
  70. data/lib/rays.rb +4 -0
  71. data/rays.gemspec +3 -4
  72. data/src/bounds.cpp +272 -63
  73. data/src/color.cpp +168 -21
  74. data/src/{colorspace.cpp → color_space.cpp} +38 -1
  75. data/src/exception.cpp +24 -15
  76. data/src/frame_buffer.cpp +275 -0
  77. data/src/frame_buffer.h +79 -0
  78. data/src/image.cpp +80 -36
  79. data/src/ios/bitmap.mm +340 -0
  80. data/src/ios/font.mm +206 -0
  81. data/src/{cocoa → ios}/helper.h +2 -2
  82. data/src/{cocoa → ios}/helper.mm +0 -0
  83. data/src/ios/opengl.mm +21 -0
  84. data/src/ios/program.cpp +122 -0
  85. data/src/{cocoa → ios}/rays.mm +8 -7
  86. data/src/matrix.cpp +10 -22
  87. data/src/opengl.cpp +64 -0
  88. data/src/{cocoa → osx}/bitmap.mm +121 -70
  89. data/src/{cocoa → osx}/font.mm +32 -24
  90. data/src/osx/helper.h +26 -0
  91. data/src/osx/helper.mm +25 -0
  92. data/src/osx/opengl.mm +103 -0
  93. data/src/osx/rays.mm +43 -0
  94. data/src/painter.cpp +596 -422
  95. data/src/point.cpp +154 -11
  96. data/src/program.cpp +513 -0
  97. data/src/program.h +73 -0
  98. data/src/render_buffer.cpp +120 -0
  99. data/src/render_buffer.h +47 -0
  100. data/src/shader.cpp +117 -0
  101. data/src/texture.cpp +104 -134
  102. data/test/helper.rb +10 -3
  103. data/test/test_bitmap.rb +18 -0
  104. data/test/test_bounds.rb +81 -35
  105. data/test/test_color.rb +29 -2
  106. data/test/test_image.rb +63 -0
  107. data/test/test_painter.rb +120 -0
  108. data/test/test_point.rb +30 -9
  109. data/test/test_shader.rb +37 -0
  110. data/test/test_texture.rb +18 -0
  111. metadata +75 -58
  112. data/.gitignore +0 -14
  113. data/ChangeLog +0 -8
@@ -0,0 +1,174 @@
1
+ #include "rays/ruby/color_space.h"
2
+
3
+
4
+ #include <rucy.h>
5
+ #include "defs.h"
6
+
7
+
8
+ using namespace Rucy;
9
+
10
+
11
+ static Class cColorSpace;
12
+
13
+ RUCY_DEFINE_VALUE_FROM_TO(Rays::ColorSpace, cColorSpace)
14
+
15
+ #define THIS to<Rays::ColorSpace*>(self)
16
+
17
+ #define CHECK RUCY_CHECK_OBJ(Rays::ColorSpace, cColorSpace, self)
18
+
19
+
20
+ static
21
+ VALUE alloc(VALUE klass)
22
+ {
23
+ return new_type<Rays::ColorSpace>(klass);
24
+ }
25
+
26
+ static
27
+ VALUE setup(VALUE self, VALUE type, VALUE premultiplied)
28
+ {
29
+ CHECK;
30
+
31
+ *THIS = Rays::ColorSpace(
32
+ (Rays::ColorSpaceType) to<uint>(type),
33
+ to<bool>(premultiplied));
34
+ return self;
35
+ }
36
+
37
+ static
38
+ VALUE initialize_copy(VALUE self, VALUE obj)
39
+ {
40
+ CHECK;
41
+ *THIS = to<Rays::ColorSpace&>(obj);
42
+ return self;
43
+ }
44
+
45
+ static
46
+ VALUE type(VALUE self)
47
+ {
48
+ CHECK;
49
+
50
+ return value(THIS->type());
51
+ }
52
+
53
+ static
54
+ VALUE is_gray(VALUE self)
55
+ {
56
+ CHECK;
57
+
58
+ return value(THIS->is_gray());
59
+ }
60
+
61
+ static
62
+ VALUE is_rgb(VALUE self)
63
+ {
64
+ CHECK;
65
+
66
+ return value(THIS->is_rgb());
67
+ }
68
+
69
+ static
70
+ VALUE is_bgr(VALUE self)
71
+ {
72
+ CHECK;
73
+
74
+ return value(THIS->is_bgr());
75
+ }
76
+
77
+ static
78
+ VALUE is_float(VALUE self)
79
+ {
80
+ CHECK;
81
+
82
+ return value(THIS->is_float());
83
+ }
84
+
85
+ static
86
+ VALUE has_alpha(VALUE self)
87
+ {
88
+ CHECK;
89
+
90
+ return value(THIS->has_alpha());
91
+ }
92
+
93
+ static
94
+ VALUE has_skip(VALUE self)
95
+ {
96
+ CHECK;
97
+
98
+ return value(THIS->has_skip());
99
+ }
100
+
101
+ static
102
+ VALUE is_premult(VALUE self)
103
+ {
104
+ CHECK;
105
+
106
+ return value(THIS->is_premult());
107
+ }
108
+
109
+
110
+ void
111
+ Init_color_space ()
112
+ {
113
+ Module mRays = rb_define_module("Rays");
114
+
115
+ cColorSpace = rb_define_class_under(mRays, "ColorSpace", rb_cObject);
116
+ rb_define_alloc_func(cColorSpace, alloc);
117
+ rb_define_private_method(cColorSpace, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1);
118
+ rb_define_private_method(cColorSpace, "setup", RUBY_METHOD_FUNC(setup), 2);
119
+ rb_define_method(cColorSpace, "type", RUBY_METHOD_FUNC(type), 0);
120
+ cColorSpace.define_method("gray?", is_gray);
121
+ cColorSpace.define_method("rgb?", is_rgb);
122
+ cColorSpace.define_method("bgr?", is_bgr);
123
+ cColorSpace.define_method("float?", is_float);
124
+ cColorSpace.define_method("alpha?", has_alpha);
125
+ cColorSpace.define_method("skip?", has_skip);
126
+ cColorSpace.define_method("premult?", is_premult);
127
+
128
+ cColorSpace.define_const("GRAY_8", Rays::GRAY_8);
129
+ cColorSpace.define_const("GRAY_16", Rays::GRAY_16);
130
+ cColorSpace.define_const("GRAY_24", Rays::GRAY_24);
131
+ cColorSpace.define_const("GRAY_32", Rays::GRAY_32);
132
+ cColorSpace.define_const("GRAY_float", Rays::GRAY_float);
133
+ cColorSpace.define_const("RGB_888", Rays:: RGB_888);
134
+ cColorSpace.define_const("RGBA_8888", Rays:: RGBA_8888);
135
+ cColorSpace.define_const("RGBX_8888", Rays:: RGBX_8888);
136
+ cColorSpace.define_const("ARGB_8888", Rays::ARGB_8888);
137
+ cColorSpace.define_const("XRGB_8888", Rays::XRGB_8888);
138
+ cColorSpace.define_const("BGR_888", Rays:: BGR_888);
139
+ cColorSpace.define_const("BGRA_8888", Rays:: BGRA_8888);
140
+ cColorSpace.define_const("BGRX_8888", Rays:: BGRX_8888);
141
+ cColorSpace.define_const("ABGR_8888", Rays::ABGR_8888);
142
+ cColorSpace.define_const("XBGR_8888", Rays::XBGR_8888);
143
+ cColorSpace.define_const("RGB_float", Rays:: RGB_float);
144
+ cColorSpace.define_const("RGBA_float", Rays:: RGBA_float);
145
+ cColorSpace.define_const("ARGB_float", Rays::ARGB_float);
146
+ cColorSpace.define_const("BGR_float", Rays:: BGR_float);
147
+ cColorSpace.define_const("BGRA_float", Rays:: BGRA_float);
148
+ cColorSpace.define_const("ABGR_float", Rays::ABGR_float);
149
+ cColorSpace.define_const("GRAY", Rays::GRAY);
150
+ cColorSpace.define_const("RGB", Rays:: RGB);
151
+ cColorSpace.define_const("BGR", Rays:: BGR);
152
+ cColorSpace.define_const("RGBA", Rays:: RGBA);
153
+ cColorSpace.define_const("RGBX", Rays:: RGBX);
154
+ cColorSpace.define_const("ARGB", Rays::ARGB);
155
+ cColorSpace.define_const("XRGB", Rays::XRGB);
156
+ cColorSpace.define_const("BGRA", Rays:: BGRA);
157
+ cColorSpace.define_const("BGRX", Rays:: BGRX);
158
+ cColorSpace.define_const("ABGR", Rays::ABGR);
159
+ cColorSpace.define_const("XBGR", Rays::XBGR);
160
+ }
161
+
162
+
163
+ namespace Rays
164
+ {
165
+
166
+
167
+ Class
168
+ color_space_class ()
169
+ {
170
+ return cColorSpace;
171
+ }
172
+
173
+
174
+ }// Rays
@@ -12,44 +12,11 @@ using Rays::coord;
12
12
 
13
13
  static Class cFont;
14
14
 
15
+ RUCY_DEFINE_VALUE_FROM_TO(Rays::Font, cFont)
15
16
 
16
- namespace Rays
17
- {
18
-
19
-
20
- Class
21
- font_class ()
22
- {
23
- return cFont;
24
- }
25
-
26
-
27
- }// Rays
28
-
29
-
30
- namespace Rucy
31
- {
32
-
33
-
34
- Value
35
- value (const Rays::Font& obj)
36
- {
37
- return new_type(cFont, new Rays::Font(obj));
38
- }
39
-
40
- Value
41
- value (const Rays::Font* obj)
42
- {
43
- return obj ? value(*obj) : nil();
44
- }
45
-
46
-
47
- }// Rucy
48
-
49
-
50
- #define THIS to<Rays::Font*>(self)
17
+ #define THIS to<Rays::Font*>(self)
51
18
 
52
- #define CHECK RUCY_CHECK_OBJECT(self, Rays::Font, cFont)
19
+ #define CHECK RUCY_CHECK_OBJECT(Rays::Font, cFont, self)
53
20
 
54
21
 
55
22
  static
@@ -61,9 +28,8 @@ VALUE alloc(VALUE klass)
61
28
  static
62
29
  VALUE initialize(VALUE self)
63
30
  {
64
- RUCY_CHECK_OBJ(self, Rays::Font, cFont);
65
- if (argc < 0 || 2 < argc)
66
- arg_count_error("Font#initialize", argc, 0, 1, 2);
31
+ RUCY_CHECK_OBJ(Rays::Font, cFont, self);
32
+ check_arg_count(__FILE__, __LINE__, "Font#initialize", argc, 0, 1, 2);
67
33
 
68
34
  const char* name = (argc >= 1) ? argv[0].c_str() : NULL;
69
35
  float size = (argc >= 2) ? to<float>(argv[1]) : 0;
@@ -72,11 +38,19 @@ VALUE initialize(VALUE self)
72
38
  return self;
73
39
  }
74
40
 
41
+ static
42
+ VALUE initialize_copy(VALUE self, VALUE obj)
43
+ {
44
+ RUCY_CHECK_OBJ(Rays::Font, cFont, self);
45
+
46
+ *THIS = to<Rays::Font&>(obj).copy();
47
+ return self;
48
+ }
49
+
75
50
  static
76
51
  VALUE name(VALUE self)
77
52
  {
78
53
  CHECK;
79
-
80
54
  return value(THIS->name().c_str());
81
55
  }
82
56
 
@@ -84,7 +58,6 @@ static
84
58
  VALUE size(VALUE self)
85
59
  {
86
60
  CHECK;
87
-
88
61
  return value(THIS->size());
89
62
  }
90
63
 
@@ -92,24 +65,14 @@ static
92
65
  VALUE width(VALUE self, VALUE str)
93
66
  {
94
67
  CHECK;
95
-
96
- coord width = 0;
97
- if (!THIS->get_width(&width, str.c_str()))
98
- rays_error("Font#width(%s) failed.", str.inspect().c_str());
99
-
100
- return value(width);
68
+ return value(THIS->get_width(str.c_str()));
101
69
  }
102
70
 
103
71
  static
104
72
  VALUE height(VALUE self)
105
73
  {
106
74
  CHECK;
107
-
108
- coord height = 0;
109
- if (!THIS->get_height(&height))
110
- rays_error("Font#height() failed.");
111
-
112
- return value(height);
75
+ return value(THIS->get_height());
113
76
  }
114
77
 
115
78
 
@@ -121,8 +84,23 @@ Init_font ()
121
84
  cFont = rb_define_class_under(mRays, "Font", rb_cObject);
122
85
  rb_define_alloc_func(cFont, alloc);
123
86
  rb_define_private_method(cFont, "initialize", RUBY_METHOD_FUNC(initialize), -1);
87
+ rb_define_private_method(cFont, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1);
124
88
  rb_define_method(cFont, "name", RUBY_METHOD_FUNC(name), 0);
125
89
  rb_define_method(cFont, "size", RUBY_METHOD_FUNC(size), 0);
126
90
  rb_define_method(cFont, "width", RUBY_METHOD_FUNC(width), 1);
127
91
  rb_define_method(cFont, "height", RUBY_METHOD_FUNC(height), 0);
128
92
  }
93
+
94
+
95
+ namespace Rays
96
+ {
97
+
98
+
99
+ Class
100
+ font_class ()
101
+ {
102
+ return cFont;
103
+ }
104
+
105
+
106
+ }// Rays
@@ -2,8 +2,10 @@
2
2
 
3
3
 
4
4
  #include <rucy.h>
5
- #include <rays/ruby/bitmap.h>
6
- #include <rays/ruby/texture.h>
5
+ #include "rays/ruby/color_space.h"
6
+ #include "rays/ruby/bitmap.h"
7
+ #include "rays/ruby/texture.h"
8
+ #include "rays/ruby/painter.h"
7
9
  #include "defs.h"
8
10
 
9
11
 
@@ -14,44 +16,11 @@ using Rays::coord;
14
16
 
15
17
  static Class cImage;
16
18
 
19
+ RUCY_DEFINE_VALUE_FROM_TO(Rays::Image, cImage)
17
20
 
18
- namespace Rays
19
- {
20
-
21
-
22
- Class
23
- image_class ()
24
- {
25
- return cImage;
26
- }
21
+ #define THIS to<Rays::Image*>(self)
27
22
 
28
-
29
- }// Rays
30
-
31
-
32
- namespace Rucy
33
- {
34
-
35
-
36
- Value
37
- value (const Rays::Image& obj)
38
- {
39
- return new_type(cImage, new Rays::Image(obj));
40
- }
41
-
42
- Value
43
- value (const Rays::Image* obj)
44
- {
45
- return obj ? value(*obj) : nil();
46
- }
47
-
48
-
49
- }// Rucy
50
-
51
-
52
- #define THIS to<Rays::Image*>(self)
53
-
54
- #define CHECK RUCY_CHECK_OBJECT(self, Rays::Image, cImage)
23
+ #define CHECK RUCY_CHECK_OBJECT(Rays::Image, cImage, self)
55
24
 
56
25
 
57
26
  static
@@ -63,23 +32,20 @@ VALUE alloc(VALUE klass)
63
32
  static
64
33
  VALUE initialize(VALUE self)
65
34
  {
66
- RUCY_CHECK_OBJ(self, Rays::Image, cImage);
67
-
68
- if (argc < 1 || 3 < argc)
69
- arg_count_error("Image#initialize", argc, 1, 2, 3);
35
+ RUCY_CHECK_OBJ(Rays::Image, cImage, self);
36
+ check_arg_count(__FILE__, __LINE__, "Image#initialize", argc, 1, 2, 3);
70
37
 
71
38
  if (argc == 0) return self;
72
39
 
73
40
  if (argv[0].is_kind_of(Rays::bitmap_class()))
74
41
  {
75
- if (argc < 1 || 2 < argc)
76
- arg_count_error("Image#initialize", argc, 1, 2);
42
+ check_arg_count(__FILE__, __LINE__, "Image#initialize", argc, 1, 2);
77
43
 
78
44
  const Rays::Bitmap* bitmap = to<Rays::Bitmap*>(argv[0]);
79
- if (!bitmap) argument_error();
45
+ if (!bitmap) argument_error(__FILE__, __LINE__);
80
46
 
81
- bool alphaonly = (argc == 2) ? to<bool>(argv[1]) : false;
82
- *THIS = Rays::Image(*bitmap, alphaonly);
47
+ bool alpha_only = (argc == 2) ? to<bool>(argv[1]) : false;
48
+ *THIS = Rays::Image(*bitmap, alpha_only);
83
49
  }
84
50
  else
85
51
  {
@@ -93,10 +59,25 @@ VALUE initialize(VALUE self)
93
59
  }
94
60
 
95
61
  static
96
- VALUE width(VALUE self)
62
+ VALUE initialize_copy(VALUE self, VALUE obj)
63
+ {
64
+ RUCY_CHECK_OBJ(Rays::Image, cImage, self);
65
+
66
+ *THIS = to<Rays::Image&>(obj).copy();
67
+ return self;
68
+ }
69
+
70
+ static
71
+ VALUE painter(VALUE self)
97
72
  {
98
73
  CHECK;
74
+ return value(THIS->painter());
75
+ }
99
76
 
77
+ static
78
+ VALUE width(VALUE self)
79
+ {
80
+ CHECK;
100
81
  return value(THIS->width());
101
82
  }
102
83
 
@@ -104,7 +85,6 @@ static
104
85
  VALUE height(VALUE self)
105
86
  {
106
87
  CHECK;
107
-
108
88
  return value(THIS->height());
109
89
  }
110
90
 
@@ -112,15 +92,20 @@ static
112
92
  VALUE color_space(VALUE self)
113
93
  {
114
94
  CHECK;
95
+ return value(THIS->color_space());
96
+ }
115
97
 
116
- return value(THIS->color_space().type());
98
+ static
99
+ VALUE alpha_only(VALUE self)
100
+ {
101
+ CHECK;
102
+ return value(THIS->alpha_only());
117
103
  }
118
104
 
119
105
  static
120
106
  VALUE bitmap(VALUE self)
121
107
  {
122
108
  CHECK;
123
-
124
109
  return value(THIS->bitmap());
125
110
  }
126
111
 
@@ -128,28 +113,22 @@ static
128
113
  VALUE texture(VALUE self)
129
114
  {
130
115
  CHECK;
131
-
132
116
  return value(THIS->texture());
133
117
  }
134
118
 
135
-
136
119
  static
137
- VALUE load(VALUE self)
120
+ VALUE save(VALUE self, VALUE path)
138
121
  {
139
- if (argc != 1 && argc != 2) arg_count_error("Image.load", argc, 1, 2);
140
-
141
- Rays::String path = argv[0].c_str();
142
- bool alphaonly = (argc == 2) ? to<bool>(argv[1]) : false;
122
+ CHECK;
123
+ Rays::save_image(*THIS, path.c_str());
124
+ return self;
125
+ }
143
126
 
144
- Rays::Image img;
145
- if (!Rays::load_image(&img, path.c_str(), alphaonly))
146
- {
147
- rays_error(
148
- "Image.load('%s', %s) failed.",
149
- path.c_str(), alphaonly ? "true" : "false");
150
- }
151
127
 
152
- return value(img);
128
+ static
129
+ VALUE load(VALUE self, VALUE path, VALUE alpha_only)
130
+ {
131
+ return value(Rays::load_image(path.c_str(), to<bool>(alpha_only)));
153
132
  }
154
133
 
155
134
 
@@ -161,10 +140,28 @@ Init_image ()
161
140
  cImage = rb_define_class_under(mRays, "Image", rb_cObject);
162
141
  rb_define_alloc_func(cImage, alloc);
163
142
  rb_define_private_method(cImage, "initialize", RUBY_METHOD_FUNC(initialize), -1);
143
+ rb_define_private_method(cImage, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1);
144
+ rb_define_method(cImage, "painter", RUBY_METHOD_FUNC(painter), 0);
164
145
  rb_define_method(cImage, "width", RUBY_METHOD_FUNC(width), 0);
165
146
  rb_define_method(cImage, "height", RUBY_METHOD_FUNC(height), 0);
166
147
  rb_define_method(cImage, "color_space", RUBY_METHOD_FUNC(color_space), 0);
148
+ rb_define_method(cImage, "alpha_only", RUBY_METHOD_FUNC(alpha_only), 0);
167
149
  rb_define_method(cImage, "bitmap", RUBY_METHOD_FUNC(bitmap), 0);
168
150
  rb_define_method(cImage, "texture", RUBY_METHOD_FUNC(texture), 0);
169
- rb_define_function(cImage, "load", RUBY_METHOD_FUNC(load), -1);
151
+ rb_define_method(cImage, "save", RUBY_METHOD_FUNC(save), 1);
152
+ rb_define_function(cImage, "load_image", RUBY_METHOD_FUNC(load), 2);
170
153
  }
154
+
155
+
156
+ namespace Rays
157
+ {
158
+
159
+
160
+ Class
161
+ image_class ()
162
+ {
163
+ return cImage;
164
+ }
165
+
166
+
167
+ }// Rays
@@ -10,44 +10,11 @@ using namespace Rucy;
10
10
 
11
11
  static Class cMatrix;
12
12
 
13
+ RUCY_DEFINE_VALUE_FROM_TO(Rays::Matrix, cMatrix)
13
14
 
14
- namespace Rays
15
- {
16
-
17
-
18
- Class
19
- matrix_class ()
20
- {
21
- return cMatrix;
22
- }
23
-
24
-
25
- }// Rays
26
-
27
-
28
- namespace Rucy
29
- {
30
-
31
-
32
- Value
33
- value (const Rays::Matrix& obj)
34
- {
35
- return new_type(cMatrix, new Rays::Matrix(obj));
36
- }
37
-
38
- Value
39
- value (const Rays::Matrix* obj)
40
- {
41
- return obj ? value(*obj) : nil();
42
- }
43
-
44
-
45
- }// Rucy
15
+ #define THIS to<Rays::Matrix*>(self)
46
16
 
47
-
48
- #define THIS to<Rays::Matrix*>(self)
49
-
50
- #define CHECK RUCY_CHECK_OBJ(self, Rays::Matrix, cMatrix)
17
+ #define CHECK RUCY_CHECK_OBJ(Rays::Matrix, cMatrix, self)
51
18
 
52
19
 
53
20
  static
@@ -59,10 +26,8 @@ VALUE alloc(VALUE klass)
59
26
  static
60
27
  VALUE initialize(VALUE self)
61
28
  {
62
- RUCY_CHECK_OBJ(self, Rays::Matrix, cMatrix);
63
-
64
- if (argc != 0 && argc != 1 && argc != 16)
65
- arg_count_error("Matrix#initialize", argc, 0, 1, 16);
29
+ CHECK;
30
+ check_arg_count(__FILE__, __LINE__, "Matrix#initialize", argc, 0, 1, 16);
66
31
 
67
32
  if (argc == 0) return self;
68
33
 
@@ -87,12 +52,8 @@ VALUE initialize(VALUE self)
87
52
  static
88
53
  VALUE initialize_copy(VALUE self, VALUE obj)
89
54
  {
90
- RUCY_CHECK_OBJ(self, Rays::Matrix, cMatrix);
91
-
92
- Rays::Matrix* matrix = to<Rays::Matrix*>(obj);
93
- if (!matrix) argument_error();
94
-
95
- *THIS = *matrix;
55
+ CHECK;
56
+ *THIS = to<Rays::Matrix&>(obj);
96
57
  return self;
97
58
  }
98
59
 
@@ -100,9 +61,7 @@ static
100
61
  VALUE set(VALUE self)
101
62
  {
102
63
  CHECK;
103
-
104
- if (argc != 0 && argc != 1 && argc != 16)
105
- arg_count_error("Matrix#initialize", argc, 0, 1, 16);
64
+ check_arg_count(__FILE__, __LINE__, "Matrix#initialize", argc, 0, 1, 16);
106
65
 
107
66
  switch (argc)
108
67
  {
@@ -130,7 +89,6 @@ static
130
89
  VALUE at(VALUE self, VALUE row, VALUE column)
131
90
  {
132
91
  CHECK;
133
-
134
92
  return value(THIS->at(row.as_i(), column.as_i()));
135
93
  }
136
94
 
@@ -147,3 +105,17 @@ Init_matrix ()
147
105
  rb_define_method(cMatrix, "set", RUBY_METHOD_FUNC(set), -1);
148
106
  rb_define_method(cMatrix, "at", RUBY_METHOD_FUNC(at), 2);
149
107
  }
108
+
109
+
110
+ namespace Rays
111
+ {
112
+
113
+
114
+ Class
115
+ matrix_class ()
116
+ {
117
+ return cMatrix;
118
+ }
119
+
120
+
121
+ }// Rays
@@ -9,26 +9,33 @@ void Init_rays ();
9
9
  void Init_point ();
10
10
  void Init_bounds ();
11
11
  void Init_color ();
12
+ void Init_color_space ();
12
13
  void Init_bitmap ();
13
14
  void Init_texture ();
14
15
  void Init_image ();
15
16
  void Init_font ();
17
+ void Init_shader ();
16
18
  void Init_painter ();
17
19
 
18
20
 
19
21
  extern "C" void
20
22
  Init_native ()
21
23
  {
22
- if (!Rucy::init())
23
- raise(rb_eLoadError, "Rucy::init() failed.");
24
+ RUCY_TRY
25
+
26
+ Rucy::init();
24
27
 
25
28
  Init_rays();
26
29
  Init_point();
27
30
  Init_bounds();
28
31
  Init_color();
32
+ Init_color_space();
29
33
  Init_bitmap();
30
34
  Init_texture();
31
35
  Init_image();
32
36
  Init_font();
37
+ Init_shader();
33
38
  Init_painter();
39
+
40
+ RUCY_CATCH
34
41
  }