rays 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +5 -5
  2. data/.doc/ext/rays/bitmap.cpp +22 -76
  3. data/.doc/ext/rays/bounds.cpp +95 -125
  4. data/.doc/ext/rays/color.cpp +224 -45
  5. data/.doc/ext/rays/color_space.cpp +137 -45
  6. data/.doc/ext/rays/defs.cpp +183 -0
  7. data/.doc/ext/rays/font.cpp +39 -21
  8. data/.doc/ext/rays/image.cpp +26 -37
  9. data/.doc/ext/rays/matrix.cpp +186 -29
  10. data/.doc/ext/rays/native.cpp +12 -6
  11. data/.doc/ext/rays/noise.cpp +53 -0
  12. data/.doc/ext/rays/painter.cpp +120 -308
  13. data/.doc/ext/rays/point.cpp +82 -77
  14. data/.doc/ext/rays/polygon.cpp +287 -0
  15. data/.doc/ext/rays/polygon_line.cpp +96 -0
  16. data/.doc/ext/rays/polyline.cpp +161 -0
  17. data/.doc/ext/rays/rays.cpp +0 -13
  18. data/.doc/ext/rays/shader.cpp +83 -9
  19. data/README.md +1 -1
  20. data/Rakefile +21 -9
  21. data/VERSION +1 -1
  22. data/ext/rays/bitmap.cpp +22 -80
  23. data/ext/rays/bounds.cpp +100 -128
  24. data/ext/rays/color.cpp +232 -51
  25. data/ext/rays/color_space.cpp +140 -46
  26. data/ext/rays/defs.cpp +183 -0
  27. data/ext/rays/defs.h +26 -2
  28. data/ext/rays/extconf.rb +1 -2
  29. data/ext/rays/font.cpp +39 -22
  30. data/ext/rays/image.cpp +27 -39
  31. data/ext/rays/matrix.cpp +198 -30
  32. data/ext/rays/native.cpp +12 -6
  33. data/ext/rays/noise.cpp +55 -0
  34. data/ext/rays/painter.cpp +129 -315
  35. data/ext/rays/point.cpp +89 -81
  36. data/ext/rays/polygon.cpp +301 -0
  37. data/ext/rays/polygon_line.cpp +99 -0
  38. data/ext/rays/polyline.cpp +170 -0
  39. data/ext/rays/rays.cpp +0 -14
  40. data/ext/rays/shader.cpp +84 -9
  41. data/include/rays.h +10 -2
  42. data/include/rays/bitmap.h +14 -26
  43. data/include/rays/bounds.h +21 -4
  44. data/include/rays/color.h +25 -14
  45. data/include/rays/color_space.h +11 -8
  46. data/include/rays/coord.h +114 -0
  47. data/include/rays/debug.h +22 -0
  48. data/include/rays/defs.h +3 -0
  49. data/include/rays/font.h +4 -4
  50. data/include/rays/image.h +11 -17
  51. data/include/rays/matrix.h +50 -24
  52. data/include/rays/noise.h +42 -0
  53. data/include/rays/opengl.h +2 -50
  54. data/include/rays/painter.h +57 -99
  55. data/include/rays/point.h +44 -51
  56. data/include/rays/polygon.h +164 -0
  57. data/include/rays/polyline.h +65 -0
  58. data/include/rays/rays.h +3 -0
  59. data/include/rays/ruby.h +7 -1
  60. data/include/rays/ruby/bounds.h +1 -1
  61. data/include/rays/ruby/color.h +1 -1
  62. data/include/rays/ruby/color_space.h +1 -1
  63. data/include/rays/ruby/font.h +1 -1
  64. data/include/rays/ruby/matrix.h +1 -1
  65. data/include/rays/ruby/point.h +1 -1
  66. data/include/rays/ruby/polygon.h +52 -0
  67. data/include/rays/ruby/polyline.h +41 -0
  68. data/include/rays/ruby/shader.h +1 -1
  69. data/include/rays/shader.h +36 -8
  70. data/lib/rays.rb +6 -1
  71. data/lib/rays/bitmap.rb +0 -15
  72. data/lib/rays/bounds.rb +17 -23
  73. data/lib/rays/color.rb +20 -47
  74. data/lib/rays/color_space.rb +13 -13
  75. data/lib/rays/image.rb +2 -6
  76. data/lib/rays/matrix.rb +28 -0
  77. data/lib/rays/module.rb +4 -19
  78. data/lib/rays/painter.rb +60 -97
  79. data/lib/rays/point.rb +13 -21
  80. data/lib/rays/polygon.rb +50 -0
  81. data/lib/rays/polygon_line.rb +36 -0
  82. data/lib/rays/polyline.rb +32 -0
  83. data/lib/rays/shader.rb +20 -1
  84. data/rays.gemspec +5 -7
  85. data/src/bitmap.h +36 -0
  86. data/src/bounds.cpp +74 -11
  87. data/src/color.cpp +58 -23
  88. data/src/color_space.cpp +50 -32
  89. data/src/color_space.h +22 -0
  90. data/src/coord.cpp +170 -0
  91. data/src/coord.h +35 -0
  92. data/src/font.cpp +118 -0
  93. data/src/font.h +64 -0
  94. data/src/frame_buffer.cpp +37 -71
  95. data/src/frame_buffer.h +4 -4
  96. data/src/image.cpp +171 -97
  97. data/src/image.h +25 -0
  98. data/src/ios/bitmap.mm +107 -105
  99. data/src/ios/font.mm +48 -60
  100. data/src/ios/helper.h +2 -2
  101. data/src/ios/opengl.mm +19 -4
  102. data/src/ios/rays.mm +3 -0
  103. data/src/matrix.cpp +111 -26
  104. data/src/matrix.h +30 -0
  105. data/src/noise.cpp +74 -0
  106. data/src/opengl.cpp +9 -27
  107. data/src/opengl.h +37 -0
  108. data/src/osx/bitmap.mm +111 -106
  109. data/src/osx/font.mm +48 -61
  110. data/src/osx/helper.h +2 -2
  111. data/src/osx/opengl.mm +19 -83
  112. data/src/osx/rays.mm +3 -0
  113. data/src/painter.cpp +780 -696
  114. data/src/painter.h +24 -0
  115. data/src/point.cpp +140 -119
  116. data/src/polygon.cpp +1100 -0
  117. data/src/polygon.h +32 -0
  118. data/src/polyline.cpp +158 -0
  119. data/src/polyline.h +67 -0
  120. data/src/render_buffer.cpp +11 -4
  121. data/src/render_buffer.h +2 -2
  122. data/src/shader.cpp +163 -106
  123. data/src/shader.h +38 -0
  124. data/src/shader_program.cpp +533 -0
  125. data/src/{program.h → shader_program.h} +28 -16
  126. data/src/shader_source.cpp +140 -0
  127. data/src/shader_source.h +52 -0
  128. data/src/texture.cpp +136 -160
  129. data/src/texture.h +65 -0
  130. data/src/win32/bitmap.cpp +62 -52
  131. data/src/win32/font.cpp +11 -13
  132. data/src/win32/font.h +24 -0
  133. data/src/win32/gdi.h +6 -6
  134. data/test/helper.rb +0 -3
  135. data/test/test_bitmap.rb +31 -7
  136. data/test/test_bounds.rb +36 -0
  137. data/test/test_color.rb +59 -19
  138. data/test/test_color_space.rb +95 -0
  139. data/test/test_image.rb +24 -20
  140. data/test/test_matrix.rb +106 -0
  141. data/test/test_painter.rb +92 -46
  142. data/test/test_painter_shape.rb +57 -0
  143. data/test/test_point.rb +21 -0
  144. data/test/test_polygon.rb +234 -0
  145. data/test/test_polygon_line.rb +167 -0
  146. data/test/test_polyline.rb +145 -0
  147. data/test/test_shader.rb +9 -9
  148. metadata +88 -67
  149. data/.doc/ext/rays/texture.cpp +0 -138
  150. data/ext/rays/texture.cpp +0 -149
  151. data/include/rays/ruby/texture.h +0 -41
  152. data/include/rays/texture.h +0 -71
  153. data/lib/rays/texture.rb +0 -24
  154. data/src/program.cpp +0 -648
  155. data/test/test_texture.rb +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3b931a32fb29a2e94bfa9cac76e1283bff56c7c8
4
- data.tar.gz: b5c8aa32f2a8d77f5e905e22e6cf37c811f13453
2
+ SHA256:
3
+ metadata.gz: 5b7f128dcb83acfc5ac2d4bbb0b08bab93cbfbc342be7671acfe546cb8c76e27
4
+ data.tar.gz: 683ab9ce64d7fa95d2f769cddb4e5aca34538bf62aa6afb7ddca30a8e198ee73
5
5
  SHA512:
6
- metadata.gz: 467d1781c98b71af426d1793fddd06c8e6e13ad2c985b01238db7f7846d35ae6748de0dbaa0a4a9621b962b306c83bf017c5e1c85d0982a297b42c90de83fc28
7
- data.tar.gz: f90e2c43a1f93d909ac9ac989d5766a2a88eaf30579e94f6d886591859336f1908d1b23b9de8593cdf08973405272aedef79297e68985f9429b3fe24612aedf5
6
+ metadata.gz: 7c88220a1c00951796d6a20862986ccd507664178fd97b9a7af0632305682d7e4d4a632585633292840ba59c13eff3c9c1a6e4f7b4e9f74ca48d8ccd5af980ab
7
+ data.tar.gz: fd4fabb2ce0d6c094dade7736892a2eabde0650744eb627f5102515583083580b80097ce3ad4bcf3d14962e6fa403f338aa7115b1c7283f11fed2e6cc1635e56
@@ -1,23 +1,12 @@
1
1
  #include "rays/ruby/bitmap.h"
2
2
 
3
3
 
4
- #include <rucy.h>
5
- #include "rays/exception.h"
6
4
  #include "rays/ruby/color_space.h"
7
5
  #include "rays/ruby/color.h"
8
6
  #include "rays/ruby/font.h"
9
- #include "rays/ruby/texture.h"
10
7
  #include "defs.h"
11
8
 
12
9
 
13
- using namespace Rucy;
14
-
15
- using Rays::uchar;
16
- using Rays::ushort;
17
- using Rays::uint;
18
- using Rays::coord;
19
-
20
-
21
10
  RUCY_DEFINE_VALUE_FROM_TO(Rays::Bitmap)
22
11
 
23
12
  #define THIS to<Rays::Bitmap*>(self)
@@ -32,40 +21,24 @@ VALUE alloc(VALUE klass)
32
21
  }
33
22
 
34
23
  static
35
- VALUE initialize_copy(VALUE self, VALUE obj)
24
+ VALUE initialize(VALUE self)
36
25
  {
37
26
  RUCY_CHECK_OBJ(Rays::Bitmap, self);
27
+ check_arg_count(__FILE__, __LINE__, "Bitmap#initialize", argc, 2, 3);
38
28
 
39
- *THIS = to<Rays::Bitmap&>(obj).copy();
40
- return self;
41
- }
29
+ *THIS = Rays::Bitmap(
30
+ to<int>(argv[0]), to<int>(argv[1]),
31
+ argc >= 3 ? to<Rays::ColorSpace>(argv[2]) : Rays::RGBA);
42
32
 
43
- static
44
- VALUE setup(VALUE self, VALUE width, VALUE height, VALUE color_space)
45
- {
46
- RUCY_CHECK_OBJ(Rays::Bitmap, self);
47
-
48
- Rays::ColorSpace* cs = to<Rays::ColorSpace*>(color_space);
49
- if (!cs)
50
- argument_error(__FILE__, __LINE__);
51
-
52
- *THIS = Rays::Bitmap(to<int>(width), to<int>(height), *cs);
53
33
  return self;
54
34
  }
55
35
 
56
36
  static
57
- VALUE draw_string(VALUE self)
37
+ VALUE initialize_copy(VALUE self, VALUE obj)
58
38
  {
59
- CHECK;
60
- check_arg_count(__FILE__, __LINE__, "Bitmap#draw_string", argc, 1, 2, 3, 4);
61
-
62
- const char* str = to<const char*>(argv[0]);
63
- coord x = argc >= 2 ? to<coord>(argv[1]) : 0;
64
- coord y = argc >= 3 ? to<coord>(argv[2]) : 0;
65
- const Rays::Font* font = argc >= 4
66
- ? to<Rays::Font*>(argv[3]) : &Rays::default_font();
39
+ RUCY_CHECK_OBJ(Rays::Bitmap, self);
67
40
 
68
- Rays::draw_string(THIS, str, x, y, *font);
41
+ *THIS = to<Rays::Bitmap&>(obj).dup();
69
42
  return self;
70
43
  }
71
44
 
@@ -94,50 +67,27 @@ VALUE color_space(VALUE self)
94
67
  }
95
68
 
96
69
  static
97
- VALUE at(VALUE self, VALUE x, VALUE y)
98
- {
99
- CHECK;
100
-
101
- return value(Rays::Color(THIS->at<void>(x.as_i(), y.as_i()), THIS->color_space()));
102
- }
103
-
104
- static
105
- VALUE set_at(VALUE self, VALUE x, VALUE y, VALUE color)
70
+ VALUE set_at(VALUE self)
106
71
  {
107
72
  CHECK;
73
+ check_arg_count(__FILE__, __LINE__, "Bitmap#set_at", argc, 3, 4, 5, 6);
108
74
 
109
- Rays::Color* col = to<Rays::Color*>(color);
110
- if (!col)
111
- argument_error(__FILE__, __LINE__);
112
-
113
- col->get(THIS->at<void>(x.as_i(), y.as_i()), THIS->color_space());
75
+ int x = to<int>(argv[0]);
76
+ int y = to<int>(argv[1]);
77
+ Rays::Color color = to<Rays::Color>(argc - 2, argv + 2);
114
78
 
115
- return color;
79
+ color.get(THIS->at<void>(x, y), THIS->color_space());
80
+ return value(color);
116
81
  }
117
82
 
118
83
  static
119
- VALUE to_texture(VALUE self)
84
+ VALUE get_at(VALUE self, VALUE x, VALUE y)
120
85
  {
121
86
  CHECK;
122
87
 
123
- bool alpha_only = (argc >= 1) ? to<bool>(argv[0]) : false;
124
- return value(Rays::Texture(*THIS, alpha_only));
125
- }
126
-
127
- static
128
- VALUE save(VALUE self, VALUE path)
129
- {
130
- CHECK;
131
-
132
- Rays::save_bitmap(*THIS, path.c_str());
133
- return self;
134
- }
135
-
136
-
137
- static
138
- VALUE load(VALUE self, VALUE path)
139
- {
140
- return value(Rays::load_bitmap(path.c_str()));
88
+ int xx = to<int>(x);
89
+ int yy = to<int>(y);
90
+ return value(Rays::Color(THIS->at<void>(xx, yy), THIS->color_space()));
141
91
  }
142
92
 
143
93
 
@@ -150,17 +100,13 @@ Init_bitmap ()
150
100
 
151
101
  cBitmap = rb_define_class_under(mRays, "Bitmap", rb_cObject);
152
102
  rb_define_alloc_func(cBitmap, alloc);
103
+ rb_define_private_method(cBitmap, "initialize", RUBY_METHOD_FUNC(initialize), -1);
153
104
  rb_define_private_method(cBitmap, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1);
154
- rb_define_private_method(cBitmap, "setup", RUBY_METHOD_FUNC(setup), 3);
155
- rb_define_method(cBitmap, "draw_string", RUBY_METHOD_FUNC(draw_string), -1);
156
105
  rb_define_method(cBitmap, "width", RUBY_METHOD_FUNC(width), 0);
157
106
  rb_define_method(cBitmap, "height", RUBY_METHOD_FUNC(height), 0);
158
107
  rb_define_method(cBitmap, "color_space", RUBY_METHOD_FUNC(color_space), 0);
159
- cBitmap.define_method("[]", at);
160
- rb_define_method(cBitmap, "set_at", RUBY_METHOD_FUNC(set_at), 3);
161
- rb_define_method(cBitmap, "to_texture", RUBY_METHOD_FUNC(to_texture), -1);
162
- rb_define_method(cBitmap, "save", RUBY_METHOD_FUNC(save), 1);
163
- rb_define_function(cBitmap, "load", RUBY_METHOD_FUNC(load), 1);
108
+ cBitmap.define_method("[]=", set_at);
109
+ cBitmap.define_method("[]", get_at);
164
110
  }
165
111
 
166
112
 
@@ -1,17 +1,11 @@
1
1
  #include "rays/ruby/bounds.h"
2
2
 
3
3
 
4
- #include <rucy.h>
5
4
  #include "rays/ruby/point.h"
6
5
  #include "defs.h"
7
6
 
8
7
 
9
- using namespace Rucy;
10
-
11
- using Rays::coord;
12
-
13
-
14
- RUCY_DEFINE_VALUE_FROM_TO(Rays::Bounds)
8
+ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Bounds)
15
9
 
16
10
  #define THIS to<Rays::Bounds*>(self)
17
11
 
@@ -30,35 +24,8 @@ VALUE initialize(VALUE self)
30
24
  CHECK;
31
25
  check_arg_count(__FILE__, __LINE__, "Bounds#initialize", argc, 0, 1, 2, 3, 4, 6);
32
26
 
33
- if (argc == 0) return self;
34
-
35
- switch (argc)
36
- {
37
- case 1:
38
- *THIS = Rays::Bounds(to<coord>(argv[0]));
39
- break;
40
-
41
- case 2:
42
- *THIS = Rays::Bounds(to<coord>(argv[0]), to<coord>(argv[1]));
43
- break;
44
-
45
- case 3:
46
- *THIS = Rays::Bounds(
47
- to<coord>(argv[0]), to<coord>(argv[1]), to<coord>(argv[2]));
48
- break;
49
-
50
- case 4:
51
- *THIS = Rays::Bounds(
52
- to<coord>(argv[0]), to<coord>(argv[1]),
53
- to<coord>(argv[2]), to<coord>(argv[3]));
54
- break;
55
-
56
- case 6:
57
- *THIS = Rays::Bounds(
58
- to<coord>(argv[0]), to<coord>(argv[1]), to<coord>(argv[2]),
59
- to<coord>(argv[3]), to<coord>(argv[4]), to<coord>(argv[5]));
60
- break;
61
- }
27
+ if (argc >= 1)
28
+ *THIS = to<Rays::Bounds>(argc, argv);
62
29
 
63
30
  return self;
64
31
  }
@@ -67,6 +34,7 @@ static
67
34
  VALUE initialize_copy(VALUE self, VALUE obj)
68
35
  {
69
36
  CHECK;
37
+
70
38
  *THIS = to<Rays::Bounds&>(obj);
71
39
  return self;
72
40
  }
@@ -112,7 +80,7 @@ VALUE move_to(VALUE self)
112
80
  }
113
81
 
114
82
  const Rays::Point& p = THIS->position();
115
- coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : p.x;
83
+ coord x = argv[0] ? to<coord>(argv[0]) : p.x;
116
84
  coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : p.y;
117
85
  coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : p.z;
118
86
  THIS->move_to(x, y, z);
@@ -137,7 +105,7 @@ VALUE move_by(VALUE self)
137
105
  argv = argv[0].as_array();
138
106
  }
139
107
 
140
- coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : 0;
108
+ coord x = argv[0] ? to<coord>(argv[0]) : 0;
141
109
  coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : 0;
142
110
  coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : 0;
143
111
  THIS->move_by(x, y, z);
@@ -163,7 +131,7 @@ VALUE resize_to(VALUE self)
163
131
  }
164
132
 
165
133
  const Rays::Point& p = THIS->size();
166
- coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : p.x;
134
+ coord x = argv[0] ? to<coord>(argv[0]) : p.x;
167
135
  coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : p.y;
168
136
  coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : p.z;
169
137
  THIS->resize_to(x, y, z);
@@ -188,7 +156,7 @@ VALUE resize_by(VALUE self)
188
156
  argv = argv[0].as_array();
189
157
  }
190
158
 
191
- coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : 0;
159
+ coord x = argv[0] ? to<coord>(argv[0]) : 0;
192
160
  coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : 0;
193
161
  coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : 0;
194
162
  THIS->resize_by(x, y, z);
@@ -213,7 +181,7 @@ VALUE inset_by(VALUE self)
213
181
  argv = argv[0].as_array();
214
182
  }
215
183
 
216
- coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : 0;
184
+ coord x = argv[0] ? to<coord>(argv[0]) : 0;
217
185
  coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : 0;
218
186
  coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : 0;
219
187
  THIS->inset_by(x, y, z);
@@ -222,12 +190,21 @@ VALUE inset_by(VALUE self)
222
190
  return self;
223
191
  }
224
192
 
193
+ static
194
+ VALUE is_valid(VALUE self)
195
+ {
196
+ CHECK;
197
+
198
+ return value(THIS->operator bool());
199
+ }
200
+
225
201
  static
226
202
  VALUE set_x(VALUE self, VALUE x)
227
203
  {
228
204
  CHECK;
229
205
 
230
- return value(THIS->x = to<coord>(x));
206
+ THIS->x = to<coord>(x);
207
+ return x;
231
208
  }
232
209
 
233
210
  static
@@ -243,7 +220,8 @@ VALUE set_y(VALUE self, VALUE y)
243
220
  {
244
221
  CHECK;
245
222
 
246
- return value(THIS->y = to<coord>(y));
223
+ THIS->y = to<coord>(y);
224
+ return y;
247
225
  }
248
226
 
249
227
  static
@@ -259,7 +237,8 @@ VALUE set_z(VALUE self, VALUE z)
259
237
  {
260
238
  CHECK;
261
239
 
262
- return value(THIS->z = to<coord>(z));
240
+ THIS->z = to<coord>(z);
241
+ return z;
263
242
  }
264
243
 
265
244
  static
@@ -275,7 +254,8 @@ VALUE set_width(VALUE self, VALUE width)
275
254
  {
276
255
  CHECK;
277
256
 
278
- return value(THIS->width = to<coord>(width));
257
+ THIS->width = to<coord>(width);
258
+ return width;
279
259
  }
280
260
 
281
261
  static
@@ -291,7 +271,8 @@ VALUE set_height(VALUE self, VALUE height)
291
271
  {
292
272
  CHECK;
293
273
 
294
- return value(THIS->height = to<coord>(height));
274
+ THIS->height = to<coord>(height);
275
+ return height;
295
276
  }
296
277
 
297
278
  static
@@ -307,7 +288,8 @@ VALUE set_depth(VALUE self, VALUE depth)
307
288
  {
308
289
  CHECK;
309
290
 
310
- return value(THIS->depth = to<coord>(depth));
291
+ THIS->depth = to<coord>(depth);
292
+ return depth;
311
293
  }
312
294
 
313
295
  static
@@ -322,10 +304,9 @@ static
322
304
  VALUE set_left(VALUE self, VALUE left)
323
305
  {
324
306
  CHECK;
325
- Rays::Bounds* this_ = THIS;
326
307
 
327
- this_->set_left(to<coord>(left));
328
- return value(this_->left());
308
+ THIS->set_left(to<coord>(left));
309
+ return left;
329
310
  }
330
311
 
331
312
  static
@@ -340,10 +321,9 @@ static
340
321
  VALUE set_right(VALUE self, VALUE right)
341
322
  {
342
323
  CHECK;
343
- Rays::Bounds* this_ = THIS;
344
324
 
345
- this_->set_right(to<coord>(right));
346
- return value(this_->right());
325
+ THIS->set_right(to<coord>(right));
326
+ return right;
347
327
  }
348
328
 
349
329
  static
@@ -358,10 +338,9 @@ static
358
338
  VALUE set_top(VALUE self, VALUE top)
359
339
  {
360
340
  CHECK;
361
- Rays::Bounds* this_ = THIS;
362
341
 
363
- this_->set_top(to<coord>(top));
364
- return value(this_->top());
342
+ THIS->set_top(to<coord>(top));
343
+ return top;
365
344
  }
366
345
 
367
346
  static
@@ -376,10 +355,9 @@ static
376
355
  VALUE set_bottom(VALUE self, VALUE bottom)
377
356
  {
378
357
  CHECK;
379
- Rays::Bounds* this_ = THIS;
380
358
 
381
- this_->set_bottom(to<coord>(bottom));
382
- return value(this_->bottom());
359
+ THIS->set_bottom(to<coord>(bottom));
360
+ return bottom;
383
361
  }
384
362
 
385
363
  static
@@ -394,10 +372,9 @@ static
394
372
  VALUE set_back(VALUE self, VALUE back)
395
373
  {
396
374
  CHECK;
397
- Rays::Bounds* this_ = THIS;
398
375
 
399
- this_->set_back(to<coord>(back));
400
- return value(this_->back());
376
+ THIS->set_back(to<coord>(back));
377
+ return back;
401
378
  }
402
379
 
403
380
  static
@@ -412,10 +389,9 @@ static
412
389
  VALUE set_front(VALUE self, VALUE front)
413
390
  {
414
391
  CHECK;
415
- Rays::Bounds* this_ = THIS;
416
392
 
417
- this_->set_front(to<coord>(front));
418
- return value(this_->front());
393
+ THIS->set_front(to<coord>(front));
394
+ return front;
419
395
  }
420
396
 
421
397
  static
@@ -430,11 +406,9 @@ static
430
406
  VALUE set_position(VALUE self)
431
407
  {
432
408
  CHECK;
433
- check_arg_count(__FILE__, __LINE__, "Bounds#set_position", argc, 1, 2, 3);
434
409
 
435
- coord* pos = THIS->position().array;
436
- for (int i = 0; i < 3; ++i)
437
- if (argc > i && !argv[i].is_nil()) pos[i] = to<coord>(argv[i]);
410
+ THIS->set_position(to<Rays::Point>(argc, argv));
411
+ return value(THIS->position());
438
412
  }
439
413
 
440
414
  static
@@ -449,11 +423,9 @@ static
449
423
  VALUE set_size(VALUE self)
450
424
  {
451
425
  CHECK;
452
- check_arg_count(__FILE__, __LINE__, "Bounds#set_size", argc, 1, 2, 3);
453
426
 
454
- coord* size = THIS->size().array;
455
- for (int i = 0; i < 3; ++i)
456
- if (argc > i && !argv[i].is_nil()) size[i] = to<coord>(argv[i]);
427
+ THIS->set_size(to<Rays::Point>(argc, argv));
428
+ return value(THIS->size());
457
429
  }
458
430
 
459
431
  static
@@ -468,24 +440,13 @@ static
468
440
  VALUE set_center(VALUE self)
469
441
  {
470
442
  CHECK;
471
- check_arg_count(__FILE__, __LINE__, "Bounds#set_center", argc, 1, 2, 3);
472
-
473
- if (argv[0].is_kind_of(Rays::point_class()))
474
- THIS->set_center(to<Rays::Point&>(argv[0]));
475
- else
476
- {
477
- Rays::Point p = THIS->center();
478
- coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : p.x;
479
- coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : p.y;
480
- coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : p.z;
481
- THIS->set_center(x, y, z);
482
- }
483
443
 
444
+ THIS->set_center(to<Rays::Point>(argc, argv));
484
445
  return value(THIS->center());
485
446
  }
486
447
 
487
448
  static
488
- VALUE center(VALUE self)
449
+ VALUE get_center(VALUE self)
489
450
  {
490
451
  CHECK;
491
452
 
@@ -493,7 +454,7 @@ VALUE center(VALUE self)
493
454
  }
494
455
 
495
456
  static
496
- VALUE array_get(VALUE self, VALUE index)
457
+ VALUE set_at(VALUE self, VALUE index, VALUE value)
497
458
  {
498
459
  CHECK;
499
460
 
@@ -501,11 +462,12 @@ VALUE array_get(VALUE self, VALUE index)
501
462
  if (i < 0 || 1 < i)
502
463
  index_error(__FILE__, __LINE__);
503
464
 
504
- return value((*THIS)[i]);
465
+ (*THIS)[i] = to<Rays::Point&>(value);
466
+ return value;
505
467
  }
506
468
 
507
469
  static
508
- VALUE array_set(VALUE self, VALUE index, VALUE value)
470
+ VALUE get_at(VALUE self, VALUE index)
509
471
  {
510
472
  CHECK;
511
473
 
@@ -513,12 +475,11 @@ VALUE array_set(VALUE self, VALUE index, VALUE value)
513
475
  if (i < 0 || 1 < i)
514
476
  index_error(__FILE__, __LINE__);
515
477
 
516
- (*THIS)[i] = to<Rays::Point&>(value);
517
- return value;
478
+ return value((*THIS)[i]);
518
479
  }
519
480
 
520
481
  static
521
- VALUE and_(VALUE self, VALUE bounds)
482
+ VALUE op_and(VALUE self, VALUE bounds)
522
483
  {
523
484
  CHECK;
524
485
 
@@ -528,12 +489,18 @@ VALUE and_(VALUE self, VALUE bounds)
528
489
  }
529
490
 
530
491
  static
531
- VALUE or_(VALUE self, VALUE bounds)
492
+ VALUE op_or(VALUE self, VALUE arg)
532
493
  {
533
494
  CHECK;
534
495
 
535
496
  Rays::Bounds b = *THIS;
536
- b |= to<Rays::Bounds&>(bounds);
497
+ if (arg.is_kind_of(Rays::bounds_class()))
498
+ b |= to<Rays::Bounds&>(arg);
499
+ else if (arg.is_kind_of(Rays::point_class()))
500
+ b |= to<Rays::Point&>(arg);
501
+ else
502
+ argument_error(__FILE__, __LINE__);
503
+
537
504
  return value(b);
538
505
  }
539
506
 
@@ -545,6 +512,12 @@ VALUE inspect(VALUE self)
545
512
  return value(Xot::stringf("#<Rays::Bounds %s>", THIS->inspect().c_str()));
546
513
  }
547
514
 
515
+ static
516
+ VALUE invalid(VALUE self)
517
+ {
518
+ return value(Rays::invalid_bounds());
519
+ }
520
+
548
521
 
549
522
  static Class cBounds;
550
523
 
@@ -564,6 +537,7 @@ Init_bounds ()
564
537
  cBounds.define_method("resize_to!", resize_to);
565
538
  cBounds.define_method("resize_by!", resize_by);
566
539
  cBounds.define_method("inset_by!", inset_by);
540
+ cBounds.define_method("valid?", is_valid);
567
541
  rb_define_method(cBounds, "x=", RUBY_METHOD_FUNC(set_x), 1);
568
542
  rb_define_method(cBounds, "x", RUBY_METHOD_FUNC(get_x), 0);
569
543
  rb_define_method(cBounds, "y=", RUBY_METHOD_FUNC(set_y), 1);
@@ -588,17 +562,18 @@ Init_bounds ()
588
562
  rb_define_method(cBounds, "back", RUBY_METHOD_FUNC(get_back), 0);
589
563
  rb_define_method(cBounds, "front=", RUBY_METHOD_FUNC(set_front), 1);
590
564
  rb_define_method(cBounds, "front", RUBY_METHOD_FUNC(get_front), 0);
591
- rb_define_method(cBounds, "set_position", RUBY_METHOD_FUNC(set_position), -1);
565
+ rb_define_method(cBounds, "position=", RUBY_METHOD_FUNC(set_position), -1);
592
566
  rb_define_method(cBounds, "position", RUBY_METHOD_FUNC(get_position), 0);
593
- rb_define_method(cBounds, "set_size", RUBY_METHOD_FUNC(set_size), -1);
567
+ rb_define_method(cBounds, "size=", RUBY_METHOD_FUNC(set_size), -1);
594
568
  rb_define_method(cBounds, "size", RUBY_METHOD_FUNC(get_size), 0);
595
- rb_define_method(cBounds, "set_center", RUBY_METHOD_FUNC(set_center), -1);
596
- rb_define_method(cBounds, "center", RUBY_METHOD_FUNC(center), 0);
597
- cBounds.define_method("[]", array_get);
598
- cBounds.define_method("[]=", array_set);
599
- cBounds.define_method("&", and_);
600
- cBounds.define_method("|", or_);
569
+ rb_define_method(cBounds, "center=", RUBY_METHOD_FUNC(set_center), -1);
570
+ rb_define_method(cBounds, "center", RUBY_METHOD_FUNC(get_center), 0);
571
+ cBounds.define_method("[]", get_at);
572
+ cBounds.define_method("[]=", set_at);
573
+ cBounds.define_method("&", op_and);
574
+ cBounds.define_method("|", op_or);
601
575
  rb_define_method(cBounds, "inspect", RUBY_METHOD_FUNC(inspect), 0);
576
+ rb_define_singleton_method(cBounds, "invalid", RUBY_METHOD_FUNC(invalid), 0);
602
577
  }
603
578
 
604
579
 
@@ -607,29 +582,21 @@ namespace Rucy
607
582
 
608
583
 
609
584
  template <> Rays::Bounds
610
- value_to<Rays::Bounds> (Value value, bool convert)
585
+ value_to<Rays::Bounds> (int argc, const Value* argv, bool convert)
611
586
  {
612
- if (convert)
587
+ if (argc == 1 && argv->is_array())
613
588
  {
614
- size_t argc = 0;
615
- Value* argv = NULL;
616
- if (value.is_array())
617
- {
618
- argc = value.size();
619
- argv = value.as_array();
620
- }
621
- else
622
- {
623
- argc = 1;
624
- argv = &value;
625
- }
589
+ argc = argv->size();
590
+ argv = argv->as_array();
591
+ }
626
592
 
627
- if (argc < 1)
628
- Rucy::argument_error(__FILE__, __LINE__);
593
+ assert(argc == 0 || (argc > 0 && argv));
629
594
 
630
- if (argv[0].is_kind_of(Rays::bounds_class()))
631
- value = argv[0];
632
- else if (argv[0].is_kind_of(Rays::point_class()))
595
+ if (convert)
596
+ {
597
+ if (argc == 0)
598
+ return Rays::Bounds();
599
+ else if (argv->is_kind_of(Rays::point_class()))
633
600
  {
634
601
  switch (argc)
635
602
  {
@@ -637,10 +604,10 @@ namespace Rucy
637
604
  case 1: return Rays::Bounds(V(0));
638
605
  case 2: return Rays::Bounds(V(0), V(1));
639
606
  #undef V
640
- default: Rucy::argument_error(__FILE__, __LINE__);
607
+ default: argument_error(__FILE__, __LINE__);
641
608
  }
642
609
  }
643
- else if (argv[0].is_i() || argv[0].is_f())
610
+ else if (argv->is_num())
644
611
  {
645
612
  switch (argc)
646
613
  {
@@ -651,12 +618,15 @@ namespace Rucy
651
618
  case 4: return Rays::Bounds(V(0), V(1), V(2), V(3));
652
619
  case 6: return Rays::Bounds(V(0), V(1), V(2), V(3), V(4), V(5));
653
620
  #undef V
654
- default: Rucy::argument_error(__FILE__, __LINE__);
621
+ default: argument_error(__FILE__, __LINE__);
655
622
  }
656
623
  }
657
624
  }
658
625
 
659
- return value_to<Rays::Bounds&>(value, convert);
626
+ if (argc != 1)
627
+ argument_error(__FILE__, __LINE__);
628
+
629
+ return value_to<Rays::Bounds&>(*argv, convert);
660
630
  }
661
631
 
662
632