rays 0.1.11 → 0.1.16

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 +88 -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 +22 -80
  25. data/ext/rays/bounds.cpp +100 -128
  26. data/ext/rays/camera.cpp +94 -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 +49 -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 +21 -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 +21 -0
  107. data/src/ios/bitmap.mm +129 -110
  108. data/src/ios/camera.mm +236 -0
  109. data/src/ios/font.mm +50 -62
  110. data/src/ios/helper.h +2 -2
  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 +21 -0
  119. data/src/osx/bitmap.mm +129 -110
  120. data/src/osx/camera.mm +236 -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
@@ -1,16 +1,10 @@
1
1
  #include "rays/ruby/point.h"
2
2
 
3
3
 
4
- #include <rucy.h>
5
4
  #include "defs.h"
6
5
 
7
6
 
8
- using namespace Rucy;
9
-
10
- using Rays::coord;
11
-
12
-
13
- RUCY_DEFINE_VALUE_FROM_TO(Rays::Point)
7
+ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Point)
14
8
 
15
9
  #define THIS to<Rays::Point*>(self)
16
10
 
@@ -30,21 +24,8 @@ RUCY_DEFN(initialize)
30
24
  CHECK;
31
25
  check_arg_count(__FILE__, __LINE__, "Point#initialize", argc, 0, 1, 2, 3);
32
26
 
33
- switch (argc)
34
- {
35
- case 1:
36
- *THIS = Rays::Point(to<coord>(argv[0]));
37
- break;
38
-
39
- case 2:
40
- *THIS = Rays::Point(to<coord>(argv[0]), to<coord>(argv[1]));
41
- break;
42
-
43
- case 3:
44
- *THIS = Rays::Point(
45
- to<coord>(argv[0]), to<coord>(argv[1]), to<coord>(argv[2]));
46
- break;
47
- }
27
+ if (argc >= 1)
28
+ *THIS = to<Rays::Point>(argc, argv);
48
29
 
49
30
  return self;
50
31
  }
@@ -100,6 +81,24 @@ RUCY_DEFN(move_by)
100
81
  }
101
82
  RUCY_END
102
83
 
84
+ static
85
+ RUCY_DEF1(rotate, degree)
86
+ {
87
+ CHECK;
88
+ Rays::Point p = *THIS;
89
+ p.rotate(to<float>(degree));
90
+ return value(p);
91
+ }
92
+ RUCY_END
93
+
94
+ static
95
+ RUCY_DEF1(rotate_self, degree)
96
+ {
97
+ CHECK;
98
+ THIS->rotate(to<float>(degree));
99
+ }
100
+ RUCY_END
101
+
103
102
  static
104
103
  RUCY_DEF0(length)
105
104
  {
@@ -129,7 +128,8 @@ static
129
128
  RUCY_DEF1(set_x, x)
130
129
  {
131
130
  CHECK;
132
- return value(THIS->x = to<coord>(x));
131
+ THIS->x = to<coord>(x);
132
+ return x;
133
133
  }
134
134
  RUCY_END
135
135
 
@@ -145,7 +145,8 @@ static
145
145
  RUCY_DEF1(set_y, y)
146
146
  {
147
147
  CHECK;
148
- return value(THIS->y = to<coord>(y));
148
+ THIS->y = to<coord>(y);
149
+ return y;
149
150
  }
150
151
  RUCY_END
151
152
 
@@ -161,7 +162,8 @@ static
161
162
  RUCY_DEF1(set_z, z)
162
163
  {
163
164
  CHECK;
164
- return value(THIS->z = to<coord>(z));
165
+ THIS->z = to<coord>(z);
166
+ return z;
165
167
  }
166
168
  RUCY_END
167
169
 
@@ -174,51 +176,59 @@ RUCY_DEF0(get_z)
174
176
  RUCY_END
175
177
 
176
178
  static
177
- RUCY_DEF1(add, point)
179
+ RUCY_DEF0(negate)
178
180
  {
179
181
  CHECK;
180
-
181
- Rays::Point p = *THIS;
182
- p += to<Rays::Point&>(point);
183
- return value(p);
182
+ return value(-*THIS);
184
183
  }
185
184
  RUCY_END
186
185
 
187
186
  static
188
- RUCY_DEF1(sub, point)
187
+ RUCY_DEFN(add)
189
188
  {
190
189
  CHECK;
191
-
192
- Rays::Point p = *THIS;
193
- p -= to<Rays::Point&>(point);
194
- return value(p);
190
+ if (argc == 1 && argv->is_num())
191
+ return value(*THIS + to<coord>(*argv));
192
+ else
193
+ return value(*THIS + to<Rays::Point>(argc, argv));
195
194
  }
196
195
  RUCY_END
197
196
 
198
197
  static
199
- RUCY_DEF1(mult, point)
198
+ RUCY_DEFN(sub)
200
199
  {
201
200
  CHECK;
202
-
203
- Rays::Point p = *THIS;
204
- p *= to<Rays::Point&>(point);
205
- return value(p);
201
+ if (argc == 1 && argv->is_num())
202
+ return value(*THIS - to<coord>(*argv));
203
+ else
204
+ return value(*THIS - to<Rays::Point>(argc, argv));
206
205
  }
207
206
  RUCY_END
208
207
 
209
208
  static
210
- RUCY_DEF1(div, point)
209
+ RUCY_DEFN(mult)
211
210
  {
212
211
  CHECK;
212
+ if (argc == 1 && argv->is_num())
213
+ return value(*THIS * to<coord>(*argv));
214
+ else
215
+ return value(*THIS * to<Rays::Point>(argc, argv));
216
+ }
217
+ RUCY_END
213
218
 
214
- Rays::Point p = *THIS;
215
- p /= to<Rays::Point&>(point);
216
- return value(p);
219
+ static
220
+ RUCY_DEFN(div)
221
+ {
222
+ CHECK;
223
+ if (argc == 1 && argv->is_num())
224
+ return value(*THIS / to<coord>(*argv));
225
+ else
226
+ return value(*THIS / to<Rays::Point>(argc, argv));
217
227
  }
218
228
  RUCY_END
219
229
 
220
230
  static
221
- RUCY_DEF1(array_get, index)
231
+ RUCY_DEF2(set_at, index, value)
222
232
  {
223
233
  CHECK;
224
234
 
@@ -226,12 +236,13 @@ RUCY_DEF1(array_get, index)
226
236
  if (i < 0 || 2 < i)
227
237
  index_error(__FILE__, __LINE__);
228
238
 
229
- return value((*THIS)[i]);
239
+ (*THIS)[i] = to<coord>(value);
240
+ return value;
230
241
  }
231
242
  RUCY_END
232
243
 
233
244
  static
234
- RUCY_DEF2(array_set, index, value)
245
+ RUCY_DEF1(get_at, index)
235
246
  {
236
247
  CHECK;
237
248
 
@@ -239,8 +250,7 @@ RUCY_DEF2(array_set, index, value)
239
250
  if (i < 0 || 2 < i)
240
251
  index_error(__FILE__, __LINE__);
241
252
 
242
- (*THIS)[i] = to<coord>(value);
243
- return value;
253
+ return value((*THIS)[i]);
244
254
  }
245
255
  RUCY_END
246
256
 
@@ -252,6 +262,20 @@ RUCY_DEF0(inspect)
252
262
  }
253
263
  RUCY_END
254
264
 
265
+ static
266
+ RUCY_DEF2(dot, p1, p2)
267
+ {
268
+ return value(Rays::dot(to<Rays::Point>(p1), to<Rays::Point>(p2)));
269
+ }
270
+ RUCY_END
271
+
272
+ static
273
+ RUCY_DEF2(cross, p1, p2)
274
+ {
275
+ return value(Rays::cross(to<Rays::Point>(p1), to<Rays::Point>(p2)));
276
+ }
277
+ RUCY_END
278
+
255
279
 
256
280
  static Class cPoint;
257
281
 
@@ -262,26 +286,31 @@ Init_point ()
262
286
 
263
287
  cPoint = mRays.define_class("Point");
264
288
  cPoint.define_alloc_func(alloc);
265
- cPoint.define_private_method("initialize", initialize);
289
+ cPoint.define_private_method("initialize", initialize);
266
290
  cPoint.define_private_method("initialize_copy", initialize_copy);
267
291
  cPoint.define_method("move_to!", move_to);
268
292
  cPoint.define_method("move_by!", move_by);
293
+ cPoint.define_method("rotate", rotate);
294
+ cPoint.define_method("rotate!", rotate_self);
269
295
  cPoint.define_method("length", length);
270
296
  cPoint.define_method("normalize", normalize);
271
297
  cPoint.define_method("normal", normal);
272
298
  cPoint.define_method("x=", set_x);
273
- cPoint.define_method("x", get_x);
299
+ cPoint.define_method("x", get_x);
274
300
  cPoint.define_method("y=", set_y);
275
- cPoint.define_method("y", get_y);
301
+ cPoint.define_method("y", get_y);
276
302
  cPoint.define_method("z=", set_z);
277
- cPoint.define_method("z", get_z);
278
- cPoint.define_method("op_add", add);
279
- cPoint.define_method("op_sub", sub);
280
- cPoint.define_method("op_mult", mult);
281
- cPoint.define_method("op_div", div);
282
- cPoint.define_method("[]", array_get);
283
- cPoint.define_method("[]=", array_set);
303
+ cPoint.define_method("z", get_z);
304
+ cPoint.define_method("-@", negate);
305
+ cPoint.define_method("+", add);
306
+ cPoint.define_method("-", sub);
307
+ cPoint.define_method("*", mult);
308
+ cPoint.define_method("/", div);
309
+ cPoint.define_method("[]=", set_at);
310
+ cPoint.define_method("[]", get_at);
284
311
  cPoint.define_method("inspect", inspect);
312
+ cPoint.define_module_function("dot", dot);
313
+ cPoint.define_module_function("cross", cross);
285
314
  }
286
315
 
287
316
 
@@ -290,43 +319,38 @@ namespace Rucy
290
319
 
291
320
 
292
321
  template <> Rays::Point
293
- value_to<Rays::Point> (Value value, bool convert)
322
+ value_to<Rays::Point> (int argc, const Value* argv, bool convert)
294
323
  {
295
- if (convert)
324
+ if (argc == 1 && argv->is_array())
296
325
  {
297
- size_t argc = 0;
298
- Value* argv = NULL;
299
- if (value.is_array())
300
- {
301
- argc = value.size();
302
- argv = value.as_array();
303
- }
304
- else
305
- {
306
- argc = 1;
307
- argv = &value;
308
- }
326
+ argc = argv->size();
327
+ argv = argv->as_array();
328
+ }
309
329
 
310
- if (argc < 1)
311
- Rucy::argument_error(__FILE__, __LINE__);
330
+ assert(argc == 0 || (argc > 0 && argv));
312
331
 
313
- if (argv[0].is_kind_of(Rays::point_class()))
314
- value = argv[0];
315
- else if (argv[0].is_i() || argv[0].is_f())
332
+ if (convert)
333
+ {
334
+ if (argc == 0)
335
+ return Rays::Point();
336
+ else if (argv->is_num())
316
337
  {
317
338
  switch (argc)
318
339
  {
319
- #define V(i) argv[i].as_f(true)
340
+ #define V(i) to<coord>(argv[i])
320
341
  case 1: return Rays::Point(V(0));
321
342
  case 2: return Rays::Point(V(0), V(1));
322
343
  case 3: return Rays::Point(V(0), V(1), V(2));
323
344
  #undef V
324
- default: Rucy::argument_error(__FILE__, __LINE__);
345
+ default: argument_error(__FILE__, __LINE__);
325
346
  }
326
347
  }
327
348
  }
328
349
 
329
- return value_to<Rays::Point&>(value, convert);
350
+ if (argc != 1)
351
+ argument_error(__FILE__, __LINE__);
352
+
353
+ return value_to<Rays::Point&>(*argv, convert);
330
354
  }
331
355
 
332
356
 
@@ -0,0 +1,329 @@
1
+ #include "rays/ruby/polygon.h"
2
+
3
+
4
+ #include <vector>
5
+ #include <functional>
6
+ #include "rays/ruby/bounds.h"
7
+ #include "rays/ruby/polyline.h"
8
+ #include "defs.h"
9
+
10
+
11
+ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Polygon)
12
+
13
+ #define THIS to<Rays::Polygon*>(self)
14
+
15
+ #define CHECK RUCY_CHECK_OBJECT(Rays::Polygon, self)
16
+
17
+
18
+ static
19
+ RUCY_DEF_ALLOC(alloc, klass)
20
+ {
21
+ return new_type<Rays::Polygon>(klass);
22
+ }
23
+ RUCY_END
24
+
25
+ static
26
+ RUCY_DEF2(setup, args, loop)
27
+ {
28
+ CHECK;
29
+
30
+ if (args[0].is_kind_of(Rays::polyline_class()))
31
+ *THIS = to<Rays::Polygon>(args.size(), args.as_array());
32
+ else
33
+ {
34
+ std::vector<Rays::Point> points;
35
+ get_line_args(&points, args.size(), args.as_array());
36
+ *THIS = Rays::Polygon(&points[0], points.size(), loop);
37
+ }
38
+ }
39
+ RUCY_END
40
+
41
+ static
42
+ RUCY_DEFN(expand)
43
+ {
44
+ CHECK;
45
+ check_arg_count(__FILE__, __LINE__, "Polygon#expand", argc, 1, 2, 3, 4);
46
+
47
+ coord width = to<coord> (argv[0]);
48
+ Rays::CapType cap = argc >= 2 ? to<Rays::CapType> (argv[1]) : Rays::CAP_DEFAULT;
49
+ Rays::JoinType join = argc >= 3 ? to<Rays::JoinType>(argv[2]) : Rays::JOIN_DEFAULT;
50
+ coord ml = argc >= 4 ? to<coord> (argv[3]) : Rays::JOIN_DEFAULT_MITER_LIMIT;
51
+
52
+ Rays::Polygon polygon;
53
+ THIS->expand(&polygon, width, cap, join, ml);
54
+ return value(polygon);
55
+ }
56
+ RUCY_END
57
+
58
+ static
59
+ RUCY_DEF0(bounds)
60
+ {
61
+ CHECK;
62
+ return value(THIS->bounds());
63
+ }
64
+ RUCY_END
65
+
66
+ static
67
+ RUCY_DEF0(size)
68
+ {
69
+ CHECK;
70
+ return value(THIS->size());
71
+ }
72
+ RUCY_END
73
+
74
+ static
75
+ RUCY_DEF0(empty)
76
+ {
77
+ CHECK;
78
+ return value(THIS->empty());
79
+ }
80
+ RUCY_END
81
+
82
+ static
83
+ RUCY_DEF1(get_at, index)
84
+ {
85
+ CHECK;
86
+
87
+ int size = (int) THIS->size();
88
+ int i = to<int>(index);
89
+ if (i < 0) i += size;
90
+
91
+ if (i < 0 || size <= i)
92
+ index_error(__FILE__, __LINE__);
93
+
94
+ return value((*THIS)[i]);
95
+ }
96
+ RUCY_END
97
+
98
+ static
99
+ RUCY_DEF0(each)
100
+ {
101
+ CHECK;
102
+
103
+ Value ret = Qnil;
104
+ for (const auto& line : *THIS)
105
+ ret = rb_yield(value(line));
106
+ return ret;
107
+ }
108
+ RUCY_END
109
+
110
+ static void
111
+ each_polygon (const Value& value, std::function<void(const Rays::Polygon&)> fun)
112
+ {
113
+ int size = value.size();
114
+ const Value* array = value.as_array();
115
+
116
+ for (int i = 0; i < size; ++i)
117
+ fun(to<Rays::Polygon&>(array[i]));
118
+ }
119
+
120
+ static
121
+ RUCY_DEF1(op_sub, obj)
122
+ {
123
+ CHECK;
124
+
125
+ if (obj.is_array())
126
+ {
127
+ Rays::Polygon result = *THIS;
128
+ each_polygon(obj, [&](const Rays::Polygon& polygon)
129
+ {
130
+ result = result - polygon;
131
+ });
132
+ return value(result);
133
+ }
134
+ else
135
+ return value(*THIS - to<Rays::Polygon&>(obj));
136
+ }
137
+ RUCY_END
138
+
139
+ static
140
+ RUCY_DEF1(op_and, obj)
141
+ {
142
+ CHECK;
143
+
144
+ if (obj.is_array())
145
+ {
146
+ Rays::Polygon result = *THIS;
147
+ each_polygon(obj, [&](const Rays::Polygon& polygon)
148
+ {
149
+ result = result & polygon;
150
+ });
151
+ return value(result);
152
+ }
153
+ else
154
+ return value(*THIS & to<Rays::Polygon&>(obj));
155
+ }
156
+ RUCY_END
157
+
158
+ static
159
+ RUCY_DEF1(op_or, obj)
160
+ {
161
+ CHECK;
162
+
163
+ if (obj.is_array())
164
+ {
165
+ Rays::Polygon result = *THIS;
166
+ each_polygon(obj, [&](const Rays::Polygon& polygon)
167
+ {
168
+ result = result | polygon;
169
+ });
170
+ return value(result);
171
+ }
172
+ else
173
+ return value(*THIS | to<Rays::Polygon&>(obj));
174
+ }
175
+ RUCY_END
176
+
177
+ static
178
+ RUCY_DEF1(op_xor, obj)
179
+ {
180
+ CHECK;
181
+
182
+ if (obj.is_array())
183
+ {
184
+ Rays::Polygon result = *THIS;
185
+ each_polygon(obj, [&](const Rays::Polygon& polygon)
186
+ {
187
+ result = result ^ polygon;
188
+ });
189
+ return value(result);
190
+ }
191
+ else
192
+ return value(*THIS ^ to<Rays::Polygon&>(obj));
193
+ }
194
+ RUCY_END
195
+
196
+ static
197
+ RUCY_DEF7(create_rect,
198
+ args, round, lefttop, righttop, leftbottom, rightbottom, nsegment)
199
+ {
200
+ coord x, y, w, h, lt, rt, lb, rb;
201
+ uint nseg;
202
+ get_rect_args(
203
+ &x, &y, &w, &h, &lt, &rt, &lb, &rb, &nseg,
204
+ args.size(), args.as_array(),
205
+ round, lefttop, righttop, leftbottom, rightbottom, nsegment);
206
+
207
+ return value(Rays::create_rect(x, y, w, h, lt, rt, lb, rb, nseg));
208
+ }
209
+ RUCY_END
210
+
211
+ static
212
+ RUCY_DEF7(create_ellipse,
213
+ args, center, radius, hole, angle_from, angle_to, nsegment)
214
+ {
215
+ coord x, y, w, h;
216
+ Rays::Point hole_size;
217
+ float from, to_;
218
+ uint nseg;
219
+ get_ellipse_args(
220
+ &x, &y, &w, &h, &hole_size, &from, &to_, &nseg,
221
+ args.size(), args.as_array(),
222
+ center, radius, hole, angle_from, angle_to, nsegment);
223
+
224
+ return value(Rays::create_ellipse(x, y, w, h, hole_size, from, to_, nseg));
225
+ }
226
+ RUCY_END
227
+
228
+ static
229
+ RUCY_DEF2(create_curve, args, loop)
230
+ {
231
+ std::vector<Rays::Point> points;
232
+ get_line_args(&points, args.size(), args.as_array());
233
+
234
+ return value(Rays::create_curve(&points[0], points.size(), loop));
235
+ }
236
+ RUCY_END
237
+
238
+ static
239
+ RUCY_DEF2(create_bezier, args, loop)
240
+ {
241
+ std::vector<Rays::Point> points;
242
+ get_line_args(&points, args.size(), args.as_array());
243
+
244
+ return value(Rays::create_bezier(&points[0], points.size(), loop));
245
+ }
246
+ RUCY_END
247
+
248
+
249
+ static Class cPolygon;
250
+
251
+ void
252
+ Init_polygon ()
253
+ {
254
+ Module mRays = define_module("Rays");
255
+
256
+ cPolygon = mRays.define_class("Polygon");
257
+ cPolygon.define_alloc_func(alloc);
258
+ cPolygon.define_private_method("setup", setup);
259
+ cPolygon.define_method("expand", expand);
260
+ cPolygon.define_method("bounds", bounds);
261
+ cPolygon.define_method("size", size);
262
+ cPolygon.define_method("empty?", empty);
263
+ cPolygon.define_method("[]", get_at);
264
+ cPolygon.define_method("each", each);
265
+ cPolygon.define_method("+", op_or);
266
+ cPolygon.define_method("-", op_sub);
267
+ cPolygon.define_method("&", op_and);
268
+ cPolygon.define_method("|", op_or);
269
+ cPolygon.define_method("^", op_xor);
270
+ cPolygon.define_singleton_method("create_rect", create_rect);
271
+ cPolygon.define_singleton_method("create_ellipse", create_ellipse);
272
+ cPolygon.define_singleton_method("create_curve", create_curve);
273
+ cPolygon.define_singleton_method("create_bezier", create_bezier);
274
+ }
275
+
276
+
277
+ namespace Rucy
278
+ {
279
+
280
+
281
+ template <> Rays::Polygon
282
+ value_to<Rays::Polygon> (int argc, const Value* argv, bool convert)
283
+ {
284
+ assert(argc == 0 || (argc > 0 && argv));
285
+
286
+ if (convert)
287
+ {
288
+ if (argc <= 0)
289
+ return Rays::Polygon();
290
+ else if (argv->is_kind_of(Rays::polygon_line_class()))
291
+ {
292
+ std::vector<Rays::Polygon::Line> lines;
293
+ lines.reserve(argc);
294
+ for (int i = 0; i < argc; ++i)
295
+ lines.emplace_back(to<Rays::Polygon::Line&>(argv[i]));
296
+ return Rays::Polygon(&lines[0], lines.size());
297
+ }
298
+ else if (argv->is_kind_of(Rays::polyline_class()))
299
+ return Rays::Polygon(to<Rays::Polyline&>(*argv));
300
+ else if (argv->is_num() || argv->is_array())
301
+ {
302
+ std::vector<Rays::Point> points;
303
+ get_line_args(&points, argc, argv);
304
+ return Rays::Polygon(&points[0], points.size());
305
+ }
306
+ }
307
+
308
+ if (argc != 1)
309
+ argument_error(__FILE__, __LINE__);
310
+
311
+ return value_to<Rays::Polygon&>(*argv, convert);
312
+ }
313
+
314
+
315
+ }// Rucy
316
+
317
+
318
+ namespace Rays
319
+ {
320
+
321
+
322
+ Class
323
+ polygon_class ()
324
+ {
325
+ return cPolygon;
326
+ }
327
+
328
+
329
+ }// Rays