rays 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
data/ext/rays/bounds.cpp CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
  #include <rucy.h>
5
- #include <rays/ruby/point.h>
5
+ #include "rays/ruby/point.h"
6
6
  #include "defs.h"
7
7
 
8
8
 
@@ -13,60 +13,25 @@ using Rays::coord;
13
13
 
14
14
  static Class cBounds;
15
15
 
16
+ RUCY_DEFINE_VALUE_FROM_TO(Rays::Bounds, cBounds)
16
17
 
17
- namespace Rays
18
- {
19
-
20
-
21
- Class
22
- bounds_class ()
23
- {
24
- return cBounds;
25
- }
26
-
27
-
28
- }// Rays
29
-
30
-
31
- namespace Rucy
32
- {
33
-
34
-
35
- Value
36
- value (const Rays::Bounds& obj)
37
- {
38
- return new_type(cBounds, new Rays::Bounds(obj));
39
- }
40
-
41
- Value
42
- value (const Rays::Bounds* obj)
43
- {
44
- return obj ? value(*obj) : nil();
45
- }
46
-
47
-
48
- }// Rucy
49
-
18
+ #define THIS to<Rays::Bounds*>(self)
50
19
 
51
- #define THIS to<Rays::Bounds*>(self)
52
-
53
- #define CHECK RUCY_CHECK_OBJ(self, Rays::Bounds, cBounds)
20
+ #define CHECK RUCY_CHECK_OBJ(Rays::Bounds, cBounds, self)
54
21
 
55
22
 
56
23
  static
57
- RUBY_DEF_ALLOC(alloc, klass)
24
+ RUCY_DEF_ALLOC(alloc, klass)
58
25
  {
59
26
  return new_type<Rays::Bounds>(klass);
60
27
  }
61
- RUBY_END
28
+ RUCY_END
62
29
 
63
30
  static
64
- RUBY_DEFN(initialize)
31
+ RUCY_DEFN(initialize)
65
32
  {
66
- RUCY_CHECK_OBJ(self, Rays::Bounds, cBounds);
67
-
68
- if (argc != 0 && argc != 1 && argc != 2 && argc != 3 && argc != 4 && argc != 6)
69
- arg_count_error("Bounds#initialize", argc, 0, 1, 2, 3, 4, 6);
33
+ CHECK;
34
+ check_arg_count(__FILE__, __LINE__, "Bounds#initialize", argc, 0, 1, 2, 3, 4, 6);
70
35
 
71
36
  if (argc == 0) return self;
72
37
 
@@ -100,131 +65,285 @@ RUBY_DEFN(initialize)
100
65
 
101
66
  return self;
102
67
  }
103
- RUBY_END
68
+ RUCY_END
69
+
70
+ static
71
+ RUCY_DEF1(initialize_copy, obj)
72
+ {
73
+ CHECK;
74
+ *THIS = to<Rays::Bounds&>(obj);
75
+ return self;
76
+ }
77
+ RUCY_END
78
+
79
+ static
80
+ RUCY_DEFN(intersect)
81
+ {
82
+ CHECK;
83
+ check_arg_count(__FILE__, __LINE__, "Bounds#intersect?", argc, 1, 2);
84
+
85
+ const Rays::Bounds& bounds = to<Rays::Bounds&>(argv[0]);
86
+ int dimension = argc >= 2 ? to<int>(argv[1]) : 2;
87
+
88
+ return value(THIS->is_intersect(bounds, dimension));
89
+ }
90
+ RUCY_END
91
+
92
+ static
93
+ RUCY_DEFN(include)
94
+ {
95
+ CHECK;
96
+ check_arg_count(__FILE__, __LINE__, "Bounds#include?", argc, 1, 2);
97
+
98
+ const Rays::Point& point = to<Rays::Point&>(argv[0]);
99
+ int dimension = argc >= 2 ? to<int>(argv[1]) : 2;
100
+
101
+ return value(THIS->is_include(point, dimension));
102
+ }
103
+ RUCY_END
104
+
105
+ static
106
+ RUCY_DEFN(move_to)
107
+ {
108
+ CHECK;
109
+ check_arg_count(__FILE__, __LINE__, "Bounds#move_to", argc, 1, 2, 3);
110
+
111
+ if (argv[0].is_kind_of(Rays::point_class()))
112
+ THIS->move_to(to<Rays::Point&>(argv[0]));
113
+ else
114
+ {
115
+ if (argv[0].is_array())
116
+ {
117
+ argc = argv[0].size();
118
+ argv = argv[0].as_array();
119
+ }
120
+
121
+ const Rays::Point& p = THIS->position();
122
+ coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : p.x;
123
+ coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : p.y;
124
+ coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : p.z;
125
+ THIS->move_to(x, y, z);
126
+ }
127
+
128
+ return self;
129
+ }
130
+ RUCY_END
131
+
132
+ static
133
+ RUCY_DEFN(move_by)
134
+ {
135
+ CHECK;
136
+ check_arg_count(__FILE__, __LINE__, "Bounds#move_by", argc, 1, 2, 3);
137
+
138
+ if (argv[0].is_kind_of(Rays::point_class()))
139
+ THIS->move_by(to<Rays::Point&>(argv[0]));
140
+ else
141
+ {
142
+ if (argv[0].is_array())
143
+ {
144
+ argc = argv[0].size();
145
+ argv = argv[0].as_array();
146
+ }
147
+
148
+ coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : 0;
149
+ coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : 0;
150
+ coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : 0;
151
+ THIS->move_by(x, y, z);
152
+ }
153
+
154
+ return self;
155
+ }
156
+ RUCY_END
104
157
 
105
158
  static
106
- RUBY_DEF1(initialize_copy, obj)
159
+ RUCY_DEFN(resize_to)
107
160
  {
108
- RUCY_CHECK_OBJ(self, Rays::Bounds, cBounds);
161
+ CHECK;
162
+ check_arg_count(__FILE__, __LINE__, "Bounds#resize_to", argc, 1, 2, 3);
109
163
 
110
- Rays::Bounds* bounds = to<Rays::Bounds*>(obj);
111
- if (!bounds) argument_error();
164
+ if (argv[0].is_kind_of(Rays::point_class()))
165
+ THIS->resize_to(to<Rays::Point&>(argv[0]));
166
+ else
167
+ {
168
+ if (argv[0].is_array())
169
+ {
170
+ argc = argv[0].size();
171
+ argv = argv[0].as_array();
172
+ }
173
+
174
+ const Rays::Point& p = THIS->size();
175
+ coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : p.x;
176
+ coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : p.y;
177
+ coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : p.z;
178
+ THIS->resize_to(x, y, z);
179
+ }
112
180
 
113
- *THIS = *bounds;
114
181
  return self;
115
182
  }
116
- RUBY_END
183
+ RUCY_END
117
184
 
118
185
  static
119
- RUBY_DEF1(set_x, x)
186
+ RUCY_DEFN(resize_by)
187
+ {
188
+ CHECK;
189
+ check_arg_count(__FILE__, __LINE__, "Bounds#resize_by", argc, 1, 2, 3);
190
+
191
+ if (argv[0].is_kind_of(Rays::point_class()))
192
+ THIS->resize_by(to<Rays::Point&>(argv[0]));
193
+ else
194
+ {
195
+ if (argv[0].is_array())
196
+ {
197
+ argc = argv[0].size();
198
+ argv = argv[0].as_array();
199
+ }
200
+
201
+ coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : 0;
202
+ coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : 0;
203
+ coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : 0;
204
+ THIS->resize_by(x, y, z);
205
+ }
206
+
207
+ return self;
208
+ }
209
+ RUCY_END
210
+
211
+ static
212
+ RUCY_DEFN(inset_by)
213
+ {
214
+ CHECK;
215
+ check_arg_count(__FILE__, __LINE__, "Bounds#inset_by", argc, 1, 2, 3);
216
+
217
+ if (argv[0].is_kind_of(Rays::point_class()))
218
+ THIS->inset_by(to<Rays::Point&>(argv[0]));
219
+ else
220
+ {
221
+ if (argv[0].is_array())
222
+ {
223
+ argc = argv[0].size();
224
+ argv = argv[0].as_array();
225
+ }
226
+
227
+ coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : 0;
228
+ coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : 0;
229
+ coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : 0;
230
+ THIS->inset_by(x, y, z);
231
+ }
232
+
233
+ return self;
234
+ }
235
+ RUCY_END
236
+
237
+ static
238
+ RUCY_DEF1(set_x, x)
120
239
  {
121
240
  CHECK;
122
241
 
123
242
  return value(THIS->x = to<coord>(x));
124
243
  }
125
- RUBY_END
244
+ RUCY_END
126
245
 
127
246
  static
128
- RUBY_DEF0(get_x)
247
+ RUCY_DEF0(get_x)
129
248
  {
130
249
  CHECK;
131
250
 
132
251
  return value(THIS->x);
133
252
  }
134
- RUBY_END
253
+ RUCY_END
135
254
 
136
255
  static
137
- RUBY_DEF1(set_y, y)
256
+ RUCY_DEF1(set_y, y)
138
257
  {
139
258
  CHECK;
140
259
 
141
260
  return value(THIS->y = to<coord>(y));
142
261
  }
143
- RUBY_END
262
+ RUCY_END
144
263
 
145
264
  static
146
- RUBY_DEF0(get_y)
265
+ RUCY_DEF0(get_y)
147
266
  {
148
267
  CHECK;
149
268
 
150
269
  return value(THIS->y);
151
270
  }
152
- RUBY_END
271
+ RUCY_END
153
272
 
154
273
  static
155
- RUBY_DEF1(set_z, z)
274
+ RUCY_DEF1(set_z, z)
156
275
  {
157
276
  CHECK;
158
277
 
159
278
  return value(THIS->z = to<coord>(z));
160
279
  }
161
- RUBY_END
280
+ RUCY_END
162
281
 
163
282
  static
164
- RUBY_DEF0(get_z)
283
+ RUCY_DEF0(get_z)
165
284
  {
166
285
  CHECK;
167
286
 
168
287
  return value(THIS->z);
169
288
  }
170
- RUBY_END
289
+ RUCY_END
171
290
 
172
291
  static
173
- RUBY_DEF1(set_width, width)
292
+ RUCY_DEF1(set_width, width)
174
293
  {
175
294
  CHECK;
176
295
 
177
296
  return value(THIS->width = to<coord>(width));
178
297
  }
179
- RUBY_END
298
+ RUCY_END
180
299
 
181
300
  static
182
- RUBY_DEF0(get_width)
301
+ RUCY_DEF0(get_width)
183
302
  {
184
303
  CHECK;
185
304
 
186
305
  return value(THIS->width);
187
306
  }
188
- RUBY_END
307
+ RUCY_END
189
308
 
190
309
  static
191
- RUBY_DEF1(set_height, height)
310
+ RUCY_DEF1(set_height, height)
192
311
  {
193
312
  CHECK;
194
313
 
195
314
  return value(THIS->height = to<coord>(height));
196
315
  }
197
- RUBY_END
316
+ RUCY_END
198
317
 
199
318
  static
200
- RUBY_DEF0(get_height)
319
+ RUCY_DEF0(get_height)
201
320
  {
202
321
  CHECK;
203
322
 
204
323
  return value(THIS->height);
205
324
  }
206
- RUBY_END
325
+ RUCY_END
207
326
 
208
327
  static
209
- RUBY_DEF1(set_depth, depth)
328
+ RUCY_DEF1(set_depth, depth)
210
329
  {
211
330
  CHECK;
212
331
 
213
332
  return value(THIS->depth = to<coord>(depth));
214
333
  }
215
- RUBY_END
334
+ RUCY_END
216
335
 
217
336
  static
218
- RUBY_DEF0(get_depth)
337
+ RUCY_DEF0(get_depth)
219
338
  {
220
339
  CHECK;
221
340
 
222
341
  return value(THIS->depth);
223
342
  }
224
- RUBY_END
343
+ RUCY_END
225
344
 
226
345
  static
227
- RUBY_DEF1(set_left, left)
346
+ RUCY_DEF1(set_left, left)
228
347
  {
229
348
  CHECK;
230
349
  Rays::Bounds* this_ = THIS;
@@ -232,19 +351,19 @@ RUBY_DEF1(set_left, left)
232
351
  this_->set_left(to<coord>(left));
233
352
  return value(this_->left());
234
353
  }
235
- RUBY_END
354
+ RUCY_END
236
355
 
237
356
  static
238
- RUBY_DEF0(get_left)
357
+ RUCY_DEF0(get_left)
239
358
  {
240
359
  CHECK;
241
360
 
242
361
  return value(THIS->left());
243
362
  }
244
- RUBY_END
363
+ RUCY_END
245
364
 
246
365
  static
247
- RUBY_DEF1(set_right, right)
366
+ RUCY_DEF1(set_right, right)
248
367
  {
249
368
  CHECK;
250
369
  Rays::Bounds* this_ = THIS;
@@ -252,19 +371,19 @@ RUBY_DEF1(set_right, right)
252
371
  this_->set_right(to<coord>(right));
253
372
  return value(this_->right());
254
373
  }
255
- RUBY_END
374
+ RUCY_END
256
375
 
257
376
  static
258
- RUBY_DEF0(get_right)
377
+ RUCY_DEF0(get_right)
259
378
  {
260
379
  CHECK;
261
380
 
262
381
  return value(THIS->right());
263
382
  }
264
- RUBY_END
383
+ RUCY_END
265
384
 
266
385
  static
267
- RUBY_DEF1(set_top, top)
386
+ RUCY_DEF1(set_top, top)
268
387
  {
269
388
  CHECK;
270
389
  Rays::Bounds* this_ = THIS;
@@ -272,19 +391,19 @@ RUBY_DEF1(set_top, top)
272
391
  this_->set_top(to<coord>(top));
273
392
  return value(this_->top());
274
393
  }
275
- RUBY_END
394
+ RUCY_END
276
395
 
277
396
  static
278
- RUBY_DEF0(get_top)
397
+ RUCY_DEF0(get_top)
279
398
  {
280
399
  CHECK;
281
400
 
282
401
  return value(THIS->top());
283
402
  }
284
- RUBY_END
403
+ RUCY_END
285
404
 
286
405
  static
287
- RUBY_DEF1(set_bottom, bottom)
406
+ RUCY_DEF1(set_bottom, bottom)
288
407
  {
289
408
  CHECK;
290
409
  Rays::Bounds* this_ = THIS;
@@ -292,19 +411,19 @@ RUBY_DEF1(set_bottom, bottom)
292
411
  this_->set_bottom(to<coord>(bottom));
293
412
  return value(this_->bottom());
294
413
  }
295
- RUBY_END
414
+ RUCY_END
296
415
 
297
416
  static
298
- RUBY_DEF0(get_bottom)
417
+ RUCY_DEF0(get_bottom)
299
418
  {
300
419
  CHECK;
301
420
 
302
421
  return value(THIS->bottom());
303
422
  }
304
- RUBY_END
423
+ RUCY_END
305
424
 
306
425
  static
307
- RUBY_DEF1(set_back, back)
426
+ RUCY_DEF1(set_back, back)
308
427
  {
309
428
  CHECK;
310
429
  Rays::Bounds* this_ = THIS;
@@ -312,19 +431,19 @@ RUBY_DEF1(set_back, back)
312
431
  this_->set_back(to<coord>(back));
313
432
  return value(this_->back());
314
433
  }
315
- RUBY_END
434
+ RUCY_END
316
435
 
317
436
  static
318
- RUBY_DEF0(get_back)
437
+ RUCY_DEF0(get_back)
319
438
  {
320
439
  CHECK;
321
440
 
322
441
  return value(THIS->back());
323
442
  }
324
- RUBY_END
443
+ RUCY_END
325
444
 
326
445
  static
327
- RUBY_DEF1(set_front, front)
446
+ RUCY_DEF1(set_front, front)
328
447
  {
329
448
  CHECK;
330
449
  Rays::Bounds* this_ = THIS;
@@ -332,58 +451,146 @@ RUBY_DEF1(set_front, front)
332
451
  this_->set_front(to<coord>(front));
333
452
  return value(this_->front());
334
453
  }
335
- RUBY_END
454
+ RUCY_END
336
455
 
337
456
  static
338
- RUBY_DEF0(get_front)
457
+ RUCY_DEF0(get_front)
339
458
  {
340
459
  CHECK;
341
460
 
342
461
  return value(THIS->front());
343
462
  }
344
- RUBY_END
463
+ RUCY_END
345
464
 
346
465
  static
347
- RUBY_DEF1(set_position, pos)
466
+ RUCY_DEFN(set_position)
348
467
  {
349
468
  CHECK;
469
+ check_arg_count(__FILE__, __LINE__, "Bounds#set_position", argc, 1, 2, 3);
350
470
 
351
- Rays::Point* p = to<Rays::Point*>(pos);
352
- if (!p) argument_error("%s is not a Rays::Point.", pos.inspect().c_str());
353
-
354
- return value(THIS->position() = *p);
471
+ coord* pos = THIS->position().array;
472
+ for (int i = 0; i < 3; ++i)
473
+ if (argc > i && !argv[i].is_nil()) pos[i] = to<coord>(argv[i]);
355
474
  }
356
- RUBY_END
475
+ RUCY_END
357
476
 
358
477
  static
359
- RUBY_DEF0(get_position)
478
+ RUCY_DEF0(get_position)
360
479
  {
361
480
  CHECK;
362
481
 
363
482
  return value(THIS->position());
364
483
  }
365
- RUBY_END
484
+ RUCY_END
366
485
 
367
486
  static
368
- RUBY_DEF1(set_size, size)
487
+ RUCY_DEFN(set_size)
369
488
  {
370
489
  CHECK;
490
+ check_arg_count(__FILE__, __LINE__, "Bounds#set_size", argc, 1, 2, 3);
371
491
 
372
- Rays::Point* p = to<Rays::Point*>(size);
373
- if (!p) argument_error("%s is not a Rays::Point.", size.inspect().c_str());
374
-
375
- return value(THIS->size() = *p);
492
+ coord* size = THIS->size().array;
493
+ for (int i = 0; i < 3; ++i)
494
+ if (argc > i && !argv[i].is_nil()) size[i] = to<coord>(argv[i]);
376
495
  }
377
- RUBY_END
496
+ RUCY_END
378
497
 
379
498
  static
380
- RUBY_DEF0(get_size)
499
+ RUCY_DEF0(get_size)
381
500
  {
382
501
  CHECK;
383
502
 
384
503
  return value(THIS->size());
385
504
  }
386
- RUBY_END
505
+ RUCY_END
506
+
507
+ static
508
+ RUCY_DEFN(set_center)
509
+ {
510
+ CHECK;
511
+ check_arg_count(__FILE__, __LINE__, "Bounds#set_center", argc, 1, 2, 3);
512
+
513
+ if (argv[0].is_kind_of(Rays::point_class()))
514
+ THIS->set_center(to<Rays::Point&>(argv[0]));
515
+ else
516
+ {
517
+ Rays::Point p = THIS->center();
518
+ coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : p.x;
519
+ coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : p.y;
520
+ coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : p.z;
521
+ THIS->set_center(x, y, z);
522
+ }
523
+
524
+ return value(THIS->center());
525
+ }
526
+ RUCY_END
527
+
528
+ static
529
+ RUCY_DEF0(center)
530
+ {
531
+ CHECK;
532
+
533
+ return value(THIS->center());
534
+ }
535
+ RUCY_END
536
+
537
+ static
538
+ RUCY_DEF1(array_get, index)
539
+ {
540
+ CHECK;
541
+
542
+ int i = index.as_i();
543
+ if (i < 0 || 1 < i)
544
+ index_error(__FILE__, __LINE__);
545
+
546
+ return value((*THIS)[i]);
547
+ }
548
+ RUCY_END
549
+
550
+ static
551
+ RUCY_DEF2(array_set, index, value)
552
+ {
553
+ CHECK;
554
+
555
+ int i = index.as_i();
556
+ if (i < 0 || 1 < i)
557
+ index_error(__FILE__, __LINE__);
558
+
559
+ (*THIS)[i] = to<Rays::Point&>(value);
560
+ return value;
561
+ }
562
+ RUCY_END
563
+
564
+ static
565
+ RUCY_DEF1(and_, bounds)
566
+ {
567
+ CHECK;
568
+
569
+ Rays::Bounds b = *THIS;
570
+ b &= to<Rays::Bounds&>(bounds);
571
+ return value(b);
572
+ }
573
+ RUCY_END
574
+
575
+ static
576
+ RUCY_DEF1(or_, bounds)
577
+ {
578
+ CHECK;
579
+
580
+ Rays::Bounds b = *THIS;
581
+ b |= to<Rays::Bounds&>(bounds);
582
+ return value(b);
583
+ }
584
+ RUCY_END
585
+
586
+ static
587
+ RUCY_DEF0(inspect)
588
+ {
589
+ CHECK;
590
+
591
+ return value(Xot::stringf("#<Rays::Bounds %s>", THIS->inspect().c_str()));
592
+ }
593
+ RUCY_END
387
594
 
388
595
 
389
596
  void
@@ -395,32 +602,121 @@ Init_bounds ()
395
602
  cBounds.define_alloc_func(alloc);
396
603
  cBounds.define_private_method("initialize", initialize);
397
604
  cBounds.define_private_method("initialize_copy", initialize_copy);
398
- cBounds.define_method("x=", set_x);
399
- cBounds.define_method("x", get_x);
400
- cBounds.define_method("y=", set_y);
401
- cBounds.define_method("y", get_y);
402
- cBounds.define_method("z=", set_z);
403
- cBounds.define_method("z", get_z);
404
- cBounds.define_method("width=", set_width);
405
- cBounds.define_method("width", get_width);
605
+ cBounds.define_method("intersect?", intersect);
606
+ cBounds.define_method("include?", include);
607
+ cBounds.define_method("move_to!", move_to);
608
+ cBounds.define_method("move_by!", move_by);
609
+ cBounds.define_method("resize_to!", resize_to);
610
+ cBounds.define_method("resize_by!", resize_by);
611
+ cBounds.define_method("inset_by!", inset_by);
612
+ cBounds.define_method("x=", set_x);
613
+ cBounds.define_method("x", get_x);
614
+ cBounds.define_method("y=", set_y);
615
+ cBounds.define_method("y", get_y);
616
+ cBounds.define_method("z=", set_z);
617
+ cBounds.define_method("z", get_z);
618
+ cBounds.define_method("width=", set_width);
619
+ cBounds.define_method("width", get_width);
406
620
  cBounds.define_method("height=", set_height);
407
- cBounds.define_method("height", get_height);
408
- cBounds.define_method("depth=", set_depth);
409
- cBounds.define_method("depth", get_depth);
410
- cBounds.define_method("left=", set_left);
411
- cBounds.define_method("left", get_left);
412
- cBounds.define_method("right=", set_right);
413
- cBounds.define_method("right", get_right);
414
- cBounds.define_method("top=", set_top);
415
- cBounds.define_method("top", get_top);
621
+ cBounds.define_method("height", get_height);
622
+ cBounds.define_method("depth=", set_depth);
623
+ cBounds.define_method("depth", get_depth);
624
+ cBounds.define_method("left=", set_left);
625
+ cBounds.define_method("left", get_left);
626
+ cBounds.define_method("right=", set_right);
627
+ cBounds.define_method("right", get_right);
628
+ cBounds.define_method("top=", set_top);
629
+ cBounds.define_method("top", get_top);
416
630
  cBounds.define_method("bottom=", set_bottom);
417
- cBounds.define_method("bottom", get_bottom);
418
- cBounds.define_method("back=", set_back);
419
- cBounds.define_method("back", get_back);
420
- cBounds.define_method("front=", set_front);
421
- cBounds.define_method("front", get_front);
422
- cBounds.define_method("position=", set_position);
423
- cBounds.define_method("position", get_position);
424
- cBounds.define_method("size=", set_size);
425
- cBounds.define_method("size", get_size);
631
+ cBounds.define_method("bottom", get_bottom);
632
+ cBounds.define_method("back=", set_back);
633
+ cBounds.define_method("back", get_back);
634
+ cBounds.define_method("front=", set_front);
635
+ cBounds.define_method("front", get_front);
636
+ cBounds.define_method("set_position", set_position);
637
+ cBounds.define_method( "position", get_position);
638
+ cBounds.define_method("set_size", set_size);
639
+ cBounds.define_method( "size", get_size);
640
+ cBounds.define_method("set_center", set_center);
641
+ cBounds.define_method("center", center);
642
+ cBounds.define_method("[]", array_get);
643
+ cBounds.define_method("[]=", array_set);
644
+ cBounds.define_method("&", and_);
645
+ cBounds.define_method("|", or_);
646
+ cBounds.define_method("inspect", inspect);
426
647
  }
648
+
649
+
650
+ namespace Rucy
651
+ {
652
+
653
+
654
+ template <> Rays::Bounds
655
+ value_to<Rays::Bounds> (Value value, bool convert)
656
+ {
657
+ if (convert)
658
+ {
659
+ size_t argc = 0;
660
+ Value* argv = NULL;
661
+ if (value.is_array())
662
+ {
663
+ argc = value.size();
664
+ argv = value.as_array();
665
+ }
666
+ else
667
+ {
668
+ argc = 1;
669
+ argv = &value;
670
+ }
671
+
672
+ if (argc < 1)
673
+ Rucy::argument_error(__FILE__, __LINE__);
674
+
675
+ if (argv[0].is_kind_of(Rays::bounds_class()))
676
+ value = argv[0];
677
+ else if (argv[0].is_kind_of(Rays::point_class()))
678
+ {
679
+ switch (argc)
680
+ {
681
+ #define V(i) to<Rays::Point&>(argv[i])
682
+ case 1: return Rays::Bounds(V(0));
683
+ case 2: return Rays::Bounds(V(0), V(1));
684
+ #undef V
685
+ default: Rucy::argument_error(__FILE__, __LINE__);
686
+ }
687
+ }
688
+ else if (argv[0].is_i() || argv[0].is_f())
689
+ {
690
+ switch (argc)
691
+ {
692
+ #define V(i) argv[i].as_f(true)
693
+ case 1: return Rays::Bounds(V(0));
694
+ case 2: return Rays::Bounds(V(0), V(1));
695
+ case 3: return Rays::Bounds(V(0), V(1), V(2));
696
+ case 4: return Rays::Bounds(V(0), V(1), V(2), V(3));
697
+ case 6: return Rays::Bounds(V(0), V(1), V(2), V(3), V(4), V(5));
698
+ #undef V
699
+ default: Rucy::argument_error(__FILE__, __LINE__);
700
+ }
701
+ }
702
+ }
703
+
704
+ return value_to<Rays::Bounds&>(value, convert);
705
+ }
706
+
707
+
708
+ }// Rucy
709
+
710
+
711
+ namespace Rays
712
+ {
713
+
714
+
715
+ Class
716
+ bounds_class ()
717
+ {
718
+ return cBounds;
719
+ }
720
+
721
+
722
+ }// Rays