rays 0.1.47 → 0.1.49
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/color.cpp +11 -0
- data/.doc/ext/rays/defs.cpp +32 -8
- data/.doc/ext/rays/font.cpp +50 -2
- data/.doc/ext/rays/image.cpp +3 -3
- data/.doc/ext/rays/matrix.cpp +65 -7
- data/.doc/ext/rays/native.cpp +2 -4
- data/.doc/ext/rays/painter.cpp +117 -9
- data/.doc/ext/rays/point.cpp +1 -11
- data/.doc/ext/rays/polygon.cpp +133 -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 +46 -0
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +288 -46
- data/ext/rays/camera.cpp +2 -2
- data/ext/rays/color.cpp +13 -1
- data/ext/rays/defs.cpp +32 -8
- data/ext/rays/defs.h +56 -3
- data/ext/rays/font.cpp +56 -4
- data/ext/rays/image.cpp +3 -3
- data/ext/rays/matrix.cpp +69 -7
- data/ext/rays/native.cpp +2 -4
- data/ext/rays/painter.cpp +132 -13
- data/ext/rays/point.cpp +1 -12
- data/ext/rays/polygon.cpp +136 -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/color.h +3 -1
- data/include/rays/defs.h +24 -26
- data/include/rays/font.h +17 -3
- data/include/rays/image.h +1 -1
- data/include/rays/matrix.h +24 -0
- data/include/rays/painter.h +24 -0
- data/include/rays/polygon.h +68 -43
- 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 +7 -1
- data/lib/rays/font.rb +1 -1
- data/lib/rays/image.rb +11 -1
- data/lib/rays/matrix.rb +16 -0
- data/lib/rays/painter.rb +18 -7
- data/lib/rays/point.rb +5 -1
- data/lib/rays/polygon.rb +44 -35
- data/lib/rays/polyline.rb +54 -8
- data/lib/rays.rb +0 -1
- data/rays.gemspec +2 -2
- data/src/color.cpp +11 -2
- data/src/font.cpp +37 -18
- data/src/font.h +6 -5
- data/src/image.cpp +58 -14
- data/src/ios/font.mm +89 -32
- data/src/ios/helper.h +2 -2
- data/src/ios/helper.mm +2 -2
- data/src/matrix.cpp +45 -0
- data/src/osx/font.mm +93 -33
- data/src/osx/helper.h +2 -2
- data/src/osx/helper.mm +2 -2
- data/src/painter.cpp +246 -114
- data/src/painter.h +11 -3
- data/src/polygon.cpp +431 -332
- 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 +23 -4
- data/src/texture.h +2 -0
- 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 +25 -4
- data/test/test_font.rb +23 -2
- data/test/test_image.rb +44 -18
- data/test/test_matrix.rb +22 -0
- data/test/test_painter.rb +27 -0
- data/test/test_point.rb +1 -1
- data/test/test_polygon.rb +52 -45
- data/test/test_polyline.rb +191 -72
- metadata +12 -18
- 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/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,19 @@ 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, VALUE nsegment)
|
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
|
+
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
|
330
|
+
VALUE create_bezier(VALUE self, VALUE points, VALUE loop, VALUE nsegment)
|
260
331
|
{
|
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));
|
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),
|
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("+",
|
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::
|
385
|
+
else if (argv->is_kind_of(Rays::polyline_class()))
|
353
386
|
{
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
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
|
-
|
401
|
+
get_points(&points, argc, argv);
|
366
402
|
return Rays::Polygon(&points[0], points.size());
|
367
403
|
}
|
368
404
|
}
|
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
|
}
|
data/.doc/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
|
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/
|
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
|
-
|
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.
|
1
|
+
0.1.49
|