rays 0.1.12 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.doc/ext/rays/bitmap.cpp +22 -76
- data/.doc/ext/rays/bounds.cpp +95 -125
- data/.doc/ext/rays/color.cpp +224 -45
- data/.doc/ext/rays/color_space.cpp +137 -45
- data/.doc/ext/rays/defs.cpp +183 -0
- data/.doc/ext/rays/font.cpp +39 -21
- data/.doc/ext/rays/image.cpp +26 -37
- data/.doc/ext/rays/matrix.cpp +186 -29
- data/.doc/ext/rays/native.cpp +12 -6
- data/.doc/ext/rays/noise.cpp +53 -0
- data/.doc/ext/rays/painter.cpp +120 -308
- data/.doc/ext/rays/point.cpp +82 -77
- data/.doc/ext/rays/polygon.cpp +287 -0
- data/.doc/ext/rays/polygon_line.cpp +96 -0
- data/.doc/ext/rays/polyline.cpp +161 -0
- data/.doc/ext/rays/rays.cpp +0 -13
- data/.doc/ext/rays/shader.cpp +83 -9
- data/README.md +1 -1
- data/Rakefile +21 -9
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +22 -80
- data/ext/rays/bounds.cpp +100 -128
- data/ext/rays/color.cpp +232 -51
- data/ext/rays/color_space.cpp +140 -46
- data/ext/rays/defs.cpp +183 -0
- data/ext/rays/defs.h +26 -2
- data/ext/rays/extconf.rb +1 -2
- data/ext/rays/font.cpp +39 -22
- data/ext/rays/image.cpp +27 -39
- data/ext/rays/matrix.cpp +198 -30
- data/ext/rays/native.cpp +12 -6
- data/ext/rays/noise.cpp +55 -0
- data/ext/rays/painter.cpp +129 -315
- data/ext/rays/point.cpp +89 -81
- data/ext/rays/polygon.cpp +301 -0
- data/ext/rays/polygon_line.cpp +99 -0
- data/ext/rays/polyline.cpp +170 -0
- data/ext/rays/rays.cpp +0 -14
- data/ext/rays/shader.cpp +84 -9
- data/include/rays.h +10 -2
- data/include/rays/bitmap.h +14 -26
- data/include/rays/bounds.h +21 -4
- data/include/rays/color.h +25 -14
- data/include/rays/color_space.h +11 -8
- data/include/rays/coord.h +114 -0
- data/include/rays/debug.h +22 -0
- data/include/rays/defs.h +3 -0
- data/include/rays/font.h +4 -4
- data/include/rays/image.h +11 -17
- data/include/rays/matrix.h +50 -24
- data/include/rays/noise.h +42 -0
- data/include/rays/opengl.h +2 -50
- data/include/rays/painter.h +57 -99
- data/include/rays/point.h +44 -51
- data/include/rays/polygon.h +164 -0
- data/include/rays/polyline.h +65 -0
- data/include/rays/rays.h +3 -0
- data/include/rays/ruby.h +7 -1
- data/include/rays/ruby/bounds.h +1 -1
- data/include/rays/ruby/color.h +1 -1
- data/include/rays/ruby/color_space.h +1 -1
- data/include/rays/ruby/font.h +1 -1
- data/include/rays/ruby/matrix.h +1 -1
- data/include/rays/ruby/point.h +1 -1
- data/include/rays/ruby/polygon.h +52 -0
- data/include/rays/ruby/polyline.h +41 -0
- data/include/rays/ruby/shader.h +1 -1
- data/include/rays/shader.h +36 -8
- data/lib/rays.rb +6 -1
- data/lib/rays/bitmap.rb +0 -15
- data/lib/rays/bounds.rb +17 -23
- data/lib/rays/color.rb +20 -47
- data/lib/rays/color_space.rb +13 -13
- data/lib/rays/image.rb +2 -6
- data/lib/rays/matrix.rb +28 -0
- data/lib/rays/module.rb +4 -19
- data/lib/rays/painter.rb +60 -97
- data/lib/rays/point.rb +13 -21
- data/lib/rays/polygon.rb +50 -0
- data/lib/rays/polygon_line.rb +36 -0
- data/lib/rays/polyline.rb +32 -0
- data/lib/rays/shader.rb +20 -1
- data/rays.gemspec +5 -7
- data/src/bitmap.h +36 -0
- data/src/bounds.cpp +74 -11
- data/src/color.cpp +58 -23
- data/src/color_space.cpp +50 -32
- data/src/color_space.h +22 -0
- data/src/coord.cpp +170 -0
- data/src/coord.h +35 -0
- data/src/font.cpp +118 -0
- data/src/font.h +64 -0
- data/src/frame_buffer.cpp +37 -71
- data/src/frame_buffer.h +4 -4
- data/src/image.cpp +171 -97
- data/src/image.h +25 -0
- data/src/ios/bitmap.mm +107 -105
- data/src/ios/font.mm +48 -60
- data/src/ios/helper.h +2 -2
- data/src/ios/opengl.mm +19 -4
- data/src/ios/rays.mm +3 -0
- data/src/matrix.cpp +111 -26
- data/src/matrix.h +30 -0
- data/src/noise.cpp +74 -0
- data/src/opengl.cpp +9 -27
- data/src/opengl.h +37 -0
- data/src/osx/bitmap.mm +111 -106
- data/src/osx/font.mm +48 -61
- data/src/osx/helper.h +2 -2
- data/src/osx/opengl.mm +19 -83
- data/src/osx/rays.mm +3 -0
- data/src/painter.cpp +780 -696
- data/src/painter.h +24 -0
- data/src/point.cpp +140 -119
- data/src/polygon.cpp +1100 -0
- data/src/polygon.h +32 -0
- data/src/polyline.cpp +158 -0
- data/src/polyline.h +67 -0
- data/src/render_buffer.cpp +11 -4
- data/src/render_buffer.h +2 -2
- data/src/shader.cpp +163 -106
- data/src/shader.h +38 -0
- data/src/shader_program.cpp +533 -0
- data/src/{program.h → shader_program.h} +28 -16
- data/src/shader_source.cpp +140 -0
- data/src/shader_source.h +52 -0
- data/src/texture.cpp +136 -160
- data/src/texture.h +65 -0
- data/src/win32/bitmap.cpp +62 -52
- data/src/win32/font.cpp +11 -13
- data/src/win32/font.h +24 -0
- data/src/win32/gdi.h +6 -6
- data/test/helper.rb +0 -3
- data/test/test_bitmap.rb +31 -7
- data/test/test_bounds.rb +36 -0
- data/test/test_color.rb +59 -19
- data/test/test_color_space.rb +95 -0
- data/test/test_image.rb +24 -20
- data/test/test_matrix.rb +106 -0
- data/test/test_painter.rb +92 -46
- data/test/test_painter_shape.rb +57 -0
- data/test/test_point.rb +21 -0
- data/test/test_polygon.rb +234 -0
- data/test/test_polygon_line.rb +167 -0
- data/test/test_polyline.rb +145 -0
- data/test/test_shader.rb +9 -9
- metadata +88 -67
- data/.doc/ext/rays/texture.cpp +0 -138
- data/ext/rays/texture.cpp +0 -149
- data/include/rays/ruby/texture.h +0 -41
- data/include/rays/texture.h +0 -71
- data/lib/rays/texture.rb +0 -24
- data/src/program.cpp +0 -648
- data/test/test_texture.rb +0 -27
@@ -0,0 +1,183 @@
|
|
1
|
+
#include "defs.h"
|
2
|
+
|
3
|
+
|
4
|
+
#include <assert.h>
|
5
|
+
#include "rays/ruby/bounds.h"
|
6
|
+
#include "rays/ruby/point.h"
|
7
|
+
|
8
|
+
|
9
|
+
void
|
10
|
+
get_line_args (std::vector<Rays::Point>* points, int argc, const Value* argv)
|
11
|
+
{
|
12
|
+
assert(points && argv);
|
13
|
+
|
14
|
+
points->clear();
|
15
|
+
|
16
|
+
if (argc <= 0)
|
17
|
+
return;
|
18
|
+
|
19
|
+
if (argv[0].is_num())
|
20
|
+
{
|
21
|
+
if (argc % 2 != 0)
|
22
|
+
argument_error(__FILE__, __LINE__);
|
23
|
+
|
24
|
+
points->reserve(argc / 2);
|
25
|
+
for (int i = 0; i < argc; i += 2)
|
26
|
+
{
|
27
|
+
coord x = to<coord>(argv[i + 0]);
|
28
|
+
coord y = to<coord>(argv[i + 1]);
|
29
|
+
points->emplace_back(Rays::Point(x, y));
|
30
|
+
}
|
31
|
+
}
|
32
|
+
else
|
33
|
+
{
|
34
|
+
points->reserve(argc);
|
35
|
+
for (int i = 0; i < argc; ++i)
|
36
|
+
points->emplace_back(to<Rays::Point>(argv[i]));
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
static uint
|
41
|
+
get_nsegment (Value nsegment)
|
42
|
+
{
|
43
|
+
int value = nsegment ? to<int>(nsegment) : 0;
|
44
|
+
if (value < 0) value = 0;
|
45
|
+
return (uint) value;
|
46
|
+
}
|
47
|
+
|
48
|
+
void get_rect_args (
|
49
|
+
coord* x, coord* y, coord* w, coord* h,
|
50
|
+
coord* lt, coord* rt, coord* lb, coord* rb,
|
51
|
+
uint* nseg,
|
52
|
+
int argc, const Value* argv,
|
53
|
+
Value round, Value lefttop, Value righttop, Value leftbottom, Value rightbottom,
|
54
|
+
Value nsegment)
|
55
|
+
{
|
56
|
+
assert(x && y && w && h && lt && rt && lb && rb && nseg && argv);
|
57
|
+
|
58
|
+
if (argc <= 0)
|
59
|
+
argument_error(__FILE__, __LINE__);
|
60
|
+
|
61
|
+
if (argv[0].is_kind_of(Rays::bounds_class()))
|
62
|
+
{
|
63
|
+
Rays::Bounds& b = to<Rays::Bounds&>(argv[0]);
|
64
|
+
*x = b.x;
|
65
|
+
*y = b.y;
|
66
|
+
*w = b.w;
|
67
|
+
*h = b.h;
|
68
|
+
*lt = argc >= 2 ? to<coord>(argv[1]) : 0;
|
69
|
+
*rt = argc >= 3 ? to<coord>(argv[2]) : *lt;
|
70
|
+
*lb = argc >= 4 ? to<coord>(argv[3]) : *lt;
|
71
|
+
*rb = argc >= 5 ? to<coord>(argv[4]) : *lt;
|
72
|
+
}
|
73
|
+
else if (argv[0].is_kind_of(Rays::point_class()))
|
74
|
+
{
|
75
|
+
if (argc < 2)
|
76
|
+
argument_error(__FILE__, __LINE__);
|
77
|
+
|
78
|
+
Rays::Point& p = to<Rays::Point&>(argv[0]);
|
79
|
+
*x = p.x;
|
80
|
+
*y = p.y;
|
81
|
+
*w = to<coord>(argv[1]);
|
82
|
+
*h = argc >= 3 ? to<coord>(argv[2]) : *w;
|
83
|
+
*lt = argc >= 4 ? to<coord>(argv[3]) : 0;
|
84
|
+
*rt = argc >= 5 ? to<coord>(argv[4]) : *lt;
|
85
|
+
*lb = argc >= 6 ? to<coord>(argv[5]) : *lt;
|
86
|
+
*rb = argc >= 7 ? to<coord>(argv[6]) : *lt;
|
87
|
+
}
|
88
|
+
else if (argc <= 2)
|
89
|
+
{
|
90
|
+
*x = *y = *lt = *rt = *lb = *rb = 0;
|
91
|
+
*w = to<coord>(argv[0]);
|
92
|
+
*h = argc >= 2 ? to<coord>(argv[1]) : *w;
|
93
|
+
}
|
94
|
+
else
|
95
|
+
{
|
96
|
+
*x = to<coord>(argv[0]);
|
97
|
+
*y = to<coord>(argv[1]);
|
98
|
+
*w = to<coord>(argv[2]);
|
99
|
+
*h = argc >= 4 ? to<coord>(argv[3]) : *w;
|
100
|
+
*lt = argc >= 5 ? to<coord>(argv[4]) : 0;
|
101
|
+
*rt = argc >= 6 ? to<coord>(argv[5]) : *lt;
|
102
|
+
*lb = argc >= 7 ? to<coord>(argv[6]) : *lt;
|
103
|
+
*rb = argc >= 8 ? to<coord>(argv[7]) : *lt;
|
104
|
+
}
|
105
|
+
|
106
|
+
if (! lefttop) lefttop = round;
|
107
|
+
if (!righttop) righttop = round;
|
108
|
+
if (! leftbottom) leftbottom = round;
|
109
|
+
if (!rightbottom) rightbottom = round;
|
110
|
+
|
111
|
+
if ( lefttop) *lt = to<coord>( lefttop);
|
112
|
+
if (righttop) *rt = to<coord>(righttop);
|
113
|
+
if ( leftbottom) *lb = to<coord>( leftbottom);
|
114
|
+
if (rightbottom) *rb = to<coord>(rightbottom);
|
115
|
+
|
116
|
+
*nseg = get_nsegment(nsegment);
|
117
|
+
}
|
118
|
+
|
119
|
+
void get_ellipse_args (
|
120
|
+
coord* x, coord* y, coord* w, coord* h,
|
121
|
+
Rays::Point* hole_size, float* from, float* to_,
|
122
|
+
uint* nseg,
|
123
|
+
int argc, const Value* argv,
|
124
|
+
Value center, Value radius, Value hole, Value angle_from, Value angle_to,
|
125
|
+
Value nsegment)
|
126
|
+
{
|
127
|
+
assert(x && y && w && h && hole_size && from && to_ && nseg && argv);
|
128
|
+
|
129
|
+
if (argc <= 0)
|
130
|
+
argument_error(__FILE__, __LINE__);
|
131
|
+
|
132
|
+
if (argv[0].is_kind_of(Rays::bounds_class()))
|
133
|
+
{
|
134
|
+
const Rays::Bounds& b = to<Rays::Bounds&>(argv[0]);
|
135
|
+
*x = b.x;
|
136
|
+
*y = b.y;
|
137
|
+
*w = b.w;
|
138
|
+
*h = b.h;
|
139
|
+
}
|
140
|
+
else if (argv[0].is_kind_of(Rays::point_class()))
|
141
|
+
{
|
142
|
+
if (argc < 2)
|
143
|
+
argument_error(__FILE__, __LINE__);
|
144
|
+
|
145
|
+
const Rays::Point& p = to<Rays::Point&>(argv[0]);
|
146
|
+
*x = p.x;
|
147
|
+
*y = p.y;
|
148
|
+
*w = to<coord>(argv[1]);
|
149
|
+
*h = argc >= 3 ? to<coord>(argv[2]) : *w;
|
150
|
+
}
|
151
|
+
else if (argc <= 2)
|
152
|
+
{
|
153
|
+
*x = *y = 0;
|
154
|
+
*w = to<coord>(argv[0]);
|
155
|
+
*h = argc >= 2 ? to<coord>(argv[1]) : *w;
|
156
|
+
}
|
157
|
+
else
|
158
|
+
{
|
159
|
+
*x = to<coord>(argv[0]);
|
160
|
+
*y = to<coord>(argv[1]);
|
161
|
+
*w = to<coord>(argv[2]);
|
162
|
+
*h = argc >= 4 ? to<coord>(argv[3]) : *w;
|
163
|
+
}
|
164
|
+
|
165
|
+
if (center)
|
166
|
+
{
|
167
|
+
Rays::Point p = to<Rays::Point>(center);
|
168
|
+
*x = p.x;
|
169
|
+
*y = p.y;
|
170
|
+
}
|
171
|
+
|
172
|
+
if (radius)
|
173
|
+
{
|
174
|
+
Rays::Point p = to<Rays::Point>(radius);
|
175
|
+
*w = p.x * 2;
|
176
|
+
*h = p.y * 2;
|
177
|
+
}
|
178
|
+
|
179
|
+
*hole_size = hole ? to<Rays::Point>(hole) : 0;
|
180
|
+
*from = angle_from ? to<float>(angle_from) : 0;
|
181
|
+
*to_ = angle_to ? to<float>(angle_to) : 360;
|
182
|
+
*nseg = get_nsegment(nsegment);
|
183
|
+
}
|
data/.doc/ext/rays/font.cpp
CHANGED
@@ -1,16 +1,10 @@
|
|
1
1
|
#include "rays/ruby/font.h"
|
2
2
|
|
3
3
|
|
4
|
-
#include <rucy.h>
|
5
4
|
#include "defs.h"
|
6
5
|
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
using Rays::coord;
|
11
|
-
|
12
|
-
|
13
|
-
RUCY_DEFINE_VALUE_FROM_TO(Rays::Font)
|
7
|
+
RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Font)
|
14
8
|
|
15
9
|
#define THIS to<Rays::Font*>(self)
|
16
10
|
|
@@ -29,19 +23,7 @@ VALUE initialize(VALUE self)
|
|
29
23
|
RUCY_CHECK_OBJ(Rays::Font, self);
|
30
24
|
check_arg_count(__FILE__, __LINE__, "Font#initialize", argc, 0, 1, 2);
|
31
25
|
|
32
|
-
|
33
|
-
float size = (argc >= 2) ? to<float>(argv[1]) : 0;
|
34
|
-
*THIS = Rays::Font(name, size);
|
35
|
-
|
36
|
-
return self;
|
37
|
-
}
|
38
|
-
|
39
|
-
static
|
40
|
-
VALUE initialize_copy(VALUE self, VALUE obj)
|
41
|
-
{
|
42
|
-
RUCY_CHECK_OBJ(Rays::Font, self);
|
43
|
-
|
44
|
-
*THIS = to<Rays::Font&>(obj).copy();
|
26
|
+
*THIS = to<Rays::Font>(argc, argv);
|
45
27
|
return self;
|
46
28
|
}
|
47
29
|
|
@@ -84,7 +66,6 @@ Init_font ()
|
|
84
66
|
cFont = rb_define_class_under(mRays, "Font", rb_cObject);
|
85
67
|
rb_define_alloc_func(cFont, alloc);
|
86
68
|
rb_define_private_method(cFont, "initialize", RUBY_METHOD_FUNC(initialize), -1);
|
87
|
-
rb_define_private_method(cFont, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1);
|
88
69
|
rb_define_method(cFont, "name", RUBY_METHOD_FUNC(name), 0);
|
89
70
|
rb_define_method(cFont, "size", RUBY_METHOD_FUNC(size), 0);
|
90
71
|
rb_define_method(cFont, "width", RUBY_METHOD_FUNC(width), 1);
|
@@ -92,6 +73,43 @@ Init_font ()
|
|
92
73
|
}
|
93
74
|
|
94
75
|
|
76
|
+
namespace Rucy
|
77
|
+
{
|
78
|
+
|
79
|
+
|
80
|
+
template <> Rays::Font
|
81
|
+
value_to<Rays::Font> (int argc, const Value* argv, bool convert)
|
82
|
+
{
|
83
|
+
if (argc == 1 && argv->is_array())
|
84
|
+
{
|
85
|
+
argc = argv->size();
|
86
|
+
argv = argv->as_array();
|
87
|
+
}
|
88
|
+
|
89
|
+
assert(argc == 0 || (argc > 0 && argv));
|
90
|
+
|
91
|
+
if (convert)
|
92
|
+
{
|
93
|
+
if (argc == 0)
|
94
|
+
return Rays::default_font();
|
95
|
+
|
96
|
+
coord size = argc >= 2 ? to<coord>(argv[1]) : 0;
|
97
|
+
if (argv->is_nil())
|
98
|
+
return Rays::Font(NULL, size);
|
99
|
+
else if (argv->is_s() || argv->is_sym())
|
100
|
+
return Rays::Font(argv[0].c_str(), size);
|
101
|
+
}
|
102
|
+
|
103
|
+
if (argc != 1)
|
104
|
+
argument_error(__FILE__, __LINE__);
|
105
|
+
|
106
|
+
return value_to<Rays::Font&>(*argv, convert);
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
}// Rucy
|
111
|
+
|
112
|
+
|
95
113
|
namespace Rays
|
96
114
|
{
|
97
115
|
|
data/.doc/ext/rays/image.cpp
CHANGED
@@ -1,19 +1,12 @@
|
|
1
1
|
#include "rays/ruby/image.h"
|
2
2
|
|
3
3
|
|
4
|
-
#include <rucy.h>
|
5
4
|
#include "rays/ruby/color_space.h"
|
6
5
|
#include "rays/ruby/bitmap.h"
|
7
|
-
#include "rays/ruby/texture.h"
|
8
6
|
#include "rays/ruby/painter.h"
|
9
7
|
#include "defs.h"
|
10
8
|
|
11
9
|
|
12
|
-
using namespace Rucy;
|
13
|
-
|
14
|
-
using Rays::coord;
|
15
|
-
|
16
|
-
|
17
10
|
RUCY_DEFINE_VALUE_FROM_TO(Rays::Image)
|
18
11
|
|
19
12
|
#define THIS to<Rays::Image*>(self)
|
@@ -31,26 +24,28 @@ static
|
|
31
24
|
VALUE initialize(VALUE self)
|
32
25
|
{
|
33
26
|
RUCY_CHECK_OBJ(Rays::Image, self);
|
34
|
-
check_arg_count(__FILE__, __LINE__, "Image#initialize", argc, 1, 2, 3);
|
35
|
-
|
36
|
-
if (argc == 0) return self;
|
27
|
+
check_arg_count(__FILE__, __LINE__, "Image#initialize", argc, 1, 2, 3, 4);
|
37
28
|
|
38
29
|
if (argv[0].is_kind_of(Rays::bitmap_class()))
|
39
30
|
{
|
40
31
|
check_arg_count(__FILE__, __LINE__, "Image#initialize", argc, 1, 2);
|
41
32
|
|
42
33
|
const Rays::Bitmap* bitmap = to<Rays::Bitmap*>(argv[0]);
|
43
|
-
if (!bitmap)
|
34
|
+
if (!bitmap)
|
35
|
+
argument_error(__FILE__, __LINE__);
|
44
36
|
|
45
|
-
|
46
|
-
*THIS = Rays::Image(*bitmap,
|
37
|
+
float pixel_density = (argc >= 2) ? to<float>(argv[1]) : 1;
|
38
|
+
*THIS = Rays::Image(*bitmap, pixel_density);
|
47
39
|
}
|
48
40
|
else
|
49
41
|
{
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
42
|
+
check_arg_count(__FILE__, __LINE__, "Image#initialize", argc, 2, 3, 4);
|
43
|
+
|
44
|
+
int width = to<int>(argv[0]);
|
45
|
+
int height = to<int>(argv[1]);
|
46
|
+
Rays::ColorSpace cs = (argc >= 3) ? to<Rays::ColorSpace>(argv[2]) : Rays::RGBA;
|
47
|
+
float pixel_density = (argc >= 4) ? to<float>(argv[3]) : 1;
|
48
|
+
*THIS = Rays::Image(width, height, cs, pixel_density);
|
54
49
|
}
|
55
50
|
|
56
51
|
return self;
|
@@ -61,17 +56,10 @@ VALUE initialize_copy(VALUE self, VALUE obj)
|
|
61
56
|
{
|
62
57
|
RUCY_CHECK_OBJ(Rays::Image, self);
|
63
58
|
|
64
|
-
*THIS = to<Rays::Image&>(obj).
|
59
|
+
*THIS = to<Rays::Image&>(obj).dup();
|
65
60
|
return self;
|
66
61
|
}
|
67
62
|
|
68
|
-
static
|
69
|
-
VALUE painter(VALUE self)
|
70
|
-
{
|
71
|
-
CHECK;
|
72
|
-
return value(THIS->painter());
|
73
|
-
}
|
74
|
-
|
75
63
|
static
|
76
64
|
VALUE width(VALUE self)
|
77
65
|
{
|
@@ -94,24 +82,24 @@ VALUE color_space(VALUE self)
|
|
94
82
|
}
|
95
83
|
|
96
84
|
static
|
97
|
-
VALUE
|
85
|
+
VALUE pixel_density(VALUE self)
|
98
86
|
{
|
99
87
|
CHECK;
|
100
|
-
return value(THIS->
|
88
|
+
return value(THIS->pixel_density());
|
101
89
|
}
|
102
90
|
|
103
91
|
static
|
104
|
-
VALUE
|
92
|
+
VALUE painter(VALUE self)
|
105
93
|
{
|
106
94
|
CHECK;
|
107
|
-
return value(THIS->
|
95
|
+
return value(THIS->painter());
|
108
96
|
}
|
109
97
|
|
110
98
|
static
|
111
|
-
VALUE
|
99
|
+
VALUE bitmap(VALUE self)
|
112
100
|
{
|
113
101
|
CHECK;
|
114
|
-
return value(THIS->
|
102
|
+
return value(THIS->bitmap());
|
115
103
|
}
|
116
104
|
|
117
105
|
static
|
@@ -124,9 +112,11 @@ VALUE save(VALUE self, VALUE path)
|
|
124
112
|
|
125
113
|
|
126
114
|
static
|
127
|
-
VALUE load(VALUE self
|
115
|
+
VALUE load(VALUE self)
|
128
116
|
{
|
129
|
-
|
117
|
+
check_arg_count(__FILE__, __LINE__, "Image.load", argc, 1);
|
118
|
+
|
119
|
+
return value(Rays::load_image(argv[0].c_str()));
|
130
120
|
}
|
131
121
|
|
132
122
|
|
@@ -141,15 +131,14 @@ Init_image ()
|
|
141
131
|
rb_define_alloc_func(cImage, alloc);
|
142
132
|
rb_define_private_method(cImage, "initialize", RUBY_METHOD_FUNC(initialize), -1);
|
143
133
|
rb_define_private_method(cImage, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1);
|
144
|
-
rb_define_method(cImage, "painter", RUBY_METHOD_FUNC(painter), 0);
|
145
134
|
rb_define_method(cImage, "width", RUBY_METHOD_FUNC(width), 0);
|
146
135
|
rb_define_method(cImage, "height", RUBY_METHOD_FUNC(height), 0);
|
147
136
|
rb_define_method(cImage, "color_space", RUBY_METHOD_FUNC(color_space), 0);
|
148
|
-
rb_define_method(cImage, "
|
137
|
+
rb_define_method(cImage, "pixel_density", RUBY_METHOD_FUNC(pixel_density), 0);
|
138
|
+
rb_define_method(cImage, "painter", RUBY_METHOD_FUNC(painter), 0);
|
149
139
|
rb_define_method(cImage, "bitmap", RUBY_METHOD_FUNC(bitmap), 0);
|
150
|
-
rb_define_method(cImage, "texture", RUBY_METHOD_FUNC(texture), 0);
|
151
140
|
rb_define_method(cImage, "save", RUBY_METHOD_FUNC(save), 1);
|
152
|
-
rb_define_function(cImage, "
|
141
|
+
rb_define_function(cImage, "load", RUBY_METHOD_FUNC(load), -1);
|
153
142
|
}
|
154
143
|
|
155
144
|
|
data/.doc/ext/rays/matrix.cpp
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
#include "rays/ruby/matrix.h"
|
2
2
|
|
3
3
|
|
4
|
-
#include
|
4
|
+
#include "rays/ruby/point.h"
|
5
5
|
#include "defs.h"
|
6
6
|
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
RUCY_DEFINE_VALUE_FROM_TO(Rays::Matrix)
|
8
|
+
RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Matrix)
|
12
9
|
|
13
10
|
#define THIS to<Rays::Matrix*>(self)
|
14
11
|
|
@@ -27,22 +24,8 @@ VALUE initialize(VALUE self)
|
|
27
24
|
CHECK;
|
28
25
|
check_arg_count(__FILE__, __LINE__, "Matrix#initialize", argc, 0, 1, 16);
|
29
26
|
|
30
|
-
if (argc
|
31
|
-
|
32
|
-
switch (argc)
|
33
|
-
{
|
34
|
-
case 1:
|
35
|
-
*THIS = Rays::Matrix(to<float>(argv[0]));
|
36
|
-
break;
|
37
|
-
|
38
|
-
case 16:
|
39
|
-
*THIS = Rays::Matrix(
|
40
|
-
to<float>(argv[0]), to<float>(argv[1]), to<float>(argv[2]), to<float>(argv[3]),
|
41
|
-
to<float>(argv[4]), to<float>(argv[5]), to<float>(argv[6]), to<float>(argv[7]),
|
42
|
-
to<float>(argv[8]), to<float>(argv[9]), to<float>(argv[10]), to<float>(argv[11]),
|
43
|
-
to<float>(argv[12]), to<float>(argv[13]), to<float>(argv[14]), to<float>(argv[15]));
|
44
|
-
break;
|
45
|
-
}
|
27
|
+
if (argc > 0)
|
28
|
+
*THIS = to<Rays::Matrix>(argc, argv);
|
46
29
|
|
47
30
|
return self;
|
48
31
|
}
|
@@ -56,23 +39,23 @@ VALUE initialize_copy(VALUE self, VALUE obj)
|
|
56
39
|
}
|
57
40
|
|
58
41
|
static
|
59
|
-
VALUE
|
42
|
+
VALUE reset(VALUE self)
|
60
43
|
{
|
61
44
|
CHECK;
|
62
|
-
check_arg_count(__FILE__, __LINE__, "Matrix#
|
45
|
+
check_arg_count(__FILE__, __LINE__, "Matrix#reset", argc, 0, 1, 16);
|
63
46
|
|
64
47
|
switch (argc)
|
65
48
|
{
|
66
49
|
case 0:
|
67
|
-
|
50
|
+
THIS->reset();
|
68
51
|
break;
|
69
52
|
|
70
53
|
case 1:
|
71
|
-
|
54
|
+
THIS->reset(to<float>(argv[0]));
|
72
55
|
break;
|
73
56
|
|
74
57
|
case 16:
|
75
|
-
|
58
|
+
THIS->reset(
|
76
59
|
to<float>(argv[0]), to<float>(argv[1]), to<float>(argv[2]), to<float>(argv[3]),
|
77
60
|
to<float>(argv[4]), to<float>(argv[5]), to<float>(argv[6]), to<float>(argv[7]),
|
78
61
|
to<float>(argv[8]), to<float>(argv[9]), to<float>(argv[10]), to<float>(argv[11]),
|
@@ -84,12 +67,128 @@ VALUE set(VALUE self)
|
|
84
67
|
}
|
85
68
|
|
86
69
|
static
|
87
|
-
VALUE
|
70
|
+
VALUE translate(VALUE self)
|
71
|
+
{
|
72
|
+
CHECK;
|
73
|
+
check_arg_count(__FILE__, __LINE__, "Matrix#translate", argc, 1, 2, 3);
|
74
|
+
|
75
|
+
THIS->translate(to<Rays::Point>(argc, argv));
|
76
|
+
return self;
|
77
|
+
}
|
78
|
+
|
79
|
+
static
|
80
|
+
VALUE scale(VALUE self)
|
81
|
+
{
|
82
|
+
CHECK;
|
83
|
+
check_arg_count(__FILE__, __LINE__, "Matrix#scale", argc, 1, 2, 3);
|
84
|
+
|
85
|
+
THIS->scale(to<Rays::Point>(argc, argv));
|
86
|
+
return self;
|
87
|
+
}
|
88
|
+
|
89
|
+
static
|
90
|
+
VALUE rotate(VALUE self)
|
91
|
+
{
|
92
|
+
CHECK;
|
93
|
+
check_arg_count(__FILE__, __LINE__, "Matrix#rotate", argc, 1, 2, 4);
|
94
|
+
|
95
|
+
float degree = to<float>(argv[0]);
|
96
|
+
|
97
|
+
if (argc == 1)
|
98
|
+
THIS->rotate(degree);
|
99
|
+
else
|
100
|
+
THIS->rotate(degree, to<Rays::Point>(argc - 1, argv + 1));
|
101
|
+
|
102
|
+
return self;
|
103
|
+
}
|
104
|
+
|
105
|
+
static
|
106
|
+
VALUE to_a(VALUE self)
|
107
|
+
{
|
108
|
+
CHECK;
|
109
|
+
return array(
|
110
|
+
THIS->x0, THIS->y0, THIS->z0, THIS->w0,
|
111
|
+
THIS->x1, THIS->y1, THIS->z1, THIS->w1,
|
112
|
+
THIS->x2, THIS->y2, THIS->z2, THIS->w2,
|
113
|
+
THIS->x3, THIS->y3, THIS->z3, THIS->w3);
|
114
|
+
}
|
115
|
+
|
116
|
+
static
|
117
|
+
VALUE mult(VALUE self, VALUE val)
|
118
|
+
{
|
119
|
+
CHECK;
|
120
|
+
|
121
|
+
if (val.is_kind_of(Rays::matrix_class()))
|
122
|
+
return value(*THIS * to<Rays::Matrix&>(val));
|
123
|
+
|
124
|
+
if (val.is_kind_of(Rays::point_class()))
|
125
|
+
return value(*THIS * to<Rays::Point&>(val));
|
126
|
+
|
127
|
+
if (val.is_array())
|
128
|
+
{
|
129
|
+
if (val.size() == 16)
|
130
|
+
return value(*THIS * to<Rays::Matrix>(val));
|
131
|
+
else
|
132
|
+
return value(*THIS * to<Rays::Point>(val));
|
133
|
+
}
|
134
|
+
|
135
|
+
argument_error(__FILE__, __LINE__);
|
136
|
+
}
|
137
|
+
|
138
|
+
static
|
139
|
+
VALUE set_at(VALUE self, VALUE row, VALUE column, VALUE val)
|
140
|
+
{
|
141
|
+
CHECK;
|
142
|
+
return value(THIS->at(row.as_i(), column.as_i()) = to<float>(val));
|
143
|
+
}
|
144
|
+
|
145
|
+
static
|
146
|
+
VALUE get_at(VALUE self, VALUE row, VALUE column)
|
88
147
|
{
|
89
148
|
CHECK;
|
90
149
|
return value(THIS->at(row.as_i(), column.as_i()));
|
91
150
|
}
|
92
151
|
|
152
|
+
static
|
153
|
+
VALUE compare(VALUE self, VALUE other)
|
154
|
+
{
|
155
|
+
CHECK;
|
156
|
+
|
157
|
+
const Rays::Matrix& a = *THIS;
|
158
|
+
const Rays::Matrix& b = to<const Rays::Matrix&>(other);
|
159
|
+
for (int i = 0; i < Rays::Matrix::NELEM; ++i)
|
160
|
+
{
|
161
|
+
if (a[i] == b[i]) continue;
|
162
|
+
return value(a[i] < b[i] ? -1 : +1);
|
163
|
+
}
|
164
|
+
return value(0);
|
165
|
+
}
|
166
|
+
|
167
|
+
static
|
168
|
+
VALUE inspect(VALUE self)
|
169
|
+
{
|
170
|
+
CHECK;
|
171
|
+
return value(Xot::stringf("#<Rays::Matrix %s>", THIS->inspect().c_str()));
|
172
|
+
}
|
173
|
+
|
174
|
+
static
|
175
|
+
VALUE s_translate(VALUE self)
|
176
|
+
{
|
177
|
+
return translate(argc, argv, value(Rays::Matrix()));
|
178
|
+
}
|
179
|
+
|
180
|
+
static
|
181
|
+
VALUE s_scale(VALUE self)
|
182
|
+
{
|
183
|
+
return scale(argc, argv, value(Rays::Matrix()));
|
184
|
+
}
|
185
|
+
|
186
|
+
static
|
187
|
+
VALUE s_rotate(VALUE self)
|
188
|
+
{
|
189
|
+
return rotate(argc, argv, value(Rays::Matrix()));
|
190
|
+
}
|
191
|
+
|
93
192
|
|
94
193
|
static Class cMatrix;
|
95
194
|
|
@@ -102,11 +201,69 @@ Init_matrix ()
|
|
102
201
|
rb_define_alloc_func(cMatrix, alloc);
|
103
202
|
rb_define_private_method(cMatrix, "initialize", RUBY_METHOD_FUNC(initialize), -1);
|
104
203
|
rb_define_private_method(cMatrix, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1);
|
105
|
-
rb_define_method(cMatrix, "
|
106
|
-
rb_define_method(cMatrix, "
|
204
|
+
rb_define_method(cMatrix, "reset", RUBY_METHOD_FUNC(reset), -1);
|
205
|
+
rb_define_method(cMatrix, "translate", RUBY_METHOD_FUNC(translate), -1);
|
206
|
+
rb_define_method(cMatrix, "scale", RUBY_METHOD_FUNC(scale), -1);
|
207
|
+
rb_define_method(cMatrix, "rotate", RUBY_METHOD_FUNC(rotate), -1);
|
208
|
+
rb_define_method(cMatrix, "to_a", RUBY_METHOD_FUNC(to_a), 0);
|
209
|
+
cMatrix.define_method("*", mult);
|
210
|
+
cMatrix.define_method("[]=", set_at);
|
211
|
+
cMatrix.define_method("[]", get_at);
|
212
|
+
cMatrix.define_method("<=>", compare);
|
213
|
+
rb_define_method(cMatrix, "inspect", RUBY_METHOD_FUNC(inspect), 0);
|
214
|
+
|
215
|
+
rb_define_singleton_method(cMatrix, "translate", RUBY_METHOD_FUNC(s_translate), -1);
|
216
|
+
rb_define_singleton_method(cMatrix, "scale", RUBY_METHOD_FUNC(s_scale), -1);
|
217
|
+
rb_define_singleton_method(cMatrix, "rotate", RUBY_METHOD_FUNC(s_rotate), -1);
|
107
218
|
}
|
108
219
|
|
109
220
|
|
221
|
+
namespace Rucy
|
222
|
+
{
|
223
|
+
|
224
|
+
|
225
|
+
template <> Rays::Matrix
|
226
|
+
value_to<Rays::Matrix> (int argc, const Value* argv, bool convert)
|
227
|
+
{
|
228
|
+
if (argc == 1 && argv->is_array())
|
229
|
+
{
|
230
|
+
argc = argv->size();
|
231
|
+
argv = argv->as_array();
|
232
|
+
}
|
233
|
+
|
234
|
+
assert(argc == 0 || (argc > 0 && argv));
|
235
|
+
|
236
|
+
if (convert)
|
237
|
+
{
|
238
|
+
if (argc == 0)
|
239
|
+
return Rays::Matrix();
|
240
|
+
else if (argv->is_num())
|
241
|
+
{
|
242
|
+
switch (argc)
|
243
|
+
{
|
244
|
+
#define V(i) argv[i].as_f(true)
|
245
|
+
case 1: return Rays::Matrix(V(0));
|
246
|
+
case 16: return Rays::Matrix(
|
247
|
+
V(0), V(1), V(2), V(3),
|
248
|
+
V(4), V(5), V(6), V(7),
|
249
|
+
V(8), V(9), V(10), V(11),
|
250
|
+
V(12), V(13), V(14), V(15));
|
251
|
+
#undef V
|
252
|
+
default: argument_error(__FILE__, __LINE__);
|
253
|
+
}
|
254
|
+
}
|
255
|
+
}
|
256
|
+
|
257
|
+
if (argc != 1)
|
258
|
+
argument_error(__FILE__, __LINE__);
|
259
|
+
|
260
|
+
return value_to<Rays::Matrix&>(*argv, convert);
|
261
|
+
}
|
262
|
+
|
263
|
+
|
264
|
+
}// Rucy
|
265
|
+
|
266
|
+
|
110
267
|
namespace Rays
|
111
268
|
{
|
112
269
|
|