rays 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.doc/ext/rays/bitmap.cpp +70 -233
- data/.doc/ext/rays/bounds.cpp +339 -57
- data/.doc/ext/rays/color.cpp +58 -48
- data/.doc/ext/rays/color_space.cpp +174 -0
- data/.doc/ext/rays/font.cpp +31 -53
- data/.doc/ext/rays/image.cpp +64 -67
- data/.doc/ext/rays/matrix.cpp +22 -50
- data/.doc/ext/rays/native.cpp +9 -2
- data/.doc/ext/rays/painter.cpp +276 -259
- data/.doc/ext/rays/point.cpp +186 -52
- data/.doc/ext/rays/rays.cpp +25 -20
- data/.doc/ext/rays/shader.cpp +61 -0
- data/.doc/ext/rays/texture.cpp +47 -59
- data/{README → README.md} +0 -0
- data/Rakefile +6 -5
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +88 -248
- data/ext/rays/bounds.cpp +437 -141
- data/ext/rays/color.cpp +79 -69
- data/ext/rays/color_space.cpp +185 -0
- data/ext/rays/extconf.rb +14 -63
- data/ext/rays/font.cpp +44 -65
- data/ext/rays/image.cpp +82 -81
- data/ext/rays/matrix.cpp +32 -60
- data/ext/rays/native.cpp +9 -2
- data/ext/rays/painter.cpp +345 -321
- data/ext/rays/point.cpp +212 -69
- data/ext/rays/rays.cpp +29 -23
- data/ext/rays/shader.cpp +63 -0
- data/ext/rays/texture.cpp +64 -74
- data/include/rays/bitmap.h +21 -12
- data/include/rays/bounds.h +67 -9
- data/include/rays/color.h +23 -7
- data/include/rays/{colorspace.h → color_space.h} +6 -3
- data/include/rays/exception.h +17 -11
- data/include/rays/font.h +4 -3
- data/include/rays/image.h +11 -6
- data/include/rays/matrix.h +15 -12
- data/include/rays/opengl.h +54 -1
- data/include/rays/painter.h +98 -108
- data/include/rays/point.h +45 -5
- data/include/rays/rays.h +2 -2
- data/include/rays/ruby/bitmap.h +2 -16
- data/include/rays/ruby/bounds.h +4 -16
- data/include/rays/ruby/color.h +3 -16
- data/include/rays/ruby/color_space.h +27 -0
- data/include/rays/ruby/font.h +2 -16
- data/include/rays/ruby/image.h +2 -16
- data/include/rays/ruby/matrix.h +2 -16
- data/include/rays/ruby/painter.h +2 -16
- data/include/rays/ruby/point.h +3 -16
- data/include/rays/ruby/shader.h +27 -0
- data/include/rays/ruby/texture.h +2 -16
- data/include/rays/ruby.h +1 -0
- data/include/rays/shader.h +48 -0
- data/include/rays/texture.h +13 -2
- data/include/rays.h +2 -1
- data/lib/rays/bitmap.rb +20 -11
- data/lib/rays/bounds.rb +29 -68
- data/lib/rays/color.rb +39 -0
- data/lib/rays/color_space.rb +33 -0
- data/lib/rays/font.rb +29 -0
- data/lib/rays/image.rb +22 -0
- data/lib/rays/module.rb +11 -7
- data/lib/rays/painter.rb +103 -40
- data/lib/rays/point.rb +19 -36
- data/lib/rays/shader.rb +13 -0
- data/lib/rays/texture.rb +9 -0
- data/lib/rays.rb +4 -0
- data/rays.gemspec +3 -4
- data/src/bounds.cpp +272 -63
- data/src/color.cpp +168 -21
- data/src/{colorspace.cpp → color_space.cpp} +38 -1
- data/src/exception.cpp +24 -15
- data/src/frame_buffer.cpp +275 -0
- data/src/frame_buffer.h +79 -0
- data/src/image.cpp +80 -36
- data/src/ios/bitmap.mm +340 -0
- data/src/ios/font.mm +206 -0
- data/src/{cocoa → ios}/helper.h +2 -2
- data/src/{cocoa → ios}/helper.mm +0 -0
- data/src/ios/opengl.mm +21 -0
- data/src/ios/program.cpp +122 -0
- data/src/{cocoa → ios}/rays.mm +8 -7
- data/src/matrix.cpp +10 -22
- data/src/opengl.cpp +64 -0
- data/src/{cocoa → osx}/bitmap.mm +121 -70
- data/src/{cocoa → osx}/font.mm +32 -24
- data/src/osx/helper.h +26 -0
- data/src/osx/helper.mm +25 -0
- data/src/osx/opengl.mm +103 -0
- data/src/osx/rays.mm +43 -0
- data/src/painter.cpp +596 -422
- data/src/point.cpp +154 -11
- data/src/program.cpp +513 -0
- data/src/program.h +73 -0
- data/src/render_buffer.cpp +120 -0
- data/src/render_buffer.h +47 -0
- data/src/shader.cpp +117 -0
- data/src/texture.cpp +104 -134
- data/test/helper.rb +10 -3
- data/test/test_bitmap.rb +18 -0
- data/test/test_bounds.rb +81 -35
- data/test/test_color.rb +29 -2
- data/test/test_image.rb +63 -0
- data/test/test_painter.rb +120 -0
- data/test/test_point.rb +30 -9
- data/test/test_shader.rb +37 -0
- data/test/test_texture.rb +18 -0
- metadata +75 -58
- data/.gitignore +0 -14
- data/ChangeLog +0 -8
data/.doc/ext/rays/bounds.cpp
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
#include <rucy.h>
|
5
|
-
#include
|
5
|
+
#include "rays/ruby/point.h"
|
6
6
|
#include "defs.h"
|
7
7
|
|
8
8
|
|
@@ -13,44 +13,11 @@ using Rays::coord;
|
|
13
13
|
|
14
14
|
static Class cBounds;
|
15
15
|
|
16
|
+
RUCY_DEFINE_VALUE_FROM_TO(Rays::Bounds, cBounds)
|
16
17
|
|
17
|
-
|
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
|
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
|
@@ -62,10 +29,8 @@ VALUE alloc(VALUE klass)
|
|
62
29
|
static
|
63
30
|
VALUE initialize(VALUE self)
|
64
31
|
{
|
65
|
-
|
66
|
-
|
67
|
-
if (argc != 0 && argc != 1 && argc != 2 && argc != 3 && argc != 4 && argc != 6)
|
68
|
-
arg_count_error("Bounds#initialize", argc, 0, 1, 2, 3, 4, 6);
|
32
|
+
CHECK;
|
33
|
+
check_arg_count(__FILE__, __LINE__, "Bounds#initialize", argc, 0, 1, 2, 3, 4, 6);
|
69
34
|
|
70
35
|
if (argc == 0) return self;
|
71
36
|
|
@@ -103,12 +68,159 @@ VALUE initialize(VALUE self)
|
|
103
68
|
static
|
104
69
|
VALUE initialize_copy(VALUE self, VALUE obj)
|
105
70
|
{
|
106
|
-
|
71
|
+
CHECK;
|
72
|
+
*THIS = to<Rays::Bounds&>(obj);
|
73
|
+
return self;
|
74
|
+
}
|
75
|
+
|
76
|
+
static
|
77
|
+
VALUE intersect(VALUE self)
|
78
|
+
{
|
79
|
+
CHECK;
|
80
|
+
check_arg_count(__FILE__, __LINE__, "Bounds#intersect?", argc, 1, 2);
|
81
|
+
|
82
|
+
const Rays::Bounds& bounds = to<Rays::Bounds&>(argv[0]);
|
83
|
+
int dimension = argc >= 2 ? to<int>(argv[1]) : 2;
|
84
|
+
|
85
|
+
return value(THIS->is_intersect(bounds, dimension));
|
86
|
+
}
|
87
|
+
|
88
|
+
static
|
89
|
+
VALUE include(VALUE self)
|
90
|
+
{
|
91
|
+
CHECK;
|
92
|
+
check_arg_count(__FILE__, __LINE__, "Bounds#include?", argc, 1, 2);
|
93
|
+
|
94
|
+
const Rays::Point& point = to<Rays::Point&>(argv[0]);
|
95
|
+
int dimension = argc >= 2 ? to<int>(argv[1]) : 2;
|
96
|
+
|
97
|
+
return value(THIS->is_include(point, dimension));
|
98
|
+
}
|
99
|
+
|
100
|
+
static
|
101
|
+
VALUE move_to(VALUE self)
|
102
|
+
{
|
103
|
+
CHECK;
|
104
|
+
check_arg_count(__FILE__, __LINE__, "Bounds#move_to", argc, 1, 2, 3);
|
105
|
+
|
106
|
+
if (argv[0].is_kind_of(Rays::point_class()))
|
107
|
+
THIS->move_to(to<Rays::Point&>(argv[0]));
|
108
|
+
else
|
109
|
+
{
|
110
|
+
if (argv[0].is_array())
|
111
|
+
{
|
112
|
+
argc = argv[0].size();
|
113
|
+
argv = argv[0].as_array();
|
114
|
+
}
|
115
|
+
|
116
|
+
const Rays::Point& p = THIS->position();
|
117
|
+
coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : p.x;
|
118
|
+
coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : p.y;
|
119
|
+
coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : p.z;
|
120
|
+
THIS->move_to(x, y, z);
|
121
|
+
}
|
122
|
+
|
123
|
+
return self;
|
124
|
+
}
|
125
|
+
|
126
|
+
static
|
127
|
+
VALUE move_by(VALUE self)
|
128
|
+
{
|
129
|
+
CHECK;
|
130
|
+
check_arg_count(__FILE__, __LINE__, "Bounds#move_by", argc, 1, 2, 3);
|
131
|
+
|
132
|
+
if (argv[0].is_kind_of(Rays::point_class()))
|
133
|
+
THIS->move_by(to<Rays::Point&>(argv[0]));
|
134
|
+
else
|
135
|
+
{
|
136
|
+
if (argv[0].is_array())
|
137
|
+
{
|
138
|
+
argc = argv[0].size();
|
139
|
+
argv = argv[0].as_array();
|
140
|
+
}
|
141
|
+
|
142
|
+
coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : 0;
|
143
|
+
coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : 0;
|
144
|
+
coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : 0;
|
145
|
+
THIS->move_by(x, y, z);
|
146
|
+
}
|
147
|
+
|
148
|
+
return self;
|
149
|
+
}
|
150
|
+
|
151
|
+
static
|
152
|
+
VALUE resize_to(VALUE self)
|
153
|
+
{
|
154
|
+
CHECK;
|
155
|
+
check_arg_count(__FILE__, __LINE__, "Bounds#resize_to", argc, 1, 2, 3);
|
107
156
|
|
108
|
-
|
109
|
-
|
157
|
+
if (argv[0].is_kind_of(Rays::point_class()))
|
158
|
+
THIS->resize_to(to<Rays::Point&>(argv[0]));
|
159
|
+
else
|
160
|
+
{
|
161
|
+
if (argv[0].is_array())
|
162
|
+
{
|
163
|
+
argc = argv[0].size();
|
164
|
+
argv = argv[0].as_array();
|
165
|
+
}
|
166
|
+
|
167
|
+
const Rays::Point& p = THIS->size();
|
168
|
+
coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : p.x;
|
169
|
+
coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : p.y;
|
170
|
+
coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : p.z;
|
171
|
+
THIS->resize_to(x, y, z);
|
172
|
+
}
|
173
|
+
|
174
|
+
return self;
|
175
|
+
}
|
176
|
+
|
177
|
+
static
|
178
|
+
VALUE resize_by(VALUE self)
|
179
|
+
{
|
180
|
+
CHECK;
|
181
|
+
check_arg_count(__FILE__, __LINE__, "Bounds#resize_by", argc, 1, 2, 3);
|
182
|
+
|
183
|
+
if (argv[0].is_kind_of(Rays::point_class()))
|
184
|
+
THIS->resize_by(to<Rays::Point&>(argv[0]));
|
185
|
+
else
|
186
|
+
{
|
187
|
+
if (argv[0].is_array())
|
188
|
+
{
|
189
|
+
argc = argv[0].size();
|
190
|
+
argv = argv[0].as_array();
|
191
|
+
}
|
192
|
+
|
193
|
+
coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : 0;
|
194
|
+
coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : 0;
|
195
|
+
coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : 0;
|
196
|
+
THIS->resize_by(x, y, z);
|
197
|
+
}
|
198
|
+
|
199
|
+
return self;
|
200
|
+
}
|
201
|
+
|
202
|
+
static
|
203
|
+
VALUE inset_by(VALUE self)
|
204
|
+
{
|
205
|
+
CHECK;
|
206
|
+
check_arg_count(__FILE__, __LINE__, "Bounds#inset_by", argc, 1, 2, 3);
|
207
|
+
|
208
|
+
if (argv[0].is_kind_of(Rays::point_class()))
|
209
|
+
THIS->inset_by(to<Rays::Point&>(argv[0]));
|
210
|
+
else
|
211
|
+
{
|
212
|
+
if (argv[0].is_array())
|
213
|
+
{
|
214
|
+
argc = argv[0].size();
|
215
|
+
argv = argv[0].as_array();
|
216
|
+
}
|
217
|
+
|
218
|
+
coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : 0;
|
219
|
+
coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : 0;
|
220
|
+
coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : 0;
|
221
|
+
THIS->inset_by(x, y, z);
|
222
|
+
}
|
110
223
|
|
111
|
-
*THIS = *bounds;
|
112
224
|
return self;
|
113
225
|
}
|
114
226
|
|
@@ -317,14 +429,14 @@ VALUE get_front(VALUE self)
|
|
317
429
|
}
|
318
430
|
|
319
431
|
static
|
320
|
-
VALUE set_position(VALUE self
|
432
|
+
VALUE set_position(VALUE self)
|
321
433
|
{
|
322
434
|
CHECK;
|
435
|
+
check_arg_count(__FILE__, __LINE__, "Bounds#set_position", argc, 1, 2, 3);
|
323
436
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
return value(THIS->position() = *p);
|
437
|
+
coord* pos = THIS->position().array;
|
438
|
+
for (int i = 0; i < 3; ++i)
|
439
|
+
if (argc > i && !argv[i].is_nil()) pos[i] = to<coord>(argv[i]);
|
328
440
|
}
|
329
441
|
|
330
442
|
static
|
@@ -336,14 +448,14 @@ VALUE get_position(VALUE self)
|
|
336
448
|
}
|
337
449
|
|
338
450
|
static
|
339
|
-
VALUE set_size(VALUE self
|
451
|
+
VALUE set_size(VALUE self)
|
340
452
|
{
|
341
453
|
CHECK;
|
454
|
+
check_arg_count(__FILE__, __LINE__, "Bounds#set_size", argc, 1, 2, 3);
|
342
455
|
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
return value(THIS->size() = *p);
|
456
|
+
coord* size = THIS->size().array;
|
457
|
+
for (int i = 0; i < 3; ++i)
|
458
|
+
if (argc > i && !argv[i].is_nil()) size[i] = to<coord>(argv[i]);
|
347
459
|
}
|
348
460
|
|
349
461
|
static
|
@@ -354,6 +466,87 @@ VALUE get_size(VALUE self)
|
|
354
466
|
return value(THIS->size());
|
355
467
|
}
|
356
468
|
|
469
|
+
static
|
470
|
+
VALUE set_center(VALUE self)
|
471
|
+
{
|
472
|
+
CHECK;
|
473
|
+
check_arg_count(__FILE__, __LINE__, "Bounds#set_center", argc, 1, 2, 3);
|
474
|
+
|
475
|
+
if (argv[0].is_kind_of(Rays::point_class()))
|
476
|
+
THIS->set_center(to<Rays::Point&>(argv[0]));
|
477
|
+
else
|
478
|
+
{
|
479
|
+
Rays::Point p = THIS->center();
|
480
|
+
coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : p.x;
|
481
|
+
coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : p.y;
|
482
|
+
coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : p.z;
|
483
|
+
THIS->set_center(x, y, z);
|
484
|
+
}
|
485
|
+
|
486
|
+
return value(THIS->center());
|
487
|
+
}
|
488
|
+
|
489
|
+
static
|
490
|
+
VALUE center(VALUE self)
|
491
|
+
{
|
492
|
+
CHECK;
|
493
|
+
|
494
|
+
return value(THIS->center());
|
495
|
+
}
|
496
|
+
|
497
|
+
static
|
498
|
+
VALUE array_get(VALUE self, VALUE index)
|
499
|
+
{
|
500
|
+
CHECK;
|
501
|
+
|
502
|
+
int i = index.as_i();
|
503
|
+
if (i < 0 || 1 < i)
|
504
|
+
index_error(__FILE__, __LINE__);
|
505
|
+
|
506
|
+
return value((*THIS)[i]);
|
507
|
+
}
|
508
|
+
|
509
|
+
static
|
510
|
+
VALUE array_set(VALUE self, VALUE index, VALUE value)
|
511
|
+
{
|
512
|
+
CHECK;
|
513
|
+
|
514
|
+
int i = index.as_i();
|
515
|
+
if (i < 0 || 1 < i)
|
516
|
+
index_error(__FILE__, __LINE__);
|
517
|
+
|
518
|
+
(*THIS)[i] = to<Rays::Point&>(value);
|
519
|
+
return value;
|
520
|
+
}
|
521
|
+
|
522
|
+
static
|
523
|
+
VALUE and_(VALUE self, VALUE bounds)
|
524
|
+
{
|
525
|
+
CHECK;
|
526
|
+
|
527
|
+
Rays::Bounds b = *THIS;
|
528
|
+
b &= to<Rays::Bounds&>(bounds);
|
529
|
+
return value(b);
|
530
|
+
}
|
531
|
+
|
532
|
+
static
|
533
|
+
VALUE or_(VALUE self, VALUE bounds)
|
534
|
+
{
|
535
|
+
CHECK;
|
536
|
+
|
537
|
+
Rays::Bounds b = *THIS;
|
538
|
+
b |= to<Rays::Bounds&>(bounds);
|
539
|
+
return value(b);
|
540
|
+
}
|
541
|
+
|
542
|
+
static
|
543
|
+
VALUE inspect(VALUE self)
|
544
|
+
{
|
545
|
+
CHECK;
|
546
|
+
|
547
|
+
return value(Xot::stringf("#<Rays::Bounds %s>", THIS->inspect().c_str()));
|
548
|
+
}
|
549
|
+
|
357
550
|
|
358
551
|
void
|
359
552
|
Init_bounds ()
|
@@ -364,6 +557,13 @@ Init_bounds ()
|
|
364
557
|
rb_define_alloc_func(cBounds, alloc);
|
365
558
|
rb_define_private_method(cBounds, "initialize", RUBY_METHOD_FUNC(initialize), -1);
|
366
559
|
rb_define_private_method(cBounds, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1);
|
560
|
+
cBounds.define_method("intersect?", intersect);
|
561
|
+
cBounds.define_method("include?", include);
|
562
|
+
cBounds.define_method("move_to!", move_to);
|
563
|
+
cBounds.define_method("move_by!", move_by);
|
564
|
+
cBounds.define_method("resize_to!", resize_to);
|
565
|
+
cBounds.define_method("resize_by!", resize_by);
|
566
|
+
cBounds.define_method("inset_by!", inset_by);
|
367
567
|
rb_define_method(cBounds, "x=", RUBY_METHOD_FUNC(set_x), 1);
|
368
568
|
rb_define_method(cBounds, "x", RUBY_METHOD_FUNC(get_x), 0);
|
369
569
|
rb_define_method(cBounds, "y=", RUBY_METHOD_FUNC(set_y), 1);
|
@@ -388,8 +588,90 @@ Init_bounds ()
|
|
388
588
|
rb_define_method(cBounds, "back", RUBY_METHOD_FUNC(get_back), 0);
|
389
589
|
rb_define_method(cBounds, "front=", RUBY_METHOD_FUNC(set_front), 1);
|
390
590
|
rb_define_method(cBounds, "front", RUBY_METHOD_FUNC(get_front), 0);
|
391
|
-
rb_define_method(cBounds, "
|
591
|
+
rb_define_method(cBounds, "set_position", RUBY_METHOD_FUNC(set_position), -1);
|
392
592
|
rb_define_method(cBounds, "position", RUBY_METHOD_FUNC(get_position), 0);
|
393
|
-
rb_define_method(cBounds, "
|
593
|
+
rb_define_method(cBounds, "set_size", RUBY_METHOD_FUNC(set_size), -1);
|
394
594
|
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_);
|
601
|
+
rb_define_method(cBounds, "inspect", RUBY_METHOD_FUNC(inspect), 0);
|
395
602
|
}
|
603
|
+
|
604
|
+
|
605
|
+
namespace Rucy
|
606
|
+
{
|
607
|
+
|
608
|
+
|
609
|
+
template <> Rays::Bounds
|
610
|
+
value_to<Rays::Bounds> (Value value, bool convert)
|
611
|
+
{
|
612
|
+
if (convert)
|
613
|
+
{
|
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
|
+
}
|
626
|
+
|
627
|
+
if (argc < 1)
|
628
|
+
Rucy::argument_error(__FILE__, __LINE__);
|
629
|
+
|
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()))
|
633
|
+
{
|
634
|
+
switch (argc)
|
635
|
+
{
|
636
|
+
#define V(i) to<Rays::Point&>(argv[i])
|
637
|
+
case 1: return Rays::Bounds(V(0));
|
638
|
+
case 2: return Rays::Bounds(V(0), V(1));
|
639
|
+
#undef V
|
640
|
+
default: Rucy::argument_error(__FILE__, __LINE__);
|
641
|
+
}
|
642
|
+
}
|
643
|
+
else if (argv[0].is_i() || argv[0].is_f())
|
644
|
+
{
|
645
|
+
switch (argc)
|
646
|
+
{
|
647
|
+
#define V(i) argv[i].as_f(true)
|
648
|
+
case 1: return Rays::Bounds(V(0));
|
649
|
+
case 2: return Rays::Bounds(V(0), V(1));
|
650
|
+
case 3: return Rays::Bounds(V(0), V(1), V(2));
|
651
|
+
case 4: return Rays::Bounds(V(0), V(1), V(2), V(3));
|
652
|
+
case 6: return Rays::Bounds(V(0), V(1), V(2), V(3), V(4), V(5));
|
653
|
+
#undef V
|
654
|
+
default: Rucy::argument_error(__FILE__, __LINE__);
|
655
|
+
}
|
656
|
+
}
|
657
|
+
}
|
658
|
+
|
659
|
+
return value_to<Rays::Bounds&>(value, convert);
|
660
|
+
}
|
661
|
+
|
662
|
+
|
663
|
+
}// Rucy
|
664
|
+
|
665
|
+
|
666
|
+
namespace Rays
|
667
|
+
{
|
668
|
+
|
669
|
+
|
670
|
+
Class
|
671
|
+
bounds_class ()
|
672
|
+
{
|
673
|
+
return cBounds;
|
674
|
+
}
|
675
|
+
|
676
|
+
|
677
|
+
}// Rays
|
data/.doc/ext/rays/color.cpp
CHANGED
@@ -10,44 +10,11 @@ using namespace Rucy;
|
|
10
10
|
|
11
11
|
static Class cColor;
|
12
12
|
|
13
|
+
RUCY_DEFINE_VALUE_FROM_TO(Rays::Color, cColor)
|
13
14
|
|
14
|
-
|
15
|
-
{
|
15
|
+
#define THIS to<Rays::Color*>(self)
|
16
16
|
|
17
|
-
|
18
|
-
Class
|
19
|
-
color_class ()
|
20
|
-
{
|
21
|
-
return cColor;
|
22
|
-
}
|
23
|
-
|
24
|
-
|
25
|
-
}// Rays
|
26
|
-
|
27
|
-
|
28
|
-
namespace Rucy
|
29
|
-
{
|
30
|
-
|
31
|
-
|
32
|
-
Value
|
33
|
-
value (const Rays::Color& obj)
|
34
|
-
{
|
35
|
-
return new_type(cColor, new Rays::Color(obj));
|
36
|
-
}
|
37
|
-
|
38
|
-
Value
|
39
|
-
value (const Rays::Color* obj)
|
40
|
-
{
|
41
|
-
return obj ? value(*obj) : nil();
|
42
|
-
}
|
43
|
-
|
44
|
-
|
45
|
-
}// Rucy
|
46
|
-
|
47
|
-
|
48
|
-
#define THIS to<Rays::Color*>(self)
|
49
|
-
|
50
|
-
#define CHECK RUCY_CHECK_OBJ(self, Rays::Color, cColor)
|
17
|
+
#define CHECK RUCY_CHECK_OBJ(Rays::Color, cColor, self)
|
51
18
|
|
52
19
|
|
53
20
|
static
|
@@ -57,12 +24,10 @@ VALUE alloc(VALUE klass)
|
|
57
24
|
}
|
58
25
|
|
59
26
|
static
|
60
|
-
VALUE
|
27
|
+
VALUE setup(VALUE self)
|
61
28
|
{
|
62
|
-
|
63
|
-
|
64
|
-
if (argc < 0 || 4 < argc)
|
65
|
-
arg_count_error("Color#initialize", argc, 0, 1, 2, 3, 4);
|
29
|
+
CHECK;
|
30
|
+
check_arg_count(__FILE__, __LINE__, "Color#initialize", argc, 0, 1, 2, 3, 4);
|
66
31
|
|
67
32
|
if (argc == 0) return self;
|
68
33
|
|
@@ -94,12 +59,8 @@ VALUE initialize(VALUE self)
|
|
94
59
|
static
|
95
60
|
VALUE initialize_copy(VALUE self, VALUE obj)
|
96
61
|
{
|
97
|
-
|
98
|
-
|
99
|
-
Rays::Color* color = to<Rays::Color*>(obj);
|
100
|
-
if (!color) argument_error();
|
101
|
-
|
102
|
-
*THIS = *color;
|
62
|
+
CHECK;
|
63
|
+
*THIS = to<Rays::Color&>(obj);
|
103
64
|
return self;
|
104
65
|
}
|
105
66
|
|
@@ -175,7 +136,7 @@ Init_color ()
|
|
175
136
|
|
176
137
|
cColor = rb_define_class_under(mRays, "Color", rb_cObject);
|
177
138
|
rb_define_alloc_func(cColor, alloc);
|
178
|
-
rb_define_private_method(cColor, "
|
139
|
+
rb_define_private_method(cColor, "setup", RUBY_METHOD_FUNC(setup), -1);
|
179
140
|
rb_define_private_method(cColor, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1);
|
180
141
|
rb_define_method(cColor, "red=", RUBY_METHOD_FUNC(set_red), 1);
|
181
142
|
rb_define_method(cColor, "red", RUBY_METHOD_FUNC(get_red), 0);
|
@@ -186,3 +147,52 @@ Init_color ()
|
|
186
147
|
rb_define_method(cColor, "alpha=", RUBY_METHOD_FUNC(set_alpha), 1);
|
187
148
|
rb_define_method(cColor, "alpha", RUBY_METHOD_FUNC(get_alpha), 0);
|
188
149
|
}
|
150
|
+
|
151
|
+
|
152
|
+
namespace Rucy
|
153
|
+
{
|
154
|
+
|
155
|
+
|
156
|
+
template <> Rays::Color
|
157
|
+
value_to<Rays::Color> (Value value, bool convert)
|
158
|
+
{
|
159
|
+
if (convert)
|
160
|
+
{
|
161
|
+
if (value.is_i() || value.is_f())
|
162
|
+
return Rays::Color(value.as_f(true));
|
163
|
+
else if (value.is_array())
|
164
|
+
{
|
165
|
+
int size = value.size();
|
166
|
+
if (size <= 0 || 4 < size)
|
167
|
+
Rucy::argument_error(__FILE__, __LINE__);
|
168
|
+
|
169
|
+
Value* a = value.as_array();
|
170
|
+
switch (size)
|
171
|
+
{
|
172
|
+
case 1: return Rays::Color(a[0].as_f(true));
|
173
|
+
case 2: return Rays::Color(a[0].as_f(true), a[1].as_f(true));
|
174
|
+
case 3: return Rays::Color(a[0].as_f(true), a[1].as_f(true), a[2].as_f(true));
|
175
|
+
case 4: return Rays::Color(a[0].as_f(true), a[1].as_f(true), a[2].as_f(true), a[3].as_f(true));
|
176
|
+
}
|
177
|
+
}
|
178
|
+
}
|
179
|
+
|
180
|
+
return value_to<Rays::Color&>(value, convert);
|
181
|
+
}
|
182
|
+
|
183
|
+
|
184
|
+
}// Rucy
|
185
|
+
|
186
|
+
|
187
|
+
namespace Rays
|
188
|
+
{
|
189
|
+
|
190
|
+
|
191
|
+
Class
|
192
|
+
color_class ()
|
193
|
+
{
|
194
|
+
return cColor;
|
195
|
+
}
|
196
|
+
|
197
|
+
|
198
|
+
}// Rays
|