rays 0.1.13 → 0.1.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/rays/camera.cpp +171 -0
  3. data/.doc/ext/rays/color.cpp +2 -3
  4. data/.doc/ext/rays/color_space.cpp +22 -14
  5. data/.doc/ext/rays/font.cpp +30 -0
  6. data/.doc/ext/rays/image.cpp +1 -1
  7. data/.doc/ext/rays/native.cpp +4 -4
  8. data/.doc/ext/rays/painter.cpp +83 -0
  9. data/.doc/ext/rays/point.cpp +14 -0
  10. data/.doc/ext/rays/polygon.cpp +33 -7
  11. data/.doc/ext/rays/polyline.cpp +12 -6
  12. data/.doc/ext/rays/rays.cpp +105 -1
  13. data/LICENSE +21 -0
  14. data/Rakefile +3 -0
  15. data/VERSION +1 -1
  16. data/ext/rays/bitmap.cpp +1 -1
  17. data/ext/rays/camera.cpp +186 -0
  18. data/ext/rays/color.cpp +2 -3
  19. data/ext/rays/color_space.cpp +22 -14
  20. data/ext/rays/extconf.rb +1 -1
  21. data/ext/rays/font.cpp +35 -2
  22. data/ext/rays/image.cpp +2 -2
  23. data/ext/rays/native.cpp +4 -4
  24. data/ext/rays/painter.cpp +94 -3
  25. data/ext/rays/point.cpp +16 -0
  26. data/ext/rays/polygon.cpp +34 -6
  27. data/ext/rays/polyline.cpp +11 -5
  28. data/ext/rays/rays.cpp +105 -1
  29. data/include/rays/camera.h +74 -0
  30. data/include/rays/color_space.h +4 -2
  31. data/include/rays/defs.h +33 -0
  32. data/include/rays/exception.h +6 -2
  33. data/include/rays/image.h +1 -1
  34. data/include/rays/painter.h +38 -0
  35. data/include/rays/polygon.h +35 -1
  36. data/include/rays/polyline.h +7 -1
  37. data/include/rays/ruby/camera.h +41 -0
  38. data/include/rays/ruby/rays.h +8 -0
  39. data/lib/rays.rb +2 -2
  40. data/lib/rays/camera.rb +24 -0
  41. data/lib/rays/image.rb +1 -1
  42. data/lib/rays/painter.rb +23 -1
  43. data/lib/rays/polygon.rb +8 -0
  44. data/rays.gemspec +2 -2
  45. data/src/color_space.cpp +2 -2
  46. data/src/image.cpp +1 -1
  47. data/src/ios/bitmap.h +23 -0
  48. data/src/ios/bitmap.mm +32 -11
  49. data/src/ios/camera.mm +517 -0
  50. data/src/ios/font.mm +2 -2
  51. data/src/ios/helper.h +2 -2
  52. data/src/osx/bitmap.h +23 -0
  53. data/src/osx/bitmap.mm +28 -10
  54. data/src/osx/camera.mm +452 -0
  55. data/src/osx/font.mm +2 -2
  56. data/src/painter.cpp +100 -10
  57. data/src/polygon.cpp +203 -37
  58. data/src/polyline.cpp +4 -2
  59. data/src/polyline.h +3 -1
  60. data/test/test_font.rb +5 -0
  61. data/test/test_painter.rb +65 -5
  62. data/test/test_painter_shape.rb +48 -3
  63. data/test/test_point.rb +8 -0
  64. data/test/test_polyline.rb +26 -0
  65. metadata +20 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b7f128dcb83acfc5ac2d4bbb0b08bab93cbfbc342be7671acfe546cb8c76e27
4
- data.tar.gz: 683ab9ce64d7fa95d2f769cddb4e5aca34538bf62aa6afb7ddca30a8e198ee73
3
+ metadata.gz: 8efafd5f580c6cc07ff8055d96a71d5b4ab7d65146e5d43872f04860b2bf9b7f
4
+ data.tar.gz: 0f3332f88fd3e413374b65ef70d72a210fbad4faa234a92ebe43ff465d97e99f
5
5
  SHA512:
6
- metadata.gz: 7c88220a1c00951796d6a20862986ccd507664178fd97b9a7af0632305682d7e4d4a632585633292840ba59c13eff3c9c1a6e4f7b4e9f74ca48d8ccd5af980ab
7
- data.tar.gz: fd4fabb2ce0d6c094dade7736892a2eabde0650744eb627f5102515583083580b80097ce3ad4bcf3d14962e6fa403f338aa7115b1c7283f11fed2e6cc1635e56
6
+ metadata.gz: 04b7cc4a91bf19910f0b846f761d0996d7c06a678a2297c2ac2768233fe56d193464f960300934d0d42496aa4882c67f5c6807285443ddad13a68d311ced3e4d
7
+ data.tar.gz: a02ba9f0b544539cbd8f826ef858a17704d1a07f8f4268e28aa4b2c95d1aa29ea17c2fa87d0a73241f8ccbe1cfdee6bee3887a974dd8c74375e4159f0b89a9e6
@@ -0,0 +1,171 @@
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
+ VALUE alloc(VALUE klass)
17
+ {
18
+ return new_type<Rays::Camera>(klass);
19
+ }
20
+
21
+ static
22
+ VALUE setup(VALUE self, VALUE device_name, VALUE min_width, VALUE min_height, VALUE resize, VALUE crop)
23
+ {
24
+ RUCY_CHECK_OBJ(Rays::Camera, self);
25
+
26
+ *THIS = Rays::Camera(
27
+ device_name ? to<const char*>(device_name) : NULL,
28
+ to<int>(min_width), to<int>(min_height),
29
+ to<bool>(resize), to<bool>(crop));
30
+ return self;
31
+ }
32
+
33
+ static
34
+ VALUE start(VALUE self)
35
+ {
36
+ CHECK;
37
+ return value(THIS->start());
38
+ }
39
+
40
+ static
41
+ VALUE stop(VALUE self)
42
+ {
43
+ CHECK;
44
+ THIS->stop();
45
+ }
46
+
47
+ static
48
+ VALUE is_active(VALUE self)
49
+ {
50
+ CHECK;
51
+ return value(THIS->is_active());
52
+ }
53
+
54
+ static
55
+ VALUE set_min_width(VALUE self, VALUE width)
56
+ {
57
+ CHECK;
58
+ THIS->set_min_width(to<int>(width));
59
+ return value(THIS->min_width());
60
+ }
61
+
62
+ static
63
+ VALUE min_width(VALUE self)
64
+ {
65
+ CHECK;
66
+ return value(THIS->min_width());
67
+ }
68
+
69
+ static
70
+ VALUE set_min_height(VALUE self, VALUE height)
71
+ {
72
+ CHECK;
73
+ THIS->set_min_height(to<int>(height));
74
+ return value(THIS->min_height());
75
+ }
76
+
77
+ static
78
+ VALUE min_height(VALUE self)
79
+ {
80
+ CHECK;
81
+ return value(THIS->min_height());
82
+ }
83
+
84
+ static
85
+ VALUE set_resize(VALUE self, VALUE resize)
86
+ {
87
+ CHECK;
88
+ THIS->set_resize(to<bool>(resize));
89
+ return value(THIS->is_resize());
90
+ }
91
+
92
+ static
93
+ VALUE is_resize(VALUE self)
94
+ {
95
+ CHECK;
96
+ return value(THIS->is_resize());
97
+ }
98
+
99
+ static
100
+ VALUE set_crop(VALUE self, VALUE crop)
101
+ {
102
+ CHECK;
103
+ THIS->set_crop(to<bool>(crop));
104
+ return value(THIS->is_crop());
105
+ }
106
+
107
+ static
108
+ VALUE is_crop(VALUE self)
109
+ {
110
+ CHECK;
111
+ return value(THIS->is_crop());
112
+ }
113
+
114
+ static
115
+ VALUE image(VALUE self)
116
+ {
117
+ CHECK;
118
+ const Rays::Image* img = THIS->image();
119
+ return img ? value(*img) : nil();
120
+ }
121
+
122
+ static
123
+ VALUE device_names(VALUE self)
124
+ {
125
+ auto names = Rays::get_camera_device_names();
126
+
127
+ std::vector<Value> v;
128
+ for (auto it = names.begin(), end = names.end(); it != end; ++it)
129
+ v.emplace_back(value(it->c_str()));
130
+ return value(v.size(), &v[0]);
131
+ }
132
+
133
+
134
+ static Class cCamera;
135
+
136
+ void
137
+ Init_camera ()
138
+ {
139
+ Module mRays = rb_define_module("Rays");
140
+
141
+ cCamera = rb_define_class_under(mRays, "Camera", rb_cObject);
142
+ rb_define_alloc_func(cCamera, alloc);
143
+ rb_define_private_method(cCamera, "setup", RUBY_METHOD_FUNC(setup), 5);
144
+ rb_define_method(cCamera, "start", RUBY_METHOD_FUNC(start), 0);
145
+ rb_define_method(cCamera, "stop", RUBY_METHOD_FUNC(stop), 0);
146
+ cCamera.define_method("active?", is_active);
147
+ rb_define_method(cCamera, "min_width=", RUBY_METHOD_FUNC(set_min_width), 1);
148
+ rb_define_method(cCamera, "min_width", RUBY_METHOD_FUNC(min_width), 0);
149
+ rb_define_method(cCamera, "min_height=", RUBY_METHOD_FUNC(set_min_height), 1);
150
+ rb_define_method(cCamera, "min_height", RUBY_METHOD_FUNC(min_height), 0);
151
+ rb_define_method(cCamera, "resize=", RUBY_METHOD_FUNC(set_resize), 1);
152
+ cCamera.define_method("resize?", is_resize);
153
+ rb_define_method(cCamera, "crop=", RUBY_METHOD_FUNC(set_crop), 1);
154
+ cCamera.define_method("crop?", is_crop);
155
+ rb_define_method(cCamera, "image", RUBY_METHOD_FUNC(image), 0);
156
+ rb_define_module_function(cCamera, "device_names", RUBY_METHOD_FUNC(device_names), 0);
157
+ }
158
+
159
+
160
+ namespace Rays
161
+ {
162
+
163
+
164
+ Class
165
+ camera_class ()
166
+ {
167
+ return cCamera;
168
+ }
169
+
170
+
171
+ }// Rays
@@ -198,9 +198,8 @@ Init_color ()
198
198
  rb_define_method(cColor, "blue", RUBY_METHOD_FUNC(get_blue), 0);
199
199
  rb_define_method(cColor, "alpha=", RUBY_METHOD_FUNC(set_alpha), 1);
200
200
  rb_define_method(cColor, "alpha", RUBY_METHOD_FUNC(get_alpha), 0);
201
-
202
- rb_define_function(cColor, "hsv", RUBY_METHOD_FUNC(hsv), -1);
203
- rb_define_function(cColor, "set_palette_color", RUBY_METHOD_FUNC(set_palette_color), -1);
201
+ rb_define_module_function(cColor, "hsv", RUBY_METHOD_FUNC(hsv), -1);
202
+ rb_define_module_function(cColor, "set_palette_color", RUBY_METHOD_FUNC(set_palette_color), -1);
204
203
  }
205
204
 
206
205
 
@@ -181,6 +181,9 @@ Init_color_space ()
181
181
  {
182
182
  Module mRays = rb_define_module("Rays");
183
183
 
184
+ for (size_t i = 0; i < COLOR_SPACES_SIZE; ++i)
185
+ mRays.define_const(COLOR_SPACES[i].name, COLOR_SPACES[i].type);
186
+
184
187
  cColorSpace = rb_define_class_under(mRays, "ColorSpace", rb_cObject);
185
188
  rb_define_alloc_func(cColorSpace, alloc);
186
189
  rb_define_private_method(cColorSpace, "initialize", RUBY_METHOD_FUNC(initialize), -1);
@@ -195,9 +198,6 @@ Init_color_space ()
195
198
  cColorSpace.define_method("has_skip?", has_skip);
196
199
  cColorSpace.define_method("premult?", is_premult);
197
200
  rb_define_method(cColorSpace, "to_s", RUBY_METHOD_FUNC(to_s), 0);
198
-
199
- for (size_t i = 0; i < COLOR_SPACES_SIZE; ++i)
200
- cColorSpace.define_const(COLOR_SPACES[i].name, COLOR_SPACES[i].type);
201
201
  }
202
202
 
203
203
 
@@ -218,16 +218,7 @@ namespace Rucy
218
218
 
219
219
  if (convert)
220
220
  {
221
- if (argv->is_s() || argv->is_sym())
222
- {
223
- const char* str = argv[0].c_str();
224
- for (size_t i = 0; i < COLOR_SPACES_SIZE; ++i)
225
- {
226
- if (strcasecmp(str, COLOR_SPACES[i].name) == 0)
227
- return Rays::ColorSpace(COLOR_SPACES[i].type);
228
- }
229
- }
230
- else if (argv->is_i())
221
+ if (argv->is_i() || argv->is_s() || argv->is_sym())
231
222
  {
232
223
  return Rays::ColorSpace(
233
224
  to<Rays::ColorSpaceType>(argv[0]),
@@ -245,7 +236,24 @@ namespace Rucy
245
236
  template <> Rays::ColorSpaceType
246
237
  value_to<Rays::ColorSpaceType> (Value value, bool convert)
247
238
  {
248
- return (Rays::ColorSpaceType) value_to<uint>(value, convert);
239
+ if (convert)
240
+ {
241
+ if (value.is_s() || value.is_sym())
242
+ {
243
+ const char* str = value.c_str();
244
+ for (size_t i = 0; i < COLOR_SPACES_SIZE; ++i)
245
+ {
246
+ if (strcasecmp(str, COLOR_SPACES[i].name) == 0)
247
+ return COLOR_SPACES[i].type;
248
+ }
249
+ }
250
+ }
251
+
252
+ uint type = value_to<uint>(value, convert);
253
+ if (type >= Rays::COLORSPACE_MAX)
254
+ argument_error(__FILE__, __LINE__, "invalid color space type -- %d", type);
255
+
256
+ return (Rays::ColorSpaceType) type;
249
257
  }
250
258
 
251
259
 
@@ -55,6 +55,33 @@ VALUE height(VALUE self)
55
55
  return value(THIS->get_height());
56
56
  }
57
57
 
58
+ static
59
+ VALUE ascent(VALUE self)
60
+ {
61
+ CHECK;
62
+ coord ascent = 0;
63
+ THIS->get_height(&ascent);
64
+ return value(ascent);
65
+ }
66
+
67
+ static
68
+ VALUE descent(VALUE self)
69
+ {
70
+ CHECK;
71
+ coord descent = 0;
72
+ THIS->get_height(NULL, &descent);
73
+ return value(descent);
74
+ }
75
+
76
+ static
77
+ VALUE leading(VALUE self)
78
+ {
79
+ CHECK;
80
+ coord leading = 0;
81
+ THIS->get_height(NULL, NULL, &leading);
82
+ return value(leading);
83
+ }
84
+
58
85
 
59
86
  static Class cFont;
60
87
 
@@ -70,6 +97,9 @@ Init_font ()
70
97
  rb_define_method(cFont, "size", RUBY_METHOD_FUNC(size), 0);
71
98
  rb_define_method(cFont, "width", RUBY_METHOD_FUNC(width), 1);
72
99
  rb_define_method(cFont, "height", RUBY_METHOD_FUNC(height), 0);
100
+ rb_define_method(cFont, "ascent", RUBY_METHOD_FUNC(ascent), 0);
101
+ rb_define_method(cFont, "descent", RUBY_METHOD_FUNC(descent), 0);
102
+ rb_define_method(cFont, "leading", RUBY_METHOD_FUNC(leading), 0);
73
103
  }
74
104
 
75
105
 
@@ -138,7 +138,7 @@ Init_image ()
138
138
  rb_define_method(cImage, "painter", RUBY_METHOD_FUNC(painter), 0);
139
139
  rb_define_method(cImage, "bitmap", RUBY_METHOD_FUNC(bitmap), 0);
140
140
  rb_define_method(cImage, "save", RUBY_METHOD_FUNC(save), 1);
141
- rb_define_function(cImage, "load", RUBY_METHOD_FUNC(load), -1);
141
+ rb_define_module_function(cImage, "load", RUBY_METHOD_FUNC(load), -1);
142
142
  }
143
143
 
144
144
 
@@ -9,6 +9,7 @@ void Init_color ();
9
9
  void Init_color_space ();
10
10
  void Init_matrix ();
11
11
 
12
+ void Init_painter ();
12
13
  void Init_polyline ();
13
14
  void Init_polygon_line ();
14
15
  void Init_polygon ();
@@ -16,8 +17,7 @@ void Init_bitmap ();
16
17
  void Init_image ();
17
18
  void Init_font ();
18
19
  void Init_shader ();
19
-
20
- void Init_painter ();
20
+ void Init_camera ();
21
21
 
22
22
  void Init_noise ();
23
23
 
@@ -41,6 +41,7 @@ extern "C" void
41
41
  Init_color_space();
42
42
  Init_matrix();
43
43
 
44
+ Init_painter();
44
45
  Init_polyline();
45
46
  Init_polygon_line();
46
47
  Init_polygon();
@@ -48,8 +49,7 @@ extern "C" void
48
49
  Init_image();
49
50
  Init_font();
50
51
  Init_shader();
51
-
52
- Init_painter();
52
+ Init_camera();
53
53
 
54
54
  Init_noise();
55
55
 
@@ -141,6 +141,36 @@ VALUE ellipse(VALUE self, VALUE args, VALUE center, VALUE radius, VALUE hole, VA
141
141
  return self;
142
142
  }
143
143
 
144
+ static
145
+ VALUE curve(VALUE self, VALUE args, VALUE loop)
146
+ {
147
+ CHECK;
148
+
149
+ if (args.empty())
150
+ argument_error(__FILE__, __LINE__);
151
+
152
+ std::vector<Rays::Point> points;
153
+ get_line_args(&points, args.size(), args.as_array());
154
+
155
+ THIS->curve(&points[0], points.size(), loop);
156
+ return self;
157
+ }
158
+
159
+ static
160
+ VALUE bezier(VALUE self, VALUE args, VALUE loop)
161
+ {
162
+ CHECK;
163
+
164
+ if (args.empty())
165
+ argument_error(__FILE__, __LINE__);
166
+
167
+ std::vector<Rays::Point> points;
168
+ get_line_args(&points, args.size(), args.as_array());
169
+
170
+ THIS->bezier(&points[0], points.size(), loop);
171
+ return self;
172
+ }
173
+
144
174
  static
145
175
  VALUE image(VALUE self)
146
176
  {
@@ -292,6 +322,51 @@ VALUE get_stroke_width(VALUE self)
292
322
  return value(THIS->stroke_width());
293
323
  }
294
324
 
325
+ static
326
+ VALUE set_stroke_cap(VALUE self, VALUE cap)
327
+ {
328
+ CHECK;
329
+ THIS->set_stroke_cap(to<Rays::CapType>(cap));
330
+ return self;
331
+ }
332
+
333
+ static
334
+ VALUE get_stroke_cap(VALUE self)
335
+ {
336
+ CHECK;
337
+ return value(THIS->stroke_cap());
338
+ }
339
+
340
+ static
341
+ VALUE set_stroke_join(VALUE self, VALUE join)
342
+ {
343
+ CHECK;
344
+ THIS->set_stroke_join(to<Rays::JoinType>(join));
345
+ return self;
346
+ }
347
+
348
+ static
349
+ VALUE get_stroke_join(VALUE self)
350
+ {
351
+ CHECK;
352
+ return value(THIS->stroke_join());
353
+ }
354
+
355
+ static
356
+ VALUE set_miter_limit(VALUE self, VALUE limit)
357
+ {
358
+ CHECK;
359
+ THIS->set_miter_limit(to<coord>(limit));
360
+ return self;
361
+ }
362
+
363
+ static
364
+ VALUE get_miter_limit(VALUE self)
365
+ {
366
+ CHECK;
367
+ return value(THIS->miter_limit());
368
+ }
369
+
295
370
  static
296
371
  VALUE set_nsegment(VALUE self, VALUE nsegment)
297
372
  {
@@ -490,6 +565,8 @@ Init_painter ()
490
565
  rb_define_private_method(cPainter, "draw_polyline", RUBY_METHOD_FUNC(polyline), 1);
491
566
  rb_define_private_method(cPainter, "draw_rect", RUBY_METHOD_FUNC(rect), 6);
492
567
  rb_define_private_method(cPainter, "draw_ellipse", RUBY_METHOD_FUNC(ellipse), 6);
568
+ rb_define_private_method(cPainter, "draw_curve", RUBY_METHOD_FUNC(curve), 2);
569
+ rb_define_private_method(cPainter, "draw_bezier", RUBY_METHOD_FUNC(bezier), 2);
493
570
  rb_define_method(cPainter, "image", RUBY_METHOD_FUNC(image), -1);
494
571
  rb_define_method(cPainter, "text", RUBY_METHOD_FUNC(text), -1);
495
572
 
@@ -504,6 +581,12 @@ Init_painter ()
504
581
  rb_define_method(cPainter, "no_stroke", RUBY_METHOD_FUNC(no_stroke), 0);
505
582
  rb_define_method(cPainter, "stroke_width=", RUBY_METHOD_FUNC(set_stroke_width), 1);
506
583
  rb_define_method(cPainter, "stroke_width", RUBY_METHOD_FUNC(get_stroke_width), 0);
584
+ rb_define_method(cPainter, "stroke_cap=", RUBY_METHOD_FUNC(set_stroke_cap), 1);
585
+ rb_define_method(cPainter, "stroke_cap", RUBY_METHOD_FUNC(get_stroke_cap), 0);
586
+ rb_define_method(cPainter, "stroke_join=", RUBY_METHOD_FUNC(set_stroke_join), 1);
587
+ rb_define_method(cPainter, "stroke_join", RUBY_METHOD_FUNC(get_stroke_join), 0);
588
+ rb_define_method(cPainter, "miter_limit=", RUBY_METHOD_FUNC(set_miter_limit), 1);
589
+ rb_define_method(cPainter, "miter_limit", RUBY_METHOD_FUNC(get_miter_limit), 0);
507
590
  rb_define_method(cPainter, "nsegment=", RUBY_METHOD_FUNC(set_nsegment), 1);
508
591
  rb_define_method(cPainter, "nsegment", RUBY_METHOD_FUNC(get_nsegment), 0);
509
592
  rb_define_method(cPainter, "clip=", RUBY_METHOD_FUNC(set_clip), -1);