rays 0.1.47 → 0.1.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.doc/ext/rays/bitmap.cpp +287 -46
- data/.doc/ext/rays/camera.cpp +2 -2
- data/.doc/ext/rays/defs.cpp +32 -8
- data/.doc/ext/rays/font.cpp +50 -2
- data/.doc/ext/rays/native.cpp +2 -4
- data/.doc/ext/rays/painter.cpp +73 -3
- data/.doc/ext/rays/polygon.cpp +131 -97
- data/.doc/ext/rays/polyline.cpp +89 -10
- data/.doc/ext/rays/rays.cpp +80 -0
- data/.doc/ext/rays/{noise.cpp → util.cpp} +2 -2
- data/ChangeLog.md +23 -0
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +288 -46
- data/ext/rays/camera.cpp +2 -2
- data/ext/rays/defs.cpp +32 -8
- data/ext/rays/defs.h +56 -3
- data/ext/rays/font.cpp +56 -4
- data/ext/rays/native.cpp +2 -4
- data/ext/rays/painter.cpp +80 -3
- data/ext/rays/polygon.cpp +134 -99
- data/ext/rays/polyline.cpp +95 -9
- data/ext/rays/rays.cpp +80 -0
- data/ext/rays/{noise.cpp → util.cpp} +2 -2
- data/include/rays/defs.h +24 -26
- data/include/rays/font.h +17 -3
- data/include/rays/painter.h +14 -0
- data/include/rays/polygon.h +56 -37
- data/include/rays/polyline.h +17 -2
- data/include/rays/ruby/polygon.h +0 -11
- data/include/rays/ruby/rays.h +4 -0
- data/include/rays/{noise.h → util.h} +2 -2
- data/lib/rays/color.rb +1 -1
- data/lib/rays/font.rb +1 -1
- data/lib/rays/image.rb +1 -1
- data/lib/rays/painter.rb +12 -1
- data/lib/rays/point.rb +1 -1
- data/lib/rays/polygon.rb +44 -35
- data/lib/rays/polyline.rb +54 -8
- data/lib/rays.rb +0 -1
- data/rays.gemspec +1 -1
- data/src/font.cpp +24 -2
- data/src/font.h +8 -1
- data/src/ios/font.mm +88 -27
- data/src/osx/font.mm +90 -28
- data/src/osx/helper.h +2 -2
- data/src/osx/helper.mm +2 -2
- data/src/painter.cpp +155 -85
- data/src/painter.h +11 -3
- data/src/polygon.cpp +404 -315
- data/src/polyline.cpp +138 -27
- data/src/polyline.h +3 -5
- data/src/shader.cpp +36 -4
- data/src/shader.h +1 -1
- data/src/texture.cpp +2 -2
- data/src/{noise.cpp → util.cpp} +1 -1
- data/src/win32/font.cpp +1 -1
- data/test/test_bitmap.rb +12 -5
- data/test/test_color.rb +4 -0
- data/test/test_font.rb +20 -2
- data/test/test_image.rb +18 -18
- data/test/test_point.rb +1 -1
- data/test/test_polygon.rb +52 -45
- data/test/test_polyline.rb +191 -72
- metadata +9 -15
- data/.doc/ext/rays/polygon_line.cpp +0 -97
- data/ext/rays/polygon_line.cpp +0 -100
- data/lib/rays/polygon_line.rb +0 -33
- data/test/test_polygon_line.rb +0 -164
data/ext/rays/polygon.cpp
CHANGED
@@ -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"
|
@@ -24,7 +23,7 @@ RUCY_DEF_ALLOC(alloc, klass)
|
|
24
23
|
RUCY_END
|
25
24
|
|
26
25
|
static
|
27
|
-
|
26
|
+
RUCY_DEF4(setup, args, loop, colors, texcoords)
|
28
27
|
{
|
29
28
|
CHECK;
|
30
29
|
|
@@ -32,9 +31,10 @@ RUCY_DEF2(setup, args, loop)
|
|
32
31
|
*THIS = to<Rays::Polygon>(args.size(), args.as_array());
|
33
32
|
else
|
34
33
|
{
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
CreateParams params(args, colors, texcoords);
|
35
|
+
*THIS = Rays::Polygon(
|
36
|
+
params.ppoints(), params.size(), loop,
|
37
|
+
params.pcolors(), params.ptexcoords());
|
38
38
|
}
|
39
39
|
}
|
40
40
|
RUCY_END
|
@@ -102,22 +102,63 @@ RUCY_DEF0(each)
|
|
102
102
|
CHECK;
|
103
103
|
|
104
104
|
Value ret = Qnil;
|
105
|
-
for (const auto&
|
106
|
-
ret = rb_yield(value(
|
105
|
+
for (const auto& polyline : *THIS)
|
106
|
+
ret = rb_yield(value(polyline));
|
107
107
|
return ret;
|
108
108
|
}
|
109
109
|
RUCY_END
|
110
110
|
|
111
|
-
|
112
|
-
|
111
|
+
template <typename T>
|
112
|
+
static inline void
|
113
|
+
each_poly (const Value& value, auto fun)
|
113
114
|
{
|
114
115
|
int size = value.size();
|
115
116
|
const Value* array = value.as_array();
|
116
117
|
|
117
118
|
for (int i = 0; i < size; ++i)
|
118
|
-
fun(to<
|
119
|
+
fun(to<T&>(array[i]));
|
119
120
|
}
|
120
121
|
|
122
|
+
static
|
123
|
+
RUCY_DEF1(op_add, obj)
|
124
|
+
{
|
125
|
+
CHECK;
|
126
|
+
|
127
|
+
if (obj.is_kind_of(Rays::polyline_class()))
|
128
|
+
return value(*THIS + to<Rays::Polyline&>(obj));
|
129
|
+
|
130
|
+
if (obj.is_kind_of(Rays::polygon_class()))
|
131
|
+
return value(*THIS + to<Rays::Polygon&>(obj));
|
132
|
+
|
133
|
+
if (!obj.is_array())
|
134
|
+
argument_error(__FILE__, __LINE__);
|
135
|
+
|
136
|
+
if (obj.empty()) return self;
|
137
|
+
|
138
|
+
std::vector<Rays::Polyline> polylines;
|
139
|
+
for (const auto& polyline : to<Rays::Polygon&>(self))
|
140
|
+
polylines.emplace_back(polyline);
|
141
|
+
|
142
|
+
if (obj[0].is_kind_of(Rays::polyline_class()))
|
143
|
+
{
|
144
|
+
each_poly<Rays::Polyline>(obj, [&](const auto& polyline)
|
145
|
+
{
|
146
|
+
polylines.emplace_back(polyline);
|
147
|
+
});
|
148
|
+
}
|
149
|
+
else
|
150
|
+
{
|
151
|
+
each_poly<Rays::Polygon>(obj, [&](const auto& polygon)
|
152
|
+
{
|
153
|
+
for (const auto& polyline : polygon)
|
154
|
+
polylines.emplace_back(polyline);
|
155
|
+
});
|
156
|
+
}
|
157
|
+
|
158
|
+
return value(Rays::Polygon(&polylines[0], polylines.size()));
|
159
|
+
}
|
160
|
+
RUCY_END
|
161
|
+
|
121
162
|
static
|
122
163
|
RUCY_DEF1(op_sub, obj)
|
123
164
|
{
|
@@ -126,7 +167,7 @@ RUCY_DEF1(op_sub, obj)
|
|
126
167
|
if (obj.is_array())
|
127
168
|
{
|
128
169
|
Rays::Polygon result = *THIS;
|
129
|
-
|
170
|
+
each_poly<Rays::Polygon>(obj, [&](const auto& polygon)
|
130
171
|
{
|
131
172
|
result = result - polygon;
|
132
173
|
});
|
@@ -145,7 +186,7 @@ RUCY_DEF1(op_and, obj)
|
|
145
186
|
if (obj.is_array())
|
146
187
|
{
|
147
188
|
Rays::Polygon result = *THIS;
|
148
|
-
|
189
|
+
each_poly<Rays::Polygon>(obj, [&](const auto& polygon)
|
149
190
|
{
|
150
191
|
result = result & polygon;
|
151
192
|
});
|
@@ -164,7 +205,7 @@ RUCY_DEF1(op_or, obj)
|
|
164
205
|
if (obj.is_array())
|
165
206
|
{
|
166
207
|
Rays::Polygon result = *THIS;
|
167
|
-
|
208
|
+
each_poly<Rays::Polygon>(obj, [&](const auto& polygon)
|
168
209
|
{
|
169
210
|
result = result | polygon;
|
170
211
|
});
|
@@ -183,7 +224,7 @@ RUCY_DEF1(op_xor, obj)
|
|
183
224
|
if (obj.is_array())
|
184
225
|
{
|
185
226
|
Rays::Polygon result = *THIS;
|
186
|
-
|
227
|
+
each_poly<Rays::Polygon>(obj, [&](const auto& polygon)
|
187
228
|
{
|
188
229
|
result = result ^ polygon;
|
189
230
|
});
|
@@ -195,131 +236,124 @@ RUCY_DEF1(op_xor, obj)
|
|
195
236
|
RUCY_END
|
196
237
|
|
197
238
|
static
|
198
|
-
RUCY_DEF1(create_points,
|
239
|
+
RUCY_DEF1(create_points, points)
|
199
240
|
{
|
200
|
-
|
201
|
-
|
202
|
-
return value(Rays::Polygon(Rays::DRAW_POINTS, &points[0], points.size()));
|
241
|
+
CreateParams params(points, nil(), nil());
|
242
|
+
return value(Rays::create_points(params.ppoints(), params.size()));
|
203
243
|
}
|
204
244
|
RUCY_END
|
205
245
|
|
206
246
|
static
|
207
|
-
|
247
|
+
RUCY_DEF2(create_line, points, loop)
|
208
248
|
{
|
209
|
-
|
210
|
-
|
211
|
-
return value(Rays::Polygon(Rays::DRAW_LINES, &points[0], points.size()));
|
249
|
+
CreateParams params(points, nil(), nil());
|
250
|
+
return value(Rays::create_line(params.ppoints(), params.size(), loop));
|
212
251
|
}
|
213
252
|
RUCY_END
|
214
253
|
|
215
254
|
static
|
216
|
-
|
255
|
+
RUCY_DEF1(create_lines, points)
|
217
256
|
{
|
218
|
-
|
219
|
-
|
220
|
-
return value(
|
221
|
-
Rays::Polygon(Rays::DRAW_LINE_STRIP, &points[0], points.size(), loop));
|
257
|
+
CreateParams params(points, nil(), nil());
|
258
|
+
return value(Rays::create_lines(params.ppoints(), params.size()));
|
222
259
|
}
|
223
260
|
RUCY_END
|
224
261
|
|
225
262
|
static
|
226
|
-
|
227
|
-
args, round, lefttop, righttop, leftbottom, rightbottom, nsegment)
|
263
|
+
RUCY_DEF4(create_triangles, points, loop, colors, texcoords)
|
228
264
|
{
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
args.size(), args.as_array(),
|
234
|
-
round, lefttop, righttop, leftbottom, rightbottom, nsegment);
|
235
|
-
|
236
|
-
return value(Rays::create_rect(x, y, w, h, lt, rt, lb, rb, nseg));
|
265
|
+
CreateParams params(points, colors, texcoords);
|
266
|
+
return value(Rays::create_triangles(
|
267
|
+
params.ppoints(), params.size(), loop,
|
268
|
+
params.pcolors(), params.ptexcoords()));
|
237
269
|
}
|
238
270
|
RUCY_END
|
239
271
|
|
240
272
|
static
|
241
|
-
|
242
|
-
args, center, radius, hole, angle_from, angle_to, nsegment)
|
273
|
+
RUCY_DEF3(create_triangle_strip, points, colors, texcoords)
|
243
274
|
{
|
244
|
-
|
245
|
-
Rays::
|
246
|
-
|
247
|
-
|
248
|
-
get_ellipse_args(
|
249
|
-
&x, &y, &w, &h, &hole_size, &from, &to_, &nseg,
|
250
|
-
args.size(), args.as_array(),
|
251
|
-
center, radius, hole, angle_from, angle_to, nsegment);
|
252
|
-
|
253
|
-
return value(Rays::create_ellipse(x, y, w, h, hole_size, from, to_, nseg));
|
275
|
+
CreateParams params(points, colors, texcoords);
|
276
|
+
return value(Rays::create_triangle_strip(
|
277
|
+
params.ppoints(), params.size(),
|
278
|
+
params.pcolors(), params.ptexcoords()));
|
254
279
|
}
|
255
280
|
RUCY_END
|
256
281
|
|
257
282
|
static
|
258
|
-
|
283
|
+
RUCY_DEF3(create_triangle_fan, points, colors, texcoords)
|
259
284
|
{
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
285
|
+
CreateParams params(points, colors, texcoords);
|
286
|
+
return value(Rays::create_triangle_fan(
|
287
|
+
params.ppoints(), params.size(),
|
288
|
+
params.pcolors(), params.ptexcoords()));
|
264
289
|
}
|
265
290
|
RUCY_END
|
266
291
|
|
267
292
|
static
|
268
|
-
|
293
|
+
RUCY_DEF7(create_rect,
|
294
|
+
args, round, lefttop, righttop, leftbottom, rightbottom, nsegment)
|
269
295
|
{
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
296
|
+
coord x, y, w, h, lt, rt, lb, rb;
|
297
|
+
uint nseg;
|
298
|
+
get_rect_args(
|
299
|
+
&x, &y, &w, &h, <, &rt, &lb, &rb, &nseg,
|
300
|
+
args.size(), args.as_array(),
|
301
|
+
round, lefttop, righttop, leftbottom, rightbottom, nsegment);
|
302
|
+
|
303
|
+
return value(Rays::create_rect(x, y, w, h, lt, rt, lb, rb, nseg));
|
274
304
|
}
|
275
305
|
RUCY_END
|
276
306
|
|
277
307
|
static
|
278
|
-
|
308
|
+
RUCY_DEF4(create_quads, points, loop, colors, texcoords)
|
279
309
|
{
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
310
|
+
CreateParams params(points, colors, texcoords);
|
311
|
+
return value(Rays::create_quads(
|
312
|
+
params.ppoints(), params.size(), loop,
|
313
|
+
params.pcolors(), params.ptexcoords()));
|
284
314
|
}
|
285
315
|
RUCY_END
|
286
316
|
|
287
317
|
static
|
288
|
-
|
318
|
+
RUCY_DEF3(create_quad_strip, points, colors, texcoords)
|
289
319
|
{
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
320
|
+
CreateParams params(points, colors, texcoords);
|
321
|
+
return value(Rays::create_quad_strip(
|
322
|
+
params.ppoints(), params.size(),
|
323
|
+
params.pcolors(), params.ptexcoords()));
|
294
324
|
}
|
295
325
|
RUCY_END
|
296
326
|
|
297
327
|
static
|
298
|
-
|
328
|
+
RUCY_DEF7(create_ellipse,
|
329
|
+
args, center, radius, hole, angle_from, angle_to, nsegment)
|
299
330
|
{
|
300
|
-
|
301
|
-
|
302
|
-
|
331
|
+
coord x, y, w, h;
|
332
|
+
Rays::Point hole_size;
|
333
|
+
float from, to_;
|
334
|
+
uint nseg;
|
335
|
+
get_ellipse_args(
|
336
|
+
&x, &y, &w, &h, &hole_size, &from, &to_, &nseg,
|
337
|
+
args.size(), args.as_array(),
|
338
|
+
center, radius, hole, angle_from, angle_to, nsegment);
|
339
|
+
|
340
|
+
return value(Rays::create_ellipse(x, y, w, h, hole_size, from, to_, nseg));
|
303
341
|
}
|
304
342
|
RUCY_END
|
305
343
|
|
306
344
|
static
|
307
|
-
RUCY_DEF2(create_curve,
|
345
|
+
RUCY_DEF2(create_curve, points, loop)
|
308
346
|
{
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
return value(Rays::create_curve(&points[0], points.size(), loop));
|
347
|
+
CreateParams params(points, nil(), nil());
|
348
|
+
return value(Rays::create_curve(params.ppoints(), params.size(), loop));
|
313
349
|
}
|
314
350
|
RUCY_END
|
315
351
|
|
316
352
|
static
|
317
|
-
RUCY_DEF2(create_bezier,
|
353
|
+
RUCY_DEF2(create_bezier, points, loop)
|
318
354
|
{
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
return value(Rays::create_bezier(&points[0], points.size(), loop));
|
355
|
+
CreateParams params(points, nil(), nil());
|
356
|
+
return value(Rays::create_bezier(params.ppoints(), params.size(), loop));
|
323
357
|
}
|
324
358
|
RUCY_END
|
325
359
|
|
@@ -336,25 +370,25 @@ Init_rays_polygon ()
|
|
336
370
|
cPolygon.define_private_method("setup", setup);
|
337
371
|
cPolygon.define_method("expand", expand);
|
338
372
|
cPolygon.define_method("bounds", bounds);
|
339
|
-
cPolygon.define_method("size",
|
373
|
+
cPolygon.define_method("size", size);
|
340
374
|
cPolygon.define_method("empty?", is_empty);
|
341
375
|
cPolygon.define_method("[]", get_at);
|
342
376
|
cPolygon.define_method("each", each);
|
343
|
-
cPolygon.define_method("+",
|
377
|
+
cPolygon.define_method("+", op_add);
|
344
378
|
cPolygon.define_method("-", op_sub);
|
345
379
|
cPolygon.define_method("&", op_and);
|
346
380
|
cPolygon.define_method("|", op_or);
|
347
381
|
cPolygon.define_method("^", op_xor);
|
348
382
|
cPolygon.define_singleton_method("points!", create_points);
|
383
|
+
cPolygon.define_singleton_method("line!", create_line);
|
349
384
|
cPolygon.define_singleton_method("lines!", create_lines);
|
350
|
-
cPolygon.define_singleton_method("line_strip!", create_line_strip);
|
351
|
-
cPolygon.define_singleton_method("rect!", create_rect);
|
352
|
-
cPolygon.define_singleton_method("ellipse!", create_ellipse);
|
353
385
|
cPolygon.define_singleton_method("triangles!", create_triangles);
|
354
386
|
cPolygon.define_singleton_method("triangle_strip!", create_triangle_strip);
|
355
387
|
cPolygon.define_singleton_method("triangle_fan!", create_triangle_fan);
|
388
|
+
cPolygon.define_singleton_method("rect!", create_rect);
|
356
389
|
cPolygon.define_singleton_method("quads!", create_quads);
|
357
390
|
cPolygon.define_singleton_method("quad_strip!", create_quad_strip);
|
391
|
+
cPolygon.define_singleton_method("ellipse!", create_ellipse);
|
358
392
|
cPolygon.define_singleton_method("curve!", create_curve);
|
359
393
|
cPolygon.define_singleton_method("bezier!", create_bezier);
|
360
394
|
}
|
@@ -367,26 +401,27 @@ namespace Rucy
|
|
367
401
|
template <> Rays::Polygon
|
368
402
|
value_to<Rays::Polygon> (int argc, const Value* argv, bool convert)
|
369
403
|
{
|
370
|
-
assert(argc == 0 || (argc > 0 && argv));
|
371
|
-
|
372
404
|
if (convert)
|
373
405
|
{
|
374
406
|
if (argc <= 0)
|
375
407
|
return Rays::Polygon();
|
376
|
-
else if (argv->is_kind_of(Rays::
|
408
|
+
else if (argv->is_kind_of(Rays::polyline_class()))
|
377
409
|
{
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
410
|
+
if (argc == 1)
|
411
|
+
return Rays::Polygon(to<Rays::Polyline&>(*argv));
|
412
|
+
else
|
413
|
+
{
|
414
|
+
std::vector<Rays::Polyline> polylines;
|
415
|
+
polylines.reserve(argc);
|
416
|
+
for (int i = 0; i < argc; ++i)
|
417
|
+
polylines.emplace_back(to<Rays::Polyline&>(argv[i]));
|
418
|
+
return Rays::Polygon(&polylines[0], polylines.size());
|
419
|
+
}
|
383
420
|
}
|
384
|
-
else if (argv->is_kind_of(Rays::polyline_class()))
|
385
|
-
return Rays::Polygon(to<Rays::Polyline&>(*argv));
|
386
421
|
else if (argv->is_num() || argv->is_array())
|
387
422
|
{
|
388
423
|
std::vector<Rays::Point> points;
|
389
|
-
|
424
|
+
get_points(&points, argc, argv);
|
390
425
|
return Rays::Polygon(&points[0], points.size());
|
391
426
|
}
|
392
427
|
}
|
data/ext/rays/polyline.cpp
CHANGED
@@ -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"
|
@@ -24,13 +25,15 @@ RUCY_DEF_ALLOC(alloc, klass)
|
|
24
25
|
RUCY_END
|
25
26
|
|
26
27
|
static
|
27
|
-
|
28
|
+
RUCY_DEF6(setup, points, loop, fill, colors, texcoords, hole)
|
28
29
|
{
|
29
30
|
CHECK;
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
CreateParams params(points, colors, texcoords);
|
33
|
+
*THIS = Rays::Polyline(
|
34
|
+
params.ppoints(), params.size(), loop, fill,
|
35
|
+
params.pcolors(), params.ptexcoords(),
|
36
|
+
hole);
|
34
37
|
}
|
35
38
|
RUCY_END
|
36
39
|
|
@@ -60,13 +63,29 @@ RUCY_DEF0(bounds)
|
|
60
63
|
RUCY_END
|
61
64
|
|
62
65
|
static
|
63
|
-
RUCY_DEF0(
|
66
|
+
RUCY_DEF0(is_loop)
|
64
67
|
{
|
65
68
|
CHECK;
|
66
69
|
return value(THIS->loop());
|
67
70
|
}
|
68
71
|
RUCY_END
|
69
72
|
|
73
|
+
static
|
74
|
+
RUCY_DEF0(is_fill)
|
75
|
+
{
|
76
|
+
CHECK;
|
77
|
+
return value(THIS->fill());
|
78
|
+
}
|
79
|
+
RUCY_END
|
80
|
+
|
81
|
+
static
|
82
|
+
RUCY_DEF0(is_hole)
|
83
|
+
{
|
84
|
+
CHECK;
|
85
|
+
return value(THIS->hole());
|
86
|
+
}
|
87
|
+
RUCY_END
|
88
|
+
|
70
89
|
static
|
71
90
|
RUCY_DEF0(size)
|
72
91
|
{
|
@@ -100,7 +119,31 @@ RUCY_DEF1(get_at, index)
|
|
100
119
|
RUCY_END
|
101
120
|
|
102
121
|
static
|
103
|
-
RUCY_DEF0(
|
122
|
+
RUCY_DEF0(has_points)
|
123
|
+
{
|
124
|
+
CHECK;
|
125
|
+
return value(THIS->points() && !THIS->empty());
|
126
|
+
}
|
127
|
+
RUCY_END
|
128
|
+
|
129
|
+
static
|
130
|
+
RUCY_DEF0(has_colors)
|
131
|
+
{
|
132
|
+
CHECK;
|
133
|
+
return value(THIS->colors() && !THIS->empty());
|
134
|
+
}
|
135
|
+
RUCY_END
|
136
|
+
|
137
|
+
static
|
138
|
+
RUCY_DEF0(has_texcoords)
|
139
|
+
{
|
140
|
+
CHECK;
|
141
|
+
return value(THIS->texcoords() && !THIS->empty());
|
142
|
+
}
|
143
|
+
RUCY_END
|
144
|
+
|
145
|
+
static
|
146
|
+
RUCY_DEF0(each_point)
|
104
147
|
{
|
105
148
|
CHECK;
|
106
149
|
|
@@ -111,6 +154,42 @@ RUCY_DEF0(each)
|
|
111
154
|
}
|
112
155
|
RUCY_END
|
113
156
|
|
157
|
+
static
|
158
|
+
RUCY_DEF0(each_color)
|
159
|
+
{
|
160
|
+
CHECK;
|
161
|
+
|
162
|
+
const Rays::Color* colors = THIS->colors();
|
163
|
+
|
164
|
+
Value ret = Qnil;
|
165
|
+
if (colors)
|
166
|
+
{
|
167
|
+
size_t size = THIS->size();
|
168
|
+
for (size_t i = 0; i < size; ++i)
|
169
|
+
ret = rb_yield(value(colors[i]));
|
170
|
+
}
|
171
|
+
return ret;
|
172
|
+
}
|
173
|
+
RUCY_END
|
174
|
+
|
175
|
+
static
|
176
|
+
RUCY_DEF0(each_texcoord)
|
177
|
+
{
|
178
|
+
CHECK;
|
179
|
+
|
180
|
+
const Rays::Coord3* texcoords = THIS->texcoords();
|
181
|
+
|
182
|
+
Value ret = Qnil;
|
183
|
+
if (texcoords)
|
184
|
+
{
|
185
|
+
size_t size = THIS->size();
|
186
|
+
for (size_t i = 0; i < size; ++i)
|
187
|
+
ret = rb_yield(value(*(Rays::Point*) &texcoords[i]));
|
188
|
+
}
|
189
|
+
return ret;
|
190
|
+
}
|
191
|
+
RUCY_END
|
192
|
+
|
114
193
|
|
115
194
|
static Class cPolyline;
|
116
195
|
|
@@ -124,11 +203,18 @@ Init_rays_polyline ()
|
|
124
203
|
cPolyline.define_private_method("setup", setup);
|
125
204
|
cPolyline.define_method("expand", expand);
|
126
205
|
cPolyline.define_method("bounds", bounds);
|
127
|
-
cPolyline.define_method("loop?",
|
206
|
+
cPolyline.define_method("loop?", is_loop);
|
207
|
+
cPolyline.define_method("fill?", is_fill);
|
208
|
+
cPolyline.define_method("hole?", is_hole);
|
128
209
|
cPolyline.define_method("size", size);
|
129
210
|
cPolyline.define_method("empty?", is_empty);
|
130
211
|
cPolyline.define_method("[]", get_at);
|
131
|
-
cPolyline.define_method("
|
212
|
+
cPolyline.define_method("points?", has_points);
|
213
|
+
cPolyline.define_method("colors?", has_colors);
|
214
|
+
cPolyline.define_method("texcoords?", has_texcoords);
|
215
|
+
cPolyline.define_private_method("each_point!", each_point);
|
216
|
+
cPolyline.define_private_method("each_color!", each_color);
|
217
|
+
cPolyline.define_private_method("each_texcoord!", each_texcoord);
|
132
218
|
}
|
133
219
|
|
134
220
|
|
@@ -148,7 +234,7 @@ namespace Rucy
|
|
148
234
|
else if (argv->is_num() || argv->is_array())
|
149
235
|
{
|
150
236
|
std::vector<Rays::Point> points;
|
151
|
-
|
237
|
+
get_points(&points, argc, argv);
|
152
238
|
return Rays::Polyline(&points[0], points.size());
|
153
239
|
}
|
154
240
|
}
|
data/ext/rays/rays.cpp
CHANGED
@@ -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
|
RUCY_DEF0(init)
|
@@ -79,6 +91,12 @@ Init_rays ()
|
|
79
91
|
|
80
92
|
for (auto it = BLEND_MODES.begin(); it != BLEND_MODES.end(); ++it)
|
81
93
|
mRays.define_const(it->name, it->value);
|
94
|
+
|
95
|
+
for (auto it = TEXCOORD_MODES.begin(); it != TEXCOORD_MODES.end(); ++it)
|
96
|
+
mRays.define_const(it->name, it->value);
|
97
|
+
|
98
|
+
for (auto it = TEXCOORD_WRAPS.begin(); it != TEXCOORD_WRAPS.end(); ++it)
|
99
|
+
mRays.define_const(it->name, it->value);
|
82
100
|
}
|
83
101
|
|
84
102
|
|
@@ -179,6 +197,68 @@ namespace Rucy
|
|
179
197
|
}
|
180
198
|
|
181
199
|
|
200
|
+
template <> Rays::TexCoordMode
|
201
|
+
value_to<Rays::TexCoordMode> (int argc, const Value* argv, bool convert)
|
202
|
+
{
|
203
|
+
assert(argc > 0 && argv);
|
204
|
+
|
205
|
+
if (convert)
|
206
|
+
{
|
207
|
+
if (argv->is_s() || argv->is_sym())
|
208
|
+
{
|
209
|
+
const char* str = argv->c_str();
|
210
|
+
for (auto it = TEXCOORD_MODES.begin(); it != TEXCOORD_MODES.end(); ++it)
|
211
|
+
{
|
212
|
+
if (
|
213
|
+
strcasecmp(str, it->name) == 0 ||
|
214
|
+
strcasecmp(str, it->short_name) == 0)
|
215
|
+
{
|
216
|
+
return it->value;
|
217
|
+
}
|
218
|
+
}
|
219
|
+
argument_error(__FILE__, __LINE__, "invalid texcoord mode -- %s", str);
|
220
|
+
}
|
221
|
+
}
|
222
|
+
|
223
|
+
int mode = value_to<int>(*argv, convert);
|
224
|
+
if (mode < 0 || Rays::TEXCOORD_MODE_MAX <= mode)
|
225
|
+
argument_error(__FILE__, __LINE__, "invalid texcoord mode -- %d", mode);
|
226
|
+
|
227
|
+
return (Rays::TexCoordMode) mode;
|
228
|
+
}
|
229
|
+
|
230
|
+
|
231
|
+
template <> Rays::TexCoordWrap
|
232
|
+
value_to<Rays::TexCoordWrap> (int argc, const Value* argv, bool convert)
|
233
|
+
{
|
234
|
+
assert(argc > 0 && argv);
|
235
|
+
|
236
|
+
if (convert)
|
237
|
+
{
|
238
|
+
if (argv->is_s() || argv->is_sym())
|
239
|
+
{
|
240
|
+
const char* str = argv->c_str();
|
241
|
+
for (auto it = TEXCOORD_WRAPS.begin(); it != TEXCOORD_WRAPS.end(); ++it)
|
242
|
+
{
|
243
|
+
if (
|
244
|
+
strcasecmp(str, it->name) == 0 ||
|
245
|
+
strcasecmp(str, it->short_name) == 0)
|
246
|
+
{
|
247
|
+
return it->value;
|
248
|
+
}
|
249
|
+
}
|
250
|
+
argument_error(__FILE__, __LINE__, "invalid texcoord wrap -- %s", str);
|
251
|
+
}
|
252
|
+
}
|
253
|
+
|
254
|
+
int wrap = value_to<int>(*argv, convert);
|
255
|
+
if (wrap < 0 || Rays::TEXCOORD_WRAP_MAX <= wrap)
|
256
|
+
argument_error(__FILE__, __LINE__, "invalid texcoord wrap -- %d", wrap);
|
257
|
+
|
258
|
+
return (Rays::TexCoordWrap) wrap;
|
259
|
+
}
|
260
|
+
|
261
|
+
|
182
262
|
}// Rucy
|
183
263
|
|
184
264
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#include "rays/
|
1
|
+
#include "rays/util.h"
|
2
2
|
#include "rays/ruby/point.h"
|
3
3
|
#include "defs.h"
|
4
4
|
|
@@ -47,7 +47,7 @@ RUCY_END
|
|
47
47
|
|
48
48
|
|
49
49
|
void
|
50
|
-
|
50
|
+
Init_rays_util ()
|
51
51
|
{
|
52
52
|
Module mRays = define_module("Rays");
|
53
53
|
mRays.define_singleton_method("perlin", perlin);
|