rays 0.1.47 → 0.1.49

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) 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/color.cpp +11 -0
  5. data/.doc/ext/rays/defs.cpp +32 -8
  6. data/.doc/ext/rays/font.cpp +50 -2
  7. data/.doc/ext/rays/image.cpp +3 -3
  8. data/.doc/ext/rays/matrix.cpp +65 -7
  9. data/.doc/ext/rays/native.cpp +2 -4
  10. data/.doc/ext/rays/painter.cpp +117 -9
  11. data/.doc/ext/rays/point.cpp +1 -11
  12. data/.doc/ext/rays/polygon.cpp +133 -97
  13. data/.doc/ext/rays/polyline.cpp +89 -10
  14. data/.doc/ext/rays/rays.cpp +80 -0
  15. data/.doc/ext/rays/{noise.cpp → util.cpp} +2 -2
  16. data/ChangeLog.md +46 -0
  17. data/VERSION +1 -1
  18. data/ext/rays/bitmap.cpp +288 -46
  19. data/ext/rays/camera.cpp +2 -2
  20. data/ext/rays/color.cpp +13 -1
  21. data/ext/rays/defs.cpp +32 -8
  22. data/ext/rays/defs.h +56 -3
  23. data/ext/rays/font.cpp +56 -4
  24. data/ext/rays/image.cpp +3 -3
  25. data/ext/rays/matrix.cpp +69 -7
  26. data/ext/rays/native.cpp +2 -4
  27. data/ext/rays/painter.cpp +132 -13
  28. data/ext/rays/point.cpp +1 -12
  29. data/ext/rays/polygon.cpp +136 -99
  30. data/ext/rays/polyline.cpp +95 -9
  31. data/ext/rays/rays.cpp +80 -0
  32. data/ext/rays/{noise.cpp → util.cpp} +2 -2
  33. data/include/rays/color.h +3 -1
  34. data/include/rays/defs.h +24 -26
  35. data/include/rays/font.h +17 -3
  36. data/include/rays/image.h +1 -1
  37. data/include/rays/matrix.h +24 -0
  38. data/include/rays/painter.h +24 -0
  39. data/include/rays/polygon.h +68 -43
  40. data/include/rays/polyline.h +17 -2
  41. data/include/rays/ruby/polygon.h +0 -11
  42. data/include/rays/ruby/rays.h +4 -0
  43. data/include/rays/{noise.h → util.h} +2 -2
  44. data/lib/rays/color.rb +7 -1
  45. data/lib/rays/font.rb +1 -1
  46. data/lib/rays/image.rb +11 -1
  47. data/lib/rays/matrix.rb +16 -0
  48. data/lib/rays/painter.rb +18 -7
  49. data/lib/rays/point.rb +5 -1
  50. data/lib/rays/polygon.rb +44 -35
  51. data/lib/rays/polyline.rb +54 -8
  52. data/lib/rays.rb +0 -1
  53. data/rays.gemspec +2 -2
  54. data/src/color.cpp +11 -2
  55. data/src/font.cpp +37 -18
  56. data/src/font.h +6 -5
  57. data/src/image.cpp +58 -14
  58. data/src/ios/font.mm +89 -32
  59. data/src/ios/helper.h +2 -2
  60. data/src/ios/helper.mm +2 -2
  61. data/src/matrix.cpp +45 -0
  62. data/src/osx/font.mm +93 -33
  63. data/src/osx/helper.h +2 -2
  64. data/src/osx/helper.mm +2 -2
  65. data/src/painter.cpp +246 -114
  66. data/src/painter.h +11 -3
  67. data/src/polygon.cpp +431 -332
  68. data/src/polyline.cpp +138 -27
  69. data/src/polyline.h +3 -5
  70. data/src/shader.cpp +36 -4
  71. data/src/shader.h +1 -1
  72. data/src/texture.cpp +23 -4
  73. data/src/texture.h +2 -0
  74. data/src/{noise.cpp → util.cpp} +1 -1
  75. data/src/win32/font.cpp +1 -1
  76. data/test/test_bitmap.rb +12 -5
  77. data/test/test_color.rb +25 -4
  78. data/test/test_font.rb +23 -2
  79. data/test/test_image.rb +44 -18
  80. data/test/test_matrix.rb +22 -0
  81. data/test/test_painter.rb +27 -0
  82. data/test/test_point.rb +1 -1
  83. data/test/test_polygon.rb +52 -45
  84. data/test/test_polyline.rb +191 -72
  85. metadata +12 -18
  86. data/.doc/ext/rays/polygon_line.cpp +0 -97
  87. data/ext/rays/polygon_line.cpp +0 -100
  88. data/lib/rays/polygon_line.rb +0 -33
  89. data/test/test_polygon_line.rb +0 -164
@@ -67,6 +67,14 @@ VALUE reset(VALUE self)
67
67
  return self;
68
68
  }
69
69
 
70
+ static
71
+ VALUE transpose(VALUE self)
72
+ {
73
+ CHECK;
74
+ THIS->transpose();
75
+ return self;
76
+ }
77
+
70
78
  static
71
79
  VALUE translate(VALUE self)
72
80
  {
@@ -108,10 +116,10 @@ VALUE to_a(VALUE self)
108
116
  {
109
117
  CHECK;
110
118
  return array(
111
- THIS->x0, THIS->y0, THIS->z0, THIS->w0,
112
- THIS->x1, THIS->y1, THIS->z1, THIS->w1,
113
- THIS->x2, THIS->y2, THIS->z2, THIS->w2,
114
- THIS->x3, THIS->y3, THIS->z3, THIS->w3);
119
+ THIS->x0, THIS->x1, THIS->x2, THIS->x3,
120
+ THIS->y0, THIS->y1, THIS->y2, THIS->y3,
121
+ THIS->z0, THIS->z1, THIS->z2, THIS->z3,
122
+ THIS->w0, THIS->w1, THIS->w2, THIS->w3);
115
123
  }
116
124
 
117
125
  static
@@ -190,6 +198,51 @@ VALUE s_rotate(VALUE self)
190
198
  return rotate(argc, argv, value(Rays::Matrix()));
191
199
  }
192
200
 
201
+ static
202
+ VALUE s_ortho(VALUE self)
203
+ {
204
+ check_arg_count(__FILE__, __LINE__, "Matrix#ortho", argc, 4, 6);
205
+
206
+ coord l = to<coord>(argv[0]);
207
+ coord r = to<coord>(argv[1]);
208
+ coord t = to<coord>(argv[2]);
209
+ coord b = to<coord>(argv[3]);
210
+ if (argc == 4)
211
+ return value(Rays::ortho(l, r, t, b));
212
+ else
213
+ return value(Rays::ortho(l, r, t, b, to<coord>(argv[4]), to<coord>(argv[5])));
214
+ }
215
+
216
+ static
217
+ VALUE s_perspective(VALUE self, VALUE fov_y, VALUE aspect_ratio, VALUE near, VALUE far)
218
+ {
219
+ return value(Rays::perspective(
220
+ to<float>(fov_y), to<float>(aspect_ratio), to<coord>(near), to<coord>(far)));
221
+ }
222
+
223
+ static
224
+ VALUE s_look_at(VALUE self)
225
+ {
226
+ check_arg_count(__FILE__, __LINE__, "Matrix#ortho", argc, 3, 6, 9);
227
+
228
+ if (argc == 3)
229
+ {
230
+ return value(Rays::look_at(
231
+ to<Rays::Point&>(argv[0]),
232
+ to<Rays::Point&>(argv[1]),
233
+ to<Rays::Point&>(argv[2])));
234
+ }
235
+ else
236
+ {
237
+ return value(Rays::look_at(
238
+ to<coord>(argv[0]), to<coord>(argv[1]), to<coord>(argv[2]),
239
+ to<coord>(argv[3]), to<coord>(argv[4]), to<coord>(argv[5]),
240
+ argc >= 7 ? to<coord>(argv[6]) : 0,
241
+ argc >= 8 ? to<coord>(argv[7]) : 1,
242
+ argc >= 9 ? to<coord>(argv[8]) : 0));
243
+ }
244
+ }
245
+
193
246
 
194
247
  static Class cMatrix;
195
248
 
@@ -203,9 +256,10 @@ Init_rays_matrix ()
203
256
  rb_define_private_method(cMatrix, "initialize", RUBY_METHOD_FUNC(initialize), -1);
204
257
  rb_define_private_method(cMatrix, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1);
205
258
  rb_define_method(cMatrix, "reset", RUBY_METHOD_FUNC(reset), -1);
206
- rb_define_method(cMatrix, "translate", RUBY_METHOD_FUNC(translate), -1);
207
- rb_define_method(cMatrix, "scale", RUBY_METHOD_FUNC(scale), -1);
208
- rb_define_method(cMatrix, "rotate", RUBY_METHOD_FUNC(rotate), -1);
259
+ cMatrix.define_method("transpose!", transpose);
260
+ cMatrix.define_method("translate!", translate);
261
+ cMatrix.define_method("scale!", scale);
262
+ cMatrix.define_method("rotate!", rotate);
209
263
  rb_define_method(cMatrix, "to_a", RUBY_METHOD_FUNC(to_a), 0);
210
264
  cMatrix.define_method("*", mult);
211
265
  cMatrix.define_method("[]=", set_at);
@@ -216,6 +270,10 @@ Init_rays_matrix ()
216
270
  rb_define_singleton_method(cMatrix, "translate", RUBY_METHOD_FUNC(s_translate), -1);
217
271
  rb_define_singleton_method(cMatrix, "scale", RUBY_METHOD_FUNC(s_scale), -1);
218
272
  rb_define_singleton_method(cMatrix, "rotate", RUBY_METHOD_FUNC(s_rotate), -1);
273
+ rb_define_singleton_method(cMatrix, "ortho", RUBY_METHOD_FUNC(s_ortho), -1);
274
+ rb_define_singleton_method(cMatrix, "perspective", RUBY_METHOD_FUNC(s_perspective), 4);
275
+ rb_define_singleton_method(cMatrix, "look_at", RUBY_METHOD_FUNC(s_look_at), -1);
276
+
219
277
  }
220
278
 
221
279
 
@@ -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
  }
@@ -147,13 +147,25 @@ VALUE polygon(VALUE self)
147
147
  return self;
148
148
  }
149
149
 
150
+ static
151
+ VALUE point(VALUE self)
152
+ {
153
+ CHECK;
154
+
155
+ std::vector<Rays::Point> points;
156
+ get_points(&points, argc, argv);
157
+
158
+ THIS->points(&points[0], points.size());
159
+ return self;
160
+ }
161
+
150
162
  static
151
163
  VALUE line(VALUE self, VALUE args, VALUE loop)
152
164
  {
153
165
  CHECK;
154
166
 
155
167
  std::vector<Rays::Point> points;
156
- get_line_args(&points, args.size(), args.as_array());
168
+ get_points(&points, args.size(), args.as_array());
157
169
 
158
170
  THIS->line(&points[0], points.size(), loop);
159
171
  return self;
@@ -211,7 +223,7 @@ VALUE curve(VALUE self, VALUE args, VALUE loop)
211
223
  argument_error(__FILE__, __LINE__);
212
224
 
213
225
  std::vector<Rays::Point> points;
214
- get_line_args(&points, args.size(), args.as_array());
226
+ get_points(&points, args.size(), args.as_array());
215
227
 
216
228
  THIS->curve(&points[0], points.size(), loop);
217
229
  return self;
@@ -226,7 +238,7 @@ VALUE bezier(VALUE self, VALUE args, VALUE loop)
226
238
  argument_error(__FILE__, __LINE__);
227
239
 
228
240
  std::vector<Rays::Point> points;
229
- get_line_args(&points, args.size(), args.as_array());
241
+ get_points(&points, args.size(), args.as_array());
230
242
 
231
243
  THIS->bezier(&points[0], points.size(), loop);
232
244
  return self;
@@ -458,6 +470,28 @@ VALUE get_nsegment(VALUE self)
458
470
  return value(THIS->nsegment());
459
471
  }
460
472
 
473
+ static
474
+ VALUE set_line_height(VALUE self, VALUE height)
475
+ {
476
+ CHECK;
477
+ THIS->set_line_height(height ? to<coord>(height) : -1);
478
+ return self;
479
+ }
480
+
481
+ static
482
+ VALUE get_line_height(VALUE self)
483
+ {
484
+ CHECK;
485
+ return value(THIS->line_height());
486
+ }
487
+
488
+ static
489
+ VALUE get_line_height_raw(VALUE self)
490
+ {
491
+ CHECK;
492
+ return value(THIS->line_height(true));
493
+ }
494
+
461
495
  static
462
496
  VALUE set_blend_mode(VALUE self, VALUE mode)
463
497
  {
@@ -513,6 +547,69 @@ VALUE get_font(VALUE self)
513
547
  return value(THIS->font());
514
548
  }
515
549
 
550
+ static
551
+ VALUE set_texture(VALUE self, VALUE image)
552
+ {
553
+ CHECK;
554
+
555
+ if (!image)
556
+ THIS->no_texture();
557
+ else
558
+ THIS->set_texture(to<Rays::Image&>(image));
559
+ return self;
560
+ }
561
+
562
+ static
563
+ VALUE get_texture(VALUE self)
564
+ {
565
+ CHECK;
566
+
567
+ const Rays::Image& image = THIS->texture();
568
+ return image ? value(image) : nil();
569
+ }
570
+
571
+ static
572
+ VALUE no_texture(VALUE self)
573
+ {
574
+ CHECK;
575
+ THIS->no_texture();
576
+ return self;
577
+ }
578
+
579
+ static
580
+ VALUE set_texcoord_mode(VALUE self, VALUE mode)
581
+ {
582
+ CHECK;
583
+
584
+ THIS->set_texcoord_mode(to<Rays::TexCoordMode>(mode));
585
+ return self;
586
+ }
587
+
588
+ static
589
+ VALUE get_texcoord_mode(VALUE self)
590
+ {
591
+ CHECK;
592
+
593
+ return value(THIS->texcoord_mode());
594
+ }
595
+
596
+ static
597
+ VALUE set_texcoord_wrap(VALUE self, VALUE wrap)
598
+ {
599
+ CHECK;
600
+
601
+ THIS->set_texcoord_wrap(to<Rays::TexCoordWrap>(wrap));
602
+ return self;
603
+ }
604
+
605
+ static
606
+ VALUE get_texcoord_wrap(VALUE self)
607
+ {
608
+ CHECK;
609
+
610
+ return value(THIS->texcoord_wrap());
611
+ }
612
+
516
613
  static
517
614
  VALUE set_shader(VALUE self)
518
615
  {
@@ -658,12 +755,13 @@ Init_rays_painter ()
658
755
  cPainter.define_method( "painting?", is_painting);
659
756
  rb_define_method(cPainter, "clear", RUBY_METHOD_FUNC(clear), 0);
660
757
  rb_define_method(cPainter, "polygon", RUBY_METHOD_FUNC(polygon), -1);
661
- rb_define_private_method(cPainter, "draw_line", RUBY_METHOD_FUNC(line), 2);
662
- rb_define_private_method(cPainter, "draw_polyline", RUBY_METHOD_FUNC(polyline), 1);
663
- rb_define_private_method(cPainter, "draw_rect", RUBY_METHOD_FUNC(rect), 6);
664
- rb_define_private_method(cPainter, "draw_ellipse", RUBY_METHOD_FUNC(ellipse), 6);
665
- rb_define_private_method(cPainter, "draw_curve", RUBY_METHOD_FUNC(curve), 2);
666
- rb_define_private_method(cPainter, "draw_bezier", RUBY_METHOD_FUNC(bezier), 2);
758
+ rb_define_method(cPainter, "point", RUBY_METHOD_FUNC(point), -1);
759
+ cPainter.define_private_method("line!", line);
760
+ cPainter.define_private_method("polyline!", polyline);
761
+ cPainter.define_private_method("rect!", rect);
762
+ cPainter.define_private_method("ellipse!", ellipse);
763
+ cPainter.define_private_method("curve!", curve);
764
+ cPainter.define_private_method("bezier!", bezier);
667
765
  rb_define_method(cPainter, "image", RUBY_METHOD_FUNC(image), -1);
668
766
  rb_define_method(cPainter, "text", RUBY_METHOD_FUNC(text), -1);
669
767
 
@@ -688,6 +786,9 @@ Init_rays_painter ()
688
786
  rb_define_method(cPainter, "miter_limit", RUBY_METHOD_FUNC(get_miter_limit), 0);
689
787
  rb_define_method(cPainter, "nsegment=", RUBY_METHOD_FUNC(set_nsegment), 1);
690
788
  rb_define_method(cPainter, "nsegment", RUBY_METHOD_FUNC(get_nsegment), 0);
789
+ rb_define_method(cPainter, "line_height=", RUBY_METHOD_FUNC(set_line_height), 1);
790
+ rb_define_method(cPainter, "line_height", RUBY_METHOD_FUNC(get_line_height), 0);
791
+ cPainter.define_method("line_height!", get_line_height_raw);
691
792
  rb_define_method(cPainter, "blend_mode=", RUBY_METHOD_FUNC(set_blend_mode), 1);
692
793
  rb_define_method(cPainter, "blend_mode", RUBY_METHOD_FUNC(get_blend_mode), 0);
693
794
  rb_define_method(cPainter, "clip=", RUBY_METHOD_FUNC(set_clip), -1);
@@ -695,6 +796,13 @@ Init_rays_painter ()
695
796
  rb_define_method(cPainter, "no_clip", RUBY_METHOD_FUNC(no_clip), 0);
696
797
  rb_define_method(cPainter, "font=", RUBY_METHOD_FUNC(set_font), -1);
697
798
  rb_define_method(cPainter, "font", RUBY_METHOD_FUNC(get_font), 0);
799
+ rb_define_method(cPainter, "texture=", RUBY_METHOD_FUNC(set_texture), 1);
800
+ rb_define_method(cPainter, "texture", RUBY_METHOD_FUNC(get_texture), 0);
801
+ rb_define_method(cPainter, "no_texture", RUBY_METHOD_FUNC(no_texture), 0);
802
+ rb_define_method(cPainter, "texcoord_mode=", RUBY_METHOD_FUNC(set_texcoord_mode), 1);
803
+ rb_define_method(cPainter, "texcoord_mode", RUBY_METHOD_FUNC(get_texcoord_mode), 0);
804
+ rb_define_method(cPainter, "texcoord_wrap=", RUBY_METHOD_FUNC(set_texcoord_wrap), 1);
805
+ rb_define_method(cPainter, "texcoord_wrap", RUBY_METHOD_FUNC(get_texcoord_wrap), 0);
698
806
  rb_define_private_method(cPainter, "set_shader", RUBY_METHOD_FUNC(set_shader), -1);
699
807
  rb_define_method(cPainter, "shader", RUBY_METHOD_FUNC(get_shader), 0);
700
808
  rb_define_method(cPainter, "no_shader", RUBY_METHOD_FUNC(no_shader), 0);
@@ -79,15 +79,6 @@ VALUE move_by(VALUE self)
79
79
 
80
80
  static
81
81
  VALUE rotate(VALUE self, VALUE degree)
82
- {
83
- CHECK;
84
- Rays::Point p = *THIS;
85
- p.rotate(to<float>(degree));
86
- return value(p);
87
- }
88
-
89
- static
90
- VALUE rotate_self(VALUE self, VALUE degree)
91
82
  {
92
83
  CHECK;
93
84
  THIS->rotate(to<float>(degree));
@@ -258,8 +249,7 @@ Init_rays_point ()
258
249
  rb_define_private_method(cPoint, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1);
259
250
  cPoint.define_method("move_to!", move_to);
260
251
  cPoint.define_method("move_by!", move_by);
261
- rb_define_method(cPoint, "rotate", RUBY_METHOD_FUNC(rotate), 1);
262
- cPoint.define_method("rotate!", rotate_self);
252
+ cPoint.define_method("rotate!", rotate);
263
253
  rb_define_method(cPoint, "length", RUBY_METHOD_FUNC(length), 0);
264
254
  rb_define_method(cPoint, "normalize", RUBY_METHOD_FUNC(normalize), 0);
265
255
  rb_define_method(cPoint, "normal", RUBY_METHOD_FUNC(normal), 0);