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 +4 -4
- data/.doc/ext/rays/camera.cpp +88 -0
- data/.doc/ext/rays/color.cpp +2 -3
- data/.doc/ext/rays/font.cpp +30 -0
- data/.doc/ext/rays/image.cpp +1 -1
- data/.doc/ext/rays/native.cpp +4 -4
- data/.doc/ext/rays/painter.cpp +2 -12
- data/.doc/ext/rays/point.cpp +14 -0
- data/.doc/ext/rays/polygon.cpp +3 -3
- data/.doc/ext/rays/polyline.cpp +3 -3
- data/.doc/ext/rays/rays.cpp +41 -41
- data/VERSION +1 -1
- data/ext/rays/camera.cpp +94 -0
- data/ext/rays/color.cpp +2 -3
- data/ext/rays/extconf.rb +1 -1
- data/ext/rays/font.cpp +35 -2
- data/ext/rays/image.cpp +2 -2
- data/ext/rays/native.cpp +4 -4
- data/ext/rays/painter.cpp +2 -12
- data/ext/rays/point.cpp +16 -0
- data/ext/rays/polygon.cpp +3 -3
- data/ext/rays/polyline.cpp +3 -3
- data/ext/rays/rays.cpp +41 -41
- data/include/rays/camera.h +49 -0
- data/include/rays/exception.h +6 -2
- data/include/rays/ruby/camera.h +41 -0
- data/include/rays/ruby/rays.h +2 -2
- data/lib/rays.rb +2 -2
- data/lib/rays/camera.rb +21 -0
- data/src/image.cpp +1 -1
- data/src/ios/bitmap.h +21 -0
- data/src/ios/bitmap.mm +24 -7
- data/src/ios/camera.mm +236 -0
- data/src/osx/bitmap.h +21 -0
- data/src/osx/bitmap.mm +20 -6
- data/src/osx/camera.mm +236 -0
- data/src/painter.cpp +1 -1
- data/src/polygon.cpp +6 -2
- data/test/test_font.rb +5 -0
- data/test/test_painter.rb +65 -5
- data/test/test_point.rb +8 -0
- data/test/test_polyline.rb +26 -0
- metadata +15 -5
data/ext/rays/color.cpp
CHANGED
@@ -211,9 +211,8 @@ Init_color ()
|
|
211
211
|
cColor.define_method("blue", get_blue);
|
212
212
|
cColor.define_method("alpha=", set_alpha);
|
213
213
|
cColor.define_method("alpha", get_alpha);
|
214
|
-
|
215
|
-
cColor.
|
216
|
-
cColor.define_function("set_palette_color", set_palette_color);
|
214
|
+
cColor.define_module_function("hsv", hsv);
|
215
|
+
cColor.define_module_function("set_palette_color", set_palette_color);
|
217
216
|
}
|
218
217
|
|
219
218
|
|
data/ext/rays/extconf.rb
CHANGED
@@ -17,7 +17,7 @@ Xot::ExtConf.new Xot, Rucy, Rays do
|
|
17
17
|
headers << 'ruby.h'
|
18
18
|
local_libs << 'rucy'
|
19
19
|
libs.unshift 'gdi21', 'opengl32' if win32?
|
20
|
-
frameworks << 'AppKit' << 'OpenGL' if osx?
|
20
|
+
frameworks << 'AppKit' << 'OpenGL' << 'AVFoundation' if osx?
|
21
21
|
$LDFLAGS << ' -Wl,--out-implib=native.dll.a' if cygwin?
|
22
22
|
end
|
23
23
|
|
data/ext/rays/font.cpp
CHANGED
@@ -61,6 +61,36 @@ RUCY_DEF0(height)
|
|
61
61
|
}
|
62
62
|
RUCY_END
|
63
63
|
|
64
|
+
static
|
65
|
+
RUCY_DEF0(ascent)
|
66
|
+
{
|
67
|
+
CHECK;
|
68
|
+
coord ascent = 0;
|
69
|
+
THIS->get_height(&ascent);
|
70
|
+
return value(ascent);
|
71
|
+
}
|
72
|
+
RUCY_END
|
73
|
+
|
74
|
+
static
|
75
|
+
RUCY_DEF0(descent)
|
76
|
+
{
|
77
|
+
CHECK;
|
78
|
+
coord descent = 0;
|
79
|
+
THIS->get_height(NULL, &descent);
|
80
|
+
return value(descent);
|
81
|
+
}
|
82
|
+
RUCY_END
|
83
|
+
|
84
|
+
static
|
85
|
+
RUCY_DEF0(leading)
|
86
|
+
{
|
87
|
+
CHECK;
|
88
|
+
coord leading = 0;
|
89
|
+
THIS->get_height(NULL, NULL, &leading);
|
90
|
+
return value(leading);
|
91
|
+
}
|
92
|
+
RUCY_END
|
93
|
+
|
64
94
|
|
65
95
|
static Class cFont;
|
66
96
|
|
@@ -74,8 +104,11 @@ Init_font ()
|
|
74
104
|
cFont.define_private_method("initialize", initialize);
|
75
105
|
cFont.define_method("name", name);
|
76
106
|
cFont.define_method("size", size);
|
77
|
-
cFont.define_method("width",
|
78
|
-
cFont.define_method("height",
|
107
|
+
cFont.define_method("width", width);
|
108
|
+
cFont.define_method("height", height);
|
109
|
+
cFont.define_method("ascent", ascent);
|
110
|
+
cFont.define_method("descent", descent);
|
111
|
+
cFont.define_method("leading", leading);
|
79
112
|
}
|
80
113
|
|
81
114
|
|
data/ext/rays/image.cpp
CHANGED
@@ -142,14 +142,14 @@ Init_image ()
|
|
142
142
|
cImage.define_alloc_func(alloc);
|
143
143
|
cImage.define_private_method("initialize", initialize);
|
144
144
|
cImage.define_private_method("initialize_copy", initialize_copy);
|
145
|
-
cImage.define_method("width",
|
145
|
+
cImage.define_method("width", width);
|
146
146
|
cImage.define_method("height", height);
|
147
147
|
cImage.define_method("color_space", color_space);
|
148
148
|
cImage.define_method("pixel_density", pixel_density);
|
149
149
|
cImage.define_method("painter", painter);
|
150
150
|
cImage.define_method("bitmap", bitmap);
|
151
151
|
cImage.define_method("save", save);
|
152
|
-
cImage.
|
152
|
+
cImage.define_module_function("load", load);
|
153
153
|
}
|
154
154
|
|
155
155
|
|
data/ext/rays/native.cpp
CHANGED
@@ -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
|
|
data/ext/rays/painter.cpp
CHANGED
@@ -353,12 +353,7 @@ static
|
|
353
353
|
RUCY_DEF1(set_stroke_cap, cap)
|
354
354
|
{
|
355
355
|
CHECK;
|
356
|
-
|
357
|
-
int type = to<int>(cap);
|
358
|
-
if (type < 0 || Rays::CAP_MAX <= type)
|
359
|
-
argument_error(__FILE__, __LINE__, "invalid stroke cap -- %d", type);
|
360
|
-
|
361
|
-
THIS->set_stroke_cap((Rays::CapType) type);
|
356
|
+
THIS->set_stroke_cap(to<Rays::CapType>(cap));
|
362
357
|
return self;
|
363
358
|
}
|
364
359
|
RUCY_END
|
@@ -375,12 +370,7 @@ static
|
|
375
370
|
RUCY_DEF1(set_stroke_join, join)
|
376
371
|
{
|
377
372
|
CHECK;
|
378
|
-
|
379
|
-
int type = to<int>(join);
|
380
|
-
if (type < 0 || Rays::JOIN_MAX <= type)
|
381
|
-
argument_error(__FILE__, __LINE__, "invalid stroke join -- %d", type);
|
382
|
-
|
383
|
-
THIS->set_stroke_join((Rays::JoinType) type);
|
373
|
+
THIS->set_stroke_join(to<Rays::JoinType>(join));
|
384
374
|
return self;
|
385
375
|
}
|
386
376
|
RUCY_END
|
data/ext/rays/point.cpp
CHANGED
@@ -262,6 +262,20 @@ RUCY_DEF0(inspect)
|
|
262
262
|
}
|
263
263
|
RUCY_END
|
264
264
|
|
265
|
+
static
|
266
|
+
RUCY_DEF2(dot, p1, p2)
|
267
|
+
{
|
268
|
+
return value(Rays::dot(to<Rays::Point>(p1), to<Rays::Point>(p2)));
|
269
|
+
}
|
270
|
+
RUCY_END
|
271
|
+
|
272
|
+
static
|
273
|
+
RUCY_DEF2(cross, p1, p2)
|
274
|
+
{
|
275
|
+
return value(Rays::cross(to<Rays::Point>(p1), to<Rays::Point>(p2)));
|
276
|
+
}
|
277
|
+
RUCY_END
|
278
|
+
|
265
279
|
|
266
280
|
static Class cPoint;
|
267
281
|
|
@@ -295,6 +309,8 @@ Init_point ()
|
|
295
309
|
cPoint.define_method("[]=", set_at);
|
296
310
|
cPoint.define_method("[]", get_at);
|
297
311
|
cPoint.define_method("inspect", inspect);
|
312
|
+
cPoint.define_module_function("dot", dot);
|
313
|
+
cPoint.define_module_function("cross", cross);
|
298
314
|
}
|
299
315
|
|
300
316
|
|
data/ext/rays/polygon.cpp
CHANGED
@@ -80,7 +80,7 @@ RUCY_DEF0(empty)
|
|
80
80
|
RUCY_END
|
81
81
|
|
82
82
|
static
|
83
|
-
RUCY_DEF1(
|
83
|
+
RUCY_DEF1(get_at, index)
|
84
84
|
{
|
85
85
|
CHECK;
|
86
86
|
|
@@ -100,7 +100,7 @@ RUCY_DEF0(each)
|
|
100
100
|
{
|
101
101
|
CHECK;
|
102
102
|
|
103
|
-
Value ret;
|
103
|
+
Value ret = Qnil;
|
104
104
|
for (const auto& line : *THIS)
|
105
105
|
ret = rb_yield(value(line));
|
106
106
|
return ret;
|
@@ -260,7 +260,7 @@ Init_polygon ()
|
|
260
260
|
cPolygon.define_method("bounds", bounds);
|
261
261
|
cPolygon.define_method("size", size);
|
262
262
|
cPolygon.define_method("empty?", empty);
|
263
|
-
cPolygon.define_method("[]",
|
263
|
+
cPolygon.define_method("[]", get_at);
|
264
264
|
cPolygon.define_method("each", each);
|
265
265
|
cPolygon.define_method("+", op_or);
|
266
266
|
cPolygon.define_method("-", op_sub);
|
data/ext/rays/polyline.cpp
CHANGED
@@ -83,7 +83,7 @@ RUCY_DEF0(empty)
|
|
83
83
|
RUCY_END
|
84
84
|
|
85
85
|
static
|
86
|
-
RUCY_DEF1(
|
86
|
+
RUCY_DEF1(get_at, index)
|
87
87
|
{
|
88
88
|
CHECK;
|
89
89
|
|
@@ -103,7 +103,7 @@ RUCY_DEF0(each)
|
|
103
103
|
{
|
104
104
|
CHECK;
|
105
105
|
|
106
|
-
Value ret;
|
106
|
+
Value ret = Qnil;
|
107
107
|
for (const auto& point : *THIS)
|
108
108
|
ret = rb_yield(value(point));
|
109
109
|
return ret;
|
@@ -126,7 +126,7 @@ Init_polyline ()
|
|
126
126
|
cPolyline.define_method("loop?", loop);
|
127
127
|
cPolyline.define_method("size", size);
|
128
128
|
cPolyline.define_method("empty?", empty);
|
129
|
-
cPolyline.define_method("[]",
|
129
|
+
cPolyline.define_method("[]", get_at);
|
130
130
|
cPolyline.define_method("each", each);
|
131
131
|
}
|
132
132
|
|
data/ext/rays/rays.cpp
CHANGED
@@ -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
|
-
|
8
|
-
|
8
|
+
RUCY_DEFINE_CONVERT_TO(Rays::CapType)
|
9
|
+
RUCY_DEFINE_CONVERT_TO(Rays::JoinType)
|
9
10
|
|
10
11
|
|
11
|
-
|
12
|
+
template <typename T>
|
13
|
+
struct EnumType
|
12
14
|
{
|
13
15
|
const char* name;
|
14
|
-
|
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
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
40
|
-
|
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
|
@@ -67,11 +57,11 @@ Init_rays ()
|
|
67
57
|
mRays.define_singleton_method("init!", init);
|
68
58
|
mRays.define_singleton_method("fin!", fin);
|
69
59
|
|
70
|
-
for (
|
71
|
-
mRays.define_const(
|
60
|
+
for (auto it = CAP_TYPES.begin(); it != CAP_TYPES.end(); ++it)
|
61
|
+
mRays.define_const(it->name, it->type);
|
72
62
|
|
73
|
-
for (
|
74
|
-
mRays.define_const(
|
63
|
+
for (auto it = JOIN_TYPES.begin(); it != JOIN_TYPES.end(); ++it)
|
64
|
+
mRays.define_const(it->name, it->type);
|
75
65
|
}
|
76
66
|
|
77
67
|
|
@@ -89,16 +79,21 @@ namespace Rucy
|
|
89
79
|
if (argv->is_s() || argv->is_sym())
|
90
80
|
{
|
91
81
|
const char* str = argv->c_str();
|
92
|
-
for (
|
82
|
+
for (auto it = CAP_TYPES.begin(); it != CAP_TYPES.end(); ++it)
|
93
83
|
{
|
94
|
-
if (
|
95
|
-
|
84
|
+
if (
|
85
|
+
strcasecmp(str, it->name) == 0 ||
|
86
|
+
strcasecmp(str, it->short_name) == 0)
|
87
|
+
{
|
88
|
+
return it->type;
|
89
|
+
}
|
96
90
|
}
|
91
|
+
argument_error(__FILE__, __LINE__, "invalid cap type -- %s", str);
|
97
92
|
}
|
98
93
|
}
|
99
94
|
|
100
|
-
|
101
|
-
if (type
|
95
|
+
int type = value_to<int>(*argv, convert);
|
96
|
+
if (type < 0 || Rays::CAP_MAX <= type)
|
102
97
|
argument_error(__FILE__, __LINE__, "invalid cap type -- %d", type);
|
103
98
|
|
104
99
|
return (Rays::CapType) type;
|
@@ -115,16 +110,21 @@ namespace Rucy
|
|
115
110
|
if (argv->is_s() || argv->is_sym())
|
116
111
|
{
|
117
112
|
const char* str = argv->c_str();
|
118
|
-
for (
|
113
|
+
for (auto it = JOIN_TYPES.begin(); it != JOIN_TYPES.end(); ++it)
|
119
114
|
{
|
120
|
-
if (
|
121
|
-
|
115
|
+
if (
|
116
|
+
strcasecmp(str, it->name) == 0 ||
|
117
|
+
strcasecmp(str, it->short_name) == 0)
|
118
|
+
{
|
119
|
+
return it->type;
|
120
|
+
}
|
122
121
|
}
|
122
|
+
argument_error(__FILE__, __LINE__, "invalid join type -- %s", str);
|
123
123
|
}
|
124
124
|
}
|
125
125
|
|
126
|
-
|
127
|
-
if (type
|
126
|
+
int type = value_to<int>(*argv, convert);
|
127
|
+
if (type < 0 || Rays::JOIN_MAX <= type)
|
128
128
|
argument_error(__FILE__, __LINE__, "invalid join type -- %d", type);
|
129
129
|
|
130
130
|
return (Rays::JoinType) type;
|
@@ -0,0 +1,49 @@
|
|
1
|
+
// -*- mode: c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RAYS_CAMERA_H__
|
4
|
+
#define __RAYS_CAMERA_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <xot/pimpl.h>
|
8
|
+
#include <rays/defs.h>
|
9
|
+
#include <rays/image.h>
|
10
|
+
|
11
|
+
|
12
|
+
namespace Rays
|
13
|
+
{
|
14
|
+
|
15
|
+
|
16
|
+
class Camera
|
17
|
+
{
|
18
|
+
|
19
|
+
typedef Camera This;
|
20
|
+
|
21
|
+
public:
|
22
|
+
|
23
|
+
Camera ();
|
24
|
+
|
25
|
+
~Camera ();
|
26
|
+
|
27
|
+
bool start ();
|
28
|
+
|
29
|
+
void stop ();
|
30
|
+
|
31
|
+
bool is_active () const;
|
32
|
+
|
33
|
+
const Image* image () const;
|
34
|
+
|
35
|
+
operator bool () const;
|
36
|
+
|
37
|
+
bool operator ! () const;
|
38
|
+
|
39
|
+
struct Data;
|
40
|
+
|
41
|
+
Xot::PSharedImpl<Data> self;
|
42
|
+
|
43
|
+
};// Camera
|
44
|
+
|
45
|
+
|
46
|
+
}// Rays
|
47
|
+
|
48
|
+
|
49
|
+
#endif//EOH
|
data/include/rays/exception.h
CHANGED
@@ -31,9 +31,13 @@ namespace Rays
|
|
31
31
|
|
32
32
|
using namespace Xot::ErrorFunctions;
|
33
33
|
|
34
|
-
|
34
|
+
[[noreturn]]
|
35
|
+
void rays_error (
|
36
|
+
const char* file, int line, const char* format = NULL, ...);
|
35
37
|
|
36
|
-
|
38
|
+
[[noreturn]]
|
39
|
+
void opengl_error (
|
40
|
+
const char* file, int line, const char* format = NULL, ...);
|
37
41
|
|
38
42
|
}// ErrorFunctions
|
39
43
|
|
@@ -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
|