rays 0.1.15 → 0.1.16

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: 257d69d9a622000399ced2465f798ffa54db2e1943cc9eeea9c1a0d3f40503c2
4
+ data.tar.gz: 302a565d951db2bdbb8d7fcf114fc26064ed55e9b1936f7683f24b77975d70d9
5
5
  SHA512:
6
- metadata.gz: 2a4771e03c225cd3f84c0d723ee3072d3a1403eec5028e38c1cc00ddda5e27dbd6ed4db14bee3fa9c8f412e49928cf4b9fd13f5cc5ae79b80149438dd3f9c96c
7
- data.tar.gz: 17567e4b335014d772f80f35c1a44859893605c65912469f00aac2ecc6f6a9a1c024d1303b42a24e78dd59b8797cc41f2af1b47627755250e74f5eac12dbc031
6
+ metadata.gz: 69618fc55b5fe15c1f13c49f4e52e468f734ceb874a5cffc0186747595ad0df06f096b63a2b6e6e8271327385373e1c9efe6b23954c94064e961d3e547658577
7
+ data.tar.gz: d0c8e174262e60747382005cefcc0c7ebf7a03d8300ea607976f861dcc0dbec61bff530aad0d890df4cfd05b116cc3b6f5d119a97be6c4e63e061dd89731b0df
@@ -0,0 +1,88 @@
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 initialize(VALUE self)
23
+ {
24
+ RUCY_CHECK_OBJ(Rays::Camera, self);
25
+
26
+ *THIS = Rays::Camera();
27
+ return self;
28
+ }
29
+
30
+ static
31
+ VALUE start(VALUE self)
32
+ {
33
+ CHECK;
34
+ return value(THIS->start());
35
+ }
36
+
37
+ static
38
+ VALUE stop(VALUE self)
39
+ {
40
+ CHECK;
41
+ THIS->stop();
42
+ }
43
+
44
+ static
45
+ VALUE is_active(VALUE self)
46
+ {
47
+ CHECK;
48
+ return value(THIS->is_active());
49
+ }
50
+
51
+ static
52
+ VALUE image(VALUE self)
53
+ {
54
+ CHECK;
55
+ const Rays::Image* img = THIS->image();
56
+ return img ? value(*img) : nil();
57
+ }
58
+
59
+
60
+ static Class cCamera;
61
+
62
+ void
63
+ Init_camera ()
64
+ {
65
+ Module mRays = rb_define_module("Rays");
66
+
67
+ cCamera = rb_define_class_under(mRays, "Camera", rb_cObject);
68
+ rb_define_alloc_func(cCamera, alloc);
69
+ rb_define_private_method(cCamera, "initialize", RUBY_METHOD_FUNC(initialize), -1);
70
+ rb_define_method(cCamera, "start", RUBY_METHOD_FUNC(start), 0);
71
+ rb_define_method(cCamera, "stop", RUBY_METHOD_FUNC(stop), 0);
72
+ cCamera.define_method("active?", is_active);
73
+ rb_define_method(cCamera, "image", RUBY_METHOD_FUNC(image), 0);
74
+ }
75
+
76
+
77
+ namespace Rays
78
+ {
79
+
80
+
81
+ Class
82
+ camera_class ()
83
+ {
84
+ return cCamera;
85
+ }
86
+
87
+
88
+ }// 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;
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.15
1
+ 0.1.16
@@ -0,0 +1,94 @@
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
+ RUCY_DEF_ALLOC(alloc, klass)
17
+ {
18
+ return new_type<Rays::Camera>(klass);
19
+ }
20
+ RUCY_END
21
+
22
+ static
23
+ RUCY_DEFN(initialize)
24
+ {
25
+ RUCY_CHECK_OBJ(Rays::Camera, self);
26
+
27
+ *THIS = Rays::Camera();
28
+ return self;
29
+ }
30
+ RUCY_END
31
+
32
+ static
33
+ RUCY_DEF0(start)
34
+ {
35
+ CHECK;
36
+ return value(THIS->start());
37
+ }
38
+ RUCY_END
39
+
40
+ static
41
+ RUCY_DEF0(stop)
42
+ {
43
+ CHECK;
44
+ THIS->stop();
45
+ }
46
+ RUCY_END
47
+
48
+ static
49
+ RUCY_DEF0(is_active)
50
+ {
51
+ CHECK;
52
+ return value(THIS->is_active());
53
+ }
54
+ RUCY_END
55
+
56
+ static
57
+ RUCY_DEF0(image)
58
+ {
59
+ CHECK;
60
+ const Rays::Image* img = THIS->image();
61
+ return img ? value(*img) : nil();
62
+ }
63
+ RUCY_END
64
+
65
+
66
+ static Class cCamera;
67
+
68
+ void
69
+ Init_camera ()
70
+ {
71
+ Module mRays = define_module("Rays");
72
+
73
+ cCamera = mRays.define_class("Camera");
74
+ cCamera.define_alloc_func(alloc);
75
+ cCamera.define_private_method("initialize", initialize);
76
+ cCamera.define_method("start", start);
77
+ cCamera.define_method("stop", stop);
78
+ cCamera.define_method("active?", is_active);
79
+ cCamera.define_method("image", image);
80
+ }
81
+
82
+
83
+ namespace Rays
84
+ {
85
+
86
+
87
+ Class
88
+ camera_class ()
89
+ {
90
+ return cCamera;
91
+ }
92
+
93
+
94
+ }// Rays