rays 0.1.15 → 0.1.20

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c784fe46265f04062957d138081db6de0d9e257600be215741d120563534420c
4
- data.tar.gz: d58b4c10a2e9f0591a6465aea2b36f01de4f0720187acd2fbf98608162bb77d0
3
+ metadata.gz: b024121da2cf3b4ac1ece9ae33ec4005ad3d39e048babec1856ec01976022cdd
4
+ data.tar.gz: f20ecfdd2812170af9fb233bb7f32a5219221b77c09f8b24faa80788294c3c67
5
5
  SHA512:
6
- metadata.gz: 2a4771e03c225cd3f84c0d723ee3072d3a1403eec5028e38c1cc00ddda5e27dbd6ed4db14bee3fa9c8f412e49928cf4b9fd13f5cc5ae79b80149438dd3f9c96c
7
- data.tar.gz: 17567e4b335014d772f80f35c1a44859893605c65912469f00aac2ecc6f6a9a1c024d1303b42a24e78dd59b8797cc41f2af1b47627755250e74f5eac12dbc031
6
+ metadata.gz: 5acf9ecd53dc6c9cbf9ebd13194f41497185bd7f6b24712fe9a7ee55f2a9fbba5bbda61ba3bc832d035b3bdb2e6be6626d5daa0ae61713438fc82b02b65c9839
7
+ data.tar.gz: 37a16d92503200564afcdca07a242d3b2932800ff4c0ebb85aae78b74b76b1ab02967c3a7e76d9968c1be4eb1491e6e18074f60b0cecbf165451c8ebb6a0ca06
@@ -0,0 +1,171 @@
1
+ #include "rays/ruby/camera.h"
2
+
3
+
4
+ #include "rays/ruby/image.h"
5
+ #include "defs.h"
6
+
7
+
8
+ RUCY_DEFINE_VALUE_FROM_TO(Rays::Camera)
9
+
10
+ #define THIS to<Rays::Camera*>(self)
11
+
12
+ #define CHECK RUCY_CHECK_OBJECT(Rays::Camera, self)
13
+
14
+
15
+ static
16
+ VALUE alloc(VALUE klass)
17
+ {
18
+ return new_type<Rays::Camera>(klass);
19
+ }
20
+
21
+ static
22
+ VALUE setup(VALUE self, VALUE device_name, VALUE min_width, VALUE min_height, VALUE resize, VALUE crop)
23
+ {
24
+ RUCY_CHECK_OBJ(Rays::Camera, self);
25
+
26
+ *THIS = Rays::Camera(
27
+ device_name ? to<const char*>(device_name) : NULL,
28
+ to<int>(min_width), to<int>(min_height),
29
+ to<bool>(resize), to<bool>(crop));
30
+ return self;
31
+ }
32
+
33
+ static
34
+ VALUE start(VALUE self)
35
+ {
36
+ CHECK;
37
+ return value(THIS->start());
38
+ }
39
+
40
+ static
41
+ VALUE stop(VALUE self)
42
+ {
43
+ CHECK;
44
+ THIS->stop();
45
+ }
46
+
47
+ static
48
+ VALUE is_active(VALUE self)
49
+ {
50
+ CHECK;
51
+ return value(THIS->is_active());
52
+ }
53
+
54
+ static
55
+ VALUE set_min_width(VALUE self, VALUE width)
56
+ {
57
+ CHECK;
58
+ THIS->set_min_width(to<int>(width));
59
+ return value(THIS->min_width());
60
+ }
61
+
62
+ static
63
+ VALUE min_width(VALUE self)
64
+ {
65
+ CHECK;
66
+ return value(THIS->min_width());
67
+ }
68
+
69
+ static
70
+ VALUE set_min_height(VALUE self, VALUE height)
71
+ {
72
+ CHECK;
73
+ THIS->set_min_height(to<int>(height));
74
+ return value(THIS->min_height());
75
+ }
76
+
77
+ static
78
+ VALUE min_height(VALUE self)
79
+ {
80
+ CHECK;
81
+ return value(THIS->min_height());
82
+ }
83
+
84
+ static
85
+ VALUE set_resize(VALUE self, VALUE resize)
86
+ {
87
+ CHECK;
88
+ THIS->set_resize(to<bool>(resize));
89
+ return value(THIS->is_resize());
90
+ }
91
+
92
+ static
93
+ VALUE is_resize(VALUE self)
94
+ {
95
+ CHECK;
96
+ return value(THIS->is_resize());
97
+ }
98
+
99
+ static
100
+ VALUE set_crop(VALUE self, VALUE crop)
101
+ {
102
+ CHECK;
103
+ THIS->set_crop(to<bool>(crop));
104
+ return value(THIS->is_crop());
105
+ }
106
+
107
+ static
108
+ VALUE is_crop(VALUE self)
109
+ {
110
+ CHECK;
111
+ return value(THIS->is_crop());
112
+ }
113
+
114
+ static
115
+ VALUE image(VALUE self)
116
+ {
117
+ CHECK;
118
+ const Rays::Image* img = THIS->image();
119
+ return img ? value(*img) : nil();
120
+ }
121
+
122
+ static
123
+ VALUE device_names(VALUE self)
124
+ {
125
+ auto names = Rays::get_camera_device_names();
126
+
127
+ std::vector<Value> v;
128
+ for (auto it = names.begin(), end = names.end(); it != end; ++it)
129
+ v.emplace_back(value(it->c_str()));
130
+ return value(v.size(), &v[0]);
131
+ }
132
+
133
+
134
+ static Class cCamera;
135
+
136
+ void
137
+ Init_camera ()
138
+ {
139
+ Module mRays = rb_define_module("Rays");
140
+
141
+ cCamera = rb_define_class_under(mRays, "Camera", rb_cObject);
142
+ rb_define_alloc_func(cCamera, alloc);
143
+ rb_define_private_method(cCamera, "setup", RUBY_METHOD_FUNC(setup), 5);
144
+ rb_define_method(cCamera, "start", RUBY_METHOD_FUNC(start), 0);
145
+ rb_define_method(cCamera, "stop", RUBY_METHOD_FUNC(stop), 0);
146
+ cCamera.define_method("active?", is_active);
147
+ rb_define_method(cCamera, "min_width=", RUBY_METHOD_FUNC(set_min_width), 1);
148
+ rb_define_method(cCamera, "min_width", RUBY_METHOD_FUNC(min_width), 0);
149
+ rb_define_method(cCamera, "min_height=", RUBY_METHOD_FUNC(set_min_height), 1);
150
+ rb_define_method(cCamera, "min_height", RUBY_METHOD_FUNC(min_height), 0);
151
+ rb_define_method(cCamera, "resize=", RUBY_METHOD_FUNC(set_resize), 1);
152
+ cCamera.define_method("resize?", is_resize);
153
+ rb_define_method(cCamera, "crop=", RUBY_METHOD_FUNC(set_crop), 1);
154
+ cCamera.define_method("crop?", is_crop);
155
+ rb_define_method(cCamera, "image", RUBY_METHOD_FUNC(image), 0);
156
+ rb_define_module_function(cCamera, "device_names", RUBY_METHOD_FUNC(device_names), 0);
157
+ }
158
+
159
+
160
+ namespace Rays
161
+ {
162
+
163
+
164
+ Class
165
+ camera_class ()
166
+ {
167
+ return cCamera;
168
+ }
169
+
170
+
171
+ }// Rays
@@ -198,9 +198,8 @@ Init_color ()
198
198
  rb_define_method(cColor, "blue", RUBY_METHOD_FUNC(get_blue), 0);
199
199
  rb_define_method(cColor, "alpha=", RUBY_METHOD_FUNC(set_alpha), 1);
200
200
  rb_define_method(cColor, "alpha", RUBY_METHOD_FUNC(get_alpha), 0);
201
-
202
- rb_define_function(cColor, "hsv", RUBY_METHOD_FUNC(hsv), -1);
203
- rb_define_function(cColor, "set_palette_color", RUBY_METHOD_FUNC(set_palette_color), -1);
201
+ rb_define_module_function(cColor, "hsv", RUBY_METHOD_FUNC(hsv), -1);
202
+ rb_define_module_function(cColor, "set_palette_color", RUBY_METHOD_FUNC(set_palette_color), -1);
204
203
  }
205
204
 
206
205
 
@@ -55,6 +55,33 @@ VALUE height(VALUE self)
55
55
  return value(THIS->get_height());
56
56
  }
57
57
 
58
+ static
59
+ VALUE ascent(VALUE self)
60
+ {
61
+ CHECK;
62
+ coord ascent = 0;
63
+ THIS->get_height(&ascent);
64
+ return value(ascent);
65
+ }
66
+
67
+ static
68
+ VALUE descent(VALUE self)
69
+ {
70
+ CHECK;
71
+ coord descent = 0;
72
+ THIS->get_height(NULL, &descent);
73
+ return value(descent);
74
+ }
75
+
76
+ static
77
+ VALUE leading(VALUE self)
78
+ {
79
+ CHECK;
80
+ coord leading = 0;
81
+ THIS->get_height(NULL, NULL, &leading);
82
+ return value(leading);
83
+ }
84
+
58
85
 
59
86
  static Class cFont;
60
87
 
@@ -70,6 +97,9 @@ Init_font ()
70
97
  rb_define_method(cFont, "size", RUBY_METHOD_FUNC(size), 0);
71
98
  rb_define_method(cFont, "width", RUBY_METHOD_FUNC(width), 1);
72
99
  rb_define_method(cFont, "height", RUBY_METHOD_FUNC(height), 0);
100
+ rb_define_method(cFont, "ascent", RUBY_METHOD_FUNC(ascent), 0);
101
+ rb_define_method(cFont, "descent", RUBY_METHOD_FUNC(descent), 0);
102
+ rb_define_method(cFont, "leading", RUBY_METHOD_FUNC(leading), 0);
73
103
  }
74
104
 
75
105
 
@@ -138,7 +138,7 @@ Init_image ()
138
138
  rb_define_method(cImage, "painter", RUBY_METHOD_FUNC(painter), 0);
139
139
  rb_define_method(cImage, "bitmap", RUBY_METHOD_FUNC(bitmap), 0);
140
140
  rb_define_method(cImage, "save", RUBY_METHOD_FUNC(save), 1);
141
- rb_define_function(cImage, "load", RUBY_METHOD_FUNC(load), -1);
141
+ rb_define_module_function(cImage, "load", RUBY_METHOD_FUNC(load), -1);
142
142
  }
143
143
 
144
144
 
@@ -9,6 +9,7 @@ void Init_color ();
9
9
  void Init_color_space ();
10
10
  void Init_matrix ();
11
11
 
12
+ void Init_painter ();
12
13
  void Init_polyline ();
13
14
  void Init_polygon_line ();
14
15
  void Init_polygon ();
@@ -16,8 +17,7 @@ void Init_bitmap ();
16
17
  void Init_image ();
17
18
  void Init_font ();
18
19
  void Init_shader ();
19
-
20
- void Init_painter ();
20
+ void Init_camera ();
21
21
 
22
22
  void Init_noise ();
23
23
 
@@ -41,6 +41,7 @@ extern "C" void
41
41
  Init_color_space();
42
42
  Init_matrix();
43
43
 
44
+ Init_painter();
44
45
  Init_polyline();
45
46
  Init_polygon_line();
46
47
  Init_polygon();
@@ -48,8 +49,7 @@ extern "C" void
48
49
  Init_image();
49
50
  Init_font();
50
51
  Init_shader();
51
-
52
- Init_painter();
52
+ Init_camera();
53
53
 
54
54
  Init_noise();
55
55
 
@@ -326,12 +326,7 @@ static
326
326
  VALUE set_stroke_cap(VALUE self, VALUE cap)
327
327
  {
328
328
  CHECK;
329
-
330
- int type = to<int>(cap);
331
- if (type < 0 || Rays::CAP_MAX <= type)
332
- argument_error(__FILE__, __LINE__, "invalid stroke cap -- %d", type);
333
-
334
- THIS->set_stroke_cap((Rays::CapType) type);
329
+ THIS->set_stroke_cap(to<Rays::CapType>(cap));
335
330
  return self;
336
331
  }
337
332
 
@@ -346,12 +341,7 @@ static
346
341
  VALUE set_stroke_join(VALUE self, VALUE join)
347
342
  {
348
343
  CHECK;
349
-
350
- int type = to<int>(join);
351
- if (type < 0 || Rays::JOIN_MAX <= type)
352
- argument_error(__FILE__, __LINE__, "invalid stroke join -- %d", type);
353
-
354
- THIS->set_stroke_join((Rays::JoinType) type);
344
+ THIS->set_stroke_join(to<Rays::JoinType>(join));
355
345
  return self;
356
346
  }
357
347
 
@@ -238,6 +238,18 @@ VALUE inspect(VALUE self)
238
238
  return value(Xot::stringf("#<Rays::Point %s>", THIS->inspect().c_str()));
239
239
  }
240
240
 
241
+ static
242
+ VALUE dot(VALUE self, VALUE p1, VALUE p2)
243
+ {
244
+ return value(Rays::dot(to<Rays::Point>(p1), to<Rays::Point>(p2)));
245
+ }
246
+
247
+ static
248
+ VALUE cross(VALUE self, VALUE p1, VALUE p2)
249
+ {
250
+ return value(Rays::cross(to<Rays::Point>(p1), to<Rays::Point>(p2)));
251
+ }
252
+
241
253
 
242
254
  static Class cPoint;
243
255
 
@@ -271,6 +283,8 @@ Init_point ()
271
283
  cPoint.define_method("[]=", set_at);
272
284
  cPoint.define_method("[]", get_at);
273
285
  rb_define_method(cPoint, "inspect", RUBY_METHOD_FUNC(inspect), 0);
286
+ rb_define_module_function(cPoint, "dot", RUBY_METHOD_FUNC(dot), 2);
287
+ rb_define_module_function(cPoint, "cross", RUBY_METHOD_FUNC(cross), 2);
274
288
  }
275
289
 
276
290
 
@@ -74,7 +74,7 @@ VALUE empty(VALUE self)
74
74
  }
75
75
 
76
76
  static
77
- VALUE at(VALUE self, VALUE index)
77
+ VALUE get_at(VALUE self, VALUE index)
78
78
  {
79
79
  CHECK;
80
80
 
@@ -93,7 +93,7 @@ VALUE each(VALUE self)
93
93
  {
94
94
  CHECK;
95
95
 
96
- Value ret;
96
+ Value ret = Qnil;
97
97
  for (const auto& line : *THIS)
98
98
  ret = rb_yield(value(line));
99
99
  return ret;
@@ -244,7 +244,7 @@ Init_polygon ()
244
244
  rb_define_method(cPolygon, "bounds", RUBY_METHOD_FUNC(bounds), 0);
245
245
  rb_define_method(cPolygon, "size", RUBY_METHOD_FUNC(size), 0);
246
246
  cPolygon.define_method("empty?", empty);
247
- cPolygon.define_method("[]", at);
247
+ cPolygon.define_method("[]", get_at);
248
248
  rb_define_method(cPolygon, "each", RUBY_METHOD_FUNC(each), 0);
249
249
  cPolygon.define_method("+", op_or);
250
250
  cPolygon.define_method("-", op_sub);
@@ -76,7 +76,7 @@ VALUE empty(VALUE self)
76
76
  }
77
77
 
78
78
  static
79
- VALUE at(VALUE self, VALUE index)
79
+ VALUE get_at(VALUE self, VALUE index)
80
80
  {
81
81
  CHECK;
82
82
 
@@ -95,7 +95,7 @@ VALUE each(VALUE self)
95
95
  {
96
96
  CHECK;
97
97
 
98
- Value ret;
98
+ Value ret = Qnil;
99
99
  for (const auto& point : *THIS)
100
100
  ret = rb_yield(value(point));
101
101
  return ret;
@@ -117,7 +117,7 @@ Init_polyline ()
117
117
  cPolyline.define_method("loop?", loop);
118
118
  rb_define_method(cPolyline, "size", RUBY_METHOD_FUNC(size), 0);
119
119
  cPolyline.define_method("empty?", empty);
120
- cPolyline.define_method("[]", at);
120
+ cPolyline.define_method("[]", get_at);
121
121
  rb_define_method(cPolyline, "each", RUBY_METHOD_FUNC(each), 0);
122
122
  }
123
123
 
@@ -1,43 +1,33 @@
1
1
  #include "rays/ruby/rays.h"
2
2
 
3
3
 
4
+ #include <vector>
4
5
  #include "defs.h"
5
6
 
6
7
 
7
- RUCY_DEFINE_VALUE_OR_ARRAY_TO(Rays::CapType)
8
- RUCY_DEFINE_VALUE_OR_ARRAY_TO(Rays::JoinType)
8
+ RUCY_DEFINE_CONVERT_TO(Rays::CapType)
9
+ RUCY_DEFINE_CONVERT_TO(Rays::JoinType)
9
10
 
10
11
 
11
- static struct CapTypeEnum
12
+ template <typename T>
13
+ struct EnumType
12
14
  {
13
15
  const char* name;
14
- Rays::CapType type;
15
- }
16
- CAP_TYPES[] =
17
- {
18
- {"CAP_BUTT", Rays::CAP_BUTT},
19
- {"CAP_ROUND", Rays::CAP_ROUND},
20
- {"CAP_SQUARE", Rays::CAP_SQUARE},
16
+ const char* short_name;
17
+ T type;
21
18
  };
22
19
 
23
- static const size_t CAP_TYPES_SIZE =
24
- sizeof(CAP_TYPES) / sizeof(CAP_TYPES[0]);
25
-
26
-
27
- static struct JoinTypeEnum
28
- {
29
- const char* name;
30
- Rays::JoinType type;
31
- }
32
- JOIN_TYPES[] =
33
- {
34
- {"JOIN_MITER", Rays::JOIN_MITER},
35
- {"JOIN_ROUND", Rays::JOIN_ROUND},
36
- {"JOIN_SQUARE", Rays::JOIN_SQUARE},
37
- };
20
+ static std::vector<EnumType<Rays::CapType>> CAP_TYPES({
21
+ {"CAP_BUTT", "BUTT", Rays::CAP_BUTT},
22
+ {"CAP_ROUND", "ROUND", Rays::CAP_ROUND},
23
+ {"CAP_SQUARE", "SQUARE", Rays::CAP_SQUARE},
24
+ });
38
25
 
39
- static const size_t JOIN_TYPES_SIZE =
40
- sizeof(JOIN_TYPES) / sizeof(JOIN_TYPES[0]);
26
+ static std::vector<EnumType<Rays::JoinType>> JOIN_TYPES({
27
+ {"JOIN_MITER", "MITER", Rays::JOIN_MITER},
28
+ {"JOIN_ROUND", "ROUND", Rays::JOIN_ROUND},
29
+ {"JOIN_SQUARE", "SQUARE", Rays::JOIN_SQUARE},
30
+ });
41
31
 
42
32
 
43
33
  static
@@ -65,11 +55,11 @@ Init_rays ()
65
55
  mRays.define_singleton_method("init!", init);
66
56
  mRays.define_singleton_method("fin!", fin);
67
57
 
68
- for (size_t i = 0; i < CAP_TYPES_SIZE; ++i)
69
- mRays.define_const(CAP_TYPES[i].name, CAP_TYPES[i].type);
58
+ for (auto it = CAP_TYPES.begin(); it != CAP_TYPES.end(); ++it)
59
+ mRays.define_const(it->name, it->type);
70
60
 
71
- for (size_t i = 0; i < JOIN_TYPES_SIZE; ++i)
72
- mRays.define_const(JOIN_TYPES[i].name, JOIN_TYPES[i].type);
61
+ for (auto it = JOIN_TYPES.begin(); it != JOIN_TYPES.end(); ++it)
62
+ mRays.define_const(it->name, it->type);
73
63
  }
74
64
 
75
65
 
@@ -87,16 +77,21 @@ namespace Rucy
87
77
  if (argv->is_s() || argv->is_sym())
88
78
  {
89
79
  const char* str = argv->c_str();
90
- for (size_t i = 0; i < CAP_TYPES_SIZE; ++i)
80
+ for (auto it = CAP_TYPES.begin(); it != CAP_TYPES.end(); ++it)
91
81
  {
92
- if (strcasecmp(str, CAP_TYPES[i].name) == 0)
93
- return CAP_TYPES[i].type;
82
+ if (
83
+ strcasecmp(str, it->name) == 0 ||
84
+ strcasecmp(str, it->short_name) == 0)
85
+ {
86
+ return it->type;
87
+ }
94
88
  }
89
+ argument_error(__FILE__, __LINE__, "invalid cap type -- %s", str);
95
90
  }
96
91
  }
97
92
 
98
- uint type = value_to<uint>(*argv, convert);
99
- if (type >= Rays::CAP_MAX)
93
+ int type = value_to<int>(*argv, convert);
94
+ if (type < 0 || Rays::CAP_MAX <= type)
100
95
  argument_error(__FILE__, __LINE__, "invalid cap type -- %d", type);
101
96
 
102
97
  return (Rays::CapType) type;
@@ -113,16 +108,21 @@ namespace Rucy
113
108
  if (argv->is_s() || argv->is_sym())
114
109
  {
115
110
  const char* str = argv->c_str();
116
- for (size_t i = 0; i < JOIN_TYPES_SIZE; ++i)
111
+ for (auto it = JOIN_TYPES.begin(); it != JOIN_TYPES.end(); ++it)
117
112
  {
118
- if (strcasecmp(str, JOIN_TYPES[i].name) == 0)
119
- return JOIN_TYPES[i].type;
113
+ if (
114
+ strcasecmp(str, it->name) == 0 ||
115
+ strcasecmp(str, it->short_name) == 0)
116
+ {
117
+ return it->type;
118
+ }
120
119
  }
120
+ argument_error(__FILE__, __LINE__, "invalid join type -- %s", str);
121
121
  }
122
122
  }
123
123
 
124
- uint type = value_to<uint>(*argv, convert);
125
- if (type >= Rays::JOIN_MAX)
124
+ int type = value_to<int>(*argv, convert);
125
+ if (type < 0 || Rays::JOIN_MAX <= type)
126
126
  argument_error(__FILE__, __LINE__, "invalid join type -- %d", type);
127
127
 
128
128
  return (Rays::JoinType) type;