rays 0.1.12 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +5 -5
  2. data/.doc/ext/rays/bitmap.cpp +22 -76
  3. data/.doc/ext/rays/bounds.cpp +95 -125
  4. data/.doc/ext/rays/camera.cpp +171 -0
  5. data/.doc/ext/rays/color.cpp +223 -45
  6. data/.doc/ext/rays/color_space.cpp +146 -46
  7. data/.doc/ext/rays/defs.cpp +183 -0
  8. data/.doc/ext/rays/font.cpp +69 -21
  9. data/.doc/ext/rays/image.cpp +26 -37
  10. data/.doc/ext/rays/matrix.cpp +186 -29
  11. data/.doc/ext/rays/native.cpp +14 -8
  12. data/.doc/ext/rays/noise.cpp +53 -0
  13. data/.doc/ext/rays/painter.cpp +187 -292
  14. data/.doc/ext/rays/point.cpp +96 -77
  15. data/.doc/ext/rays/polygon.cpp +313 -0
  16. data/.doc/ext/rays/polygon_line.cpp +96 -0
  17. data/.doc/ext/rays/polyline.cpp +167 -0
  18. data/.doc/ext/rays/rays.cpp +103 -12
  19. data/.doc/ext/rays/shader.cpp +83 -9
  20. data/LICENSE +21 -0
  21. data/README.md +1 -1
  22. data/Rakefile +24 -9
  23. data/VERSION +1 -1
  24. data/ext/rays/bitmap.cpp +23 -81
  25. data/ext/rays/bounds.cpp +100 -128
  26. data/ext/rays/camera.cpp +186 -0
  27. data/ext/rays/color.cpp +231 -51
  28. data/ext/rays/color_space.cpp +149 -47
  29. data/ext/rays/defs.cpp +183 -0
  30. data/ext/rays/defs.h +26 -2
  31. data/ext/rays/extconf.rb +2 -3
  32. data/ext/rays/font.cpp +74 -24
  33. data/ext/rays/image.cpp +28 -40
  34. data/ext/rays/matrix.cpp +198 -30
  35. data/ext/rays/native.cpp +14 -8
  36. data/ext/rays/noise.cpp +55 -0
  37. data/ext/rays/painter.cpp +203 -298
  38. data/ext/rays/point.cpp +105 -81
  39. data/ext/rays/polygon.cpp +329 -0
  40. data/ext/rays/polygon_line.cpp +99 -0
  41. data/ext/rays/polyline.cpp +176 -0
  42. data/ext/rays/rays.cpp +103 -13
  43. data/ext/rays/shader.cpp +84 -9
  44. data/include/rays.h +10 -2
  45. data/include/rays/bitmap.h +14 -26
  46. data/include/rays/bounds.h +21 -4
  47. data/include/rays/camera.h +74 -0
  48. data/include/rays/color.h +25 -14
  49. data/include/rays/color_space.h +15 -10
  50. data/include/rays/coord.h +114 -0
  51. data/include/rays/debug.h +22 -0
  52. data/include/rays/defs.h +36 -0
  53. data/include/rays/exception.h +6 -2
  54. data/include/rays/font.h +4 -4
  55. data/include/rays/image.h +12 -18
  56. data/include/rays/matrix.h +50 -24
  57. data/include/rays/noise.h +42 -0
  58. data/include/rays/opengl.h +2 -50
  59. data/include/rays/painter.h +89 -93
  60. data/include/rays/point.h +44 -51
  61. data/include/rays/polygon.h +198 -0
  62. data/include/rays/polyline.h +71 -0
  63. data/include/rays/rays.h +3 -0
  64. data/include/rays/ruby.h +7 -1
  65. data/include/rays/ruby/bounds.h +1 -1
  66. data/include/rays/ruby/camera.h +41 -0
  67. data/include/rays/ruby/color.h +1 -1
  68. data/include/rays/ruby/color_space.h +1 -1
  69. data/include/rays/ruby/font.h +1 -1
  70. data/include/rays/ruby/matrix.h +1 -1
  71. data/include/rays/ruby/point.h +1 -1
  72. data/include/rays/ruby/polygon.h +52 -0
  73. data/include/rays/ruby/polyline.h +41 -0
  74. data/include/rays/ruby/rays.h +8 -0
  75. data/include/rays/ruby/shader.h +1 -1
  76. data/include/rays/shader.h +36 -8
  77. data/lib/rays.rb +7 -2
  78. data/lib/rays/bitmap.rb +0 -15
  79. data/lib/rays/bounds.rb +17 -23
  80. data/lib/rays/camera.rb +24 -0
  81. data/lib/rays/color.rb +20 -47
  82. data/lib/rays/color_space.rb +13 -13
  83. data/lib/rays/image.rb +3 -7
  84. data/lib/rays/matrix.rb +28 -0
  85. data/lib/rays/module.rb +4 -19
  86. data/lib/rays/painter.rb +78 -93
  87. data/lib/rays/point.rb +13 -21
  88. data/lib/rays/polygon.rb +58 -0
  89. data/lib/rays/polygon_line.rb +36 -0
  90. data/lib/rays/polyline.rb +32 -0
  91. data/lib/rays/shader.rb +20 -1
  92. data/rays.gemspec +5 -7
  93. data/src/bitmap.h +36 -0
  94. data/src/bounds.cpp +74 -11
  95. data/src/color.cpp +58 -23
  96. data/src/color_space.cpp +52 -34
  97. data/src/color_space.h +22 -0
  98. data/src/coord.cpp +170 -0
  99. data/src/coord.h +35 -0
  100. data/src/font.cpp +118 -0
  101. data/src/font.h +64 -0
  102. data/src/frame_buffer.cpp +37 -71
  103. data/src/frame_buffer.h +4 -4
  104. data/src/image.cpp +172 -98
  105. data/src/image.h +25 -0
  106. data/src/ios/bitmap.h +23 -0
  107. data/src/ios/bitmap.mm +133 -110
  108. data/src/ios/camera.mm +510 -0
  109. data/src/ios/font.mm +50 -62
  110. data/src/ios/helper.h +4 -4
  111. data/src/ios/opengl.mm +19 -4
  112. data/src/ios/rays.mm +3 -0
  113. data/src/matrix.cpp +111 -26
  114. data/src/matrix.h +30 -0
  115. data/src/noise.cpp +74 -0
  116. data/src/opengl.cpp +9 -27
  117. data/src/opengl.h +37 -0
  118. data/src/osx/bitmap.h +23 -0
  119. data/src/osx/bitmap.mm +133 -110
  120. data/src/osx/camera.mm +451 -0
  121. data/src/osx/font.mm +49 -62
  122. data/src/osx/helper.h +2 -2
  123. data/src/osx/opengl.mm +19 -83
  124. data/src/osx/rays.mm +3 -0
  125. data/src/painter.cpp +845 -671
  126. data/src/painter.h +24 -0
  127. data/src/point.cpp +140 -119
  128. data/src/polygon.cpp +1266 -0
  129. data/src/polygon.h +32 -0
  130. data/src/polyline.cpp +160 -0
  131. data/src/polyline.h +69 -0
  132. data/src/render_buffer.cpp +11 -4
  133. data/src/render_buffer.h +2 -2
  134. data/src/shader.cpp +163 -106
  135. data/src/shader.h +38 -0
  136. data/src/shader_program.cpp +533 -0
  137. data/src/{program.h → shader_program.h} +28 -16
  138. data/src/shader_source.cpp +140 -0
  139. data/src/shader_source.h +52 -0
  140. data/src/texture.cpp +136 -160
  141. data/src/texture.h +65 -0
  142. data/src/win32/bitmap.cpp +62 -52
  143. data/src/win32/font.cpp +11 -13
  144. data/src/win32/font.h +24 -0
  145. data/src/win32/gdi.h +6 -6
  146. data/test/helper.rb +0 -3
  147. data/test/test_bitmap.rb +31 -7
  148. data/test/test_bounds.rb +36 -0
  149. data/test/test_color.rb +59 -19
  150. data/test/test_color_space.rb +95 -0
  151. data/test/test_font.rb +5 -0
  152. data/test/test_image.rb +24 -20
  153. data/test/test_matrix.rb +106 -0
  154. data/test/test_painter.rb +157 -51
  155. data/test/test_painter_shape.rb +102 -0
  156. data/test/test_point.rb +29 -0
  157. data/test/test_polygon.rb +234 -0
  158. data/test/test_polygon_line.rb +167 -0
  159. data/test/test_polyline.rb +171 -0
  160. data/test/test_shader.rb +9 -9
  161. metadata +102 -70
  162. data/.doc/ext/rays/texture.cpp +0 -138
  163. data/ext/rays/texture.cpp +0 -149
  164. data/include/rays/ruby/texture.h +0 -41
  165. data/include/rays/texture.h +0 -71
  166. data/lib/rays/texture.rb +0 -24
  167. data/src/program.cpp +0 -648
  168. data/test/test_texture.rb +0 -27
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 xord.org
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  # Rays - A Drawing Engine using OpenGL.
3
3
 
4
- by snori@xord.org
4
+ by xordog@gmail.com
data/Rakefile CHANGED
@@ -2,25 +2,40 @@
2
2
 
3
3
 
4
4
  %w[../xot ../rucy .]
5
- .map {|s| File.expand_path "../#{s}/lib", __FILE__}
5
+ .map {|s| File.expand_path "#{s}/lib", __dir__}
6
6
  .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
7
7
 
8
- require 'xot/rake'
8
+ require 'rucy/rake'
9
+
9
10
  require 'xot/module'
10
11
  require 'rucy/module'
11
12
  require 'rays/module'
12
13
 
13
- include Xot::Rake
14
-
15
14
 
16
- MODULES = [Xot, Rucy, Rays].map {|m| m.const_get :Module}
17
- MODULE = MODULES.last
15
+ MODULES = [Xot, Rucy, Rays]
18
16
  TESTS_ALONE = ['test/test_rays.rb']
19
17
 
18
+ use_external_library 'https://github.com/g-truc/glm',
19
+ tag: '0.9.8.5',
20
+ srcdir: 'NOSRC'
21
+
22
+ use_external_library 'https://github.com/skyrpex/clipper',
23
+ tag: '6.4.2',
24
+ incdir: 'cpp',
25
+ srcdir: 'cpp',
26
+ excludes: 'clipper/cpp/cpp_'
20
27
 
21
- task :default => :build
28
+ use_external_library 'https://github.com/greenm01/poly2tri',
29
+ incdir: 'poly2tri',
30
+ srcdir: 'poly2tri'
22
31
 
23
- task :build => :ext
32
+ use_external_library 'https://github.com/andrewwillmott/splines-lib.git',
33
+ excludes: 'Test\.cpp'
24
34
 
35
+ build_native_library
36
+ build_ruby_extension
37
+ test_ruby_extension
38
+ generate_documents
39
+ build_ruby_gem
25
40
 
26
- MODULES.each {|m| m.load_tasks :lib, :ext, :test, :doc, :gem}
41
+ task :default => :test
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.12
1
+ 0.1.17
@@ -1,23 +1,12 @@
1
1
  #include "rays/ruby/bitmap.h"
2
2
 
3
3
 
4
- #include <rucy.h>
5
- #include "rays/exception.h"
6
4
  #include "rays/ruby/color_space.h"
7
5
  #include "rays/ruby/color.h"
8
6
  #include "rays/ruby/font.h"
9
- #include "rays/ruby/texture.h"
10
7
  #include "defs.h"
11
8
 
12
9
 
13
- using namespace Rucy;
14
-
15
- using Rays::uchar;
16
- using Rays::ushort;
17
- using Rays::uint;
18
- using Rays::coord;
19
-
20
-
21
10
  RUCY_DEFINE_VALUE_FROM_TO(Rays::Bitmap)
22
11
 
23
12
  #define THIS to<Rays::Bitmap*>(self)
@@ -33,42 +22,25 @@ RUCY_DEF_ALLOC(alloc, klass)
33
22
  RUCY_END
34
23
 
35
24
  static
36
- RUCY_DEF1(initialize_copy, obj)
25
+ RUCY_DEFN(initialize)
37
26
  {
38
27
  RUCY_CHECK_OBJ(Rays::Bitmap, self);
28
+ check_arg_count(__FILE__, __LINE__, "Bitmap#initialize", argc, 2, 3);
39
29
 
40
- *THIS = to<Rays::Bitmap&>(obj).copy();
41
- return self;
42
- }
43
- RUCY_END
30
+ *THIS = Rays::Bitmap(
31
+ to<int>(argv[0]), to<int>(argv[1]),
32
+ argc >= 3 ? to<Rays::ColorSpace>(argv[2]) : Rays::RGBA);
44
33
 
45
- static
46
- RUCY_DEF3(setup, width, height, color_space)
47
- {
48
- RUCY_CHECK_OBJ(Rays::Bitmap, self);
49
-
50
- Rays::ColorSpace* cs = to<Rays::ColorSpace*>(color_space);
51
- if (!cs)
52
- argument_error(__FILE__, __LINE__);
53
-
54
- *THIS = Rays::Bitmap(to<int>(width), to<int>(height), *cs);
55
34
  return self;
56
35
  }
57
36
  RUCY_END
58
37
 
59
38
  static
60
- RUCY_DEFN(draw_string)
39
+ RUCY_DEF1(initialize_copy, obj)
61
40
  {
62
- CHECK;
63
- check_arg_count(__FILE__, __LINE__, "Bitmap#draw_string", argc, 1, 2, 3, 4);
64
-
65
- const char* str = to<const char*>(argv[0]);
66
- coord x = argc >= 2 ? to<coord>(argv[1]) : 0;
67
- coord y = argc >= 3 ? to<coord>(argv[2]) : 0;
68
- const Rays::Font* font = argc >= 4
69
- ? to<Rays::Font*>(argv[3]) : &Rays::default_font();
41
+ RUCY_CHECK_OBJ(Rays::Bitmap, self);
70
42
 
71
- Rays::draw_string(THIS, str, x, y, *font);
43
+ *THIS = to<Rays::Bitmap&>(obj).dup();
72
44
  return self;
73
45
  }
74
46
  RUCY_END
@@ -101,54 +73,28 @@ RUCY_DEF0(color_space)
101
73
  RUCY_END
102
74
 
103
75
  static
104
- RUCY_DEF2(at, x, y)
105
- {
106
- CHECK;
107
-
108
- return value(Rays::Color(THIS->at<void>(x.as_i(), y.as_i()), THIS->color_space()));
109
- }
110
- RUCY_END
111
-
112
- static
113
- RUCY_DEF3(set_at, x, y, color)
76
+ RUCY_DEFN(set_at)
114
77
  {
115
78
  CHECK;
79
+ check_arg_count(__FILE__, __LINE__, "Bitmap#set_at", argc, 3, 4, 5, 6);
116
80
 
117
- Rays::Color* col = to<Rays::Color*>(color);
118
- if (!col)
119
- argument_error(__FILE__, __LINE__);
120
-
121
- col->get(THIS->at<void>(x.as_i(), y.as_i()), THIS->color_space());
81
+ int x = to<int>(argv[0]);
82
+ int y = to<int>(argv[1]);
83
+ Rays::Color color = to<Rays::Color>(argc - 2, argv + 2);
122
84
 
123
- return color;
85
+ color.get(THIS->at<void>(x, y), THIS->color_space());
86
+ return value(color);
124
87
  }
125
88
  RUCY_END
126
89
 
127
90
  static
128
- RUCY_DEFN(to_texture)
91
+ RUCY_DEF2(get_at, x, y)
129
92
  {
130
93
  CHECK;
131
94
 
132
- bool alpha_only = (argc >= 1) ? to<bool>(argv[0]) : false;
133
- return value(Rays::Texture(*THIS, alpha_only));
134
- }
135
- RUCY_END
136
-
137
- static
138
- RUCY_DEF1(save, path)
139
- {
140
- CHECK;
141
-
142
- Rays::save_bitmap(*THIS, path.c_str());
143
- return self;
144
- }
145
- RUCY_END
146
-
147
-
148
- static
149
- RUCY_DEF1(load, path)
150
- {
151
- return value(Rays::load_bitmap(path.c_str()));
95
+ int xx = to<int>(x);
96
+ int yy = to<int>(y);
97
+ return value(Rays::Color(THIS->at<void>(xx, yy), THIS->color_space()));
152
98
  }
153
99
  RUCY_END
154
100
 
@@ -162,17 +108,13 @@ Init_bitmap ()
162
108
 
163
109
  cBitmap = mRays.define_class("Bitmap");
164
110
  cBitmap.define_alloc_func(alloc);
111
+ cBitmap.define_private_method("initialize", initialize);
165
112
  cBitmap.define_private_method("initialize_copy", initialize_copy);
166
- cBitmap.define_private_method("setup", setup);
167
- cBitmap.define_method("draw_string", draw_string);
168
- cBitmap.define_method("width", width);
113
+ cBitmap.define_method("width", width);
169
114
  cBitmap.define_method("height", height);
170
115
  cBitmap.define_method("color_space", color_space);
171
- cBitmap.define_method("[]", at);
172
- cBitmap.define_method("set_at", set_at);
173
- cBitmap.define_method("to_texture", to_texture);
174
- cBitmap.define_method("save", save);
175
- cBitmap.define_function("load", load);
116
+ cBitmap.define_method("[]=", set_at);
117
+ cBitmap.define_method("[]", get_at);
176
118
  }
177
119
 
178
120
 
@@ -1,17 +1,11 @@
1
1
  #include "rays/ruby/bounds.h"
2
2
 
3
3
 
4
- #include <rucy.h>
5
4
  #include "rays/ruby/point.h"
6
5
  #include "defs.h"
7
6
 
8
7
 
9
- using namespace Rucy;
10
-
11
- using Rays::coord;
12
-
13
-
14
- RUCY_DEFINE_VALUE_FROM_TO(Rays::Bounds)
8
+ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Bounds)
15
9
 
16
10
  #define THIS to<Rays::Bounds*>(self)
17
11
 
@@ -31,35 +25,8 @@ RUCY_DEFN(initialize)
31
25
  CHECK;
32
26
  check_arg_count(__FILE__, __LINE__, "Bounds#initialize", argc, 0, 1, 2, 3, 4, 6);
33
27
 
34
- if (argc == 0) return self;
35
-
36
- switch (argc)
37
- {
38
- case 1:
39
- *THIS = Rays::Bounds(to<coord>(argv[0]));
40
- break;
41
-
42
- case 2:
43
- *THIS = Rays::Bounds(to<coord>(argv[0]), to<coord>(argv[1]));
44
- break;
45
-
46
- case 3:
47
- *THIS = Rays::Bounds(
48
- to<coord>(argv[0]), to<coord>(argv[1]), to<coord>(argv[2]));
49
- break;
50
-
51
- case 4:
52
- *THIS = Rays::Bounds(
53
- to<coord>(argv[0]), to<coord>(argv[1]),
54
- to<coord>(argv[2]), to<coord>(argv[3]));
55
- break;
56
-
57
- case 6:
58
- *THIS = Rays::Bounds(
59
- to<coord>(argv[0]), to<coord>(argv[1]), to<coord>(argv[2]),
60
- to<coord>(argv[3]), to<coord>(argv[4]), to<coord>(argv[5]));
61
- break;
62
- }
28
+ if (argc >= 1)
29
+ *THIS = to<Rays::Bounds>(argc, argv);
63
30
 
64
31
  return self;
65
32
  }
@@ -69,6 +36,7 @@ static
69
36
  RUCY_DEF1(initialize_copy, obj)
70
37
  {
71
38
  CHECK;
39
+
72
40
  *THIS = to<Rays::Bounds&>(obj);
73
41
  return self;
74
42
  }
@@ -117,7 +85,7 @@ RUCY_DEFN(move_to)
117
85
  }
118
86
 
119
87
  const Rays::Point& p = THIS->position();
120
- coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : p.x;
88
+ coord x = argv[0] ? to<coord>(argv[0]) : p.x;
121
89
  coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : p.y;
122
90
  coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : p.z;
123
91
  THIS->move_to(x, y, z);
@@ -143,7 +111,7 @@ RUCY_DEFN(move_by)
143
111
  argv = argv[0].as_array();
144
112
  }
145
113
 
146
- coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : 0;
114
+ coord x = argv[0] ? to<coord>(argv[0]) : 0;
147
115
  coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : 0;
148
116
  coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : 0;
149
117
  THIS->move_by(x, y, z);
@@ -170,7 +138,7 @@ RUCY_DEFN(resize_to)
170
138
  }
171
139
 
172
140
  const Rays::Point& p = THIS->size();
173
- coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : p.x;
141
+ coord x = argv[0] ? to<coord>(argv[0]) : p.x;
174
142
  coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : p.y;
175
143
  coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : p.z;
176
144
  THIS->resize_to(x, y, z);
@@ -196,7 +164,7 @@ RUCY_DEFN(resize_by)
196
164
  argv = argv[0].as_array();
197
165
  }
198
166
 
199
- coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : 0;
167
+ coord x = argv[0] ? to<coord>(argv[0]) : 0;
200
168
  coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : 0;
201
169
  coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : 0;
202
170
  THIS->resize_by(x, y, z);
@@ -222,7 +190,7 @@ RUCY_DEFN(inset_by)
222
190
  argv = argv[0].as_array();
223
191
  }
224
192
 
225
- coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : 0;
193
+ coord x = argv[0] ? to<coord>(argv[0]) : 0;
226
194
  coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : 0;
227
195
  coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : 0;
228
196
  THIS->inset_by(x, y, z);
@@ -232,12 +200,22 @@ RUCY_DEFN(inset_by)
232
200
  }
233
201
  RUCY_END
234
202
 
203
+ static
204
+ RUCY_DEF0(is_valid)
205
+ {
206
+ CHECK;
207
+
208
+ return value(THIS->operator bool());
209
+ }
210
+ RUCY_END
211
+
235
212
  static
236
213
  RUCY_DEF1(set_x, x)
237
214
  {
238
215
  CHECK;
239
216
 
240
- return value(THIS->x = to<coord>(x));
217
+ THIS->x = to<coord>(x);
218
+ return x;
241
219
  }
242
220
  RUCY_END
243
221
 
@@ -255,7 +233,8 @@ RUCY_DEF1(set_y, y)
255
233
  {
256
234
  CHECK;
257
235
 
258
- return value(THIS->y = to<coord>(y));
236
+ THIS->y = to<coord>(y);
237
+ return y;
259
238
  }
260
239
  RUCY_END
261
240
 
@@ -273,7 +252,8 @@ RUCY_DEF1(set_z, z)
273
252
  {
274
253
  CHECK;
275
254
 
276
- return value(THIS->z = to<coord>(z));
255
+ THIS->z = to<coord>(z);
256
+ return z;
277
257
  }
278
258
  RUCY_END
279
259
 
@@ -291,7 +271,8 @@ RUCY_DEF1(set_width, width)
291
271
  {
292
272
  CHECK;
293
273
 
294
- return value(THIS->width = to<coord>(width));
274
+ THIS->width = to<coord>(width);
275
+ return width;
295
276
  }
296
277
  RUCY_END
297
278
 
@@ -309,7 +290,8 @@ RUCY_DEF1(set_height, height)
309
290
  {
310
291
  CHECK;
311
292
 
312
- return value(THIS->height = to<coord>(height));
293
+ THIS->height = to<coord>(height);
294
+ return height;
313
295
  }
314
296
  RUCY_END
315
297
 
@@ -327,7 +309,8 @@ RUCY_DEF1(set_depth, depth)
327
309
  {
328
310
  CHECK;
329
311
 
330
- return value(THIS->depth = to<coord>(depth));
312
+ THIS->depth = to<coord>(depth);
313
+ return depth;
331
314
  }
332
315
  RUCY_END
333
316
 
@@ -344,10 +327,9 @@ static
344
327
  RUCY_DEF1(set_left, left)
345
328
  {
346
329
  CHECK;
347
- Rays::Bounds* this_ = THIS;
348
330
 
349
- this_->set_left(to<coord>(left));
350
- return value(this_->left());
331
+ THIS->set_left(to<coord>(left));
332
+ return left;
351
333
  }
352
334
  RUCY_END
353
335
 
@@ -364,10 +346,9 @@ static
364
346
  RUCY_DEF1(set_right, right)
365
347
  {
366
348
  CHECK;
367
- Rays::Bounds* this_ = THIS;
368
349
 
369
- this_->set_right(to<coord>(right));
370
- return value(this_->right());
350
+ THIS->set_right(to<coord>(right));
351
+ return right;
371
352
  }
372
353
  RUCY_END
373
354
 
@@ -384,10 +365,9 @@ static
384
365
  RUCY_DEF1(set_top, top)
385
366
  {
386
367
  CHECK;
387
- Rays::Bounds* this_ = THIS;
388
368
 
389
- this_->set_top(to<coord>(top));
390
- return value(this_->top());
369
+ THIS->set_top(to<coord>(top));
370
+ return top;
391
371
  }
392
372
  RUCY_END
393
373
 
@@ -404,10 +384,9 @@ static
404
384
  RUCY_DEF1(set_bottom, bottom)
405
385
  {
406
386
  CHECK;
407
- Rays::Bounds* this_ = THIS;
408
387
 
409
- this_->set_bottom(to<coord>(bottom));
410
- return value(this_->bottom());
388
+ THIS->set_bottom(to<coord>(bottom));
389
+ return bottom;
411
390
  }
412
391
  RUCY_END
413
392
 
@@ -424,10 +403,9 @@ static
424
403
  RUCY_DEF1(set_back, back)
425
404
  {
426
405
  CHECK;
427
- Rays::Bounds* this_ = THIS;
428
406
 
429
- this_->set_back(to<coord>(back));
430
- return value(this_->back());
407
+ THIS->set_back(to<coord>(back));
408
+ return back;
431
409
  }
432
410
  RUCY_END
433
411
 
@@ -444,10 +422,9 @@ static
444
422
  RUCY_DEF1(set_front, front)
445
423
  {
446
424
  CHECK;
447
- Rays::Bounds* this_ = THIS;
448
425
 
449
- this_->set_front(to<coord>(front));
450
- return value(this_->front());
426
+ THIS->set_front(to<coord>(front));
427
+ return front;
451
428
  }
452
429
  RUCY_END
453
430
 
@@ -464,11 +441,9 @@ static
464
441
  RUCY_DEFN(set_position)
465
442
  {
466
443
  CHECK;
467
- check_arg_count(__FILE__, __LINE__, "Bounds#set_position", argc, 1, 2, 3);
468
444
 
469
- coord* pos = THIS->position().array;
470
- for (int i = 0; i < 3; ++i)
471
- if (argc > i && !argv[i].is_nil()) pos[i] = to<coord>(argv[i]);
445
+ THIS->set_position(to<Rays::Point>(argc, argv));
446
+ return value(THIS->position());
472
447
  }
473
448
  RUCY_END
474
449
 
@@ -485,11 +460,9 @@ static
485
460
  RUCY_DEFN(set_size)
486
461
  {
487
462
  CHECK;
488
- check_arg_count(__FILE__, __LINE__, "Bounds#set_size", argc, 1, 2, 3);
489
463
 
490
- coord* size = THIS->size().array;
491
- for (int i = 0; i < 3; ++i)
492
- if (argc > i && !argv[i].is_nil()) size[i] = to<coord>(argv[i]);
464
+ THIS->set_size(to<Rays::Point>(argc, argv));
465
+ return value(THIS->size());
493
466
  }
494
467
  RUCY_END
495
468
 
@@ -506,25 +479,14 @@ static
506
479
  RUCY_DEFN(set_center)
507
480
  {
508
481
  CHECK;
509
- check_arg_count(__FILE__, __LINE__, "Bounds#set_center", argc, 1, 2, 3);
510
-
511
- if (argv[0].is_kind_of(Rays::point_class()))
512
- THIS->set_center(to<Rays::Point&>(argv[0]));
513
- else
514
- {
515
- Rays::Point p = THIS->center();
516
- coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : p.x;
517
- coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : p.y;
518
- coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : p.z;
519
- THIS->set_center(x, y, z);
520
- }
521
482
 
483
+ THIS->set_center(to<Rays::Point>(argc, argv));
522
484
  return value(THIS->center());
523
485
  }
524
486
  RUCY_END
525
487
 
526
488
  static
527
- RUCY_DEF0(center)
489
+ RUCY_DEF0(get_center)
528
490
  {
529
491
  CHECK;
530
492
 
@@ -533,7 +495,7 @@ RUCY_DEF0(center)
533
495
  RUCY_END
534
496
 
535
497
  static
536
- RUCY_DEF1(array_get, index)
498
+ RUCY_DEF2(set_at, index, value)
537
499
  {
538
500
  CHECK;
539
501
 
@@ -541,12 +503,13 @@ RUCY_DEF1(array_get, index)
541
503
  if (i < 0 || 1 < i)
542
504
  index_error(__FILE__, __LINE__);
543
505
 
544
- return value((*THIS)[i]);
506
+ (*THIS)[i] = to<Rays::Point&>(value);
507
+ return value;
545
508
  }
546
509
  RUCY_END
547
510
 
548
511
  static
549
- RUCY_DEF2(array_set, index, value)
512
+ RUCY_DEF1(get_at, index)
550
513
  {
551
514
  CHECK;
552
515
 
@@ -554,13 +517,12 @@ RUCY_DEF2(array_set, index, value)
554
517
  if (i < 0 || 1 < i)
555
518
  index_error(__FILE__, __LINE__);
556
519
 
557
- (*THIS)[i] = to<Rays::Point&>(value);
558
- return value;
520
+ return value((*THIS)[i]);
559
521
  }
560
522
  RUCY_END
561
523
 
562
524
  static
563
- RUCY_DEF1(and_, bounds)
525
+ RUCY_DEF1(op_and, bounds)
564
526
  {
565
527
  CHECK;
566
528
 
@@ -571,12 +533,18 @@ RUCY_DEF1(and_, bounds)
571
533
  RUCY_END
572
534
 
573
535
  static
574
- RUCY_DEF1(or_, bounds)
536
+ RUCY_DEF1(op_or, arg)
575
537
  {
576
538
  CHECK;
577
539
 
578
540
  Rays::Bounds b = *THIS;
579
- b |= to<Rays::Bounds&>(bounds);
541
+ if (arg.is_kind_of(Rays::bounds_class()))
542
+ b |= to<Rays::Bounds&>(arg);
543
+ else if (arg.is_kind_of(Rays::point_class()))
544
+ b |= to<Rays::Point&>(arg);
545
+ else
546
+ argument_error(__FILE__, __LINE__);
547
+
580
548
  return value(b);
581
549
  }
582
550
  RUCY_END
@@ -590,6 +558,13 @@ RUCY_DEF0(inspect)
590
558
  }
591
559
  RUCY_END
592
560
 
561
+ static
562
+ RUCY_DEF0(invalid)
563
+ {
564
+ return value(Rays::invalid_bounds());
565
+ }
566
+ RUCY_END
567
+
593
568
 
594
569
  static Class cBounds;
595
570
 
@@ -600,7 +575,7 @@ Init_bounds ()
600
575
 
601
576
  cBounds = mRays.define_class("Bounds");
602
577
  cBounds.define_alloc_func(alloc);
603
- cBounds.define_private_method("initialize", initialize);
578
+ cBounds.define_private_method("initialize", initialize);
604
579
  cBounds.define_private_method("initialize_copy", initialize_copy);
605
580
  cBounds.define_method("intersect?", intersect);
606
581
  cBounds.define_method("include?", include);
@@ -609,6 +584,7 @@ Init_bounds ()
609
584
  cBounds.define_method("resize_to!", resize_to);
610
585
  cBounds.define_method("resize_by!", resize_by);
611
586
  cBounds.define_method("inset_by!", inset_by);
587
+ cBounds.define_method("valid?", is_valid);
612
588
  cBounds.define_method("x=", set_x);
613
589
  cBounds.define_method("x", get_x);
614
590
  cBounds.define_method("y=", set_y);
@@ -633,17 +609,18 @@ Init_bounds ()
633
609
  cBounds.define_method("back", get_back);
634
610
  cBounds.define_method("front=", set_front);
635
611
  cBounds.define_method("front", get_front);
636
- cBounds.define_method("set_position", set_position);
637
- cBounds.define_method( "position", get_position);
638
- cBounds.define_method("set_size", set_size);
639
- cBounds.define_method( "size", get_size);
640
- cBounds.define_method("set_center", set_center);
641
- cBounds.define_method("center", center);
642
- cBounds.define_method("[]", array_get);
643
- cBounds.define_method("[]=", array_set);
644
- cBounds.define_method("&", and_);
645
- cBounds.define_method("|", or_);
612
+ cBounds.define_method("position=", set_position);
613
+ cBounds.define_method("position", get_position);
614
+ cBounds.define_method("size=", set_size);
615
+ cBounds.define_method("size", get_size);
616
+ cBounds.define_method("center=", set_center);
617
+ cBounds.define_method("center", get_center);
618
+ cBounds.define_method("[]", get_at);
619
+ cBounds.define_method("[]=", set_at);
620
+ cBounds.define_method("&", op_and);
621
+ cBounds.define_method("|", op_or);
646
622
  cBounds.define_method("inspect", inspect);
623
+ cBounds.define_singleton_method("invalid", invalid);
647
624
  }
648
625
 
649
626
 
@@ -652,29 +629,21 @@ namespace Rucy
652
629
 
653
630
 
654
631
  template <> Rays::Bounds
655
- value_to<Rays::Bounds> (Value value, bool convert)
632
+ value_to<Rays::Bounds> (int argc, const Value* argv, bool convert)
656
633
  {
657
- if (convert)
634
+ if (argc == 1 && argv->is_array())
658
635
  {
659
- size_t argc = 0;
660
- Value* argv = NULL;
661
- if (value.is_array())
662
- {
663
- argc = value.size();
664
- argv = value.as_array();
665
- }
666
- else
667
- {
668
- argc = 1;
669
- argv = &value;
670
- }
636
+ argc = argv->size();
637
+ argv = argv->as_array();
638
+ }
671
639
 
672
- if (argc < 1)
673
- Rucy::argument_error(__FILE__, __LINE__);
640
+ assert(argc == 0 || (argc > 0 && argv));
674
641
 
675
- if (argv[0].is_kind_of(Rays::bounds_class()))
676
- value = argv[0];
677
- else if (argv[0].is_kind_of(Rays::point_class()))
642
+ if (convert)
643
+ {
644
+ if (argc == 0)
645
+ return Rays::Bounds();
646
+ else if (argv->is_kind_of(Rays::point_class()))
678
647
  {
679
648
  switch (argc)
680
649
  {
@@ -682,10 +651,10 @@ namespace Rucy
682
651
  case 1: return Rays::Bounds(V(0));
683
652
  case 2: return Rays::Bounds(V(0), V(1));
684
653
  #undef V
685
- default: Rucy::argument_error(__FILE__, __LINE__);
654
+ default: argument_error(__FILE__, __LINE__);
686
655
  }
687
656
  }
688
- else if (argv[0].is_i() || argv[0].is_f())
657
+ else if (argv->is_num())
689
658
  {
690
659
  switch (argc)
691
660
  {
@@ -696,12 +665,15 @@ namespace Rucy
696
665
  case 4: return Rays::Bounds(V(0), V(1), V(2), V(3));
697
666
  case 6: return Rays::Bounds(V(0), V(1), V(2), V(3), V(4), V(5));
698
667
  #undef V
699
- default: Rucy::argument_error(__FILE__, __LINE__);
668
+ default: argument_error(__FILE__, __LINE__);
700
669
  }
701
670
  }
702
671
  }
703
672
 
704
- return value_to<Rays::Bounds&>(value, convert);
673
+ if (argc != 1)
674
+ argument_error(__FILE__, __LINE__);
675
+
676
+ return value_to<Rays::Bounds&>(*argv, convert);
705
677
  }
706
678
 
707
679