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
@@ -211,9 +211,8 @@ Init_color ()
211
211
  cColor.define_method("blue", get_blue);
212
212
  cColor.define_method("alpha=", set_alpha);
213
213
  cColor.define_method("alpha", get_alpha);
214
-
215
- cColor.define_function("hsv", hsv);
216
- cColor.define_function("set_palette_color", set_palette_color);
214
+ cColor.define_module_function("hsv", hsv);
215
+ cColor.define_module_function("set_palette_color", set_palette_color);
217
216
  }
218
217
 
219
218
 
@@ -194,6 +194,9 @@ Init_color_space ()
194
194
  {
195
195
  Module mRays = define_module("Rays");
196
196
 
197
+ for (size_t i = 0; i < COLOR_SPACES_SIZE; ++i)
198
+ mRays.define_const(COLOR_SPACES[i].name, COLOR_SPACES[i].type);
199
+
197
200
  cColorSpace = mRays.define_class("ColorSpace");
198
201
  cColorSpace.define_alloc_func(alloc);
199
202
  cColorSpace.define_private_method("initialize", initialize);
@@ -208,9 +211,6 @@ Init_color_space ()
208
211
  cColorSpace.define_method("has_skip?", has_skip);
209
212
  cColorSpace.define_method("premult?", is_premult);
210
213
  cColorSpace.define_method("to_s", to_s);
211
-
212
- for (size_t i = 0; i < COLOR_SPACES_SIZE; ++i)
213
- cColorSpace.define_const(COLOR_SPACES[i].name, COLOR_SPACES[i].type);
214
214
  }
215
215
 
216
216
 
@@ -231,16 +231,7 @@ namespace Rucy
231
231
 
232
232
  if (convert)
233
233
  {
234
- if (argv->is_s() || argv->is_sym())
235
- {
236
- const char* str = argv[0].c_str();
237
- for (size_t i = 0; i < COLOR_SPACES_SIZE; ++i)
238
- {
239
- if (strcasecmp(str, COLOR_SPACES[i].name) == 0)
240
- return Rays::ColorSpace(COLOR_SPACES[i].type);
241
- }
242
- }
243
- else if (argv->is_i())
234
+ if (argv->is_i() || argv->is_s() || argv->is_sym())
244
235
  {
245
236
  return Rays::ColorSpace(
246
237
  to<Rays::ColorSpaceType>(argv[0]),
@@ -258,7 +249,24 @@ namespace Rucy
258
249
  template <> Rays::ColorSpaceType
259
250
  value_to<Rays::ColorSpaceType> (Value value, bool convert)
260
251
  {
261
- return (Rays::ColorSpaceType) value_to<uint>(value, convert);
252
+ if (convert)
253
+ {
254
+ if (value.is_s() || value.is_sym())
255
+ {
256
+ const char* str = value.c_str();
257
+ for (size_t i = 0; i < COLOR_SPACES_SIZE; ++i)
258
+ {
259
+ if (strcasecmp(str, COLOR_SPACES[i].name) == 0)
260
+ return COLOR_SPACES[i].type;
261
+ }
262
+ }
263
+ }
264
+
265
+ uint type = value_to<uint>(value, convert);
266
+ if (type >= Rays::COLORSPACE_MAX)
267
+ argument_error(__FILE__, __LINE__, "invalid color space type -- %d", type);
268
+
269
+ return (Rays::ColorSpaceType) type;
262
270
  }
263
271
 
264
272
 
@@ -17,7 +17,7 @@ Xot::ExtConf.new Xot, Rucy, Rays do
17
17
  headers << 'ruby.h'
18
18
  local_libs << 'rucy'
19
19
  libs.unshift 'gdi21', 'opengl32' if win32?
20
- frameworks << 'AppKit' << 'OpenGL' if osx?
20
+ frameworks << 'AppKit' << 'OpenGL' << 'AVFoundation' if osx?
21
21
  $LDFLAGS << ' -Wl,--out-implib=native.dll.a' if cygwin?
22
22
  end
23
23
 
@@ -61,6 +61,36 @@ RUCY_DEF0(height)
61
61
  }
62
62
  RUCY_END
63
63
 
64
+ static
65
+ RUCY_DEF0(ascent)
66
+ {
67
+ CHECK;
68
+ coord ascent = 0;
69
+ THIS->get_height(&ascent);
70
+ return value(ascent);
71
+ }
72
+ RUCY_END
73
+
74
+ static
75
+ RUCY_DEF0(descent)
76
+ {
77
+ CHECK;
78
+ coord descent = 0;
79
+ THIS->get_height(NULL, &descent);
80
+ return value(descent);
81
+ }
82
+ RUCY_END
83
+
84
+ static
85
+ RUCY_DEF0(leading)
86
+ {
87
+ CHECK;
88
+ coord leading = 0;
89
+ THIS->get_height(NULL, NULL, &leading);
90
+ return value(leading);
91
+ }
92
+ RUCY_END
93
+
64
94
 
65
95
  static Class cFont;
66
96
 
@@ -74,8 +104,11 @@ Init_font ()
74
104
  cFont.define_private_method("initialize", initialize);
75
105
  cFont.define_method("name", name);
76
106
  cFont.define_method("size", size);
77
- cFont.define_method("width", width);
78
- cFont.define_method("height", height);
107
+ cFont.define_method("width", width);
108
+ cFont.define_method("height", height);
109
+ cFont.define_method("ascent", ascent);
110
+ cFont.define_method("descent", descent);
111
+ cFont.define_method("leading", leading);
79
112
  }
80
113
 
81
114
 
@@ -142,14 +142,14 @@ Init_image ()
142
142
  cImage.define_alloc_func(alloc);
143
143
  cImage.define_private_method("initialize", initialize);
144
144
  cImage.define_private_method("initialize_copy", initialize_copy);
145
- cImage.define_method("width", width);
145
+ cImage.define_method("width", width);
146
146
  cImage.define_method("height", height);
147
147
  cImage.define_method("color_space", color_space);
148
148
  cImage.define_method("pixel_density", pixel_density);
149
149
  cImage.define_method("painter", painter);
150
150
  cImage.define_method("bitmap", bitmap);
151
151
  cImage.define_method("save", save);
152
- cImage.define_function("load", load);
152
+ cImage.define_module_function("load", load);
153
153
  }
154
154
 
155
155
 
@@ -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
 
@@ -153,6 +153,38 @@ RUCY_DEF6(ellipse, args, center, radius, hole, angle_from, angle_to)
153
153
  }
154
154
  RUCY_END
155
155
 
156
+ static
157
+ RUCY_DEF2(curve, args, loop)
158
+ {
159
+ CHECK;
160
+
161
+ if (args.empty())
162
+ argument_error(__FILE__, __LINE__);
163
+
164
+ std::vector<Rays::Point> points;
165
+ get_line_args(&points, args.size(), args.as_array());
166
+
167
+ THIS->curve(&points[0], points.size(), loop);
168
+ return self;
169
+ }
170
+ RUCY_END
171
+
172
+ static
173
+ RUCY_DEF2(bezier, args, loop)
174
+ {
175
+ CHECK;
176
+
177
+ if (args.empty())
178
+ argument_error(__FILE__, __LINE__);
179
+
180
+ std::vector<Rays::Point> points;
181
+ get_line_args(&points, args.size(), args.as_array());
182
+
183
+ THIS->bezier(&points[0], points.size(), loop);
184
+ return self;
185
+ }
186
+ RUCY_END
187
+
156
188
  static
157
189
  RUCY_DEFN(image)
158
190
  {
@@ -317,6 +349,57 @@ RUCY_DEF0(get_stroke_width)
317
349
  }
318
350
  RUCY_END
319
351
 
352
+ static
353
+ RUCY_DEF1(set_stroke_cap, cap)
354
+ {
355
+ CHECK;
356
+ THIS->set_stroke_cap(to<Rays::CapType>(cap));
357
+ return self;
358
+ }
359
+ RUCY_END
360
+
361
+ static
362
+ RUCY_DEF0(get_stroke_cap)
363
+ {
364
+ CHECK;
365
+ return value(THIS->stroke_cap());
366
+ }
367
+ RUCY_END
368
+
369
+ static
370
+ RUCY_DEF1(set_stroke_join, join)
371
+ {
372
+ CHECK;
373
+ THIS->set_stroke_join(to<Rays::JoinType>(join));
374
+ return self;
375
+ }
376
+ RUCY_END
377
+
378
+ static
379
+ RUCY_DEF0(get_stroke_join)
380
+ {
381
+ CHECK;
382
+ return value(THIS->stroke_join());
383
+ }
384
+ RUCY_END
385
+
386
+ static
387
+ RUCY_DEF1(set_miter_limit, limit)
388
+ {
389
+ CHECK;
390
+ THIS->set_miter_limit(to<coord>(limit));
391
+ return self;
392
+ }
393
+ RUCY_END
394
+
395
+ static
396
+ RUCY_DEF0(get_miter_limit)
397
+ {
398
+ CHECK;
399
+ return value(THIS->miter_limit());
400
+ }
401
+ RUCY_END
402
+
320
403
  static
321
404
  RUCY_DEF1(set_nsegment, nsegment)
322
405
  {
@@ -534,6 +617,8 @@ Init_painter ()
534
617
  cPainter.define_private_method("draw_polyline", polyline);
535
618
  cPainter.define_private_method("draw_rect", rect);
536
619
  cPainter.define_private_method("draw_ellipse", ellipse);
620
+ cPainter.define_private_method("draw_curve", curve);
621
+ cPainter.define_private_method("draw_bezier", bezier);
537
622
  cPainter.define_method("image", image);
538
623
  cPainter.define_method("text", text);
539
624
 
@@ -543,11 +628,17 @@ Init_painter ()
543
628
  cPainter.define_method( "fill=", set_fill);
544
629
  cPainter.define_method( "fill", get_fill);
545
630
  cPainter.define_method("no_fill", no_fill);
546
- cPainter.define_method( "stroke=", set_stroke);
547
- cPainter.define_method( "stroke", get_stroke);
548
- cPainter.define_method("no_stroke", no_stroke);
631
+ cPainter.define_method( "stroke=", set_stroke);
632
+ cPainter.define_method( "stroke", get_stroke);
633
+ cPainter.define_method("no_stroke", no_stroke);
549
634
  cPainter.define_method( "stroke_width=", set_stroke_width);
550
635
  cPainter.define_method( "stroke_width", get_stroke_width);
636
+ cPainter.define_method( "stroke_cap=", set_stroke_cap);
637
+ cPainter.define_method( "stroke_cap", get_stroke_cap);
638
+ cPainter.define_method( "stroke_join=", set_stroke_join);
639
+ cPainter.define_method( "stroke_join", get_stroke_join);
640
+ cPainter.define_method("miter_limit=", set_miter_limit);
641
+ cPainter.define_method("miter_limit", get_miter_limit);
551
642
  cPainter.define_method("nsegment=", set_nsegment);
552
643
  cPainter.define_method("nsegment", get_nsegment);
553
644
  cPainter.define_method( "clip=", set_clip);
@@ -262,6 +262,20 @@ RUCY_DEF0(inspect)
262
262
  }
263
263
  RUCY_END
264
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
+
265
279
 
266
280
  static Class cPoint;
267
281
 
@@ -295,6 +309,8 @@ Init_point ()
295
309
  cPoint.define_method("[]=", set_at);
296
310
  cPoint.define_method("[]", get_at);
297
311
  cPoint.define_method("inspect", inspect);
312
+ cPoint.define_module_function("dot", dot);
313
+ cPoint.define_module_function("cross", cross);
298
314
  }
299
315
 
300
316
 
@@ -27,7 +27,7 @@ RUCY_DEF2(setup, args, loop)
27
27
  {
28
28
  CHECK;
29
29
 
30
- if (loop)
30
+ if (args[0].is_kind_of(Rays::polyline_class()))
31
31
  *THIS = to<Rays::Polygon>(args.size(), args.as_array());
32
32
  else
33
33
  {
@@ -39,12 +39,18 @@ RUCY_DEF2(setup, args, loop)
39
39
  RUCY_END
40
40
 
41
41
  static
42
- RUCY_DEF1(expand, width)
42
+ RUCY_DEFN(expand)
43
43
  {
44
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;
45
51
 
46
52
  Rays::Polygon polygon;
47
- THIS->expand(&polygon, to<coord>(width));
53
+ THIS->expand(&polygon, width, cap, join, ml);
48
54
  return value(polygon);
49
55
  }
50
56
  RUCY_END
@@ -74,7 +80,7 @@ RUCY_DEF0(empty)
74
80
  RUCY_END
75
81
 
76
82
  static
77
- RUCY_DEF1(at, index)
83
+ RUCY_DEF1(get_at, index)
78
84
  {
79
85
  CHECK;
80
86
 
@@ -94,7 +100,7 @@ RUCY_DEF0(each)
94
100
  {
95
101
  CHECK;
96
102
 
97
- Value ret;
103
+ Value ret = Qnil;
98
104
  for (const auto& line : *THIS)
99
105
  ret = rb_yield(value(line));
100
106
  return ret;
@@ -219,6 +225,26 @@ RUCY_DEF7(create_ellipse,
219
225
  }
220
226
  RUCY_END
221
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
+
222
248
 
223
249
  static Class cPolygon;
224
250
 
@@ -234,7 +260,7 @@ Init_polygon ()
234
260
  cPolygon.define_method("bounds", bounds);
235
261
  cPolygon.define_method("size", size);
236
262
  cPolygon.define_method("empty?", empty);
237
- cPolygon.define_method("[]", at);
263
+ cPolygon.define_method("[]", get_at);
238
264
  cPolygon.define_method("each", each);
239
265
  cPolygon.define_method("+", op_or);
240
266
  cPolygon.define_method("-", op_sub);
@@ -243,6 +269,8 @@ Init_polygon ()
243
269
  cPolygon.define_method("^", op_xor);
244
270
  cPolygon.define_singleton_method("create_rect", create_rect);
245
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);
246
274
  }
247
275
 
248
276
 
@@ -34,12 +34,18 @@ RUCY_DEF2(setup, points, loop)
34
34
  RUCY_END
35
35
 
36
36
  static
37
- RUCY_DEF1(expand, width)
37
+ RUCY_DEFN(expand)
38
38
  {
39
39
  CHECK;
40
+ check_arg_count(__FILE__, __LINE__, "Polyline#expand", argc, 1, 2, 3, 4);
41
+
42
+ coord width = to<coord> (argv[0]);
43
+ Rays::CapType cap = argc >= 2 ? to<Rays::CapType> (argv[1]) : Rays::CAP_DEFAULT;
44
+ Rays::JoinType join = argc >= 3 ? to<Rays::JoinType>(argv[2]) : Rays::JOIN_DEFAULT;
45
+ coord ml = argc >= 4 ? to<coord> (argv[3]) : Rays::JOIN_DEFAULT_MITER_LIMIT;
40
46
 
41
47
  Rays::Polygon polygon;
42
- THIS->expand(&polygon, to<coord>(width));
48
+ THIS->expand(&polygon, width, cap, join, ml);
43
49
  return value(polygon);
44
50
  }
45
51
  RUCY_END
@@ -77,7 +83,7 @@ RUCY_DEF0(empty)
77
83
  RUCY_END
78
84
 
79
85
  static
80
- RUCY_DEF1(at, index)
86
+ RUCY_DEF1(get_at, index)
81
87
  {
82
88
  CHECK;
83
89
 
@@ -97,7 +103,7 @@ RUCY_DEF0(each)
97
103
  {
98
104
  CHECK;
99
105
 
100
- Value ret;
106
+ Value ret = Qnil;
101
107
  for (const auto& point : *THIS)
102
108
  ret = rb_yield(value(point));
103
109
  return ret;
@@ -120,7 +126,7 @@ Init_polyline ()
120
126
  cPolyline.define_method("loop?", loop);
121
127
  cPolyline.define_method("size", size);
122
128
  cPolyline.define_method("empty?", empty);
123
- cPolyline.define_method("[]", at);
129
+ cPolyline.define_method("[]", get_at);
124
130
  cPolyline.define_method("each", each);
125
131
  }
126
132