rays 0.1.47 → 0.1.48
Sign up to get free protection for your applications and to get access to all the features.
- 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/.doc/ext/rays/painter.cpp
CHANGED
@@ -153,7 +153,7 @@ VALUE line(VALUE self, VALUE args, VALUE loop)
|
|
153
153
|
CHECK;
|
154
154
|
|
155
155
|
std::vector<Rays::Point> points;
|
156
|
-
|
156
|
+
get_points(&points, args.size(), args.as_array());
|
157
157
|
|
158
158
|
THIS->line(&points[0], points.size(), loop);
|
159
159
|
return self;
|
@@ -211,7 +211,7 @@ VALUE curve(VALUE self, VALUE args, VALUE loop)
|
|
211
211
|
argument_error(__FILE__, __LINE__);
|
212
212
|
|
213
213
|
std::vector<Rays::Point> points;
|
214
|
-
|
214
|
+
get_points(&points, args.size(), args.as_array());
|
215
215
|
|
216
216
|
THIS->curve(&points[0], points.size(), loop);
|
217
217
|
return self;
|
@@ -226,7 +226,7 @@ VALUE bezier(VALUE self, VALUE args, VALUE loop)
|
|
226
226
|
argument_error(__FILE__, __LINE__);
|
227
227
|
|
228
228
|
std::vector<Rays::Point> points;
|
229
|
-
|
229
|
+
get_points(&points, args.size(), args.as_array());
|
230
230
|
|
231
231
|
THIS->bezier(&points[0], points.size(), loop);
|
232
232
|
return self;
|
@@ -513,6 +513,69 @@ VALUE get_font(VALUE self)
|
|
513
513
|
return value(THIS->font());
|
514
514
|
}
|
515
515
|
|
516
|
+
static
|
517
|
+
VALUE set_texture(VALUE self, VALUE image)
|
518
|
+
{
|
519
|
+
CHECK;
|
520
|
+
|
521
|
+
if (!image)
|
522
|
+
THIS->no_texture();
|
523
|
+
else
|
524
|
+
THIS->set_texture(to<Rays::Image&>(image));
|
525
|
+
return self;
|
526
|
+
}
|
527
|
+
|
528
|
+
static
|
529
|
+
VALUE get_texture(VALUE self)
|
530
|
+
{
|
531
|
+
CHECK;
|
532
|
+
|
533
|
+
const Rays::Image& image = THIS->texture();
|
534
|
+
return image ? value(image) : nil();
|
535
|
+
}
|
536
|
+
|
537
|
+
static
|
538
|
+
VALUE no_texture(VALUE self)
|
539
|
+
{
|
540
|
+
CHECK;
|
541
|
+
THIS->no_texture();
|
542
|
+
return self;
|
543
|
+
}
|
544
|
+
|
545
|
+
static
|
546
|
+
VALUE set_texcoord_mode(VALUE self, VALUE mode)
|
547
|
+
{
|
548
|
+
CHECK;
|
549
|
+
|
550
|
+
THIS->set_texcoord_mode(to<Rays::TexCoordMode>(mode));
|
551
|
+
return self;
|
552
|
+
}
|
553
|
+
|
554
|
+
static
|
555
|
+
VALUE get_texcoord_mode(VALUE self)
|
556
|
+
{
|
557
|
+
CHECK;
|
558
|
+
|
559
|
+
return value(THIS->texcoord_mode());
|
560
|
+
}
|
561
|
+
|
562
|
+
static
|
563
|
+
VALUE set_texcoord_wrap(VALUE self, VALUE wrap)
|
564
|
+
{
|
565
|
+
CHECK;
|
566
|
+
|
567
|
+
THIS->set_texcoord_wrap(to<Rays::TexCoordWrap>(wrap));
|
568
|
+
return self;
|
569
|
+
}
|
570
|
+
|
571
|
+
static
|
572
|
+
VALUE get_texcoord_wrap(VALUE self)
|
573
|
+
{
|
574
|
+
CHECK;
|
575
|
+
|
576
|
+
return value(THIS->texcoord_wrap());
|
577
|
+
}
|
578
|
+
|
516
579
|
static
|
517
580
|
VALUE set_shader(VALUE self)
|
518
581
|
{
|
@@ -695,6 +758,13 @@ Init_rays_painter ()
|
|
695
758
|
rb_define_method(cPainter, "no_clip", RUBY_METHOD_FUNC(no_clip), 0);
|
696
759
|
rb_define_method(cPainter, "font=", RUBY_METHOD_FUNC(set_font), -1);
|
697
760
|
rb_define_method(cPainter, "font", RUBY_METHOD_FUNC(get_font), 0);
|
761
|
+
rb_define_method(cPainter, "texture=", RUBY_METHOD_FUNC(set_texture), 1);
|
762
|
+
rb_define_method(cPainter, "texture", RUBY_METHOD_FUNC(get_texture), 0);
|
763
|
+
rb_define_method(cPainter, "no_texture", RUBY_METHOD_FUNC(no_texture), 0);
|
764
|
+
rb_define_method(cPainter, "texcoord_mode=", RUBY_METHOD_FUNC(set_texcoord_mode), 1);
|
765
|
+
rb_define_method(cPainter, "texcoord_mode", RUBY_METHOD_FUNC(get_texcoord_mode), 0);
|
766
|
+
rb_define_method(cPainter, "texcoord_wrap=", RUBY_METHOD_FUNC(set_texcoord_wrap), 1);
|
767
|
+
rb_define_method(cPainter, "texcoord_wrap", RUBY_METHOD_FUNC(get_texcoord_wrap), 0);
|
698
768
|
rb_define_private_method(cPainter, "set_shader", RUBY_METHOD_FUNC(set_shader), -1);
|
699
769
|
rb_define_method(cPainter, "shader", RUBY_METHOD_FUNC(get_shader), 0);
|
700
770
|
rb_define_method(cPainter, "no_shader", RUBY_METHOD_FUNC(no_shader), 0);
|
data/.doc/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"
|
@@ -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
|
-
|
35
|
-
|
36
|
-
|
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&
|
99
|
-
ret = rb_yield(value(
|
98
|
+
for (const auto& polyline : *THIS)
|
99
|
+
ret = rb_yield(value(polyline));
|
100
100
|
return ret;
|
101
101
|
}
|
102
102
|
|
103
|
-
|
104
|
-
|
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<
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
226
|
+
VALUE create_points(VALUE self, VALUE points)
|
187
227
|
{
|
188
|
-
|
189
|
-
|
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
|
233
|
+
VALUE create_line(VALUE self, VALUE points, VALUE loop)
|
195
234
|
{
|
196
|
-
|
197
|
-
|
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
|
240
|
+
VALUE create_lines(VALUE self, VALUE points)
|
203
241
|
{
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
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,17 @@ VALUE create_ellipse(VALUE self, VALUE
|
|
238
319
|
}
|
239
320
|
|
240
321
|
static
|
241
|
-
VALUE
|
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)
|
251
323
|
{
|
252
|
-
|
253
|
-
|
254
|
-
return value(
|
255
|
-
Rays::Polygon(Rays::DRAW_TRIANGLE_STRIP, &points[0], points.size()));
|
324
|
+
CreateParams params(points, nil(), nil());
|
325
|
+
return value(Rays::create_curve(params.ppoints(), params.size(), loop));
|
256
326
|
}
|
257
327
|
|
258
328
|
static
|
259
|
-
VALUE
|
329
|
+
VALUE create_bezier(VALUE self, VALUE points, VALUE loop)
|
260
330
|
{
|
261
|
-
|
262
|
-
|
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));
|
331
|
+
CreateParams params(points, nil(), nil());
|
332
|
+
return value(Rays::create_bezier(params.ppoints(), params.size(), loop));
|
300
333
|
}
|
301
334
|
|
302
335
|
|
@@ -309,28 +342,28 @@ Init_rays_polygon ()
|
|
309
342
|
|
310
343
|
cPolygon = rb_define_class_under(mRays, "Polygon", rb_cObject);
|
311
344
|
rb_define_alloc_func(cPolygon, alloc);
|
312
|
-
rb_define_private_method(cPolygon, "setup", RUBY_METHOD_FUNC(setup),
|
345
|
+
rb_define_private_method(cPolygon, "setup", RUBY_METHOD_FUNC(setup), 4);
|
313
346
|
rb_define_method(cPolygon, "expand", RUBY_METHOD_FUNC(expand), -1);
|
314
347
|
rb_define_method(cPolygon, "bounds", RUBY_METHOD_FUNC(bounds), 0);
|
315
348
|
rb_define_method(cPolygon, "size", RUBY_METHOD_FUNC(size), 0);
|
316
349
|
cPolygon.define_method("empty?", is_empty);
|
317
350
|
cPolygon.define_method("[]", get_at);
|
318
351
|
rb_define_method(cPolygon, "each", RUBY_METHOD_FUNC(each), 0);
|
319
|
-
cPolygon.define_method("+",
|
352
|
+
cPolygon.define_method("+", op_add);
|
320
353
|
cPolygon.define_method("-", op_sub);
|
321
354
|
cPolygon.define_method("&", op_and);
|
322
355
|
cPolygon.define_method("|", op_or);
|
323
356
|
cPolygon.define_method("^", op_xor);
|
324
357
|
cPolygon.define_singleton_method("points!", create_points);
|
358
|
+
cPolygon.define_singleton_method("line!", create_line);
|
325
359
|
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
360
|
cPolygon.define_singleton_method("triangles!", create_triangles);
|
330
361
|
cPolygon.define_singleton_method("triangle_strip!", create_triangle_strip);
|
331
362
|
cPolygon.define_singleton_method("triangle_fan!", create_triangle_fan);
|
363
|
+
cPolygon.define_singleton_method("rect!", create_rect);
|
332
364
|
cPolygon.define_singleton_method("quads!", create_quads);
|
333
365
|
cPolygon.define_singleton_method("quad_strip!", create_quad_strip);
|
366
|
+
cPolygon.define_singleton_method("ellipse!", create_ellipse);
|
334
367
|
cPolygon.define_singleton_method("curve!", create_curve);
|
335
368
|
cPolygon.define_singleton_method("bezier!", create_bezier);
|
336
369
|
}
|
@@ -343,26 +376,27 @@ namespace Rucy
|
|
343
376
|
template <> Rays::Polygon
|
344
377
|
value_to<Rays::Polygon> (int argc, const Value* argv, bool convert)
|
345
378
|
{
|
346
|
-
assert(argc == 0 || (argc > 0 && argv));
|
347
|
-
|
348
379
|
if (convert)
|
349
380
|
{
|
350
381
|
if (argc <= 0)
|
351
382
|
return Rays::Polygon();
|
352
|
-
else if (argv->is_kind_of(Rays::
|
383
|
+
else if (argv->is_kind_of(Rays::polyline_class()))
|
353
384
|
{
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
385
|
+
if (argc == 1)
|
386
|
+
return Rays::Polygon(to<Rays::Polyline&>(*argv));
|
387
|
+
else
|
388
|
+
{
|
389
|
+
std::vector<Rays::Polyline> polylines;
|
390
|
+
polylines.reserve(argc);
|
391
|
+
for (int i = 0; i < argc; ++i)
|
392
|
+
polylines.emplace_back(to<Rays::Polyline&>(argv[i]));
|
393
|
+
return Rays::Polygon(&polylines[0], polylines.size());
|
394
|
+
}
|
359
395
|
}
|
360
|
-
else if (argv->is_kind_of(Rays::polyline_class()))
|
361
|
-
return Rays::Polygon(to<Rays::Polyline&>(*argv));
|
362
396
|
else if (argv->is_num() || argv->is_array())
|
363
397
|
{
|
364
398
|
std::vector<Rays::Point> points;
|
365
|
-
|
399
|
+
get_points(&points, argc, argv);
|
366
400
|
return Rays::Polygon(&points[0], points.size());
|
367
401
|
}
|
368
402
|
}
|
data/.doc/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"
|
@@ -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
|
-
|
31
|
-
|
32
|
-
|
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
|
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
|
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),
|
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?",
|
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
|
-
|
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
|
-
|
221
|
+
get_points(&points, argc, argv);
|
143
222
|
return Rays::Polyline(&points[0], points.size());
|
144
223
|
}
|
145
224
|
}
|