rays 0.1.13 → 0.1.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/rays/camera.cpp +171 -0
  3. data/.doc/ext/rays/color.cpp +2 -3
  4. data/.doc/ext/rays/color_space.cpp +22 -14
  5. data/.doc/ext/rays/font.cpp +30 -0
  6. data/.doc/ext/rays/image.cpp +1 -1
  7. data/.doc/ext/rays/native.cpp +4 -4
  8. data/.doc/ext/rays/painter.cpp +83 -0
  9. data/.doc/ext/rays/point.cpp +14 -0
  10. data/.doc/ext/rays/polygon.cpp +33 -7
  11. data/.doc/ext/rays/polyline.cpp +12 -6
  12. data/.doc/ext/rays/rays.cpp +105 -1
  13. data/LICENSE +21 -0
  14. data/Rakefile +3 -0
  15. data/VERSION +1 -1
  16. data/ext/rays/bitmap.cpp +1 -1
  17. data/ext/rays/camera.cpp +186 -0
  18. data/ext/rays/color.cpp +2 -3
  19. data/ext/rays/color_space.cpp +22 -14
  20. data/ext/rays/extconf.rb +1 -1
  21. data/ext/rays/font.cpp +35 -2
  22. data/ext/rays/image.cpp +2 -2
  23. data/ext/rays/native.cpp +4 -4
  24. data/ext/rays/painter.cpp +94 -3
  25. data/ext/rays/point.cpp +16 -0
  26. data/ext/rays/polygon.cpp +34 -6
  27. data/ext/rays/polyline.cpp +11 -5
  28. data/ext/rays/rays.cpp +105 -1
  29. data/include/rays/camera.h +74 -0
  30. data/include/rays/color_space.h +4 -2
  31. data/include/rays/defs.h +33 -0
  32. data/include/rays/exception.h +6 -2
  33. data/include/rays/image.h +1 -1
  34. data/include/rays/painter.h +38 -0
  35. data/include/rays/polygon.h +35 -1
  36. data/include/rays/polyline.h +7 -1
  37. data/include/rays/ruby/camera.h +41 -0
  38. data/include/rays/ruby/rays.h +8 -0
  39. data/lib/rays.rb +2 -2
  40. data/lib/rays/camera.rb +24 -0
  41. data/lib/rays/image.rb +1 -1
  42. data/lib/rays/painter.rb +23 -1
  43. data/lib/rays/polygon.rb +8 -0
  44. data/rays.gemspec +2 -2
  45. data/src/color_space.cpp +2 -2
  46. data/src/image.cpp +1 -1
  47. data/src/ios/bitmap.h +23 -0
  48. data/src/ios/bitmap.mm +32 -11
  49. data/src/ios/camera.mm +517 -0
  50. data/src/ios/font.mm +2 -2
  51. data/src/ios/helper.h +2 -2
  52. data/src/osx/bitmap.h +23 -0
  53. data/src/osx/bitmap.mm +28 -10
  54. data/src/osx/camera.mm +452 -0
  55. data/src/osx/font.mm +2 -2
  56. data/src/painter.cpp +100 -10
  57. data/src/polygon.cpp +203 -37
  58. data/src/polyline.cpp +4 -2
  59. data/src/polyline.h +3 -1
  60. data/test/test_font.rb +5 -0
  61. data/test/test_painter.rb +65 -5
  62. data/test/test_painter_shape.rb +48 -3
  63. data/test/test_point.rb +8 -0
  64. data/test/test_polyline.rb +26 -0
  65. metadata +20 -9
@@ -1,7 +1,35 @@
1
- #include "rays/rays.h"
1
+ #include "rays/ruby/rays.h"
2
+
3
+
4
+ #include <vector>
2
5
  #include "defs.h"
3
6
 
4
7
 
8
+ RUCY_DEFINE_CONVERT_TO(Rays::CapType)
9
+ RUCY_DEFINE_CONVERT_TO(Rays::JoinType)
10
+
11
+
12
+ template <typename T>
13
+ struct EnumType
14
+ {
15
+ const char* name;
16
+ const char* short_name;
17
+ T type;
18
+ };
19
+
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
+ });
25
+
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
+ });
31
+
32
+
5
33
  static
6
34
  RUCY_DEF0(init)
7
35
  {
@@ -25,11 +53,87 @@ void
25
53
  Init_rays ()
26
54
  {
27
55
  mRays = define_module("Rays");
56
+
28
57
  mRays.define_singleton_method("init!", init);
29
58
  mRays.define_singleton_method("fin!", fin);
59
+
60
+ for (auto it = CAP_TYPES.begin(); it != CAP_TYPES.end(); ++it)
61
+ mRays.define_const(it->name, it->type);
62
+
63
+ for (auto it = JOIN_TYPES.begin(); it != JOIN_TYPES.end(); ++it)
64
+ mRays.define_const(it->name, it->type);
30
65
  }
31
66
 
32
67
 
68
+ namespace Rucy
69
+ {
70
+
71
+
72
+ template <> Rays::CapType
73
+ value_to<Rays::CapType> (int argc, const Value* argv, bool convert)
74
+ {
75
+ assert(argc > 0 && argv);
76
+
77
+ if (convert)
78
+ {
79
+ if (argv->is_s() || argv->is_sym())
80
+ {
81
+ const char* str = argv->c_str();
82
+ for (auto it = CAP_TYPES.begin(); it != CAP_TYPES.end(); ++it)
83
+ {
84
+ if (
85
+ strcasecmp(str, it->name) == 0 ||
86
+ strcasecmp(str, it->short_name) == 0)
87
+ {
88
+ return it->type;
89
+ }
90
+ }
91
+ argument_error(__FILE__, __LINE__, "invalid cap type -- %s", str);
92
+ }
93
+ }
94
+
95
+ int type = value_to<int>(*argv, convert);
96
+ if (type < 0 || Rays::CAP_MAX <= type)
97
+ argument_error(__FILE__, __LINE__, "invalid cap type -- %d", type);
98
+
99
+ return (Rays::CapType) type;
100
+ }
101
+
102
+
103
+ template <> Rays::JoinType
104
+ value_to<Rays::JoinType> (int argc, const Value* argv, bool convert)
105
+ {
106
+ assert(argc > 0 && argv);
107
+
108
+ if (convert)
109
+ {
110
+ if (argv->is_s() || argv->is_sym())
111
+ {
112
+ const char* str = argv->c_str();
113
+ for (auto it = JOIN_TYPES.begin(); it != JOIN_TYPES.end(); ++it)
114
+ {
115
+ if (
116
+ strcasecmp(str, it->name) == 0 ||
117
+ strcasecmp(str, it->short_name) == 0)
118
+ {
119
+ return it->type;
120
+ }
121
+ }
122
+ argument_error(__FILE__, __LINE__, "invalid join type -- %s", str);
123
+ }
124
+ }
125
+
126
+ int type = value_to<int>(*argv, convert);
127
+ if (type < 0 || Rays::JOIN_MAX <= type)
128
+ argument_error(__FILE__, __LINE__, "invalid join type -- %d", type);
129
+
130
+ return (Rays::JoinType) type;
131
+ }
132
+
133
+
134
+ }// Rucy
135
+
136
+
33
137
  namespace Rays
34
138
  {
35
139
 
@@ -0,0 +1,74 @@
1
+ // -*- mode: c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_CAMERA_H__
4
+ #define __RAYS_CAMERA_H__
5
+
6
+
7
+ #include <vector>
8
+ #include <xot/pimpl.h>
9
+ #include <rays/defs.h>
10
+ #include <rays/image.h>
11
+
12
+
13
+ namespace Rays
14
+ {
15
+
16
+
17
+ class Camera
18
+ {
19
+
20
+ typedef Camera This;
21
+
22
+ public:
23
+
24
+ Camera (
25
+ const char* device_name = NULL,
26
+ int min_width = -1,
27
+ int min_height = -1,
28
+ bool resize = true,
29
+ bool crop = true);
30
+
31
+ ~Camera ();
32
+
33
+ bool start ();
34
+
35
+ void stop ();
36
+
37
+ bool is_active () const;
38
+
39
+ void set_min_width (int width);
40
+
41
+ int min_width () const;
42
+
43
+ void set_min_height (int height);
44
+
45
+ int min_height () const;
46
+
47
+ void set_resize (bool resize = true);
48
+
49
+ bool is_resize () const;
50
+
51
+ void set_crop (bool crop = true);
52
+
53
+ bool is_crop () const;
54
+
55
+ const Image* image () const;
56
+
57
+ operator bool () const;
58
+
59
+ bool operator ! () const;
60
+
61
+ struct Data;
62
+
63
+ Xot::PSharedImpl<Data> self;
64
+
65
+ };// Camera
66
+
67
+
68
+ std::vector<String> get_camera_device_names ();
69
+
70
+
71
+ }// Rays
72
+
73
+
74
+ #endif//EOH
@@ -14,7 +14,7 @@ namespace Rays
14
14
  enum ColorSpaceType
15
15
  {
16
16
 
17
- COLORSPACE_UNKNOWN = Xot::UNKNOWN,
17
+ COLORSPACE_UNKNOWN = 0,
18
18
 
19
19
  GRAY_8, GRAY_16, GRAY_24, GRAY_32, GRAY_float,
20
20
 
@@ -28,7 +28,7 @@ namespace Rays
28
28
 
29
29
  BGR_float, BGRA_float, ABGR_float,
30
30
 
31
- COLORSPACE_LAST,
31
+ COLORSPACE_MAX,
32
32
 
33
33
  GRAY = GRAY_8,
34
34
 
@@ -40,6 +40,8 @@ namespace Rays
40
40
 
41
41
  BGRA = BGRA_8888, BGRX = BGRX_8888, ABGR = ABGR_8888, XBGR = XBGR_8888,
42
42
 
43
+ DEFAULT_COLOR_SPACE = RGBA
44
+
43
45
  };// ColorSpaceType
44
46
 
45
47
 
@@ -23,6 +23,39 @@ namespace Rays
23
23
  typedef float coord;
24
24
 
25
25
 
26
+ enum CapType
27
+ {
28
+
29
+ CAP_BUTT = 0,
30
+
31
+ CAP_ROUND,
32
+
33
+ CAP_SQUARE,
34
+
35
+ CAP_MAX,
36
+
37
+ CAP_DEFAULT = CAP_BUTT
38
+
39
+ };// CapType
40
+
41
+
42
+ enum JoinType
43
+ {
44
+
45
+ JOIN_MITER = 0,
46
+
47
+ JOIN_ROUND,
48
+
49
+ JOIN_SQUARE,
50
+
51
+ JOIN_MAX,
52
+
53
+ JOIN_DEFAULT = JOIN_MITER,
54
+ JOIN_DEFAULT_MITER_LIMIT = 2
55
+
56
+ };// JoinType
57
+
58
+
26
59
  }// Rays
27
60
 
28
61
 
@@ -31,9 +31,13 @@ namespace Rays
31
31
 
32
32
  using namespace Xot::ErrorFunctions;
33
33
 
34
- void rays_error (const char* file, int line, const char* format = NULL, ...);
34
+ [[noreturn]]
35
+ void rays_error (
36
+ const char* file, int line, const char* format = NULL, ...);
35
37
 
36
- void opengl_error (const char* file, int line, const char* format = NULL, ...);
38
+ [[noreturn]]
39
+ void opengl_error (
40
+ const char* file, int line, const char* format = NULL, ...);
37
41
 
38
42
  }// ErrorFunctions
39
43
 
@@ -26,7 +26,7 @@ namespace Rays
26
26
  Image ();
27
27
 
28
28
  Image (
29
- int width, int height, const ColorSpace& cs = RGBA,
29
+ int width, int height, const ColorSpace& cs = DEFAULT_COLOR_SPACE,
30
30
  float pixel_density = 1);
31
31
 
32
32
  Image (const Bitmap& bitmap, float pixel_density = 1);
@@ -106,6 +106,32 @@ namespace Rays
106
106
  const Point& hole_radius = 0,
107
107
  float angle_from = 0, float angle_to = 360);
108
108
 
109
+ void curve (
110
+ coord x1, coord y1, coord x2, coord y2,
111
+ coord x3, coord y3, coord x4, coord y4,
112
+ bool loop = false);
113
+
114
+ void curve (
115
+ const Point& p1, const Point& p2, const Point& p3, const Point& p4,
116
+ bool loop = false);
117
+
118
+ void curve (
119
+ const Point* points, size_t size,
120
+ bool loop = false);
121
+
122
+ void bezier (
123
+ coord x1, coord y1, coord x2, coord y2,
124
+ coord x3, coord y3, coord x4, coord y4,
125
+ bool loop = false);
126
+
127
+ void bezier (
128
+ const Point& p1, const Point& p2, const Point& p3, const Point& p4,
129
+ bool loop = false);
130
+
131
+ void bezier (
132
+ const Point* points, size_t size,
133
+ bool loop = false);
134
+
109
135
  void image (
110
136
  const Image& image, coord x = 0, coord y = 0);
111
137
 
@@ -176,6 +202,18 @@ namespace Rays
176
202
 
177
203
  coord stroke_width () const;
178
204
 
205
+ void set_stroke_cap (CapType cap);
206
+
207
+ CapType stroke_cap () const;
208
+
209
+ void set_stroke_join (JoinType join);
210
+
211
+ JoinType stroke_join () const;
212
+
213
+ void set_miter_limit (coord limit);
214
+
215
+ coord miter_limit () const;
216
+
179
217
  void set_nsegment (int nsegment);
180
218
 
181
219
  uint nsegment () const;
@@ -6,6 +6,7 @@
6
6
 
7
7
  #include <vector>
8
8
  #include <xot/pimpl.h>
9
+ #include <rays/defs.h>
9
10
  #include <rays/bounds.h>
10
11
  #include <rays/polyline.h>
11
12
 
@@ -61,7 +62,12 @@ namespace Rays
61
62
 
62
63
  ~Polygon ();
63
64
 
64
- bool expand (Polygon* result, coord width) const;
65
+ bool expand (
66
+ Polygon* result,
67
+ coord width,
68
+ CapType cap = CAP_DEFAULT,
69
+ JoinType join = JOIN_DEFAULT,
70
+ coord miter_limit = JOIN_DEFAULT_MITER_LIMIT) const;
65
71
 
66
72
  Bounds bounds () const;
67
73
 
@@ -158,6 +164,34 @@ namespace Rays
158
164
  uint nsegment = 0);
159
165
 
160
166
 
167
+ Polygon create_curve (
168
+ coord x1, coord y1, coord x2, coord y2,
169
+ coord x3, coord y3, coord x4, coord y4,
170
+ bool loop = false);
171
+
172
+ Polygon create_curve (
173
+ const Point& p1, const Point& p2, const Point& p3, const Point& p4,
174
+ bool loop = false);
175
+
176
+ Polygon create_curve (
177
+ const Point* points, size_t size,
178
+ bool loop = false);
179
+
180
+
181
+ Polygon create_bezier (
182
+ coord x1, coord y1, coord x2, coord y2,
183
+ coord x3, coord y3, coord x4, coord y4,
184
+ bool loop = false);
185
+
186
+ Polygon create_bezier (
187
+ const Point& p1, const Point& p2, const Point& p3, const Point& p4,
188
+ bool loop = false);
189
+
190
+ Polygon create_bezier (
191
+ const Point* points, size_t size,
192
+ bool loop = false);
193
+
194
+
161
195
  }// Rays
162
196
 
163
197
 
@@ -6,6 +6,7 @@
6
6
 
7
7
  #include <vector>
8
8
  #include <xot/pimpl.h>
9
+ #include <rays/defs.h>
9
10
  #include <rays/point.h>
10
11
  #include <rays/bounds.h>
11
12
 
@@ -32,7 +33,12 @@ namespace Rays
32
33
 
33
34
  ~Polyline ();
34
35
 
35
- bool expand (Polygon* result, coord width) const;
36
+ bool expand (
37
+ Polygon* result,
38
+ coord width,
39
+ CapType cap = CAP_DEFAULT,
40
+ JoinType join = JOIN_DEFAULT,
41
+ coord miter_limit = JOIN_DEFAULT_MITER_LIMIT) const;
36
42
 
37
43
  Bounds bounds () const;
38
44
 
@@ -0,0 +1,41 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_RUBY_CAMERA_H__
4
+ #define __RAYS_RUBY_CAMERA_H__
5
+
6
+
7
+ #include <rucy/rucy.h>
8
+ #include <rucy/class.h>
9
+ #include <rucy/extension.h>
10
+ #include <rays/camera.h>
11
+
12
+
13
+ namespace Rays
14
+ {
15
+
16
+
17
+ Rucy::Class camera_class ();
18
+ // class Rays::Camera
19
+
20
+
21
+ }// Rays
22
+
23
+
24
+ RUCY_DECLARE_VALUE_FROM_TO(Rays::Camera)
25
+
26
+
27
+ namespace Rucy
28
+ {
29
+
30
+
31
+ template <> inline Class
32
+ get_ruby_class<Rays::Camera> ()
33
+ {
34
+ return Rays::camera_class();
35
+ }
36
+
37
+
38
+ }// Rucy
39
+
40
+
41
+ #endif//EOH