rays 0.1.12 → 0.1.13

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