rays 0.1.3 → 0.1.4

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.
Files changed (88) hide show
  1. data/.doc/ext/rays/bitmap.cpp +76 -53
  2. data/.doc/ext/rays/font.cpp +31 -27
  3. data/.doc/ext/rays/image.cpp +44 -37
  4. data/.doc/ext/rays/native.cpp +6 -0
  5. data/.doc/ext/rays/painter.cpp +276 -160
  6. data/.doc/ext/rays/rays.cpp +8 -9
  7. data/.doc/ext/rays/texture.cpp +50 -28
  8. data/.gitignore +14 -0
  9. data/Rakefile +5 -30
  10. data/VERSION +1 -1
  11. data/ext/rays/bitmap.cpp +77 -53
  12. data/ext/rays/bounds.cpp +426 -0
  13. data/ext/rays/color.cpp +199 -0
  14. data/ext/rays/defs.h +1 -18
  15. data/ext/rays/extconf.rb +10 -8
  16. data/ext/rays/font.cpp +31 -27
  17. data/ext/rays/image.cpp +44 -37
  18. data/ext/rays/matrix.cpp +154 -0
  19. data/ext/rays/native.cpp +6 -0
  20. data/ext/rays/painter.cpp +288 -163
  21. data/ext/rays/point.cpp +175 -0
  22. data/ext/rays/rays.cpp +8 -9
  23. data/ext/rays/texture.cpp +52 -28
  24. data/include/rays.h +1 -2
  25. data/include/rays/bitmap.h +5 -3
  26. data/include/rays/bounds.h +94 -0
  27. data/include/rays/color.h +53 -0
  28. data/include/rays/colorspace.h +2 -2
  29. data/include/rays/exception.h +1 -1
  30. data/include/rays/font.h +7 -3
  31. data/include/rays/image.h +6 -2
  32. data/include/rays/matrix.h +63 -0
  33. data/include/rays/opengl.h +1 -1
  34. data/include/rays/painter.h +138 -39
  35. data/include/rays/point.h +39 -0
  36. data/include/rays/ruby.h +3 -0
  37. data/include/rays/ruby/bitmap.h +5 -3
  38. data/include/rays/ruby/bounds.h +41 -0
  39. data/include/rays/ruby/color.h +41 -0
  40. data/include/rays/ruby/font.h +5 -3
  41. data/include/rays/ruby/image.h +5 -3
  42. data/include/rays/ruby/matrix.h +41 -0
  43. data/include/rays/ruby/painter.h +5 -3
  44. data/include/rays/ruby/point.h +41 -0
  45. data/include/rays/ruby/texture.h +5 -3
  46. data/include/rays/texture.h +6 -2
  47. data/lib/rays.rb +3 -0
  48. data/lib/rays/autoinit.rb +1 -1
  49. data/lib/rays/bitmap.rb +15 -1
  50. data/lib/rays/bounds.rb +138 -0
  51. data/lib/rays/color.rb +52 -0
  52. data/lib/rays/ext.rb +4 -0
  53. data/lib/rays/image.rb +1 -1
  54. data/lib/rays/module.rb +9 -2
  55. data/lib/rays/painter.rb +40 -41
  56. data/lib/rays/point.rb +82 -0
  57. data/lib/rays/texture.rb +1 -1
  58. data/rays.gemspec +16 -37
  59. data/src/bounds.cpp +234 -0
  60. data/src/cocoa/bitmap.mm +4 -4
  61. data/src/cocoa/font.mm +35 -30
  62. data/src/cocoa/rays.mm +2 -0
  63. data/src/color.cpp +77 -0
  64. data/src/colorspace.cpp +3 -3
  65. data/src/exception.cpp +3 -18
  66. data/src/image.cpp +9 -2
  67. data/src/matrix.cpp +103 -0
  68. data/src/painter.cpp +475 -224
  69. data/src/point.cpp +52 -0
  70. data/src/texture.cpp +14 -2
  71. data/src/win32/bitmap.cpp +2 -2
  72. data/src/win32/gdi.cpp +22 -13
  73. data/src/win32/gdi.h +7 -7
  74. data/test/helpers.rb +1 -5
  75. data/test/test_bitmap.rb +9 -0
  76. data/test/test_bounds.rb +246 -0
  77. data/test/test_color.rb +88 -0
  78. data/test/test_font.rb +28 -0
  79. data/test/test_image.rb +9 -0
  80. data/test/test_painter.rb +1 -3
  81. data/test/test_point.rb +121 -0
  82. data/test/test_rays.rb +2 -3
  83. data/test/test_texture.rb +1 -3
  84. metadata +146 -75
  85. data/include/rays/helpers.h +0 -37
  86. data/include/rays/transform.h +0 -35
  87. data/src/helpers.cpp +0 -22
  88. data/src/transform.cpp +0 -88
@@ -0,0 +1,39 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_POINT_H__
4
+ #define __RAYS_POINT_H__
5
+
6
+
7
+ #include <rays/defs.h>
8
+
9
+
10
+ namespace Rays
11
+ {
12
+
13
+
14
+ struct Point
15
+ {
16
+
17
+ coord x, y, z;
18
+
19
+ Point (coord value = 0);
20
+
21
+ Point (coord x, coord y, coord z = 0);
22
+
23
+ Point dup () const;
24
+
25
+ Point& set (coord value = 0);
26
+
27
+ Point& set (coord x, coord y, coord z = 0);
28
+
29
+ coord* array ();
30
+
31
+ const coord* array () const;
32
+
33
+ };// Point
34
+
35
+
36
+ }// Rays
37
+
38
+
39
+ #endif//EOH
data/include/rays/ruby.h CHANGED
@@ -5,6 +5,9 @@
5
5
 
6
6
 
7
7
  #include <rays/ruby/rays.h>
8
+ #include <rays/ruby/point.h>
9
+ #include <rays/ruby/bounds.h>
10
+ #include <rays/ruby/color.h>
8
11
  #include <rays/ruby/bitmap.h>
9
12
  #include <rays/ruby/texture.h>
10
13
  #include <rays/ruby/image.h>
@@ -24,12 +24,14 @@ namespace Rucy
24
24
  {
25
25
 
26
26
 
27
- Value value (const Rays::Bitmap& bitmap);
27
+ Value value (const Rays::Bitmap& obj);
28
+
29
+ Value value (const Rays::Bitmap* obj);
28
30
 
29
31
  template <> inline Rays::Bitmap*
30
- value_to<Rays::Bitmap*> (Value obj, bool convert)
32
+ value_to<Rays::Bitmap*> (Value val, bool)
31
33
  {
32
- return get_type<Rays::Bitmap>(obj, Rays::bitmap_class());
34
+ return get_type_ptr<Rays::Bitmap>(val, Rays::bitmap_class());
33
35
  }
34
36
 
35
37
 
@@ -0,0 +1,41 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_RUBY_BOUNDS_H__
4
+ #define __RAYS_RUBY_BOUNDS_H__
5
+
6
+
7
+ #include <rucy/rucy.h>
8
+ #include <rucy/class.h>
9
+ #include <rays/bounds.h>
10
+
11
+
12
+ namespace Rays
13
+ {
14
+
15
+
16
+ Rucy::Class bounds_class ();
17
+ // class Rays::Bounds
18
+
19
+
20
+ }// Rays
21
+
22
+
23
+ namespace Rucy
24
+ {
25
+
26
+
27
+ Value value (const Rays::Bounds& obj);
28
+
29
+ Value value (const Rays::Bounds* obj);
30
+
31
+ template <> inline Rays::Bounds*
32
+ value_to<Rays::Bounds*> (Value val, bool)
33
+ {
34
+ return get_type_ptr<Rays::Bounds>(val, Rays::bounds_class());
35
+ }
36
+
37
+
38
+ }// Rucy
39
+
40
+
41
+ #endif//EOH
@@ -0,0 +1,41 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_RUBY_COLOR_H__
4
+ #define __RAYS_RUBY_COLOR_H__
5
+
6
+
7
+ #include <rucy/rucy.h>
8
+ #include <rucy/class.h>
9
+ #include <rays/color.h>
10
+
11
+
12
+ namespace Rays
13
+ {
14
+
15
+
16
+ Rucy::Class color_class ();
17
+ // class Rays::Color
18
+
19
+
20
+ }// Rays
21
+
22
+
23
+ namespace Rucy
24
+ {
25
+
26
+
27
+ Value value (const Rays::Color& obj);
28
+
29
+ Value value (const Rays::Color* obj);
30
+
31
+ template <> inline Rays::Color*
32
+ value_to<Rays::Color*> (Value val, bool)
33
+ {
34
+ return get_type_ptr<Rays::Color>(val, Rays::color_class());
35
+ }
36
+
37
+
38
+ }// Rucy
39
+
40
+
41
+ #endif//EOH
@@ -24,12 +24,14 @@ namespace Rucy
24
24
  {
25
25
 
26
26
 
27
- Value value (const Rays::Font& font);
27
+ Value value (const Rays::Font& obj);
28
+
29
+ Value value (const Rays::Font* obj);
28
30
 
29
31
  template <> inline Rays::Font*
30
- value_to<Rays::Font*> (Value obj, bool convert)
32
+ value_to<Rays::Font*> (Value val, bool)
31
33
  {
32
- return get_type<Rays::Font>(obj, Rays::font_class());
34
+ return get_type_ptr<Rays::Font>(val, Rays::font_class());
33
35
  }
34
36
 
35
37
 
@@ -24,12 +24,14 @@ namespace Rucy
24
24
  {
25
25
 
26
26
 
27
- Value value (const Rays::Image& image);
27
+ Value value (const Rays::Image& obj);
28
+
29
+ Value value (const Rays::Image* obj);
28
30
 
29
31
  template <> inline Rays::Image*
30
- value_to<Rays::Image*> (Value obj, bool convert)
32
+ value_to<Rays::Image*> (Value val, bool)
31
33
  {
32
- return get_type<Rays::Image>(obj, Rays::image_class());
34
+ return get_type_ptr<Rays::Image>(val, Rays::image_class());
33
35
  }
34
36
 
35
37
 
@@ -0,0 +1,41 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_RUBY_MATRIX_H__
4
+ #define __RAYS_RUBY_MATRIX_H__
5
+
6
+
7
+ #include <rucy/rucy.h>
8
+ #include <rucy/class.h>
9
+ #include <rays/matrix.h>
10
+
11
+
12
+ namespace Rays
13
+ {
14
+
15
+
16
+ Rucy::Class matrix_class ();
17
+ // class Rays::Matrix
18
+
19
+
20
+ }// Rays
21
+
22
+
23
+ namespace Rucy
24
+ {
25
+
26
+
27
+ Value value (const Rays::Matrix& obj);
28
+
29
+ Value value (const Rays::Matrix* obj);
30
+
31
+ template <> inline Rays::Matrix*
32
+ value_to<Rays::Matrix*> (Value val, bool)
33
+ {
34
+ return get_type_ptr<Rays::Matrix>(val, Rays::matrix_class());
35
+ }
36
+
37
+
38
+ }// Rucy
39
+
40
+
41
+ #endif//EOH
@@ -24,12 +24,14 @@ namespace Rucy
24
24
  {
25
25
 
26
26
 
27
- Value value (const Rays::Painter& painter);
27
+ Value value (const Rays::Painter& obj);
28
+
29
+ Value value (const Rays::Painter* obj);
28
30
 
29
31
  template <> inline Rays::Painter*
30
- value_to<Rays::Painter*> (Value obj, bool convert)
32
+ value_to<Rays::Painter*> (Value val, bool)
31
33
  {
32
- return get_type<Rays::Painter>(obj, Rays::painter_class());
34
+ return get_type_ptr<Rays::Painter>(val, Rays::painter_class());
33
35
  }
34
36
 
35
37
 
@@ -0,0 +1,41 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_RUBY_POINT_H__
4
+ #define __RAYS_RUBY_POINT_H__
5
+
6
+
7
+ #include <rucy/rucy.h>
8
+ #include <rucy/class.h>
9
+ #include <rays/point.h>
10
+
11
+
12
+ namespace Rays
13
+ {
14
+
15
+
16
+ Rucy::Class point_class ();
17
+ // class Rays::Point
18
+
19
+
20
+ }// Rays
21
+
22
+
23
+ namespace Rucy
24
+ {
25
+
26
+
27
+ Value value (const Rays::Point& obj);
28
+
29
+ Value value (const Rays::Point* obj);
30
+
31
+ template <> inline Rays::Point*
32
+ value_to<Rays::Point*> (Value val, bool)
33
+ {
34
+ return get_type_ptr<Rays::Point>(val, Rays::point_class());
35
+ }
36
+
37
+
38
+ }// Rucy
39
+
40
+
41
+ #endif//EOH
@@ -24,12 +24,14 @@ namespace Rucy
24
24
  {
25
25
 
26
26
 
27
- Value value (const Rays::Texture& texture);
27
+ Value value (const Rays::Texture& obj);
28
+
29
+ Value value (const Rays::Texture* obj);
28
30
 
29
31
  template <> inline Rays::Texture*
30
- value_to<Rays::Texture*> (Value obj, bool convert)
32
+ value_to<Rays::Texture*> (Value val, bool)
31
33
  {
32
- return get_type<Rays::Texture>(obj, Rays::texture_class());
34
+ return get_type_ptr<Rays::Texture>(val, Rays::texture_class());
33
35
  }
34
36
 
35
37
 
@@ -4,9 +4,9 @@
4
4
  #define __RAYS_TEXTURE_H__
5
5
 
6
6
 
7
+ #include <xot/pimpl.h>
7
8
  #include <rays/defs.h>
8
9
  #include <rays/opengl.h>
9
- #include <rays/helpers.h>
10
10
 
11
11
 
12
12
  namespace Rays
@@ -33,6 +33,10 @@ namespace Rays
33
33
 
34
34
  int height () const;
35
35
 
36
+ float s (float x) const;
37
+
38
+ float t (float y) const;
39
+
36
40
  float s_max () const;
37
41
 
38
42
  float t_max () const;
@@ -45,7 +49,7 @@ namespace Rays
45
49
 
46
50
  struct Data;
47
51
 
48
- Impl<Data> self;
52
+ Xot::PImpl<Data, true> self;
49
53
 
50
54
  };// Texture
51
55
 
data/lib/rays.rb CHANGED
@@ -3,6 +3,9 @@
3
3
 
4
4
  require 'rays/autoinit'
5
5
  require 'rays/module'
6
+ require 'rays/point'
7
+ require 'rays/bounds'
8
+ require 'rays/color'
6
9
  require 'rays/bitmap'
7
10
  require 'rays/texture'
8
11
  require 'rays/image'
data/lib/rays/autoinit.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- require 'rays/native'
4
+ require 'rays/ext'
5
5
 
6
6
 
7
7
  unless $RAYS_NOAUTOINIT
data/lib/rays/bitmap.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- require 'rays/native'
4
+ require 'rays/ext'
5
5
 
6
6
 
7
7
  module Rays
@@ -11,6 +11,16 @@ module Rays
11
11
 
12
12
  include Enumerable
13
13
 
14
+ def initialize (width, height, colorspace = RGBA)
15
+ colorspace = case colorspace
16
+ when :GRAY then GRAY
17
+ when :RGB then RGB
18
+ when :RGBA then RGBA
19
+ else colorspace
20
+ end
21
+ setup width, height, colorspace
22
+ end
23
+
14
24
  def each ()
15
25
  height.times do |y|
16
26
  width.times do |x|
@@ -19,6 +29,10 @@ module Rays
19
29
  end
20
30
  end
21
31
 
32
+ def size ()
33
+ [width, height]
34
+ end
35
+
22
36
  end# Bitmap
23
37
 
24
38
 
@@ -0,0 +1,138 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'rays/ext'
5
+ require 'rays/point'
6
+
7
+
8
+ module Rays
9
+
10
+
11
+ class Bounds
12
+
13
+ include Comparable
14
+
15
+ alias w width
16
+ alias w= width=
17
+
18
+ alias h height
19
+ alias h= height=
20
+
21
+ alias d depth
22
+ alias d= depth=
23
+
24
+ alias pos position
25
+ alias pos= position=
26
+
27
+ def move_to! (*args)
28
+ case args.size
29
+ when 1 then self.x = self.y = args[0]
30
+ when 2 then self.x, self.y = args
31
+ when 3 then self.x, self.y, self.z = args
32
+ else raise ArgumentError
33
+ end
34
+ self
35
+ end
36
+
37
+ def move_to (*args)
38
+ dup.move_to! *args
39
+ end
40
+
41
+ def move_by! (*args)
42
+ case args.size
43
+ when 1 then self.x += args[0]; self.y += args[0]
44
+ when 2 then self.x += args[0]; self.y += args[1]
45
+ when 3 then self.x += args[0]; self.y += args[1]; self.z += args[2]
46
+ else raise ArgumentError
47
+ end
48
+ self
49
+ end
50
+
51
+ def move_by (*args)
52
+ dup.move_by! *args
53
+ end
54
+
55
+ def resize_to! (*args)
56
+ case args.size
57
+ when 1 then self.w = self.h = args[0]
58
+ when 2 then self.w, self.h = args
59
+ when 3 then self.w, self.h, self.d = args
60
+ else raise ArgumentError
61
+ end
62
+ self
63
+ end
64
+
65
+ def resize_to (*args)
66
+ dup.resize_to! *args
67
+ end
68
+
69
+ def resize_by! (*args)
70
+ case args.size
71
+ when 1 then self.w += args[0]; self.h += args[0]
72
+ when 2 then self.w += args[0]; self.h += args[1]
73
+ when 3 then self.w += args[0]; self.h += args[1]; self.d += args[2]
74
+ else raise ArgumentError
75
+ end
76
+ self
77
+ end
78
+
79
+ def resize_by (*args)
80
+ dup.resize_by! *args
81
+ end
82
+
83
+ def inset_by! (*args)
84
+ move_by! *args
85
+ resize_by! *args.map {|n| -n * 2}
86
+ self
87
+ end
88
+
89
+ def inset_by (*args)
90
+ dup.inset_by! *args
91
+ end
92
+
93
+ def center ()
94
+ Point.new (x + w / 2).round, (y + h / 2).round
95
+ end
96
+
97
+ def to_a (dimension = 2)
98
+ case dimension
99
+ when 1 then [x, w]
100
+ when 2 then [x, y, w, h]
101
+ when 3 then [x, y, z, w, h, d]
102
+ else raise ArgumentError
103
+ end
104
+ end
105
+
106
+ def [] (index)
107
+ case index
108
+ when 0 then Point.new(left, top, back)
109
+ when 1 then Point.new(right, bottom, front)
110
+ else raise IndexError
111
+ end
112
+ end
113
+
114
+ def []= (index, point)
115
+ case index
116
+ when 0 then self.left, self.top, self.back = point.to_a(3)
117
+ when 1 then self.right, self.bottom, self.front = point.to_a(3)
118
+ else raise IndexError
119
+ end
120
+ end
121
+
122
+ def <=> (o)
123
+ ret = x <=> o.x; return ret if ret != 0
124
+ ret = y <=> o.y; return ret if ret != 0
125
+ ret = z <=> o.z; return ret if ret != 0
126
+ ret = w <=> o.w; return ret if ret != 0
127
+ ret = h <=> o.h; return ret if ret != 0
128
+ d <=> o.d
129
+ end
130
+
131
+ def inspect ()
132
+ "#<Rays::Bounds x=#{x}, y=#{y}, z=#{z}, width=#{w}, height=#{h}, depth=#{d}>"
133
+ end
134
+
135
+ end# Bounds
136
+
137
+
138
+ end# Rays