rays 0.1.47 → 0.1.48

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/rays/bitmap.cpp +287 -46
  3. data/.doc/ext/rays/camera.cpp +2 -2
  4. data/.doc/ext/rays/defs.cpp +32 -8
  5. data/.doc/ext/rays/font.cpp +50 -2
  6. data/.doc/ext/rays/native.cpp +2 -4
  7. data/.doc/ext/rays/painter.cpp +73 -3
  8. data/.doc/ext/rays/polygon.cpp +131 -97
  9. data/.doc/ext/rays/polyline.cpp +89 -10
  10. data/.doc/ext/rays/rays.cpp +80 -0
  11. data/.doc/ext/rays/{noise.cpp → util.cpp} +2 -2
  12. data/ChangeLog.md +23 -0
  13. data/VERSION +1 -1
  14. data/ext/rays/bitmap.cpp +288 -46
  15. data/ext/rays/camera.cpp +2 -2
  16. data/ext/rays/defs.cpp +32 -8
  17. data/ext/rays/defs.h +56 -3
  18. data/ext/rays/font.cpp +56 -4
  19. data/ext/rays/native.cpp +2 -4
  20. data/ext/rays/painter.cpp +80 -3
  21. data/ext/rays/polygon.cpp +134 -99
  22. data/ext/rays/polyline.cpp +95 -9
  23. data/ext/rays/rays.cpp +80 -0
  24. data/ext/rays/{noise.cpp → util.cpp} +2 -2
  25. data/include/rays/defs.h +24 -26
  26. data/include/rays/font.h +17 -3
  27. data/include/rays/painter.h +14 -0
  28. data/include/rays/polygon.h +56 -37
  29. data/include/rays/polyline.h +17 -2
  30. data/include/rays/ruby/polygon.h +0 -11
  31. data/include/rays/ruby/rays.h +4 -0
  32. data/include/rays/{noise.h → util.h} +2 -2
  33. data/lib/rays/color.rb +1 -1
  34. data/lib/rays/font.rb +1 -1
  35. data/lib/rays/image.rb +1 -1
  36. data/lib/rays/painter.rb +12 -1
  37. data/lib/rays/point.rb +1 -1
  38. data/lib/rays/polygon.rb +44 -35
  39. data/lib/rays/polyline.rb +54 -8
  40. data/lib/rays.rb +0 -1
  41. data/rays.gemspec +1 -1
  42. data/src/font.cpp +24 -2
  43. data/src/font.h +8 -1
  44. data/src/ios/font.mm +88 -27
  45. data/src/osx/font.mm +90 -28
  46. data/src/osx/helper.h +2 -2
  47. data/src/osx/helper.mm +2 -2
  48. data/src/painter.cpp +155 -85
  49. data/src/painter.h +11 -3
  50. data/src/polygon.cpp +404 -315
  51. data/src/polyline.cpp +138 -27
  52. data/src/polyline.h +3 -5
  53. data/src/shader.cpp +36 -4
  54. data/src/shader.h +1 -1
  55. data/src/texture.cpp +2 -2
  56. data/src/{noise.cpp → util.cpp} +1 -1
  57. data/src/win32/font.cpp +1 -1
  58. data/test/test_bitmap.rb +12 -5
  59. data/test/test_color.rb +4 -0
  60. data/test/test_font.rb +20 -2
  61. data/test/test_image.rb +18 -18
  62. data/test/test_point.rb +1 -1
  63. data/test/test_polygon.rb +52 -45
  64. data/test/test_polyline.rb +191 -72
  65. metadata +9 -15
  66. data/.doc/ext/rays/polygon_line.cpp +0 -97
  67. data/ext/rays/polygon_line.cpp +0 -100
  68. data/lib/rays/polygon_line.rb +0 -33
  69. data/test/test_polygon_line.rb +0 -164
@@ -153,7 +153,7 @@ VALUE line(VALUE self, VALUE args, VALUE loop)
153
153
  CHECK;
154
154
 
155
155
  std::vector<Rays::Point> points;
156
- get_line_args(&points, args.size(), args.as_array());
156
+ get_points(&points, args.size(), args.as_array());
157
157
 
158
158
  THIS->line(&points[0], points.size(), loop);
159
159
  return self;
@@ -211,7 +211,7 @@ VALUE curve(VALUE self, VALUE args, VALUE loop)
211
211
  argument_error(__FILE__, __LINE__);
212
212
 
213
213
  std::vector<Rays::Point> points;
214
- get_line_args(&points, args.size(), args.as_array());
214
+ get_points(&points, args.size(), args.as_array());
215
215
 
216
216
  THIS->curve(&points[0], points.size(), loop);
217
217
  return self;
@@ -226,7 +226,7 @@ VALUE bezier(VALUE self, VALUE args, VALUE loop)
226
226
  argument_error(__FILE__, __LINE__);
227
227
 
228
228
  std::vector<Rays::Point> points;
229
- get_line_args(&points, args.size(), args.as_array());
229
+ get_points(&points, args.size(), args.as_array());
230
230
 
231
231
  THIS->bezier(&points[0], points.size(), loop);
232
232
  return self;
@@ -513,6 +513,69 @@ VALUE get_font(VALUE self)
513
513
  return value(THIS->font());
514
514
  }
515
515
 
516
+ static
517
+ VALUE set_texture(VALUE self, VALUE image)
518
+ {
519
+ CHECK;
520
+
521
+ if (!image)
522
+ THIS->no_texture();
523
+ else
524
+ THIS->set_texture(to<Rays::Image&>(image));
525
+ return self;
526
+ }
527
+
528
+ static
529
+ VALUE get_texture(VALUE self)
530
+ {
531
+ CHECK;
532
+
533
+ const Rays::Image& image = THIS->texture();
534
+ return image ? value(image) : nil();
535
+ }
536
+
537
+ static
538
+ VALUE no_texture(VALUE self)
539
+ {
540
+ CHECK;
541
+ THIS->no_texture();
542
+ return self;
543
+ }
544
+
545
+ static
546
+ VALUE set_texcoord_mode(VALUE self, VALUE mode)
547
+ {
548
+ CHECK;
549
+
550
+ THIS->set_texcoord_mode(to<Rays::TexCoordMode>(mode));
551
+ return self;
552
+ }
553
+
554
+ static
555
+ VALUE get_texcoord_mode(VALUE self)
556
+ {
557
+ CHECK;
558
+
559
+ return value(THIS->texcoord_mode());
560
+ }
561
+
562
+ static
563
+ VALUE set_texcoord_wrap(VALUE self, VALUE wrap)
564
+ {
565
+ CHECK;
566
+
567
+ THIS->set_texcoord_wrap(to<Rays::TexCoordWrap>(wrap));
568
+ return self;
569
+ }
570
+
571
+ static
572
+ VALUE get_texcoord_wrap(VALUE self)
573
+ {
574
+ CHECK;
575
+
576
+ return value(THIS->texcoord_wrap());
577
+ }
578
+
516
579
  static
517
580
  VALUE set_shader(VALUE self)
518
581
  {
@@ -695,6 +758,13 @@ Init_rays_painter ()
695
758
  rb_define_method(cPainter, "no_clip", RUBY_METHOD_FUNC(no_clip), 0);
696
759
  rb_define_method(cPainter, "font=", RUBY_METHOD_FUNC(set_font), -1);
697
760
  rb_define_method(cPainter, "font", RUBY_METHOD_FUNC(get_font), 0);
761
+ rb_define_method(cPainter, "texture=", RUBY_METHOD_FUNC(set_texture), 1);
762
+ rb_define_method(cPainter, "texture", RUBY_METHOD_FUNC(get_texture), 0);
763
+ rb_define_method(cPainter, "no_texture", RUBY_METHOD_FUNC(no_texture), 0);
764
+ rb_define_method(cPainter, "texcoord_mode=", RUBY_METHOD_FUNC(set_texcoord_mode), 1);
765
+ rb_define_method(cPainter, "texcoord_mode", RUBY_METHOD_FUNC(get_texcoord_mode), 0);
766
+ rb_define_method(cPainter, "texcoord_wrap=", RUBY_METHOD_FUNC(set_texcoord_wrap), 1);
767
+ rb_define_method(cPainter, "texcoord_wrap", RUBY_METHOD_FUNC(get_texcoord_wrap), 0);
698
768
  rb_define_private_method(cPainter, "set_shader", RUBY_METHOD_FUNC(set_shader), -1);
699
769
  rb_define_method(cPainter, "shader", RUBY_METHOD_FUNC(get_shader), 0);
700
770
  rb_define_method(cPainter, "no_shader", RUBY_METHOD_FUNC(no_shader), 0);
@@ -1,7 +1,6 @@
1
1
  #include "rays/ruby/polygon.h"
2
2
 
3
3
 
4
- #include <assert.h>
5
4
  #include <vector>
6
5
  #include <functional>
7
6
  #include "rays/ruby/bounds.h"
@@ -23,7 +22,7 @@ VALUE alloc(VALUE klass)
23
22
  }
24
23
 
25
24
  static
26
- VALUE setup(VALUE self, VALUE args, VALUE loop)
25
+ VALUE setup(VALUE self, VALUE args, VALUE loop, VALUE colors, VALUE texcoords)
27
26
  {
28
27
  CHECK;
29
28
 
@@ -31,9 +30,10 @@ VALUE setup(VALUE self, VALUE args, VALUE loop)
31
30
  *THIS = to<Rays::Polygon>(args.size(), args.as_array());
32
31
  else
33
32
  {
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);
33
+ CreateParams params(args, colors, texcoords);
34
+ *THIS = Rays::Polygon(
35
+ params.ppoints(), params.size(), loop,
36
+ params.pcolors(), params.ptexcoords());
37
37
  }
38
38
  }
39
39
 
@@ -95,19 +95,59 @@ VALUE each(VALUE self)
95
95
  CHECK;
96
96
 
97
97
  Value ret = Qnil;
98
- for (const auto& line : *THIS)
99
- ret = rb_yield(value(line));
98
+ for (const auto& polyline : *THIS)
99
+ ret = rb_yield(value(polyline));
100
100
  return ret;
101
101
  }
102
102
 
103
- static void
104
- each_polygon (const Value& value, std::function<void(const Rays::Polygon&)> fun)
103
+ template <typename T>
104
+ static inline void
105
+ each_poly (const Value& value, auto fun)
105
106
  {
106
107
  int size = value.size();
107
108
  const Value* array = value.as_array();
108
109
 
109
110
  for (int i = 0; i < size; ++i)
110
- fun(to<Rays::Polygon&>(array[i]));
111
+ fun(to<T&>(array[i]));
112
+ }
113
+
114
+ static
115
+ VALUE op_add(VALUE self, VALUE obj)
116
+ {
117
+ CHECK;
118
+
119
+ if (obj.is_kind_of(Rays::polyline_class()))
120
+ return value(*THIS + to<Rays::Polyline&>(obj));
121
+
122
+ if (obj.is_kind_of(Rays::polygon_class()))
123
+ return value(*THIS + to<Rays::Polygon&>(obj));
124
+
125
+ if (!obj.is_array())
126
+ argument_error(__FILE__, __LINE__);
127
+
128
+ if (obj.empty()) return self;
129
+
130
+ std::vector<Rays::Polyline> polylines;
131
+ for (const auto& polyline : to<Rays::Polygon&>(self))
132
+ polylines.emplace_back(polyline);
133
+
134
+ if (obj[0].is_kind_of(Rays::polyline_class()))
135
+ {
136
+ each_poly<Rays::Polyline>(obj, [&](const auto& polyline)
137
+ {
138
+ polylines.emplace_back(polyline);
139
+ });
140
+ }
141
+ else
142
+ {
143
+ each_poly<Rays::Polygon>(obj, [&](const auto& polygon)
144
+ {
145
+ for (const auto& polyline : polygon)
146
+ polylines.emplace_back(polyline);
147
+ });
148
+ }
149
+
150
+ return value(Rays::Polygon(&polylines[0], polylines.size()));
111
151
  }
112
152
 
113
153
  static
@@ -118,7 +158,7 @@ VALUE op_sub(VALUE self, VALUE obj)
118
158
  if (obj.is_array())
119
159
  {
120
160
  Rays::Polygon result = *THIS;
121
- each_polygon(obj, [&](const Rays::Polygon& polygon)
161
+ each_poly<Rays::Polygon>(obj, [&](const auto& polygon)
122
162
  {
123
163
  result = result - polygon;
124
164
  });
@@ -136,7 +176,7 @@ VALUE op_and(VALUE self, VALUE obj)
136
176
  if (obj.is_array())
137
177
  {
138
178
  Rays::Polygon result = *THIS;
139
- each_polygon(obj, [&](const Rays::Polygon& polygon)
179
+ each_poly<Rays::Polygon>(obj, [&](const auto& polygon)
140
180
  {
141
181
  result = result & polygon;
142
182
  });
@@ -154,7 +194,7 @@ VALUE op_or(VALUE self, VALUE obj)
154
194
  if (obj.is_array())
155
195
  {
156
196
  Rays::Polygon result = *THIS;
157
- each_polygon(obj, [&](const Rays::Polygon& polygon)
197
+ each_poly<Rays::Polygon>(obj, [&](const auto& polygon)
158
198
  {
159
199
  result = result | polygon;
160
200
  });
@@ -172,7 +212,7 @@ VALUE op_xor(VALUE self, VALUE obj)
172
212
  if (obj.is_array())
173
213
  {
174
214
  Rays::Polygon result = *THIS;
175
- each_polygon(obj, [&](const Rays::Polygon& polygon)
215
+ each_poly<Rays::Polygon>(obj, [&](const auto& polygon)
176
216
  {
177
217
  result = result ^ polygon;
178
218
  });
@@ -183,28 +223,51 @@ VALUE op_xor(VALUE self, VALUE obj)
183
223
  }
184
224
 
185
225
  static
186
- VALUE create_points(VALUE self, VALUE args)
226
+ VALUE create_points(VALUE self, VALUE points)
187
227
  {
188
- std::vector<Rays::Point> points;
189
- get_line_args(&points, args.size(), args.as_array());
190
- return value(Rays::Polygon(Rays::DRAW_POINTS, &points[0], points.size()));
228
+ CreateParams params(points, nil(), nil());
229
+ return value(Rays::create_points(params.ppoints(), params.size()));
191
230
  }
192
231
 
193
232
  static
194
- VALUE create_lines(VALUE self, VALUE args)
233
+ VALUE create_line(VALUE self, VALUE points, VALUE loop)
195
234
  {
196
- std::vector<Rays::Point> points;
197
- get_line_args(&points, args.size(), args.as_array());
198
- return value(Rays::Polygon(Rays::DRAW_LINES, &points[0], points.size()));
235
+ CreateParams params(points, nil(), nil());
236
+ return value(Rays::create_line(params.ppoints(), params.size(), loop));
199
237
  }
200
238
 
201
239
  static
202
- VALUE create_line_strip(VALUE self, VALUE args, VALUE loop)
240
+ VALUE create_lines(VALUE self, VALUE points)
203
241
  {
204
- std::vector<Rays::Point> points;
205
- get_line_args(&points, args.size(), args.as_array());
206
- return value(
207
- Rays::Polygon(Rays::DRAW_LINE_STRIP, &points[0], points.size(), loop));
242
+ CreateParams params(points, nil(), nil());
243
+ return value(Rays::create_lines(params.ppoints(), params.size()));
244
+ }
245
+
246
+ static
247
+ VALUE create_triangles(VALUE self, VALUE points, VALUE loop, VALUE colors, VALUE texcoords)
248
+ {
249
+ CreateParams params(points, colors, texcoords);
250
+ return value(Rays::create_triangles(
251
+ params.ppoints(), params.size(), loop,
252
+ params.pcolors(), params.ptexcoords()));
253
+ }
254
+
255
+ static
256
+ VALUE create_triangle_strip(VALUE self, VALUE points, VALUE colors, VALUE texcoords)
257
+ {
258
+ CreateParams params(points, colors, texcoords);
259
+ return value(Rays::create_triangle_strip(
260
+ params.ppoints(), params.size(),
261
+ params.pcolors(), params.ptexcoords()));
262
+ }
263
+
264
+ static
265
+ VALUE create_triangle_fan(VALUE self, VALUE points, VALUE colors, VALUE texcoords)
266
+ {
267
+ CreateParams params(points, colors, texcoords);
268
+ return value(Rays::create_triangle_fan(
269
+ params.ppoints(), params.size(),
270
+ params.pcolors(), params.ptexcoords()));
208
271
  }
209
272
 
210
273
  static
@@ -221,6 +284,24 @@ VALUE create_rect(VALUE self, VALUE
221
284
  return value(Rays::create_rect(x, y, w, h, lt, rt, lb, rb, nseg));
222
285
  }
223
286
 
287
+ static
288
+ VALUE create_quads(VALUE self, VALUE points, VALUE loop, VALUE colors, VALUE texcoords)
289
+ {
290
+ CreateParams params(points, colors, texcoords);
291
+ return value(Rays::create_quads(
292
+ params.ppoints(), params.size(), loop,
293
+ params.pcolors(), params.ptexcoords()));
294
+ }
295
+
296
+ static
297
+ VALUE create_quad_strip(VALUE self, VALUE points, VALUE colors, VALUE texcoords)
298
+ {
299
+ CreateParams params(points, colors, texcoords);
300
+ return value(Rays::create_quad_strip(
301
+ params.ppoints(), params.size(),
302
+ params.pcolors(), params.ptexcoords()));
303
+ }
304
+
224
305
  static
225
306
  VALUE create_ellipse(VALUE self, VALUE
226
307
  args, VALUE center, VALUE radius, VALUE hole, VALUE angle_from, VALUE angle_to, VALUE nsegment)
@@ -238,65 +319,17 @@ VALUE create_ellipse(VALUE self, VALUE
238
319
  }
239
320
 
240
321
  static
241
- VALUE create_triangles(VALUE self, VALUE args, VALUE loop)
242
- {
243
- std::vector<Rays::Point> points;
244
- get_line_args(&points, args.size(), args.as_array());
245
- return value(
246
- Rays::Polygon(Rays::DRAW_TRIANGLES, &points[0], points.size(), loop));
247
- }
248
-
249
- static
250
- VALUE create_triangle_strip(VALUE self, VALUE args)
322
+ VALUE create_curve(VALUE self, VALUE points, VALUE loop)
251
323
  {
252
- std::vector<Rays::Point> points;
253
- get_line_args(&points, args.size(), args.as_array());
254
- return value(
255
- Rays::Polygon(Rays::DRAW_TRIANGLE_STRIP, &points[0], points.size()));
324
+ CreateParams params(points, nil(), nil());
325
+ return value(Rays::create_curve(params.ppoints(), params.size(), loop));
256
326
  }
257
327
 
258
328
  static
259
- VALUE create_triangle_fan(VALUE self, VALUE args)
329
+ VALUE create_bezier(VALUE self, VALUE points, VALUE loop)
260
330
  {
261
- std::vector<Rays::Point> points;
262
- get_line_args(&points, args.size(), args.as_array());
263
- return value(
264
- Rays::Polygon(Rays::DRAW_TRIANGLE_FAN, &points[0], points.size()));
265
- }
266
-
267
- static
268
- VALUE create_quads(VALUE self, VALUE args, VALUE loop)
269
- {
270
- std::vector<Rays::Point> points;
271
- get_line_args(&points, args.size(), args.as_array());
272
- return value(
273
- Rays::Polygon(Rays::DRAW_QUADS, &points[0], points.size(), loop));
274
- }
275
-
276
- static
277
- VALUE create_quad_strip(VALUE self, VALUE args)
278
- {
279
- std::vector<Rays::Point> points;
280
- get_line_args(&points, args.size(), args.as_array());
281
- return value(Rays::Polygon(Rays::DRAW_QUAD_STRIP, &points[0], points.size()));
282
- }
283
-
284
- static
285
- VALUE create_curve(VALUE self, VALUE args, VALUE loop)
286
- {
287
- std::vector<Rays::Point> points;
288
- get_line_args(&points, args.size(), args.as_array());
289
-
290
- return value(Rays::create_curve(&points[0], points.size(), loop));
291
- }
292
-
293
- static
294
- VALUE create_bezier(VALUE self, VALUE args, VALUE loop)
295
- {
296
- std::vector<Rays::Point> points;
297
- get_line_args(&points, args.size(), args.as_array());
298
-
299
- return value(Rays::create_bezier(&points[0], points.size(), loop));
331
+ CreateParams params(points, nil(), nil());
332
+ return value(Rays::create_bezier(params.ppoints(), params.size(), loop));
300
333
  }
301
334
 
302
335
 
@@ -309,28 +342,28 @@ Init_rays_polygon ()
309
342
 
310
343
  cPolygon = rb_define_class_under(mRays, "Polygon", rb_cObject);
311
344
  rb_define_alloc_func(cPolygon, alloc);
312
- rb_define_private_method(cPolygon, "setup", RUBY_METHOD_FUNC(setup), 2);
345
+ rb_define_private_method(cPolygon, "setup", RUBY_METHOD_FUNC(setup), 4);
313
346
  rb_define_method(cPolygon, "expand", RUBY_METHOD_FUNC(expand), -1);
314
347
  rb_define_method(cPolygon, "bounds", RUBY_METHOD_FUNC(bounds), 0);
315
348
  rb_define_method(cPolygon, "size", RUBY_METHOD_FUNC(size), 0);
316
349
  cPolygon.define_method("empty?", is_empty);
317
350
  cPolygon.define_method("[]", get_at);
318
351
  rb_define_method(cPolygon, "each", RUBY_METHOD_FUNC(each), 0);
319
- cPolygon.define_method("+", op_or);
352
+ cPolygon.define_method("+", op_add);
320
353
  cPolygon.define_method("-", op_sub);
321
354
  cPolygon.define_method("&", op_and);
322
355
  cPolygon.define_method("|", op_or);
323
356
  cPolygon.define_method("^", op_xor);
324
357
  cPolygon.define_singleton_method("points!", create_points);
358
+ cPolygon.define_singleton_method("line!", create_line);
325
359
  cPolygon.define_singleton_method("lines!", create_lines);
326
- cPolygon.define_singleton_method("line_strip!", create_line_strip);
327
- cPolygon.define_singleton_method("rect!", create_rect);
328
- cPolygon.define_singleton_method("ellipse!", create_ellipse);
329
360
  cPolygon.define_singleton_method("triangles!", create_triangles);
330
361
  cPolygon.define_singleton_method("triangle_strip!", create_triangle_strip);
331
362
  cPolygon.define_singleton_method("triangle_fan!", create_triangle_fan);
363
+ cPolygon.define_singleton_method("rect!", create_rect);
332
364
  cPolygon.define_singleton_method("quads!", create_quads);
333
365
  cPolygon.define_singleton_method("quad_strip!", create_quad_strip);
366
+ cPolygon.define_singleton_method("ellipse!", create_ellipse);
334
367
  cPolygon.define_singleton_method("curve!", create_curve);
335
368
  cPolygon.define_singleton_method("bezier!", create_bezier);
336
369
  }
@@ -343,26 +376,27 @@ namespace Rucy
343
376
  template <> Rays::Polygon
344
377
  value_to<Rays::Polygon> (int argc, const Value* argv, bool convert)
345
378
  {
346
- assert(argc == 0 || (argc > 0 && argv));
347
-
348
379
  if (convert)
349
380
  {
350
381
  if (argc <= 0)
351
382
  return Rays::Polygon();
352
- else if (argv->is_kind_of(Rays::polygon_line_class()))
383
+ else if (argv->is_kind_of(Rays::polyline_class()))
353
384
  {
354
- std::vector<Rays::Polygon::Line> lines;
355
- lines.reserve(argc);
356
- for (int i = 0; i < argc; ++i)
357
- lines.emplace_back(to<Rays::Polygon::Line&>(argv[i]));
358
- return Rays::Polygon(&lines[0], lines.size());
385
+ if (argc == 1)
386
+ return Rays::Polygon(to<Rays::Polyline&>(*argv));
387
+ else
388
+ {
389
+ std::vector<Rays::Polyline> polylines;
390
+ polylines.reserve(argc);
391
+ for (int i = 0; i < argc; ++i)
392
+ polylines.emplace_back(to<Rays::Polyline&>(argv[i]));
393
+ return Rays::Polygon(&polylines[0], polylines.size());
394
+ }
359
395
  }
360
- else if (argv->is_kind_of(Rays::polyline_class()))
361
- return Rays::Polygon(to<Rays::Polyline&>(*argv));
362
396
  else if (argv->is_num() || argv->is_array())
363
397
  {
364
398
  std::vector<Rays::Point> points;
365
- get_line_args(&points, argc, argv);
399
+ get_points(&points, argc, argv);
366
400
  return Rays::Polygon(&points[0], points.size());
367
401
  }
368
402
  }
@@ -3,6 +3,7 @@
3
3
 
4
4
  #include <assert.h>
5
5
  #include <vector>
6
+ #include "rays/ruby/color.h"
6
7
  #include "rays/ruby/point.h"
7
8
  #include "rays/ruby/bounds.h"
8
9
  #include "rays/ruby/polygon.h"
@@ -23,13 +24,15 @@ VALUE alloc(VALUE klass)
23
24
  }
24
25
 
25
26
  static
26
- VALUE setup(VALUE self, VALUE points, VALUE loop)
27
+ VALUE setup(VALUE self, VALUE points, VALUE loop, VALUE fill, VALUE colors, VALUE texcoords, VALUE hole)
27
28
  {
28
29
  CHECK;
29
30
 
30
- std::vector<Rays::Point> array;
31
- get_line_args(&array, points.size(), points.as_array());
32
- *THIS = Rays::Polyline(&array[0], array.size(), loop);
31
+ CreateParams params(points, colors, texcoords);
32
+ *THIS = Rays::Polyline(
33
+ params.ppoints(), params.size(), loop, fill,
34
+ params.pcolors(), params.ptexcoords(),
35
+ hole);
33
36
  }
34
37
 
35
38
  static
@@ -56,12 +59,26 @@ VALUE bounds(VALUE self)
56
59
  }
57
60
 
58
61
  static
59
- VALUE loop(VALUE self)
62
+ VALUE is_loop(VALUE self)
60
63
  {
61
64
  CHECK;
62
65
  return value(THIS->loop());
63
66
  }
64
67
 
68
+ static
69
+ VALUE is_fill(VALUE self)
70
+ {
71
+ CHECK;
72
+ return value(THIS->fill());
73
+ }
74
+
75
+ static
76
+ VALUE is_hole(VALUE self)
77
+ {
78
+ CHECK;
79
+ return value(THIS->hole());
80
+ }
81
+
65
82
  static
66
83
  VALUE size(VALUE self)
67
84
  {
@@ -92,7 +109,28 @@ VALUE get_at(VALUE self, VALUE index)
92
109
  }
93
110
 
94
111
  static
95
- VALUE each(VALUE self)
112
+ VALUE has_points(VALUE self)
113
+ {
114
+ CHECK;
115
+ return value(THIS->points() && !THIS->empty());
116
+ }
117
+
118
+ static
119
+ VALUE has_colors(VALUE self)
120
+ {
121
+ CHECK;
122
+ return value(THIS->colors() && !THIS->empty());
123
+ }
124
+
125
+ static
126
+ VALUE has_texcoords(VALUE self)
127
+ {
128
+ CHECK;
129
+ return value(THIS->texcoords() && !THIS->empty());
130
+ }
131
+
132
+ static
133
+ VALUE each_point(VALUE self)
96
134
  {
97
135
  CHECK;
98
136
 
@@ -102,6 +140,40 @@ VALUE each(VALUE self)
102
140
  return ret;
103
141
  }
104
142
 
143
+ static
144
+ VALUE each_color(VALUE self)
145
+ {
146
+ CHECK;
147
+
148
+ const Rays::Color* colors = THIS->colors();
149
+
150
+ Value ret = Qnil;
151
+ if (colors)
152
+ {
153
+ size_t size = THIS->size();
154
+ for (size_t i = 0; i < size; ++i)
155
+ ret = rb_yield(value(colors[i]));
156
+ }
157
+ return ret;
158
+ }
159
+
160
+ static
161
+ VALUE each_texcoord(VALUE self)
162
+ {
163
+ CHECK;
164
+
165
+ const Rays::Coord3* texcoords = THIS->texcoords();
166
+
167
+ Value ret = Qnil;
168
+ if (texcoords)
169
+ {
170
+ size_t size = THIS->size();
171
+ for (size_t i = 0; i < size; ++i)
172
+ ret = rb_yield(value(*(Rays::Point*) &texcoords[i]));
173
+ }
174
+ return ret;
175
+ }
176
+
105
177
 
106
178
  static Class cPolyline;
107
179
 
@@ -112,14 +184,21 @@ Init_rays_polyline ()
112
184
 
113
185
  cPolyline = rb_define_class_under(mRays, "Polyline", rb_cObject);
114
186
  rb_define_alloc_func(cPolyline, alloc);
115
- rb_define_private_method(cPolyline, "setup", RUBY_METHOD_FUNC(setup), 2);
187
+ rb_define_private_method(cPolyline, "setup", RUBY_METHOD_FUNC(setup), 6);
116
188
  rb_define_method(cPolyline, "expand", RUBY_METHOD_FUNC(expand), -1);
117
189
  rb_define_method(cPolyline, "bounds", RUBY_METHOD_FUNC(bounds), 0);
118
- cPolyline.define_method("loop?", loop);
190
+ cPolyline.define_method("loop?", is_loop);
191
+ cPolyline.define_method("fill?", is_fill);
192
+ cPolyline.define_method("hole?", is_hole);
119
193
  rb_define_method(cPolyline, "size", RUBY_METHOD_FUNC(size), 0);
120
194
  cPolyline.define_method("empty?", is_empty);
121
195
  cPolyline.define_method("[]", get_at);
122
- rb_define_method(cPolyline, "each", RUBY_METHOD_FUNC(each), 0);
196
+ cPolyline.define_method("points?", has_points);
197
+ cPolyline.define_method("colors?", has_colors);
198
+ cPolyline.define_method("texcoords?", has_texcoords);
199
+ cPolyline.define_private_method("each_point!", each_point);
200
+ cPolyline.define_private_method("each_color!", each_color);
201
+ cPolyline.define_private_method("each_texcoord!", each_texcoord);
123
202
  }
124
203
 
125
204
 
@@ -139,7 +218,7 @@ namespace Rucy
139
218
  else if (argv->is_num() || argv->is_array())
140
219
  {
141
220
  std::vector<Rays::Point> points;
142
- get_line_args(&points, argc, argv);
221
+ get_points(&points, argc, argv);
143
222
  return Rays::Polyline(&points[0], points.size());
144
223
  }
145
224
  }