rays 0.1.46 → 0.1.48

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 (74) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/rays/bitmap.cpp +499 -0
  3. data/.doc/ext/rays/camera.cpp +2 -2
  4. data/.doc/ext/rays/defs.cpp +35 -11
  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 +111 -6
  8. data/.doc/ext/rays/polygon.cpp +152 -41
  9. data/.doc/ext/rays/polyline.cpp +89 -10
  10. data/.doc/ext/rays/rays.cpp +91 -11
  11. data/.doc/ext/rays/{noise.cpp → util.cpp} +2 -2
  12. data/.github/workflows/test.yml +0 -1
  13. data/ChangeLog.md +38 -0
  14. data/Rakefile +4 -4
  15. data/VERSION +1 -1
  16. data/ext/rays/bitmap.cpp +501 -0
  17. data/ext/rays/camera.cpp +2 -2
  18. data/ext/rays/defs.cpp +35 -11
  19. data/ext/rays/defs.h +56 -3
  20. data/ext/rays/font.cpp +56 -4
  21. data/ext/rays/native.cpp +2 -4
  22. data/ext/rays/painter.cpp +125 -11
  23. data/ext/rays/polygon.cpp +161 -41
  24. data/ext/rays/polyline.cpp +95 -9
  25. data/ext/rays/rays.cpp +91 -11
  26. data/ext/rays/{noise.cpp → util.cpp} +2 -2
  27. data/include/rays/defs.h +24 -0
  28. data/include/rays/font.h +17 -3
  29. data/include/rays/matrix.h +2 -0
  30. data/include/rays/painter.h +29 -1
  31. data/include/rays/polygon.h +57 -33
  32. data/include/rays/polyline.h +20 -1
  33. data/include/rays/ruby/polygon.h +0 -11
  34. data/include/rays/ruby/rays.h +4 -0
  35. data/include/rays/{noise.h → util.h} +2 -2
  36. data/lib/rays/color.rb +1 -1
  37. data/lib/rays/font.rb +1 -1
  38. data/lib/rays/image.rb +1 -1
  39. data/lib/rays/painter.rb +13 -2
  40. data/lib/rays/point.rb +1 -1
  41. data/lib/rays/polygon.rb +54 -16
  42. data/lib/rays/polyline.rb +54 -8
  43. data/lib/rays.rb +0 -1
  44. data/rays.gemspec +2 -2
  45. data/src/color_space.cpp +2 -2
  46. data/src/font.cpp +24 -2
  47. data/src/font.h +8 -1
  48. data/src/ios/font.mm +88 -27
  49. data/src/matrix.cpp +8 -0
  50. data/src/osx/font.mm +90 -28
  51. data/src/osx/helper.h +2 -2
  52. data/src/osx/helper.mm +2 -2
  53. data/src/painter.cpp +227 -90
  54. data/src/painter.h +11 -3
  55. data/src/polygon.cpp +588 -205
  56. data/src/polyline.cpp +154 -28
  57. data/src/polyline.h +3 -5
  58. data/src/shader.cpp +36 -4
  59. data/src/shader.h +1 -1
  60. data/src/texture.cpp +2 -2
  61. data/src/{noise.cpp → util.cpp} +1 -1
  62. data/src/win32/font.cpp +1 -1
  63. data/test/test_bitmap.rb +16 -2
  64. data/test/test_color.rb +4 -0
  65. data/test/test_font.rb +20 -2
  66. data/test/test_image.rb +18 -18
  67. data/test/test_point.rb +1 -1
  68. data/test/test_polygon.rb +52 -45
  69. data/test/test_polyline.rb +191 -72
  70. metadata +11 -17
  71. data/.doc/ext/rays/polygon_line.cpp +0 -97
  72. data/ext/rays/polygon_line.cpp +0 -100
  73. data/lib/rays/polygon_line.rb +0 -33
  74. data/test/test_polygon_line.rb +0 -164
@@ -12,7 +12,6 @@ void Init_rays_matrix ();
12
12
 
13
13
  void Init_rays_painter ();
14
14
  void Init_rays_polyline ();
15
- void Init_rays_polygon_line ();
16
15
  void Init_rays_polygon ();
17
16
  void Init_rays_bitmap ();
18
17
  void Init_rays_image ();
@@ -20,7 +19,7 @@ void Init_rays_font ();
20
19
  void Init_rays_shader ();
21
20
  void Init_rays_camera ();
22
21
 
23
- void Init_rays_noise ();
22
+ void Init_rays_util ();
24
23
 
25
24
 
26
25
  extern "C" void
@@ -45,7 +44,6 @@ extern "C" void
45
44
 
46
45
  Init_rays_painter();
47
46
  Init_rays_polyline();
48
- Init_rays_polygon_line();
49
47
  Init_rays_polygon();
50
48
  Init_rays_bitmap();
51
49
  Init_rays_image();
@@ -53,7 +51,7 @@ extern "C" void
53
51
  Init_rays_shader();
54
52
  Init_rays_camera();
55
53
 
56
- Init_rays_noise();
54
+ Init_rays_util();
57
55
 
58
56
  RUCY_CATCH
59
57
  }
@@ -121,11 +121,29 @@ VALUE clear(VALUE self)
121
121
  }
122
122
 
123
123
  static
124
- VALUE polygon(VALUE self, VALUE poly)
124
+ VALUE polygon(VALUE self)
125
125
  {
126
126
  CHECK;
127
+ check_arg_count(__FILE__, __LINE__, "Painter#polygon", argc, 1, 3, 5);
128
+
129
+ const Rays::Polygon* polygon = to<Rays::Polygon*>(argv[0]);
130
+ if (!polygon)
131
+ argument_error(__FILE__, __LINE__, "%s is not a polygon.", argv[0].inspect().c_str());
132
+
133
+ if (argc == 1)
134
+ THIS->polygon(*polygon);
135
+ else if (argc == 3)
136
+ {
137
+ coord x = to<coord>(argv[1]), y = to<coord>(argv[2]);
138
+ THIS->polygon(*polygon, x, y);
139
+ }
140
+ else if (argc == 5)
141
+ {
142
+ coord x = to<coord>(argv[1]), w = to<coord>(argv[3]);
143
+ coord y = to<coord>(argv[2]), h = to<coord>(argv[4]);
144
+ THIS->polygon(*polygon, x, y, w, h);
145
+ }
127
146
 
128
- THIS->polygon(to<Rays::Polygon&>(poly));
129
147
  return self;
130
148
  }
131
149
 
@@ -135,7 +153,7 @@ VALUE line(VALUE self, VALUE args, VALUE loop)
135
153
  CHECK;
136
154
 
137
155
  std::vector<Rays::Point> points;
138
- get_line_args(&points, args.size(), args.as_array());
156
+ get_points(&points, args.size(), args.as_array());
139
157
 
140
158
  THIS->line(&points[0], points.size(), loop);
141
159
  return self;
@@ -193,7 +211,7 @@ VALUE curve(VALUE self, VALUE args, VALUE loop)
193
211
  argument_error(__FILE__, __LINE__);
194
212
 
195
213
  std::vector<Rays::Point> points;
196
- get_line_args(&points, args.size(), args.as_array());
214
+ get_points(&points, args.size(), args.as_array());
197
215
 
198
216
  THIS->curve(&points[0], points.size(), loop);
199
217
  return self;
@@ -208,7 +226,7 @@ VALUE bezier(VALUE self, VALUE args, VALUE loop)
208
226
  argument_error(__FILE__, __LINE__);
209
227
 
210
228
  std::vector<Rays::Point> points;
211
- get_line_args(&points, args.size(), args.as_array());
229
+ get_points(&points, args.size(), args.as_array());
212
230
 
213
231
  THIS->bezier(&points[0], points.size(), loop);
214
232
  return self;
@@ -365,6 +383,21 @@ VALUE get_stroke_width(VALUE self)
365
383
  return value(THIS->stroke_width());
366
384
  }
367
385
 
386
+ static
387
+ VALUE set_stroke_outset(VALUE self, VALUE outset)
388
+ {
389
+ CHECK;
390
+ THIS->set_stroke_outset(to<float>(outset));
391
+ return self;
392
+ }
393
+
394
+ static
395
+ VALUE get_stroke_outset(VALUE self)
396
+ {
397
+ CHECK;
398
+ return value(THIS->stroke_outset());
399
+ }
400
+
368
401
  static
369
402
  VALUE set_stroke_cap(VALUE self, VALUE cap)
370
403
  {
@@ -480,6 +513,69 @@ VALUE get_font(VALUE self)
480
513
  return value(THIS->font());
481
514
  }
482
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
+
483
579
  static
484
580
  VALUE set_shader(VALUE self)
485
581
  {
@@ -624,7 +720,7 @@ Init_rays_painter ()
624
720
  rb_define_private_method(cPainter, "end_paint", RUBY_METHOD_FUNC(end_paint), 0);
625
721
  cPainter.define_method( "painting?", is_painting);
626
722
  rb_define_method(cPainter, "clear", RUBY_METHOD_FUNC(clear), 0);
627
- rb_define_method(cPainter, "polygon", RUBY_METHOD_FUNC(polygon), 1);
723
+ rb_define_method(cPainter, "polygon", RUBY_METHOD_FUNC(polygon), -1);
628
724
  rb_define_private_method(cPainter, "draw_line", RUBY_METHOD_FUNC(line), 2);
629
725
  rb_define_private_method(cPainter, "draw_polyline", RUBY_METHOD_FUNC(polyline), 1);
630
726
  rb_define_private_method(cPainter, "draw_rect", RUBY_METHOD_FUNC(rect), 6);
@@ -645,6 +741,8 @@ Init_rays_painter ()
645
741
  rb_define_method(cPainter, "no_stroke", RUBY_METHOD_FUNC(no_stroke), 0);
646
742
  rb_define_method(cPainter, "stroke_width=", RUBY_METHOD_FUNC(set_stroke_width), 1);
647
743
  rb_define_method(cPainter, "stroke_width", RUBY_METHOD_FUNC(get_stroke_width), 0);
744
+ rb_define_method(cPainter, "stroke_outset=", RUBY_METHOD_FUNC(set_stroke_outset), 1);
745
+ rb_define_method(cPainter, "stroke_outset", RUBY_METHOD_FUNC(get_stroke_outset), 0);
648
746
  rb_define_method(cPainter, "stroke_cap=", RUBY_METHOD_FUNC(set_stroke_cap), 1);
649
747
  rb_define_method(cPainter, "stroke_cap", RUBY_METHOD_FUNC(get_stroke_cap), 0);
650
748
  rb_define_method(cPainter, "stroke_join=", RUBY_METHOD_FUNC(set_stroke_join), 1);
@@ -660,6 +758,13 @@ Init_rays_painter ()
660
758
  rb_define_method(cPainter, "no_clip", RUBY_METHOD_FUNC(no_clip), 0);
661
759
  rb_define_method(cPainter, "font=", RUBY_METHOD_FUNC(set_font), -1);
662
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);
663
768
  rb_define_private_method(cPainter, "set_shader", RUBY_METHOD_FUNC(set_shader), -1);
664
769
  rb_define_method(cPainter, "shader", RUBY_METHOD_FUNC(get_shader), 0);
665
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
  });
@@ -182,6 +222,54 @@ VALUE op_xor(VALUE self, VALUE obj)
182
222
  return value(*THIS ^ to<Rays::Polygon&>(obj));
183
223
  }
184
224
 
225
+ static
226
+ VALUE create_points(VALUE self, VALUE points)
227
+ {
228
+ CreateParams params(points, nil(), nil());
229
+ return value(Rays::create_points(params.ppoints(), params.size()));
230
+ }
231
+
232
+ static
233
+ VALUE create_line(VALUE self, VALUE points, VALUE loop)
234
+ {
235
+ CreateParams params(points, nil(), nil());
236
+ return value(Rays::create_line(params.ppoints(), params.size(), loop));
237
+ }
238
+
239
+ static
240
+ VALUE create_lines(VALUE self, VALUE points)
241
+ {
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()));
271
+ }
272
+
185
273
  static
186
274
  VALUE create_rect(VALUE self, VALUE
187
275
  args, VALUE round, VALUE lefttop, VALUE righttop, VALUE leftbottom, VALUE rightbottom, VALUE nsegment)
@@ -196,6 +284,24 @@ VALUE create_rect(VALUE self, VALUE
196
284
  return value(Rays::create_rect(x, y, w, h, lt, rt, lb, rb, nseg));
197
285
  }
198
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
+
199
305
  static
200
306
  VALUE create_ellipse(VALUE self, VALUE
201
307
  args, VALUE center, VALUE radius, VALUE hole, VALUE angle_from, VALUE angle_to, VALUE nsegment)
@@ -213,21 +319,17 @@ VALUE create_ellipse(VALUE self, VALUE
213
319
  }
214
320
 
215
321
  static
216
- VALUE create_curve(VALUE self, VALUE args, VALUE loop)
322
+ VALUE create_curve(VALUE self, VALUE points, VALUE loop)
217
323
  {
218
- std::vector<Rays::Point> points;
219
- get_line_args(&points, args.size(), args.as_array());
220
-
221
- return value(Rays::create_curve(&points[0], points.size(), loop));
324
+ CreateParams params(points, nil(), nil());
325
+ return value(Rays::create_curve(params.ppoints(), params.size(), loop));
222
326
  }
223
327
 
224
328
  static
225
- VALUE create_bezier(VALUE self, VALUE args, VALUE loop)
329
+ VALUE create_bezier(VALUE self, VALUE points, VALUE loop)
226
330
  {
227
- std::vector<Rays::Point> points;
228
- get_line_args(&points, args.size(), args.as_array());
229
-
230
- 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));
231
333
  }
232
334
 
233
335
 
@@ -240,22 +342,30 @@ Init_rays_polygon ()
240
342
 
241
343
  cPolygon = rb_define_class_under(mRays, "Polygon", rb_cObject);
242
344
  rb_define_alloc_func(cPolygon, alloc);
243
- rb_define_private_method(cPolygon, "setup", RUBY_METHOD_FUNC(setup), 2);
345
+ rb_define_private_method(cPolygon, "setup", RUBY_METHOD_FUNC(setup), 4);
244
346
  rb_define_method(cPolygon, "expand", RUBY_METHOD_FUNC(expand), -1);
245
347
  rb_define_method(cPolygon, "bounds", RUBY_METHOD_FUNC(bounds), 0);
246
348
  rb_define_method(cPolygon, "size", RUBY_METHOD_FUNC(size), 0);
247
349
  cPolygon.define_method("empty?", is_empty);
248
350
  cPolygon.define_method("[]", get_at);
249
351
  rb_define_method(cPolygon, "each", RUBY_METHOD_FUNC(each), 0);
250
- cPolygon.define_method("+", op_or);
352
+ cPolygon.define_method("+", op_add);
251
353
  cPolygon.define_method("-", op_sub);
252
354
  cPolygon.define_method("&", op_and);
253
355
  cPolygon.define_method("|", op_or);
254
356
  cPolygon.define_method("^", op_xor);
255
- rb_define_singleton_method(cPolygon, "create_rect", RUBY_METHOD_FUNC(create_rect), 7);
256
- rb_define_singleton_method(cPolygon, "create_ellipse", RUBY_METHOD_FUNC(create_ellipse), 7);
257
- rb_define_singleton_method(cPolygon, "create_curve", RUBY_METHOD_FUNC(create_curve), 2);
258
- rb_define_singleton_method(cPolygon, "create_bezier", RUBY_METHOD_FUNC(create_bezier), 2);
357
+ cPolygon.define_singleton_method("points!", create_points);
358
+ cPolygon.define_singleton_method("line!", create_line);
359
+ cPolygon.define_singleton_method("lines!", create_lines);
360
+ cPolygon.define_singleton_method("triangles!", create_triangles);
361
+ cPolygon.define_singleton_method("triangle_strip!", create_triangle_strip);
362
+ cPolygon.define_singleton_method("triangle_fan!", create_triangle_fan);
363
+ cPolygon.define_singleton_method("rect!", create_rect);
364
+ cPolygon.define_singleton_method("quads!", create_quads);
365
+ cPolygon.define_singleton_method("quad_strip!", create_quad_strip);
366
+ cPolygon.define_singleton_method("ellipse!", create_ellipse);
367
+ cPolygon.define_singleton_method("curve!", create_curve);
368
+ cPolygon.define_singleton_method("bezier!", create_bezier);
259
369
  }
260
370
 
261
371
 
@@ -266,26 +376,27 @@ namespace Rucy
266
376
  template <> Rays::Polygon
267
377
  value_to<Rays::Polygon> (int argc, const Value* argv, bool convert)
268
378
  {
269
- assert(argc == 0 || (argc > 0 && argv));
270
-
271
379
  if (convert)
272
380
  {
273
381
  if (argc <= 0)
274
382
  return Rays::Polygon();
275
- else if (argv->is_kind_of(Rays::polygon_line_class()))
383
+ else if (argv->is_kind_of(Rays::polyline_class()))
276
384
  {
277
- std::vector<Rays::Polygon::Line> lines;
278
- lines.reserve(argc);
279
- for (int i = 0; i < argc; ++i)
280
- lines.emplace_back(to<Rays::Polygon::Line&>(argv[i]));
281
- 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
+ }
282
395
  }
283
- else if (argv->is_kind_of(Rays::polyline_class()))
284
- return Rays::Polygon(to<Rays::Polyline&>(*argv));
285
396
  else if (argv->is_num() || argv->is_array())
286
397
  {
287
398
  std::vector<Rays::Point> points;
288
- get_line_args(&points, argc, argv);
399
+ get_points(&points, argc, argv);
289
400
  return Rays::Polygon(&points[0], points.size());
290
401
  }
291
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
  }