rays 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b638147e270acdfa9515fa0f8d8407a8f2026aeaa16e2ff724bee70949949732
4
- data.tar.gz: bcf27b5481561456ee6bf5519cfa8bdb74618a076b355a8c8a577e6fc7c0d494
3
+ metadata.gz: c784fe46265f04062957d138081db6de0d9e257600be215741d120563534420c
4
+ data.tar.gz: d58b4c10a2e9f0591a6465aea2b36f01de4f0720187acd2fbf98608162bb77d0
5
5
  SHA512:
6
- metadata.gz: ff95edf30be8dcfdf0f03e784ba1d74131635b1619265fd6b5ef3c7ea63e58eeeebf0e0448ef8c0d138999ef87378bd3cd666e266d0db0cf1707fc07c26b5cc7
7
- data.tar.gz: cb2088c67197218c3ada99d85c8d98b3ccb0b1ca73aed1944d43c5c4fc002ec158d2200eea1f21dd25b4867c554e13a3d16c20de2f63f28f12d29f5dea326efe
6
+ metadata.gz: 2a4771e03c225cd3f84c0d723ee3072d3a1403eec5028e38c1cc00ddda5e27dbd6ed4db14bee3fa9c8f412e49928cf4b9fd13f5cc5ae79b80149438dd3f9c96c
7
+ data.tar.gz: 17567e4b335014d772f80f35c1a44859893605c65912469f00aac2ecc6f6a9a1c024d1303b42a24e78dd59b8797cc41f2af1b47627755250e74f5eac12dbc031
@@ -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
 
@@ -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,61 @@ 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
+
330
+ int type = to<int>(cap);
331
+ if (type < 0 || Rays::CAP_MAX <= type)
332
+ argument_error(__FILE__, __LINE__, "invalid stroke cap -- %d", type);
333
+
334
+ THIS->set_stroke_cap((Rays::CapType) type);
335
+ return self;
336
+ }
337
+
338
+ static
339
+ VALUE get_stroke_cap(VALUE self)
340
+ {
341
+ CHECK;
342
+ return value(THIS->stroke_cap());
343
+ }
344
+
345
+ static
346
+ VALUE set_stroke_join(VALUE self, VALUE join)
347
+ {
348
+ CHECK;
349
+
350
+ int type = to<int>(join);
351
+ if (type < 0 || Rays::JOIN_MAX <= type)
352
+ argument_error(__FILE__, __LINE__, "invalid stroke join -- %d", type);
353
+
354
+ THIS->set_stroke_join((Rays::JoinType) type);
355
+ return self;
356
+ }
357
+
358
+ static
359
+ VALUE get_stroke_join(VALUE self)
360
+ {
361
+ CHECK;
362
+ return value(THIS->stroke_join());
363
+ }
364
+
365
+ static
366
+ VALUE set_miter_limit(VALUE self, VALUE limit)
367
+ {
368
+ CHECK;
369
+ THIS->set_miter_limit(to<coord>(limit));
370
+ return self;
371
+ }
372
+
373
+ static
374
+ VALUE get_miter_limit(VALUE self)
375
+ {
376
+ CHECK;
377
+ return value(THIS->miter_limit());
378
+ }
379
+
295
380
  static
296
381
  VALUE set_nsegment(VALUE self, VALUE nsegment)
297
382
  {
@@ -490,6 +575,8 @@ Init_painter ()
490
575
  rb_define_private_method(cPainter, "draw_polyline", RUBY_METHOD_FUNC(polyline), 1);
491
576
  rb_define_private_method(cPainter, "draw_rect", RUBY_METHOD_FUNC(rect), 6);
492
577
  rb_define_private_method(cPainter, "draw_ellipse", RUBY_METHOD_FUNC(ellipse), 6);
578
+ rb_define_private_method(cPainter, "draw_curve", RUBY_METHOD_FUNC(curve), 2);
579
+ rb_define_private_method(cPainter, "draw_bezier", RUBY_METHOD_FUNC(bezier), 2);
493
580
  rb_define_method(cPainter, "image", RUBY_METHOD_FUNC(image), -1);
494
581
  rb_define_method(cPainter, "text", RUBY_METHOD_FUNC(text), -1);
495
582
 
@@ -504,6 +591,12 @@ Init_painter ()
504
591
  rb_define_method(cPainter, "no_stroke", RUBY_METHOD_FUNC(no_stroke), 0);
505
592
  rb_define_method(cPainter, "stroke_width=", RUBY_METHOD_FUNC(set_stroke_width), 1);
506
593
  rb_define_method(cPainter, "stroke_width", RUBY_METHOD_FUNC(get_stroke_width), 0);
594
+ rb_define_method(cPainter, "stroke_cap=", RUBY_METHOD_FUNC(set_stroke_cap), 1);
595
+ rb_define_method(cPainter, "stroke_cap", RUBY_METHOD_FUNC(get_stroke_cap), 0);
596
+ rb_define_method(cPainter, "stroke_join=", RUBY_METHOD_FUNC(set_stroke_join), 1);
597
+ rb_define_method(cPainter, "stroke_join", RUBY_METHOD_FUNC(get_stroke_join), 0);
598
+ rb_define_method(cPainter, "miter_limit=", RUBY_METHOD_FUNC(set_miter_limit), 1);
599
+ rb_define_method(cPainter, "miter_limit", RUBY_METHOD_FUNC(get_miter_limit), 0);
507
600
  rb_define_method(cPainter, "nsegment=", RUBY_METHOD_FUNC(set_nsegment), 1);
508
601
  rb_define_method(cPainter, "nsegment", RUBY_METHOD_FUNC(get_nsegment), 0);
509
602
  rb_define_method(cPainter, "clip=", RUBY_METHOD_FUNC(set_clip), -1);
@@ -26,7 +26,7 @@ VALUE setup(VALUE self, VALUE args, VALUE loop)
26
26
  {
27
27
  CHECK;
28
28
 
29
- if (loop)
29
+ if (args[0].is_kind_of(Rays::polyline_class()))
30
30
  *THIS = to<Rays::Polygon>(args.size(), args.as_array());
31
31
  else
32
32
  {
@@ -37,12 +37,18 @@ VALUE setup(VALUE self, VALUE args, VALUE loop)
37
37
  }
38
38
 
39
39
  static
40
- VALUE expand(VALUE self, VALUE width)
40
+ VALUE expand(VALUE self)
41
41
  {
42
42
  CHECK;
43
+ check_arg_count(__FILE__, __LINE__, "Polygon#expand", argc, 1, 2, 3, 4);
44
+
45
+ coord width = to<coord> (argv[0]);
46
+ Rays::CapType cap = argc >= 2 ? to<Rays::CapType> (argv[1]) : Rays::CAP_DEFAULT;
47
+ Rays::JoinType join = argc >= 3 ? to<Rays::JoinType>(argv[2]) : Rays::JOIN_DEFAULT;
48
+ coord ml = argc >= 4 ? to<coord> (argv[3]) : Rays::JOIN_DEFAULT_MITER_LIMIT;
43
49
 
44
50
  Rays::Polygon polygon;
45
- THIS->expand(&polygon, to<coord>(width));
51
+ THIS->expand(&polygon, width, cap, join, ml);
46
52
  return value(polygon);
47
53
  }
48
54
 
@@ -205,6 +211,24 @@ VALUE create_ellipse(VALUE self, VALUE
205
211
  return value(Rays::create_ellipse(x, y, w, h, hole_size, from, to_, nseg));
206
212
  }
207
213
 
214
+ static
215
+ VALUE create_curve(VALUE self, VALUE args, VALUE loop)
216
+ {
217
+ std::vector<Rays::Point> points;
218
+ get_line_args(&points, args.size(), args.as_array());
219
+
220
+ return value(Rays::create_curve(&points[0], points.size(), loop));
221
+ }
222
+
223
+ static
224
+ VALUE create_bezier(VALUE self, VALUE args, VALUE loop)
225
+ {
226
+ std::vector<Rays::Point> points;
227
+ get_line_args(&points, args.size(), args.as_array());
228
+
229
+ return value(Rays::create_bezier(&points[0], points.size(), loop));
230
+ }
231
+
208
232
 
209
233
  static Class cPolygon;
210
234
 
@@ -216,7 +240,7 @@ Init_polygon ()
216
240
  cPolygon = rb_define_class_under(mRays, "Polygon", rb_cObject);
217
241
  rb_define_alloc_func(cPolygon, alloc);
218
242
  rb_define_private_method(cPolygon, "setup", RUBY_METHOD_FUNC(setup), 2);
219
- rb_define_method(cPolygon, "expand", RUBY_METHOD_FUNC(expand), 1);
243
+ rb_define_method(cPolygon, "expand", RUBY_METHOD_FUNC(expand), -1);
220
244
  rb_define_method(cPolygon, "bounds", RUBY_METHOD_FUNC(bounds), 0);
221
245
  rb_define_method(cPolygon, "size", RUBY_METHOD_FUNC(size), 0);
222
246
  cPolygon.define_method("empty?", empty);
@@ -229,6 +253,8 @@ Init_polygon ()
229
253
  cPolygon.define_method("^", op_xor);
230
254
  rb_define_singleton_method(cPolygon, "create_rect", RUBY_METHOD_FUNC(create_rect), 7);
231
255
  rb_define_singleton_method(cPolygon, "create_ellipse", RUBY_METHOD_FUNC(create_ellipse), 7);
256
+ rb_define_singleton_method(cPolygon, "create_curve", RUBY_METHOD_FUNC(create_curve), 2);
257
+ rb_define_singleton_method(cPolygon, "create_bezier", RUBY_METHOD_FUNC(create_bezier), 2);
232
258
  }
233
259
 
234
260
 
@@ -32,12 +32,18 @@ VALUE setup(VALUE self, VALUE points, VALUE loop)
32
32
  }
33
33
 
34
34
  static
35
- VALUE expand(VALUE self, VALUE width)
35
+ VALUE expand(VALUE self)
36
36
  {
37
37
  CHECK;
38
+ check_arg_count(__FILE__, __LINE__, "Polyline#expand", argc, 1, 2, 3, 4);
39
+
40
+ coord width = to<coord> (argv[0]);
41
+ Rays::CapType cap = argc >= 2 ? to<Rays::CapType> (argv[1]) : Rays::CAP_DEFAULT;
42
+ Rays::JoinType join = argc >= 3 ? to<Rays::JoinType>(argv[2]) : Rays::JOIN_DEFAULT;
43
+ coord ml = argc >= 4 ? to<coord> (argv[3]) : Rays::JOIN_DEFAULT_MITER_LIMIT;
38
44
 
39
45
  Rays::Polygon polygon;
40
- THIS->expand(&polygon, to<coord>(width));
46
+ THIS->expand(&polygon, width, cap, join, ml);
41
47
  return value(polygon);
42
48
  }
43
49
 
@@ -106,7 +112,7 @@ Init_polyline ()
106
112
  cPolyline = rb_define_class_under(mRays, "Polyline", rb_cObject);
107
113
  rb_define_alloc_func(cPolyline, alloc);
108
114
  rb_define_private_method(cPolyline, "setup", RUBY_METHOD_FUNC(setup), 2);
109
- rb_define_method(cPolyline, "expand", RUBY_METHOD_FUNC(expand), 1);
115
+ rb_define_method(cPolyline, "expand", RUBY_METHOD_FUNC(expand), -1);
110
116
  rb_define_method(cPolyline, "bounds", RUBY_METHOD_FUNC(bounds), 0);
111
117
  cPolyline.define_method("loop?", loop);
112
118
  rb_define_method(cPolyline, "size", RUBY_METHOD_FUNC(size), 0);
@@ -1,7 +1,45 @@
1
- #include "rays/rays.h"
1
+ #include "rays/ruby/rays.h"
2
+
3
+
2
4
  #include "defs.h"
3
5
 
4
6
 
7
+ RUCY_DEFINE_VALUE_OR_ARRAY_TO(Rays::CapType)
8
+ RUCY_DEFINE_VALUE_OR_ARRAY_TO(Rays::JoinType)
9
+
10
+
11
+ static struct CapTypeEnum
12
+ {
13
+ const char* name;
14
+ Rays::CapType type;
15
+ }
16
+ CAP_TYPES[] =
17
+ {
18
+ {"CAP_BUTT", Rays::CAP_BUTT},
19
+ {"CAP_ROUND", Rays::CAP_ROUND},
20
+ {"CAP_SQUARE", Rays::CAP_SQUARE},
21
+ };
22
+
23
+ static const size_t CAP_TYPES_SIZE =
24
+ sizeof(CAP_TYPES) / sizeof(CAP_TYPES[0]);
25
+
26
+
27
+ static struct JoinTypeEnum
28
+ {
29
+ const char* name;
30
+ Rays::JoinType type;
31
+ }
32
+ JOIN_TYPES[] =
33
+ {
34
+ {"JOIN_MITER", Rays::JOIN_MITER},
35
+ {"JOIN_ROUND", Rays::JOIN_ROUND},
36
+ {"JOIN_SQUARE", Rays::JOIN_SQUARE},
37
+ };
38
+
39
+ static const size_t JOIN_TYPES_SIZE =
40
+ sizeof(JOIN_TYPES) / sizeof(JOIN_TYPES[0]);
41
+
42
+
5
43
  static
6
44
  VALUE init(VALUE self)
7
45
  {
@@ -23,11 +61,77 @@ void
23
61
  Init_rays ()
24
62
  {
25
63
  mRays = rb_define_module("Rays");
64
+
26
65
  mRays.define_singleton_method("init!", init);
27
66
  mRays.define_singleton_method("fin!", fin);
67
+
68
+ for (size_t i = 0; i < CAP_TYPES_SIZE; ++i)
69
+ mRays.define_const(CAP_TYPES[i].name, CAP_TYPES[i].type);
70
+
71
+ for (size_t i = 0; i < JOIN_TYPES_SIZE; ++i)
72
+ mRays.define_const(JOIN_TYPES[i].name, JOIN_TYPES[i].type);
28
73
  }
29
74
 
30
75
 
76
+ namespace Rucy
77
+ {
78
+
79
+
80
+ template <> Rays::CapType
81
+ value_to<Rays::CapType> (int argc, const Value* argv, bool convert)
82
+ {
83
+ assert(argc > 0 && argv);
84
+
85
+ if (convert)
86
+ {
87
+ if (argv->is_s() || argv->is_sym())
88
+ {
89
+ const char* str = argv->c_str();
90
+ for (size_t i = 0; i < CAP_TYPES_SIZE; ++i)
91
+ {
92
+ if (strcasecmp(str, CAP_TYPES[i].name) == 0)
93
+ return CAP_TYPES[i].type;
94
+ }
95
+ }
96
+ }
97
+
98
+ uint type = value_to<uint>(*argv, convert);
99
+ if (type >= Rays::CAP_MAX)
100
+ argument_error(__FILE__, __LINE__, "invalid cap type -- %d", type);
101
+
102
+ return (Rays::CapType) type;
103
+ }
104
+
105
+
106
+ template <> Rays::JoinType
107
+ value_to<Rays::JoinType> (int argc, const Value* argv, bool convert)
108
+ {
109
+ assert(argc > 0 && argv);
110
+
111
+ if (convert)
112
+ {
113
+ if (argv->is_s() || argv->is_sym())
114
+ {
115
+ const char* str = argv->c_str();
116
+ for (size_t i = 0; i < JOIN_TYPES_SIZE; ++i)
117
+ {
118
+ if (strcasecmp(str, JOIN_TYPES[i].name) == 0)
119
+ return JOIN_TYPES[i].type;
120
+ }
121
+ }
122
+ }
123
+
124
+ uint type = value_to<uint>(*argv, convert);
125
+ if (type >= Rays::JOIN_MAX)
126
+ argument_error(__FILE__, __LINE__, "invalid join type -- %d", type);
127
+
128
+ return (Rays::JoinType) type;
129
+ }
130
+
131
+
132
+ }// Rucy
133
+
134
+
31
135
  namespace Rays
32
136
  {
33
137
 
data/Rakefile CHANGED
@@ -29,6 +29,9 @@ use_external_library 'https://github.com/greenm01/poly2tri',
29
29
  incdir: 'poly2tri',
30
30
  srcdir: 'poly2tri'
31
31
 
32
+ use_external_library 'https://github.com/andrewwillmott/splines-lib.git',
33
+ excludes: 'Test\.cpp'
34
+
32
35
  build_native_library
33
36
  build_ruby_extension
34
37
  test_ruby_extension
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.14
1
+ 0.1.15
@@ -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