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
@@ -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
  });
@@ -183,28 +223,51 @@ VALUE op_xor(VALUE self, VALUE obj)
183
223
  }
184
224
 
185
225
  static
186
- VALUE create_points(VALUE self, VALUE args)
226
+ VALUE create_points(VALUE self, VALUE points)
187
227
  {
188
- std::vector<Rays::Point> points;
189
- get_line_args(&points, args.size(), args.as_array());
190
- return value(Rays::Polygon(Rays::DRAW_POINTS, &points[0], points.size()));
228
+ CreateParams params(points, nil(), nil());
229
+ return value(Rays::create_points(params.ppoints(), params.size()));
191
230
  }
192
231
 
193
232
  static
194
- VALUE create_lines(VALUE self, VALUE args)
233
+ VALUE create_line(VALUE self, VALUE points, VALUE loop)
195
234
  {
196
- std::vector<Rays::Point> points;
197
- get_line_args(&points, args.size(), args.as_array());
198
- return value(Rays::Polygon(Rays::DRAW_LINES, &points[0], points.size()));
235
+ CreateParams params(points, nil(), nil());
236
+ return value(Rays::create_line(params.ppoints(), params.size(), loop));
199
237
  }
200
238
 
201
239
  static
202
- VALUE create_line_strip(VALUE self, VALUE args, VALUE loop)
240
+ VALUE create_lines(VALUE self, VALUE points)
203
241
  {
204
- std::vector<Rays::Point> points;
205
- get_line_args(&points, args.size(), args.as_array());
206
- return value(
207
- Rays::Polygon(Rays::DRAW_LINE_STRIP, &points[0], points.size(), loop));
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()));
208
271
  }
209
272
 
210
273
  static
@@ -221,6 +284,24 @@ VALUE create_rect(VALUE self, VALUE
221
284
  return value(Rays::create_rect(x, y, w, h, lt, rt, lb, rb, nseg));
222
285
  }
223
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
+
224
305
  static
225
306
  VALUE create_ellipse(VALUE self, VALUE
226
307
  args, VALUE center, VALUE radius, VALUE hole, VALUE angle_from, VALUE angle_to, VALUE nsegment)
@@ -238,65 +319,19 @@ VALUE create_ellipse(VALUE self, VALUE
238
319
  }
239
320
 
240
321
  static
241
- VALUE create_triangles(VALUE self, VALUE args, VALUE loop)
242
- {
243
- std::vector<Rays::Point> points;
244
- get_line_args(&points, args.size(), args.as_array());
245
- return value(
246
- Rays::Polygon(Rays::DRAW_TRIANGLES, &points[0], points.size(), loop));
247
- }
248
-
249
- static
250
- VALUE create_triangle_strip(VALUE self, VALUE args)
322
+ VALUE create_curve(VALUE self, VALUE points, VALUE loop, VALUE nsegment)
251
323
  {
252
- std::vector<Rays::Point> points;
253
- get_line_args(&points, args.size(), args.as_array());
254
- return value(
255
- Rays::Polygon(Rays::DRAW_TRIANGLE_STRIP, &points[0], points.size()));
324
+ CreateParams params(points, nil(), nil());
325
+ uint nseg = nsegment ? 0 : to<uint>(nsegment);
326
+ return value(Rays::create_curve(params.ppoints(), params.size(), loop, nseg));
256
327
  }
257
328
 
258
329
  static
259
- VALUE create_triangle_fan(VALUE self, VALUE args)
330
+ VALUE create_bezier(VALUE self, VALUE points, VALUE loop, VALUE nsegment)
260
331
  {
261
- std::vector<Rays::Point> points;
262
- get_line_args(&points, args.size(), args.as_array());
263
- return value(
264
- Rays::Polygon(Rays::DRAW_TRIANGLE_FAN, &points[0], points.size()));
265
- }
266
-
267
- static
268
- VALUE create_quads(VALUE self, VALUE args, VALUE loop)
269
- {
270
- std::vector<Rays::Point> points;
271
- get_line_args(&points, args.size(), args.as_array());
272
- return value(
273
- Rays::Polygon(Rays::DRAW_QUADS, &points[0], points.size(), loop));
274
- }
275
-
276
- static
277
- VALUE create_quad_strip(VALUE self, VALUE args)
278
- {
279
- std::vector<Rays::Point> points;
280
- get_line_args(&points, args.size(), args.as_array());
281
- return value(Rays::Polygon(Rays::DRAW_QUAD_STRIP, &points[0], points.size()));
282
- }
283
-
284
- static
285
- VALUE create_curve(VALUE self, VALUE args, VALUE loop)
286
- {
287
- std::vector<Rays::Point> points;
288
- get_line_args(&points, args.size(), args.as_array());
289
-
290
- return value(Rays::create_curve(&points[0], points.size(), loop));
291
- }
292
-
293
- static
294
- VALUE create_bezier(VALUE self, VALUE args, VALUE loop)
295
- {
296
- std::vector<Rays::Point> points;
297
- get_line_args(&points, args.size(), args.as_array());
298
-
299
- return value(Rays::create_bezier(&points[0], points.size(), loop));
332
+ CreateParams params(points, nil(), nil());
333
+ uint nseg = nsegment ? 0 : to<uint>(nsegment);
334
+ return value(Rays::create_bezier(params.ppoints(), params.size(), loop, nseg));
300
335
  }
301
336
 
302
337
 
@@ -309,28 +344,28 @@ Init_rays_polygon ()
309
344
 
310
345
  cPolygon = rb_define_class_under(mRays, "Polygon", rb_cObject);
311
346
  rb_define_alloc_func(cPolygon, alloc);
312
- rb_define_private_method(cPolygon, "setup", RUBY_METHOD_FUNC(setup), 2);
347
+ rb_define_private_method(cPolygon, "setup", RUBY_METHOD_FUNC(setup), 4);
313
348
  rb_define_method(cPolygon, "expand", RUBY_METHOD_FUNC(expand), -1);
314
349
  rb_define_method(cPolygon, "bounds", RUBY_METHOD_FUNC(bounds), 0);
315
350
  rb_define_method(cPolygon, "size", RUBY_METHOD_FUNC(size), 0);
316
351
  cPolygon.define_method("empty?", is_empty);
317
352
  cPolygon.define_method("[]", get_at);
318
353
  rb_define_method(cPolygon, "each", RUBY_METHOD_FUNC(each), 0);
319
- cPolygon.define_method("+", op_or);
354
+ cPolygon.define_method("+", op_add);
320
355
  cPolygon.define_method("-", op_sub);
321
356
  cPolygon.define_method("&", op_and);
322
357
  cPolygon.define_method("|", op_or);
323
358
  cPolygon.define_method("^", op_xor);
324
359
  cPolygon.define_singleton_method("points!", create_points);
360
+ cPolygon.define_singleton_method("line!", create_line);
325
361
  cPolygon.define_singleton_method("lines!", create_lines);
326
- cPolygon.define_singleton_method("line_strip!", create_line_strip);
327
- cPolygon.define_singleton_method("rect!", create_rect);
328
- cPolygon.define_singleton_method("ellipse!", create_ellipse);
329
362
  cPolygon.define_singleton_method("triangles!", create_triangles);
330
363
  cPolygon.define_singleton_method("triangle_strip!", create_triangle_strip);
331
364
  cPolygon.define_singleton_method("triangle_fan!", create_triangle_fan);
365
+ cPolygon.define_singleton_method("rect!", create_rect);
332
366
  cPolygon.define_singleton_method("quads!", create_quads);
333
367
  cPolygon.define_singleton_method("quad_strip!", create_quad_strip);
368
+ cPolygon.define_singleton_method("ellipse!", create_ellipse);
334
369
  cPolygon.define_singleton_method("curve!", create_curve);
335
370
  cPolygon.define_singleton_method("bezier!", create_bezier);
336
371
  }
@@ -343,26 +378,27 @@ namespace Rucy
343
378
  template <> Rays::Polygon
344
379
  value_to<Rays::Polygon> (int argc, const Value* argv, bool convert)
345
380
  {
346
- assert(argc == 0 || (argc > 0 && argv));
347
-
348
381
  if (convert)
349
382
  {
350
383
  if (argc <= 0)
351
384
  return Rays::Polygon();
352
- else if (argv->is_kind_of(Rays::polygon_line_class()))
385
+ else if (argv->is_kind_of(Rays::polyline_class()))
353
386
  {
354
- std::vector<Rays::Polygon::Line> lines;
355
- lines.reserve(argc);
356
- for (int i = 0; i < argc; ++i)
357
- lines.emplace_back(to<Rays::Polygon::Line&>(argv[i]));
358
- return Rays::Polygon(&lines[0], lines.size());
387
+ if (argc == 1)
388
+ return Rays::Polygon(to<Rays::Polyline&>(*argv));
389
+ else
390
+ {
391
+ std::vector<Rays::Polyline> polylines;
392
+ polylines.reserve(argc);
393
+ for (int i = 0; i < argc; ++i)
394
+ polylines.emplace_back(to<Rays::Polyline&>(argv[i]));
395
+ return Rays::Polygon(&polylines[0], polylines.size());
396
+ }
359
397
  }
360
- else if (argv->is_kind_of(Rays::polyline_class()))
361
- return Rays::Polygon(to<Rays::Polyline&>(*argv));
362
398
  else if (argv->is_num() || argv->is_array())
363
399
  {
364
400
  std::vector<Rays::Point> points;
365
- get_line_args(&points, argc, argv);
401
+ get_points(&points, argc, argv);
366
402
  return Rays::Polygon(&points[0], points.size());
367
403
  }
368
404
  }
@@ -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
  }
@@ -9,6 +9,8 @@
9
9
  RUCY_DEFINE_CONVERT_TO(Rays::CapType)
10
10
  RUCY_DEFINE_CONVERT_TO(Rays::JoinType)
11
11
  RUCY_DEFINE_CONVERT_TO(Rays::BlendMode)
12
+ RUCY_DEFINE_CONVERT_TO(Rays::TexCoordMode)
13
+ RUCY_DEFINE_CONVERT_TO(Rays::TexCoordWrap)
12
14
 
13
15
 
14
16
  template <typename T>
@@ -43,6 +45,16 @@ static std::vector<EnumType<Rays::BlendMode>> BLEND_MODES({
43
45
  {"BLEND_REPLACE", "REPLACE", Rays::BLEND_REPLACE},
44
46
  });
45
47
 
48
+ static std::vector<EnumType<Rays::TexCoordMode>> TEXCOORD_MODES({
49
+ {"TEXCOORD_IMAGE", "IMAGE", Rays::TEXCOORD_IMAGE},
50
+ {"TEXCOORD_NORMAL", "NORMAL", Rays::TEXCOORD_NORMAL},
51
+ });
52
+
53
+ static std::vector<EnumType<Rays::TexCoordWrap>> TEXCOORD_WRAPS({
54
+ {"TEXCOORD_CLAMP", "CLAMP", Rays::TEXCOORD_CLAMP},
55
+ {"TEXCOORD_REPEAT", "REPEAT", Rays::TEXCOORD_REPEAT},
56
+ });
57
+
46
58
 
47
59
  static
48
60
  VALUE init(VALUE self)
@@ -77,6 +89,12 @@ Init_rays ()
77
89
 
78
90
  for (auto it = BLEND_MODES.begin(); it != BLEND_MODES.end(); ++it)
79
91
  mRays.define_const(it->name, it->value);
92
+
93
+ for (auto it = TEXCOORD_MODES.begin(); it != TEXCOORD_MODES.end(); ++it)
94
+ mRays.define_const(it->name, it->value);
95
+
96
+ for (auto it = TEXCOORD_WRAPS.begin(); it != TEXCOORD_WRAPS.end(); ++it)
97
+ mRays.define_const(it->name, it->value);
80
98
  }
81
99
 
82
100
 
@@ -177,6 +195,68 @@ namespace Rucy
177
195
  }
178
196
 
179
197
 
198
+ template <> Rays::TexCoordMode
199
+ value_to<Rays::TexCoordMode> (int argc, const Value* argv, bool convert)
200
+ {
201
+ assert(argc > 0 && argv);
202
+
203
+ if (convert)
204
+ {
205
+ if (argv->is_s() || argv->is_sym())
206
+ {
207
+ const char* str = argv->c_str();
208
+ for (auto it = TEXCOORD_MODES.begin(); it != TEXCOORD_MODES.end(); ++it)
209
+ {
210
+ if (
211
+ strcasecmp(str, it->name) == 0 ||
212
+ strcasecmp(str, it->short_name) == 0)
213
+ {
214
+ return it->value;
215
+ }
216
+ }
217
+ argument_error(__FILE__, __LINE__, "invalid texcoord mode -- %s", str);
218
+ }
219
+ }
220
+
221
+ int mode = value_to<int>(*argv, convert);
222
+ if (mode < 0 || Rays::TEXCOORD_MODE_MAX <= mode)
223
+ argument_error(__FILE__, __LINE__, "invalid texcoord mode -- %d", mode);
224
+
225
+ return (Rays::TexCoordMode) mode;
226
+ }
227
+
228
+
229
+ template <> Rays::TexCoordWrap
230
+ value_to<Rays::TexCoordWrap> (int argc, const Value* argv, bool convert)
231
+ {
232
+ assert(argc > 0 && argv);
233
+
234
+ if (convert)
235
+ {
236
+ if (argv->is_s() || argv->is_sym())
237
+ {
238
+ const char* str = argv->c_str();
239
+ for (auto it = TEXCOORD_WRAPS.begin(); it != TEXCOORD_WRAPS.end(); ++it)
240
+ {
241
+ if (
242
+ strcasecmp(str, it->name) == 0 ||
243
+ strcasecmp(str, it->short_name) == 0)
244
+ {
245
+ return it->value;
246
+ }
247
+ }
248
+ argument_error(__FILE__, __LINE__, "invalid texcoord wrap -- %s", str);
249
+ }
250
+ }
251
+
252
+ int wrap = value_to<int>(*argv, convert);
253
+ if (wrap < 0 || Rays::TEXCOORD_WRAP_MAX <= wrap)
254
+ argument_error(__FILE__, __LINE__, "invalid texcoord wrap -- %d", wrap);
255
+
256
+ return (Rays::TexCoordWrap) wrap;
257
+ }
258
+
259
+
180
260
  }// Rucy
181
261
 
182
262
 
@@ -1,4 +1,4 @@
1
- #include "rays/noise.h"
1
+ #include "rays/util.h"
2
2
  #include "rays/ruby/point.h"
3
3
  #include "defs.h"
4
4
 
@@ -45,7 +45,7 @@ VALUE simplex(VALUE self)
45
45
 
46
46
 
47
47
  void
48
- Init_rays_noise ()
48
+ Init_rays_util ()
49
49
  {
50
50
  Module mRays = rb_define_module("Rays");
51
51
  rb_define_singleton_method(mRays, "perlin", RUBY_METHOD_FUNC(perlin), -1);
data/ChangeLog.md CHANGED
@@ -1,6 +1,52 @@
1
1
  # rays ChangeLog
2
2
 
3
3
 
4
+ ## [v0.1.49] - 2024-02-07
5
+
6
+ - Add point(), line_height(), and line_height!() to Painter
7
+ - Add translate!(), scale!(), rotate!(), transpose(), and transpose!() to Rays::Matrix class
8
+ - Add ortho(), perspective(), and look_at() to Rays::Matrix
9
+ - Add Color#to_hsv
10
+ - Add get_hsv()
11
+ - hsb as an alias for hsv
12
+
13
+ - Font::get_width() handles multiple lines if there is a newline character
14
+ - Painter::curve() and Painter::bezier() use nsegment state
15
+ - Polygon.curve() and Polygon.bezier() can take 'nsegment' parameter
16
+ - When updating a texture with a bitmap, the texture is reused, not created anew
17
+ - If the texture is bound to the frame buffer, replacing it with a new texture will cause the drawing target to shift
18
+ - Set the modified flag on the texture in the framebuffer at the beginning of painting
19
+ - Set modified flag for bitmap if needed
20
+ - Throw error on conflict between bitmap and texture
21
+
22
+ - Fix a bug that dust was drawn on the right edge when drawing text
23
+ - Fix that Painter#point ignores stroke_cap
24
+ - Fix Matrix::to_a order
25
+
26
+
27
+ ## [v0.1.48] - 2024-01-08
28
+
29
+ - Add Bitmap#pixels=
30
+ - Add Font#dup, Font#size=, Font.families, and Font.load
31
+ - Add Polyline#with
32
+ - Add Painter#texture, Painter#texcoord_mode, and Painter#texcoord_wrap
33
+
34
+ - Delete Polygon::Line because it was merged into Polyline
35
+
36
+ - Polygon and Polyline can take colors and texcoords for each vertex
37
+ - Polyline.new can take 'hole' parameter
38
+ - 'polygonA + polygonB' means Polygon.new(*polygonA.to_a, *polygonB.to_a)
39
+ - Polygon with only holes raises an ArgumentError
40
+ - Image delegates 'pixels' accessors to Bitmap
41
+ - Use GL_CLAMP_TO_EDGE for texturing
42
+ - Refine Point#inspect(), Color#inspect(), and Font#inspect()
43
+ - default_font() -> get_default_font()
44
+ - rays/include/noise.h -> rays/include/util.h
45
+
46
+ - Fix Polygon.bezier() returns broken object
47
+ - Fix get_pixels() does not work with float colors
48
+
49
+
4
50
  ## [v0.1.47] - 2023-12-09
5
51
 
6
52
  - Add Polygon's singleton methods: points(), lines(), triangles(), triangle_strip(), triangle_fan(), quads(), quad_strip()
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.47
1
+ 0.1.49