rays 0.1.12 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) 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/camera.cpp +171 -0
  5. data/.doc/ext/rays/color.cpp +223 -45
  6. data/.doc/ext/rays/color_space.cpp +146 -46
  7. data/.doc/ext/rays/defs.cpp +183 -0
  8. data/.doc/ext/rays/font.cpp +69 -21
  9. data/.doc/ext/rays/image.cpp +26 -37
  10. data/.doc/ext/rays/matrix.cpp +186 -29
  11. data/.doc/ext/rays/native.cpp +14 -8
  12. data/.doc/ext/rays/noise.cpp +53 -0
  13. data/.doc/ext/rays/painter.cpp +187 -292
  14. data/.doc/ext/rays/point.cpp +96 -77
  15. data/.doc/ext/rays/polygon.cpp +313 -0
  16. data/.doc/ext/rays/polygon_line.cpp +96 -0
  17. data/.doc/ext/rays/polyline.cpp +167 -0
  18. data/.doc/ext/rays/rays.cpp +103 -12
  19. data/.doc/ext/rays/shader.cpp +83 -9
  20. data/LICENSE +21 -0
  21. data/README.md +1 -1
  22. data/Rakefile +24 -9
  23. data/VERSION +1 -1
  24. data/ext/rays/bitmap.cpp +23 -81
  25. data/ext/rays/bounds.cpp +100 -128
  26. data/ext/rays/camera.cpp +186 -0
  27. data/ext/rays/color.cpp +231 -51
  28. data/ext/rays/color_space.cpp +149 -47
  29. data/ext/rays/defs.cpp +183 -0
  30. data/ext/rays/defs.h +26 -2
  31. data/ext/rays/extconf.rb +2 -3
  32. data/ext/rays/font.cpp +74 -24
  33. data/ext/rays/image.cpp +28 -40
  34. data/ext/rays/matrix.cpp +198 -30
  35. data/ext/rays/native.cpp +14 -8
  36. data/ext/rays/noise.cpp +55 -0
  37. data/ext/rays/painter.cpp +203 -298
  38. data/ext/rays/point.cpp +105 -81
  39. data/ext/rays/polygon.cpp +329 -0
  40. data/ext/rays/polygon_line.cpp +99 -0
  41. data/ext/rays/polyline.cpp +176 -0
  42. data/ext/rays/rays.cpp +103 -13
  43. data/ext/rays/shader.cpp +84 -9
  44. data/include/rays.h +10 -2
  45. data/include/rays/bitmap.h +14 -26
  46. data/include/rays/bounds.h +21 -4
  47. data/include/rays/camera.h +74 -0
  48. data/include/rays/color.h +25 -14
  49. data/include/rays/color_space.h +15 -10
  50. data/include/rays/coord.h +114 -0
  51. data/include/rays/debug.h +22 -0
  52. data/include/rays/defs.h +36 -0
  53. data/include/rays/exception.h +6 -2
  54. data/include/rays/font.h +4 -4
  55. data/include/rays/image.h +12 -18
  56. data/include/rays/matrix.h +50 -24
  57. data/include/rays/noise.h +42 -0
  58. data/include/rays/opengl.h +2 -50
  59. data/include/rays/painter.h +89 -93
  60. data/include/rays/point.h +44 -51
  61. data/include/rays/polygon.h +198 -0
  62. data/include/rays/polyline.h +71 -0
  63. data/include/rays/rays.h +3 -0
  64. data/include/rays/ruby.h +7 -1
  65. data/include/rays/ruby/bounds.h +1 -1
  66. data/include/rays/ruby/camera.h +41 -0
  67. data/include/rays/ruby/color.h +1 -1
  68. data/include/rays/ruby/color_space.h +1 -1
  69. data/include/rays/ruby/font.h +1 -1
  70. data/include/rays/ruby/matrix.h +1 -1
  71. data/include/rays/ruby/point.h +1 -1
  72. data/include/rays/ruby/polygon.h +52 -0
  73. data/include/rays/ruby/polyline.h +41 -0
  74. data/include/rays/ruby/rays.h +8 -0
  75. data/include/rays/ruby/shader.h +1 -1
  76. data/include/rays/shader.h +36 -8
  77. data/lib/rays.rb +7 -2
  78. data/lib/rays/bitmap.rb +0 -15
  79. data/lib/rays/bounds.rb +17 -23
  80. data/lib/rays/camera.rb +24 -0
  81. data/lib/rays/color.rb +20 -47
  82. data/lib/rays/color_space.rb +13 -13
  83. data/lib/rays/image.rb +3 -7
  84. data/lib/rays/matrix.rb +28 -0
  85. data/lib/rays/module.rb +4 -19
  86. data/lib/rays/painter.rb +78 -93
  87. data/lib/rays/point.rb +13 -21
  88. data/lib/rays/polygon.rb +58 -0
  89. data/lib/rays/polygon_line.rb +36 -0
  90. data/lib/rays/polyline.rb +32 -0
  91. data/lib/rays/shader.rb +20 -1
  92. data/rays.gemspec +5 -7
  93. data/src/bitmap.h +36 -0
  94. data/src/bounds.cpp +74 -11
  95. data/src/color.cpp +58 -23
  96. data/src/color_space.cpp +52 -34
  97. data/src/color_space.h +22 -0
  98. data/src/coord.cpp +170 -0
  99. data/src/coord.h +35 -0
  100. data/src/font.cpp +118 -0
  101. data/src/font.h +64 -0
  102. data/src/frame_buffer.cpp +37 -71
  103. data/src/frame_buffer.h +4 -4
  104. data/src/image.cpp +172 -98
  105. data/src/image.h +25 -0
  106. data/src/ios/bitmap.h +23 -0
  107. data/src/ios/bitmap.mm +133 -110
  108. data/src/ios/camera.mm +510 -0
  109. data/src/ios/font.mm +50 -62
  110. data/src/ios/helper.h +4 -4
  111. data/src/ios/opengl.mm +19 -4
  112. data/src/ios/rays.mm +3 -0
  113. data/src/matrix.cpp +111 -26
  114. data/src/matrix.h +30 -0
  115. data/src/noise.cpp +74 -0
  116. data/src/opengl.cpp +9 -27
  117. data/src/opengl.h +37 -0
  118. data/src/osx/bitmap.h +23 -0
  119. data/src/osx/bitmap.mm +133 -110
  120. data/src/osx/camera.mm +451 -0
  121. data/src/osx/font.mm +49 -62
  122. data/src/osx/helper.h +2 -2
  123. data/src/osx/opengl.mm +19 -83
  124. data/src/osx/rays.mm +3 -0
  125. data/src/painter.cpp +845 -671
  126. data/src/painter.h +24 -0
  127. data/src/point.cpp +140 -119
  128. data/src/polygon.cpp +1266 -0
  129. data/src/polygon.h +32 -0
  130. data/src/polyline.cpp +160 -0
  131. data/src/polyline.h +69 -0
  132. data/src/render_buffer.cpp +11 -4
  133. data/src/render_buffer.h +2 -2
  134. data/src/shader.cpp +163 -106
  135. data/src/shader.h +38 -0
  136. data/src/shader_program.cpp +533 -0
  137. data/src/{program.h → shader_program.h} +28 -16
  138. data/src/shader_source.cpp +140 -0
  139. data/src/shader_source.h +52 -0
  140. data/src/texture.cpp +136 -160
  141. data/src/texture.h +65 -0
  142. data/src/win32/bitmap.cpp +62 -52
  143. data/src/win32/font.cpp +11 -13
  144. data/src/win32/font.h +24 -0
  145. data/src/win32/gdi.h +6 -6
  146. data/test/helper.rb +0 -3
  147. data/test/test_bitmap.rb +31 -7
  148. data/test/test_bounds.rb +36 -0
  149. data/test/test_color.rb +59 -19
  150. data/test/test_color_space.rb +95 -0
  151. data/test/test_font.rb +5 -0
  152. data/test/test_image.rb +24 -20
  153. data/test/test_matrix.rb +106 -0
  154. data/test/test_painter.rb +157 -51
  155. data/test/test_painter_shape.rb +102 -0
  156. data/test/test_point.rb +29 -0
  157. data/test/test_polygon.rb +234 -0
  158. data/test/test_polygon_line.rb +167 -0
  159. data/test/test_polyline.rb +171 -0
  160. data/test/test_shader.rb +9 -9
  161. metadata +102 -70
  162. data/.doc/ext/rays/texture.cpp +0 -138
  163. data/ext/rays/texture.cpp +0 -149
  164. data/include/rays/ruby/texture.h +0 -41
  165. data/include/rays/texture.h +0 -71
  166. data/lib/rays/texture.rb +0 -24
  167. data/src/program.cpp +0 -648
  168. data/test/test_texture.rb +0 -27
@@ -0,0 +1,186 @@
1
+ #include "rays/ruby/camera.h"
2
+
3
+
4
+ #include "rays/ruby/image.h"
5
+ #include "defs.h"
6
+
7
+
8
+ RUCY_DEFINE_VALUE_FROM_TO(Rays::Camera)
9
+
10
+ #define THIS to<Rays::Camera*>(self)
11
+
12
+ #define CHECK RUCY_CHECK_OBJECT(Rays::Camera, self)
13
+
14
+
15
+ static
16
+ RUCY_DEF_ALLOC(alloc, klass)
17
+ {
18
+ return new_type<Rays::Camera>(klass);
19
+ }
20
+ RUCY_END
21
+
22
+ static
23
+ RUCY_DEF5(setup, device_name, min_width, min_height, resize, crop)
24
+ {
25
+ RUCY_CHECK_OBJ(Rays::Camera, self);
26
+
27
+ *THIS = Rays::Camera(
28
+ device_name ? to<const char*>(device_name) : NULL,
29
+ to<int>(min_width), to<int>(min_height),
30
+ to<bool>(resize), to<bool>(crop));
31
+ return self;
32
+ }
33
+ RUCY_END
34
+
35
+ static
36
+ RUCY_DEF0(start)
37
+ {
38
+ CHECK;
39
+ return value(THIS->start());
40
+ }
41
+ RUCY_END
42
+
43
+ static
44
+ RUCY_DEF0(stop)
45
+ {
46
+ CHECK;
47
+ THIS->stop();
48
+ }
49
+ RUCY_END
50
+
51
+ static
52
+ RUCY_DEF0(is_active)
53
+ {
54
+ CHECK;
55
+ return value(THIS->is_active());
56
+ }
57
+ RUCY_END
58
+
59
+ static
60
+ RUCY_DEF1(set_min_width, width)
61
+ {
62
+ CHECK;
63
+ THIS->set_min_width(to<int>(width));
64
+ return value(THIS->min_width());
65
+ }
66
+ RUCY_END
67
+
68
+ static
69
+ RUCY_DEF0(min_width)
70
+ {
71
+ CHECK;
72
+ return value(THIS->min_width());
73
+ }
74
+ RUCY_END
75
+
76
+ static
77
+ RUCY_DEF1(set_min_height, height)
78
+ {
79
+ CHECK;
80
+ THIS->set_min_height(to<int>(height));
81
+ return value(THIS->min_height());
82
+ }
83
+ RUCY_END
84
+
85
+ static
86
+ RUCY_DEF0(min_height)
87
+ {
88
+ CHECK;
89
+ return value(THIS->min_height());
90
+ }
91
+ RUCY_END
92
+
93
+ static
94
+ RUCY_DEF1(set_resize, resize)
95
+ {
96
+ CHECK;
97
+ THIS->set_resize(to<bool>(resize));
98
+ return value(THIS->is_resize());
99
+ }
100
+ RUCY_END
101
+
102
+ static
103
+ RUCY_DEF0(is_resize)
104
+ {
105
+ CHECK;
106
+ return value(THIS->is_resize());
107
+ }
108
+ RUCY_END
109
+
110
+ static
111
+ RUCY_DEF1(set_crop, crop)
112
+ {
113
+ CHECK;
114
+ THIS->set_crop(to<bool>(crop));
115
+ return value(THIS->is_crop());
116
+ }
117
+ RUCY_END
118
+
119
+ static
120
+ RUCY_DEF0(is_crop)
121
+ {
122
+ CHECK;
123
+ return value(THIS->is_crop());
124
+ }
125
+ RUCY_END
126
+
127
+ static
128
+ RUCY_DEF0(image)
129
+ {
130
+ CHECK;
131
+ const Rays::Image* img = THIS->image();
132
+ return img ? value(*img) : nil();
133
+ }
134
+ RUCY_END
135
+
136
+ static
137
+ RUCY_DEF0(device_names)
138
+ {
139
+ auto names = Rays::get_camera_device_names();
140
+
141
+ std::vector<Value> v;
142
+ for (auto it = names.begin(), end = names.end(); it != end; ++it)
143
+ v.emplace_back(value(it->c_str()));
144
+ return value(v.size(), &v[0]);
145
+ }
146
+ RUCY_END
147
+
148
+
149
+ static Class cCamera;
150
+
151
+ void
152
+ Init_camera ()
153
+ {
154
+ Module mRays = define_module("Rays");
155
+
156
+ cCamera = mRays.define_class("Camera");
157
+ cCamera.define_alloc_func(alloc);
158
+ cCamera.define_private_method("setup", setup);
159
+ cCamera.define_method("start", start);
160
+ cCamera.define_method("stop", stop);
161
+ cCamera.define_method("active?", is_active);
162
+ cCamera.define_method("min_width=", set_min_width);
163
+ cCamera.define_method("min_width", min_width);
164
+ cCamera.define_method("min_height=", set_min_height);
165
+ cCamera.define_method("min_height", min_height);
166
+ cCamera.define_method("resize=", set_resize);
167
+ cCamera.define_method("resize?", is_resize);
168
+ cCamera.define_method("crop=", set_crop);
169
+ cCamera.define_method("crop?", is_crop);
170
+ cCamera.define_method("image", image);
171
+ cCamera.define_module_function("device_names", device_names);
172
+ }
173
+
174
+
175
+ namespace Rays
176
+ {
177
+
178
+
179
+ Class
180
+ camera_class ()
181
+ {
182
+ return cCamera;
183
+ }
184
+
185
+
186
+ }// Rays
@@ -1,14 +1,11 @@
1
1
  #include "rays/ruby/color.h"
2
2
 
3
3
 
4
- #include <rucy.h>
4
+ #include <map>
5
5
  #include "defs.h"
6
6
 
7
7
 
8
- using namespace Rucy;
9
-
10
-
11
- RUCY_DEFINE_VALUE_FROM_TO(Rays::Color)
8
+ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Color)
12
9
 
13
10
  #define THIS to<Rays::Color*>(self)
14
11
 
@@ -23,34 +20,13 @@ RUCY_DEF_ALLOC(alloc, klass)
23
20
  RUCY_END
24
21
 
25
22
  static
26
- RUCY_DEFN(setup)
23
+ RUCY_DEFN(initialize)
27
24
  {
28
25
  CHECK;
29
26
  check_arg_count(__FILE__, __LINE__, "Color#initialize", argc, 0, 1, 2, 3, 4);
30
27
 
31
- if (argc == 0) return self;
32
-
33
- switch (argc)
34
- {
35
- case 1:
36
- *THIS = Rays::Color(to<float>(argv[0]));
37
- break;
38
-
39
- case 2:
40
- *THIS = Rays::Color(to<float>(argv[0]), to<float>(argv[1]));
41
- break;
42
-
43
- case 3:
44
- *THIS = Rays::Color(
45
- to<float>(argv[0]), to<float>(argv[1]), to<float>(argv[2]));
46
- break;
47
-
48
- case 4:
49
- *THIS = Rays::Color(
50
- to<float>(argv[0]), to<float>(argv[1]),
51
- to<float>(argv[2]), to<float>(argv[3]));
52
- break;
53
- }
28
+ if (argc >= 1)
29
+ *THIS = to<Rays::Color>(argc, argv);
54
30
 
55
31
  return self;
56
32
  }
@@ -138,6 +114,84 @@ RUCY_DEF0(get_alpha)
138
114
  RUCY_END
139
115
 
140
116
 
117
+ typedef std::map<Rays::String, Rays::Color> ColorMap;
118
+
119
+ static ColorMap&
120
+ get_color_map ()
121
+ {
122
+ static ColorMap map;
123
+ if (map.empty())
124
+ {
125
+ map["no"] =
126
+ map["none"] =
127
+ map["transp"] =
128
+ map["transparent"] = Rays::gray(0, 0);
129
+
130
+ map["black"] = Rays::rgb8( 0, 0, 0);
131
+ map["white"] = Rays::rgb8(255, 241, 232);
132
+ map["gray"] =
133
+ map["lightgray"] = Rays::rgb8(194, 195, 199);
134
+ map["darkgray"] = Rays::rgb8( 95, 87, 79);
135
+ map["brown"] = Rays::rgb8(171, 82, 54);
136
+ map["red"] = Rays::rgb8(255, 0, 77);
137
+ map["orange"] = Rays::rgb8(255, 163, 0);
138
+ map["yellow"] = Rays::rgb8(255, 236, 39);
139
+ map["green"] = Rays::rgb8( 0, 228, 54);
140
+ map["darkgreen"] = Rays::rgb8( 0, 135, 81);
141
+ map["blue"] = Rays::rgb8( 41, 173, 255);
142
+ map["darkblue"] = Rays::rgb8( 29, 43, 83);
143
+ map["indigo"] = Rays::rgb8(131, 118, 156);
144
+ map["pink"] = Rays::rgb8(255, 119, 168);
145
+ map["peach"] = Rays::rgb8(255, 204, 170);
146
+ map["darkpurple"] = Rays::rgb8(126, 37, 83);
147
+ }
148
+ return map;
149
+ }
150
+
151
+ static const Rays::String
152
+ to_color_name (const char* name)
153
+ {
154
+ return Rays::String(name).downcase();
155
+ }
156
+
157
+ static const Rays::Color&
158
+ find_color (const char* name)
159
+ {
160
+ assert(name);
161
+
162
+ const ColorMap& map = get_color_map();
163
+ ColorMap::const_iterator it = map.find(to_color_name(name));
164
+ if (it == map.end())
165
+ argument_error(__FILE__, __LINE__, "color '%s' is not found.", name);
166
+
167
+ return it->second;
168
+ }
169
+
170
+ static
171
+ RUCY_DEFN(hsv)
172
+ {
173
+ check_arg_count(__FILE__, __LINE__, "Color.hsv", argc, 3, 4);
174
+
175
+ float h = to<float>(argv[0]);
176
+ float s = to<float>(argv[1]);
177
+ float v = to<float>(argv[2]);
178
+ if (argc >= 4)
179
+ return value(Rays::hsv(h, s, v, to<float>(argv[3])));
180
+ else
181
+ return value(Rays::hsv(h, s, v));
182
+ }
183
+ RUCY_END
184
+
185
+ static
186
+ RUCY_DEFN(set_palette_color)
187
+ {
188
+ check_arg_count(__FILE__, __LINE__, "Color.set_palette_color", argc, 2, 3, 4, 5);
189
+
190
+ get_color_map()[to_color_name(argv[0].c_str())] = to<Rays::Color>(argc - 1, &argv[1]);
191
+ }
192
+ RUCY_END
193
+
194
+
141
195
  static Class cColor;
142
196
 
143
197
  void
@@ -147,16 +201,18 @@ Init_color ()
147
201
 
148
202
  cColor = mRays.define_class("Color");
149
203
  cColor.define_alloc_func(alloc);
150
- cColor.define_private_method("setup", setup);
204
+ cColor.define_private_method("initialize", initialize);
151
205
  cColor.define_private_method("initialize_copy", initialize_copy);
152
- cColor.define_method("red=", set_red);
153
- cColor.define_method("red", get_red);
206
+ cColor.define_method("red=", set_red);
207
+ cColor.define_method("red", get_red);
154
208
  cColor.define_method("green=", set_green);
155
- cColor.define_method("green", get_green);
156
- cColor.define_method("blue=", set_blue);
157
- cColor.define_method("blue", get_blue);
209
+ cColor.define_method("green", get_green);
210
+ cColor.define_method("blue=", set_blue);
211
+ cColor.define_method("blue", get_blue);
158
212
  cColor.define_method("alpha=", set_alpha);
159
- cColor.define_method("alpha", get_alpha);
213
+ cColor.define_method("alpha", get_alpha);
214
+ cColor.define_module_function("hsv", hsv);
215
+ cColor.define_module_function("set_palette_color", set_palette_color);
160
216
  }
161
217
 
162
218
 
@@ -164,31 +220,155 @@ namespace Rucy
164
220
  {
165
221
 
166
222
 
223
+ static int
224
+ char2hex (char c)
225
+ {
226
+ if ('0' <= c && c <= '9') return c - '0';
227
+ else if ('a' <= c && c <= 'f') return 10 + c - 'a';
228
+ else if ('A' <= c && c <= 'F') return 10 + c - 'A';
229
+ else return -1;
230
+ }
231
+
232
+ static bool
233
+ parse_channel (float* channel, const char* str, size_t nchars, size_t index)
234
+ {
235
+ assert(channel && str && 1 <= nchars && nchars <= 2 && 0 <= index && index <= 3);
236
+
237
+ const char* p = str + index * nchars;
238
+
239
+ if (nchars == 1)
240
+ {
241
+ int c0 = char2hex(p[0]);
242
+ if (c0 < 0)
243
+ return false;
244
+
245
+ assert(c0 < 16);
246
+
247
+ *channel = c0 / 15.f;
248
+ return true;
249
+ }
250
+ else
251
+ {
252
+ int c0 = char2hex(p[0]);
253
+ int c1 = char2hex(p[1]);
254
+ if (c0 < 0 || c1 < 0)
255
+ return false;
256
+
257
+ assert(c0 < 16 && c1 < 16);
258
+
259
+ *channel = (c0 * 16 + c1) / 255.f;
260
+ return true;
261
+ }
262
+ }
263
+
264
+ static bool
265
+ parse_string (Rays::Color* color, const char* str)
266
+ {
267
+ assert(color && str);
268
+
269
+ if (*str != '#') return false;
270
+ ++str;
271
+
272
+ size_t len = strlen(str);
273
+ switch (len)
274
+ {
275
+ case 3:
276
+ case 6:
277
+ {
278
+ size_t nchars = len / 3;
279
+
280
+ float r, g, b;
281
+ if (
282
+ !parse_channel(&r, str, nchars, 0) ||
283
+ !parse_channel(&g, str, nchars, 1) ||
284
+ !parse_channel(&b, str, nchars, 2))
285
+ {
286
+ return false;
287
+ }
288
+
289
+ color->reset(r, g, b);
290
+ break;
291
+ }
292
+
293
+ case 4:
294
+ case 8:
295
+ {
296
+ size_t nchars = len / 4;
297
+
298
+ float r, g, b, a;
299
+ if (
300
+ !parse_channel(&r, str, nchars, 0) ||
301
+ !parse_channel(&g, str, nchars, 1) ||
302
+ !parse_channel(&b, str, nchars, 2) ||
303
+ !parse_channel(&a, str, nchars, 3))
304
+ {
305
+ return false;
306
+ }
307
+
308
+ color->reset(r, g, b, a);
309
+ break;
310
+ }
311
+
312
+ default: return false;
313
+ }
314
+
315
+ return true;
316
+ }
317
+
318
+ static Rays::Color
319
+ str2color (const char* str)
320
+ {
321
+ if (!str)
322
+ argument_error(__FILE__, __LINE__);
323
+
324
+ Rays::String str_ = str;
325
+ str_ = str_.strip();
326
+
327
+ Rays::Color color;
328
+ if (parse_string(&color, str_.c_str()))
329
+ return color;
330
+ else
331
+ return find_color(str_.c_str());
332
+ }
333
+
167
334
  template <> Rays::Color
168
- value_to<Rays::Color> (Value value, bool convert)
335
+ value_to<Rays::Color> (int argc, const Value*argv, bool convert)
169
336
  {
337
+ if (argc == 1 && argv->is_array())
338
+ {
339
+ argc = argv->size();
340
+ argv = argv->as_array();
341
+ }
342
+
343
+ assert(argc == 0 || (argc > 0 && argv));
344
+
170
345
  if (convert)
171
346
  {
172
- if (value.is_i() || value.is_f())
173
- return Rays::Color(value.as_f(true));
174
- else if (value.is_array())
347
+ if (argc == 0)
348
+ return Rays::Color();
349
+ else if (argv->is_nil())
350
+ return str2color("none");
351
+ else if (argv->is_s() || argv->is_sym())
352
+ return str2color(argv[0].c_str());
353
+ else if (argv->is_num())
175
354
  {
176
- int size = value.size();
177
- if (size <= 0 || 4 < size)
178
- Rucy::argument_error(__FILE__, __LINE__);
179
-
180
- Value* a = value.as_array();
181
- switch (size)
355
+ switch (argc)
182
356
  {
183
- case 1: return Rays::Color(a[0].as_f(true));
184
- case 2: return Rays::Color(a[0].as_f(true), a[1].as_f(true));
185
- case 3: return Rays::Color(a[0].as_f(true), a[1].as_f(true), a[2].as_f(true));
186
- 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));
357
+ #define V(i) argv[i].as_f(true)
358
+ case 1: return Rays::Color(V(0));
359
+ case 2: return Rays::Color(V(0), V(1));
360
+ case 3: return Rays::Color(V(0), V(1), V(2));
361
+ case 4: return Rays::Color(V(0), V(1), V(2), V(3));
362
+ #undef V
363
+ default: argument_error(__FILE__, __LINE__, "invalid array size.");
187
364
  }
188
365
  }
189
366
  }
190
367
 
191
- return value_to<Rays::Color&>(value, convert);
368
+ if (argc != 1)
369
+ argument_error(__FILE__, __LINE__);
370
+
371
+ return value_to<Rays::Color&>(*argv, convert);
192
372
  }
193
373
 
194
374