rays 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.doc/ext/rays/bitmap.cpp +22 -76
- data/.doc/ext/rays/bounds.cpp +95 -125
- data/.doc/ext/rays/color.cpp +224 -45
- data/.doc/ext/rays/color_space.cpp +137 -45
- data/.doc/ext/rays/defs.cpp +183 -0
- data/.doc/ext/rays/font.cpp +39 -21
- data/.doc/ext/rays/image.cpp +26 -37
- data/.doc/ext/rays/matrix.cpp +186 -29
- data/.doc/ext/rays/native.cpp +12 -6
- data/.doc/ext/rays/noise.cpp +53 -0
- data/.doc/ext/rays/painter.cpp +120 -308
- data/.doc/ext/rays/point.cpp +82 -77
- data/.doc/ext/rays/polygon.cpp +287 -0
- data/.doc/ext/rays/polygon_line.cpp +96 -0
- data/.doc/ext/rays/polyline.cpp +161 -0
- data/.doc/ext/rays/rays.cpp +0 -13
- data/.doc/ext/rays/shader.cpp +83 -9
- data/README.md +1 -1
- data/Rakefile +21 -9
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +22 -80
- data/ext/rays/bounds.cpp +100 -128
- data/ext/rays/color.cpp +232 -51
- data/ext/rays/color_space.cpp +140 -46
- data/ext/rays/defs.cpp +183 -0
- data/ext/rays/defs.h +26 -2
- data/ext/rays/extconf.rb +1 -2
- data/ext/rays/font.cpp +39 -22
- data/ext/rays/image.cpp +27 -39
- data/ext/rays/matrix.cpp +198 -30
- data/ext/rays/native.cpp +12 -6
- data/ext/rays/noise.cpp +55 -0
- data/ext/rays/painter.cpp +129 -315
- data/ext/rays/point.cpp +89 -81
- data/ext/rays/polygon.cpp +301 -0
- data/ext/rays/polygon_line.cpp +99 -0
- data/ext/rays/polyline.cpp +170 -0
- data/ext/rays/rays.cpp +0 -14
- data/ext/rays/shader.cpp +84 -9
- data/include/rays.h +10 -2
- data/include/rays/bitmap.h +14 -26
- data/include/rays/bounds.h +21 -4
- data/include/rays/color.h +25 -14
- data/include/rays/color_space.h +11 -8
- data/include/rays/coord.h +114 -0
- data/include/rays/debug.h +22 -0
- data/include/rays/defs.h +3 -0
- data/include/rays/font.h +4 -4
- data/include/rays/image.h +11 -17
- data/include/rays/matrix.h +50 -24
- data/include/rays/noise.h +42 -0
- data/include/rays/opengl.h +2 -50
- data/include/rays/painter.h +57 -99
- data/include/rays/point.h +44 -51
- data/include/rays/polygon.h +164 -0
- data/include/rays/polyline.h +65 -0
- data/include/rays/rays.h +3 -0
- data/include/rays/ruby.h +7 -1
- data/include/rays/ruby/bounds.h +1 -1
- data/include/rays/ruby/color.h +1 -1
- data/include/rays/ruby/color_space.h +1 -1
- data/include/rays/ruby/font.h +1 -1
- data/include/rays/ruby/matrix.h +1 -1
- data/include/rays/ruby/point.h +1 -1
- data/include/rays/ruby/polygon.h +52 -0
- data/include/rays/ruby/polyline.h +41 -0
- data/include/rays/ruby/shader.h +1 -1
- data/include/rays/shader.h +36 -8
- data/lib/rays.rb +6 -1
- data/lib/rays/bitmap.rb +0 -15
- data/lib/rays/bounds.rb +17 -23
- data/lib/rays/color.rb +20 -47
- data/lib/rays/color_space.rb +13 -13
- data/lib/rays/image.rb +2 -6
- data/lib/rays/matrix.rb +28 -0
- data/lib/rays/module.rb +4 -19
- data/lib/rays/painter.rb +60 -97
- data/lib/rays/point.rb +13 -21
- data/lib/rays/polygon.rb +50 -0
- data/lib/rays/polygon_line.rb +36 -0
- data/lib/rays/polyline.rb +32 -0
- data/lib/rays/shader.rb +20 -1
- data/rays.gemspec +5 -7
- data/src/bitmap.h +36 -0
- data/src/bounds.cpp +74 -11
- data/src/color.cpp +58 -23
- data/src/color_space.cpp +50 -32
- data/src/color_space.h +22 -0
- data/src/coord.cpp +170 -0
- data/src/coord.h +35 -0
- data/src/font.cpp +118 -0
- data/src/font.h +64 -0
- data/src/frame_buffer.cpp +37 -71
- data/src/frame_buffer.h +4 -4
- data/src/image.cpp +171 -97
- data/src/image.h +25 -0
- data/src/ios/bitmap.mm +107 -105
- data/src/ios/font.mm +48 -60
- data/src/ios/helper.h +2 -2
- data/src/ios/opengl.mm +19 -4
- data/src/ios/rays.mm +3 -0
- data/src/matrix.cpp +111 -26
- data/src/matrix.h +30 -0
- data/src/noise.cpp +74 -0
- data/src/opengl.cpp +9 -27
- data/src/opengl.h +37 -0
- data/src/osx/bitmap.mm +111 -106
- data/src/osx/font.mm +48 -61
- data/src/osx/helper.h +2 -2
- data/src/osx/opengl.mm +19 -83
- data/src/osx/rays.mm +3 -0
- data/src/painter.cpp +780 -696
- data/src/painter.h +24 -0
- data/src/point.cpp +140 -119
- data/src/polygon.cpp +1100 -0
- data/src/polygon.h +32 -0
- data/src/polyline.cpp +158 -0
- data/src/polyline.h +67 -0
- data/src/render_buffer.cpp +11 -4
- data/src/render_buffer.h +2 -2
- data/src/shader.cpp +163 -106
- data/src/shader.h +38 -0
- data/src/shader_program.cpp +533 -0
- data/src/{program.h → shader_program.h} +28 -16
- data/src/shader_source.cpp +140 -0
- data/src/shader_source.h +52 -0
- data/src/texture.cpp +136 -160
- data/src/texture.h +65 -0
- data/src/win32/bitmap.cpp +62 -52
- data/src/win32/font.cpp +11 -13
- data/src/win32/font.h +24 -0
- data/src/win32/gdi.h +6 -6
- data/test/helper.rb +0 -3
- data/test/test_bitmap.rb +31 -7
- data/test/test_bounds.rb +36 -0
- data/test/test_color.rb +59 -19
- data/test/test_color_space.rb +95 -0
- data/test/test_image.rb +24 -20
- data/test/test_matrix.rb +106 -0
- data/test/test_painter.rb +92 -46
- data/test/test_painter_shape.rb +57 -0
- data/test/test_point.rb +21 -0
- data/test/test_polygon.rb +234 -0
- data/test/test_polygon_line.rb +167 -0
- data/test/test_polyline.rb +145 -0
- data/test/test_shader.rb +9 -9
- metadata +88 -67
- data/.doc/ext/rays/texture.cpp +0 -138
- data/ext/rays/texture.cpp +0 -149
- data/include/rays/ruby/texture.h +0 -41
- data/include/rays/texture.h +0 -71
- data/lib/rays/texture.rb +0 -24
- data/src/program.cpp +0 -648
- data/test/test_texture.rb +0 -27
data/ext/rays/point.cpp
CHANGED
@@ -1,16 +1,10 @@
|
|
1
1
|
#include "rays/ruby/point.h"
|
2
2
|
|
3
3
|
|
4
|
-
#include <rucy.h>
|
5
4
|
#include "defs.h"
|
6
5
|
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
using Rays::coord;
|
11
|
-
|
12
|
-
|
13
|
-
RUCY_DEFINE_VALUE_FROM_TO(Rays::Point)
|
7
|
+
RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Point)
|
14
8
|
|
15
9
|
#define THIS to<Rays::Point*>(self)
|
16
10
|
|
@@ -30,21 +24,8 @@ RUCY_DEFN(initialize)
|
|
30
24
|
CHECK;
|
31
25
|
check_arg_count(__FILE__, __LINE__, "Point#initialize", argc, 0, 1, 2, 3);
|
32
26
|
|
33
|
-
|
34
|
-
|
35
|
-
case 1:
|
36
|
-
*THIS = Rays::Point(to<coord>(argv[0]));
|
37
|
-
break;
|
38
|
-
|
39
|
-
case 2:
|
40
|
-
*THIS = Rays::Point(to<coord>(argv[0]), to<coord>(argv[1]));
|
41
|
-
break;
|
42
|
-
|
43
|
-
case 3:
|
44
|
-
*THIS = Rays::Point(
|
45
|
-
to<coord>(argv[0]), to<coord>(argv[1]), to<coord>(argv[2]));
|
46
|
-
break;
|
47
|
-
}
|
27
|
+
if (argc >= 1)
|
28
|
+
*THIS = to<Rays::Point>(argc, argv);
|
48
29
|
|
49
30
|
return self;
|
50
31
|
}
|
@@ -100,6 +81,24 @@ RUCY_DEFN(move_by)
|
|
100
81
|
}
|
101
82
|
RUCY_END
|
102
83
|
|
84
|
+
static
|
85
|
+
RUCY_DEF1(rotate, degree)
|
86
|
+
{
|
87
|
+
CHECK;
|
88
|
+
Rays::Point p = *THIS;
|
89
|
+
p.rotate(to<float>(degree));
|
90
|
+
return value(p);
|
91
|
+
}
|
92
|
+
RUCY_END
|
93
|
+
|
94
|
+
static
|
95
|
+
RUCY_DEF1(rotate_self, degree)
|
96
|
+
{
|
97
|
+
CHECK;
|
98
|
+
THIS->rotate(to<float>(degree));
|
99
|
+
}
|
100
|
+
RUCY_END
|
101
|
+
|
103
102
|
static
|
104
103
|
RUCY_DEF0(length)
|
105
104
|
{
|
@@ -129,7 +128,8 @@ static
|
|
129
128
|
RUCY_DEF1(set_x, x)
|
130
129
|
{
|
131
130
|
CHECK;
|
132
|
-
|
131
|
+
THIS->x = to<coord>(x);
|
132
|
+
return x;
|
133
133
|
}
|
134
134
|
RUCY_END
|
135
135
|
|
@@ -145,7 +145,8 @@ static
|
|
145
145
|
RUCY_DEF1(set_y, y)
|
146
146
|
{
|
147
147
|
CHECK;
|
148
|
-
|
148
|
+
THIS->y = to<coord>(y);
|
149
|
+
return y;
|
149
150
|
}
|
150
151
|
RUCY_END
|
151
152
|
|
@@ -161,7 +162,8 @@ static
|
|
161
162
|
RUCY_DEF1(set_z, z)
|
162
163
|
{
|
163
164
|
CHECK;
|
164
|
-
|
165
|
+
THIS->z = to<coord>(z);
|
166
|
+
return z;
|
165
167
|
}
|
166
168
|
RUCY_END
|
167
169
|
|
@@ -174,51 +176,59 @@ RUCY_DEF0(get_z)
|
|
174
176
|
RUCY_END
|
175
177
|
|
176
178
|
static
|
177
|
-
|
179
|
+
RUCY_DEF0(negate)
|
178
180
|
{
|
179
181
|
CHECK;
|
180
|
-
|
181
|
-
Rays::Point p = *THIS;
|
182
|
-
p += to<Rays::Point&>(point);
|
183
|
-
return value(p);
|
182
|
+
return value(-*THIS);
|
184
183
|
}
|
185
184
|
RUCY_END
|
186
185
|
|
187
186
|
static
|
188
|
-
|
187
|
+
RUCY_DEFN(add)
|
189
188
|
{
|
190
189
|
CHECK;
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
190
|
+
if (argc == 1 && argv->is_num())
|
191
|
+
return value(*THIS + to<coord>(*argv));
|
192
|
+
else
|
193
|
+
return value(*THIS + to<Rays::Point>(argc, argv));
|
195
194
|
}
|
196
195
|
RUCY_END
|
197
196
|
|
198
197
|
static
|
199
|
-
|
198
|
+
RUCY_DEFN(sub)
|
200
199
|
{
|
201
200
|
CHECK;
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
201
|
+
if (argc == 1 && argv->is_num())
|
202
|
+
return value(*THIS - to<coord>(*argv));
|
203
|
+
else
|
204
|
+
return value(*THIS - to<Rays::Point>(argc, argv));
|
206
205
|
}
|
207
206
|
RUCY_END
|
208
207
|
|
209
208
|
static
|
210
|
-
|
209
|
+
RUCY_DEFN(mult)
|
211
210
|
{
|
212
211
|
CHECK;
|
212
|
+
if (argc == 1 && argv->is_num())
|
213
|
+
return value(*THIS * to<coord>(*argv));
|
214
|
+
else
|
215
|
+
return value(*THIS * to<Rays::Point>(argc, argv));
|
216
|
+
}
|
217
|
+
RUCY_END
|
213
218
|
|
214
|
-
|
215
|
-
|
216
|
-
|
219
|
+
static
|
220
|
+
RUCY_DEFN(div)
|
221
|
+
{
|
222
|
+
CHECK;
|
223
|
+
if (argc == 1 && argv->is_num())
|
224
|
+
return value(*THIS / to<coord>(*argv));
|
225
|
+
else
|
226
|
+
return value(*THIS / to<Rays::Point>(argc, argv));
|
217
227
|
}
|
218
228
|
RUCY_END
|
219
229
|
|
220
230
|
static
|
221
|
-
|
231
|
+
RUCY_DEF2(set_at, index, value)
|
222
232
|
{
|
223
233
|
CHECK;
|
224
234
|
|
@@ -226,12 +236,13 @@ RUCY_DEF1(array_get, index)
|
|
226
236
|
if (i < 0 || 2 < i)
|
227
237
|
index_error(__FILE__, __LINE__);
|
228
238
|
|
229
|
-
|
239
|
+
(*THIS)[i] = to<coord>(value);
|
240
|
+
return value;
|
230
241
|
}
|
231
242
|
RUCY_END
|
232
243
|
|
233
244
|
static
|
234
|
-
|
245
|
+
RUCY_DEF1(get_at, index)
|
235
246
|
{
|
236
247
|
CHECK;
|
237
248
|
|
@@ -239,8 +250,7 @@ RUCY_DEF2(array_set, index, value)
|
|
239
250
|
if (i < 0 || 2 < i)
|
240
251
|
index_error(__FILE__, __LINE__);
|
241
252
|
|
242
|
-
(*THIS)[i]
|
243
|
-
return value;
|
253
|
+
return value((*THIS)[i]);
|
244
254
|
}
|
245
255
|
RUCY_END
|
246
256
|
|
@@ -262,25 +272,28 @@ Init_point ()
|
|
262
272
|
|
263
273
|
cPoint = mRays.define_class("Point");
|
264
274
|
cPoint.define_alloc_func(alloc);
|
265
|
-
cPoint.define_private_method("initialize",
|
275
|
+
cPoint.define_private_method("initialize", initialize);
|
266
276
|
cPoint.define_private_method("initialize_copy", initialize_copy);
|
267
277
|
cPoint.define_method("move_to!", move_to);
|
268
278
|
cPoint.define_method("move_by!", move_by);
|
279
|
+
cPoint.define_method("rotate", rotate);
|
280
|
+
cPoint.define_method("rotate!", rotate_self);
|
269
281
|
cPoint.define_method("length", length);
|
270
282
|
cPoint.define_method("normalize", normalize);
|
271
283
|
cPoint.define_method("normal", normal);
|
272
284
|
cPoint.define_method("x=", set_x);
|
273
|
-
cPoint.define_method("x",
|
285
|
+
cPoint.define_method("x", get_x);
|
274
286
|
cPoint.define_method("y=", set_y);
|
275
|
-
cPoint.define_method("y",
|
287
|
+
cPoint.define_method("y", get_y);
|
276
288
|
cPoint.define_method("z=", set_z);
|
277
|
-
cPoint.define_method("z",
|
278
|
-
cPoint.define_method("
|
279
|
-
cPoint.define_method("
|
280
|
-
cPoint.define_method("
|
281
|
-
cPoint.define_method("
|
282
|
-
cPoint.define_method("
|
283
|
-
cPoint.define_method("[]=",
|
289
|
+
cPoint.define_method("z", get_z);
|
290
|
+
cPoint.define_method("-@", negate);
|
291
|
+
cPoint.define_method("+", add);
|
292
|
+
cPoint.define_method("-", sub);
|
293
|
+
cPoint.define_method("*", mult);
|
294
|
+
cPoint.define_method("/", div);
|
295
|
+
cPoint.define_method("[]=", set_at);
|
296
|
+
cPoint.define_method("[]", get_at);
|
284
297
|
cPoint.define_method("inspect", inspect);
|
285
298
|
}
|
286
299
|
|
@@ -290,43 +303,38 @@ namespace Rucy
|
|
290
303
|
|
291
304
|
|
292
305
|
template <> Rays::Point
|
293
|
-
value_to<Rays::Point> (Value
|
306
|
+
value_to<Rays::Point> (int argc, const Value* argv, bool convert)
|
294
307
|
{
|
295
|
-
if (
|
308
|
+
if (argc == 1 && argv->is_array())
|
296
309
|
{
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
{
|
301
|
-
argc = value.size();
|
302
|
-
argv = value.as_array();
|
303
|
-
}
|
304
|
-
else
|
305
|
-
{
|
306
|
-
argc = 1;
|
307
|
-
argv = &value;
|
308
|
-
}
|
310
|
+
argc = argv->size();
|
311
|
+
argv = argv->as_array();
|
312
|
+
}
|
309
313
|
|
310
|
-
|
311
|
-
Rucy::argument_error(__FILE__, __LINE__);
|
314
|
+
assert(argc == 0 || (argc > 0 && argv));
|
312
315
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
+
if (convert)
|
317
|
+
{
|
318
|
+
if (argc == 0)
|
319
|
+
return Rays::Point();
|
320
|
+
else if (argv->is_num())
|
316
321
|
{
|
317
322
|
switch (argc)
|
318
323
|
{
|
319
|
-
#define V(i) argv[i]
|
324
|
+
#define V(i) to<coord>(argv[i])
|
320
325
|
case 1: return Rays::Point(V(0));
|
321
326
|
case 2: return Rays::Point(V(0), V(1));
|
322
327
|
case 3: return Rays::Point(V(0), V(1), V(2));
|
323
328
|
#undef V
|
324
|
-
default:
|
329
|
+
default: argument_error(__FILE__, __LINE__);
|
325
330
|
}
|
326
331
|
}
|
327
332
|
}
|
328
333
|
|
329
|
-
|
334
|
+
if (argc != 1)
|
335
|
+
argument_error(__FILE__, __LINE__);
|
336
|
+
|
337
|
+
return value_to<Rays::Point&>(*argv, convert);
|
330
338
|
}
|
331
339
|
|
332
340
|
|
@@ -0,0 +1,301 @@
|
|
1
|
+
#include "rays/ruby/polygon.h"
|
2
|
+
|
3
|
+
|
4
|
+
#include <vector>
|
5
|
+
#include <functional>
|
6
|
+
#include "rays/ruby/bounds.h"
|
7
|
+
#include "rays/ruby/polyline.h"
|
8
|
+
#include "defs.h"
|
9
|
+
|
10
|
+
|
11
|
+
RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Polygon)
|
12
|
+
|
13
|
+
#define THIS to<Rays::Polygon*>(self)
|
14
|
+
|
15
|
+
#define CHECK RUCY_CHECK_OBJECT(Rays::Polygon, self)
|
16
|
+
|
17
|
+
|
18
|
+
static
|
19
|
+
RUCY_DEF_ALLOC(alloc, klass)
|
20
|
+
{
|
21
|
+
return new_type<Rays::Polygon>(klass);
|
22
|
+
}
|
23
|
+
RUCY_END
|
24
|
+
|
25
|
+
static
|
26
|
+
RUCY_DEF2(setup, args, loop)
|
27
|
+
{
|
28
|
+
CHECK;
|
29
|
+
|
30
|
+
if (loop)
|
31
|
+
*THIS = to<Rays::Polygon>(args.size(), args.as_array());
|
32
|
+
else
|
33
|
+
{
|
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);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
RUCY_END
|
40
|
+
|
41
|
+
static
|
42
|
+
RUCY_DEF1(expand, width)
|
43
|
+
{
|
44
|
+
CHECK;
|
45
|
+
|
46
|
+
Rays::Polygon polygon;
|
47
|
+
THIS->expand(&polygon, to<coord>(width));
|
48
|
+
return value(polygon);
|
49
|
+
}
|
50
|
+
RUCY_END
|
51
|
+
|
52
|
+
static
|
53
|
+
RUCY_DEF0(bounds)
|
54
|
+
{
|
55
|
+
CHECK;
|
56
|
+
return value(THIS->bounds());
|
57
|
+
}
|
58
|
+
RUCY_END
|
59
|
+
|
60
|
+
static
|
61
|
+
RUCY_DEF0(size)
|
62
|
+
{
|
63
|
+
CHECK;
|
64
|
+
return value(THIS->size());
|
65
|
+
}
|
66
|
+
RUCY_END
|
67
|
+
|
68
|
+
static
|
69
|
+
RUCY_DEF0(empty)
|
70
|
+
{
|
71
|
+
CHECK;
|
72
|
+
return value(THIS->empty());
|
73
|
+
}
|
74
|
+
RUCY_END
|
75
|
+
|
76
|
+
static
|
77
|
+
RUCY_DEF1(at, index)
|
78
|
+
{
|
79
|
+
CHECK;
|
80
|
+
|
81
|
+
int size = (int) THIS->size();
|
82
|
+
int i = to<int>(index);
|
83
|
+
if (i < 0) i += size;
|
84
|
+
|
85
|
+
if (i < 0 || size <= i)
|
86
|
+
index_error(__FILE__, __LINE__);
|
87
|
+
|
88
|
+
return value((*THIS)[i]);
|
89
|
+
}
|
90
|
+
RUCY_END
|
91
|
+
|
92
|
+
static
|
93
|
+
RUCY_DEF0(each)
|
94
|
+
{
|
95
|
+
CHECK;
|
96
|
+
|
97
|
+
Value ret;
|
98
|
+
for (const auto& line : *THIS)
|
99
|
+
ret = rb_yield(value(line));
|
100
|
+
return ret;
|
101
|
+
}
|
102
|
+
RUCY_END
|
103
|
+
|
104
|
+
static void
|
105
|
+
each_polygon (const Value& value, std::function<void(const Rays::Polygon&)> fun)
|
106
|
+
{
|
107
|
+
int size = value.size();
|
108
|
+
const Value* array = value.as_array();
|
109
|
+
|
110
|
+
for (int i = 0; i < size; ++i)
|
111
|
+
fun(to<Rays::Polygon&>(array[i]));
|
112
|
+
}
|
113
|
+
|
114
|
+
static
|
115
|
+
RUCY_DEF1(op_sub, obj)
|
116
|
+
{
|
117
|
+
CHECK;
|
118
|
+
|
119
|
+
if (obj.is_array())
|
120
|
+
{
|
121
|
+
Rays::Polygon result = *THIS;
|
122
|
+
each_polygon(obj, [&](const Rays::Polygon& polygon)
|
123
|
+
{
|
124
|
+
result = result - polygon;
|
125
|
+
});
|
126
|
+
return value(result);
|
127
|
+
}
|
128
|
+
else
|
129
|
+
return value(*THIS - to<Rays::Polygon&>(obj));
|
130
|
+
}
|
131
|
+
RUCY_END
|
132
|
+
|
133
|
+
static
|
134
|
+
RUCY_DEF1(op_and, obj)
|
135
|
+
{
|
136
|
+
CHECK;
|
137
|
+
|
138
|
+
if (obj.is_array())
|
139
|
+
{
|
140
|
+
Rays::Polygon result = *THIS;
|
141
|
+
each_polygon(obj, [&](const Rays::Polygon& polygon)
|
142
|
+
{
|
143
|
+
result = result & polygon;
|
144
|
+
});
|
145
|
+
return value(result);
|
146
|
+
}
|
147
|
+
else
|
148
|
+
return value(*THIS & to<Rays::Polygon&>(obj));
|
149
|
+
}
|
150
|
+
RUCY_END
|
151
|
+
|
152
|
+
static
|
153
|
+
RUCY_DEF1(op_or, obj)
|
154
|
+
{
|
155
|
+
CHECK;
|
156
|
+
|
157
|
+
if (obj.is_array())
|
158
|
+
{
|
159
|
+
Rays::Polygon result = *THIS;
|
160
|
+
each_polygon(obj, [&](const Rays::Polygon& polygon)
|
161
|
+
{
|
162
|
+
result = result | polygon;
|
163
|
+
});
|
164
|
+
return value(result);
|
165
|
+
}
|
166
|
+
else
|
167
|
+
return value(*THIS | to<Rays::Polygon&>(obj));
|
168
|
+
}
|
169
|
+
RUCY_END
|
170
|
+
|
171
|
+
static
|
172
|
+
RUCY_DEF1(op_xor, obj)
|
173
|
+
{
|
174
|
+
CHECK;
|
175
|
+
|
176
|
+
if (obj.is_array())
|
177
|
+
{
|
178
|
+
Rays::Polygon result = *THIS;
|
179
|
+
each_polygon(obj, [&](const Rays::Polygon& polygon)
|
180
|
+
{
|
181
|
+
result = result ^ polygon;
|
182
|
+
});
|
183
|
+
return value(result);
|
184
|
+
}
|
185
|
+
else
|
186
|
+
return value(*THIS ^ to<Rays::Polygon&>(obj));
|
187
|
+
}
|
188
|
+
RUCY_END
|
189
|
+
|
190
|
+
static
|
191
|
+
RUCY_DEF7(create_rect,
|
192
|
+
args, round, lefttop, righttop, leftbottom, rightbottom, nsegment)
|
193
|
+
{
|
194
|
+
coord x, y, w, h, lt, rt, lb, rb;
|
195
|
+
uint nseg;
|
196
|
+
get_rect_args(
|
197
|
+
&x, &y, &w, &h, <, &rt, &lb, &rb, &nseg,
|
198
|
+
args.size(), args.as_array(),
|
199
|
+
round, lefttop, righttop, leftbottom, rightbottom, nsegment);
|
200
|
+
|
201
|
+
return value(Rays::create_rect(x, y, w, h, lt, rt, lb, rb, nseg));
|
202
|
+
}
|
203
|
+
RUCY_END
|
204
|
+
|
205
|
+
static
|
206
|
+
RUCY_DEF7(create_ellipse,
|
207
|
+
args, center, radius, hole, angle_from, angle_to, nsegment)
|
208
|
+
{
|
209
|
+
coord x, y, w, h;
|
210
|
+
Rays::Point hole_size;
|
211
|
+
float from, to_;
|
212
|
+
uint nseg;
|
213
|
+
get_ellipse_args(
|
214
|
+
&x, &y, &w, &h, &hole_size, &from, &to_, &nseg,
|
215
|
+
args.size(), args.as_array(),
|
216
|
+
center, radius, hole, angle_from, angle_to, nsegment);
|
217
|
+
|
218
|
+
return value(Rays::create_ellipse(x, y, w, h, hole_size, from, to_, nseg));
|
219
|
+
}
|
220
|
+
RUCY_END
|
221
|
+
|
222
|
+
|
223
|
+
static Class cPolygon;
|
224
|
+
|
225
|
+
void
|
226
|
+
Init_polygon ()
|
227
|
+
{
|
228
|
+
Module mRays = define_module("Rays");
|
229
|
+
|
230
|
+
cPolygon = mRays.define_class("Polygon");
|
231
|
+
cPolygon.define_alloc_func(alloc);
|
232
|
+
cPolygon.define_private_method("setup", setup);
|
233
|
+
cPolygon.define_method("expand", expand);
|
234
|
+
cPolygon.define_method("bounds", bounds);
|
235
|
+
cPolygon.define_method("size", size);
|
236
|
+
cPolygon.define_method("empty?", empty);
|
237
|
+
cPolygon.define_method("[]", at);
|
238
|
+
cPolygon.define_method("each", each);
|
239
|
+
cPolygon.define_method("+", op_or);
|
240
|
+
cPolygon.define_method("-", op_sub);
|
241
|
+
cPolygon.define_method("&", op_and);
|
242
|
+
cPolygon.define_method("|", op_or);
|
243
|
+
cPolygon.define_method("^", op_xor);
|
244
|
+
cPolygon.define_singleton_method("create_rect", create_rect);
|
245
|
+
cPolygon.define_singleton_method("create_ellipse", create_ellipse);
|
246
|
+
}
|
247
|
+
|
248
|
+
|
249
|
+
namespace Rucy
|
250
|
+
{
|
251
|
+
|
252
|
+
|
253
|
+
template <> Rays::Polygon
|
254
|
+
value_to<Rays::Polygon> (int argc, const Value* argv, bool convert)
|
255
|
+
{
|
256
|
+
assert(argc == 0 || (argc > 0 && argv));
|
257
|
+
|
258
|
+
if (convert)
|
259
|
+
{
|
260
|
+
if (argc <= 0)
|
261
|
+
return Rays::Polygon();
|
262
|
+
else if (argv->is_kind_of(Rays::polygon_line_class()))
|
263
|
+
{
|
264
|
+
std::vector<Rays::Polygon::Line> lines;
|
265
|
+
lines.reserve(argc);
|
266
|
+
for (int i = 0; i < argc; ++i)
|
267
|
+
lines.emplace_back(to<Rays::Polygon::Line&>(argv[i]));
|
268
|
+
return Rays::Polygon(&lines[0], lines.size());
|
269
|
+
}
|
270
|
+
else if (argv->is_kind_of(Rays::polyline_class()))
|
271
|
+
return Rays::Polygon(to<Rays::Polyline&>(*argv));
|
272
|
+
else if (argv->is_num() || argv->is_array())
|
273
|
+
{
|
274
|
+
std::vector<Rays::Point> points;
|
275
|
+
get_line_args(&points, argc, argv);
|
276
|
+
return Rays::Polygon(&points[0], points.size());
|
277
|
+
}
|
278
|
+
}
|
279
|
+
|
280
|
+
if (argc != 1)
|
281
|
+
argument_error(__FILE__, __LINE__);
|
282
|
+
|
283
|
+
return value_to<Rays::Polygon&>(*argv, convert);
|
284
|
+
}
|
285
|
+
|
286
|
+
|
287
|
+
}// Rucy
|
288
|
+
|
289
|
+
|
290
|
+
namespace Rays
|
291
|
+
{
|
292
|
+
|
293
|
+
|
294
|
+
Class
|
295
|
+
polygon_class ()
|
296
|
+
{
|
297
|
+
return cPolygon;
|
298
|
+
}
|
299
|
+
|
300
|
+
|
301
|
+
}// Rays
|