rays 0.1.12 → 0.1.17

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 (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
@@ -10,24 +10,19 @@ module Rays
10
10
  class Color
11
11
 
12
12
  include Comparable
13
+ include Enumerable
13
14
 
14
- def self.color (*args)
15
- c = case arg0 = args[0]
16
- when Color then arg0
17
- when Symbol then COLORS[arg0]
18
- when /^\s*#[\da-fA-F]+\s*$/ then Color.new arg0
19
- when String then COLORS[arg0.intern]
20
- else Color.new *args
21
- end
22
- raise ArgumentError, "invalid argument '#{args}.'" unless c
23
- c
24
- end
15
+ alias r= red=
16
+ alias r red
25
17
 
26
- def initialize (*args)
27
- arg0 = args[0]
28
- args = parse arg0 if arg0 && arg0.kind_of?(String)
29
- setup *args
30
- end
18
+ alias g= green=
19
+ alias g green
20
+
21
+ alias b= blue=
22
+ alias b blue
23
+
24
+ alias a= alpha=
25
+ alias a alpha
31
26
 
32
27
  def opaque? ()
33
28
  alpha >= 1
@@ -42,12 +37,16 @@ module Rays
42
37
  0 < a && a < 1
43
38
  end
44
39
 
40
+ def each (&block)
41
+ to_a.each &block
42
+ end
43
+
45
44
  def to_a ()
46
45
  [red, green, blue, alpha]
47
46
  end
48
47
 
49
48
  def to_s ()
50
- to_a.map {|o| o.to_s}
49
+ to_a.to_s
51
50
  end
52
51
 
53
52
  def [] (index)
@@ -77,6 +76,10 @@ module Rays
77
76
  alpha <=> o.alpha
78
77
  end
79
78
 
79
+ def hash ()
80
+ red.hash + green.hash + blue.hash + alpha.hash
81
+ end
82
+
80
83
  def eql? (o)
81
84
  self == o
82
85
  end
@@ -85,36 +88,6 @@ module Rays
85
88
  "#<#{self.class.name} #{to_s}>"
86
89
  end
87
90
 
88
- COLORS = {
89
- black: [0, 0, 0],
90
- red: [1, 0, 0],
91
- green: [0, 1, 0],
92
- blue: [0, 0, 1],
93
- yellow: [1, 1, 0],
94
- cyan: [0, 1, 1],
95
- magenta: [1, 0, 1],
96
- white: [1, 1, 1],
97
- gray: [0.5, 0.5, 0.5],
98
- no: [0, 0],
99
- none: [0, 0],
100
- nil: [0, 0],
101
- }.inject({}) {|h, (k, v)| h[k] = Color.new *v; h}
102
-
103
- private
104
-
105
- RE_RGBA = /^\s*##{'([\da-fA-F]{1})' * 4}?\s*$/
106
- RE_RRGGBBAA = /^\s*##{'([\da-fA-F]{2})' * 4}?\s*$/
107
-
108
- def parse (str)
109
- case str
110
- when RE_RGBA
111
- [$1, $2, $3, $4 || 'f' ].map {|s| s.to_i(16) / 15.0}
112
- when RE_RRGGBBAA
113
- [$1, $2, $3, $4 || 'ff'].map {|s| s.to_i(16) / 255.0}
114
- else raise ArgumentError, "can not parse '#{str}'."
115
- end
116
- end
117
-
118
91
  end# Color
119
92
 
120
93
 
@@ -9,25 +9,25 @@ module Rays
9
9
 
10
10
  class ColorSpace
11
11
 
12
- def initialize (type = :RGBA, premultiplied = true)
13
- setup self.class.get_type(type), premultiplied
12
+ include Comparable
13
+
14
+ def <=> (o)
15
+ type <=> o.type
16
+ end
17
+
18
+ def hash ()
19
+ type.hash
14
20
  end
15
21
 
16
- def self.get_type (obj)
17
- case obj
18
- when Integer then obj
19
- when String, Symbol then const_get obj
20
- else raise ArgumentError, "can not convert '#{obj}' to ColorSpace type."
21
- end
22
- rescue NameError
23
- raise "ColoeSpace::#{obj} is not found."
22
+ def eql? (o)
23
+ self == o
24
24
  end
25
25
 
26
- def self.get_color_space (obj)
27
- (ColorSpace === obj) ? obj : (ColorSpace.new get_type(obj))
26
+ def inspect ()
27
+ "#<#{self.class.name} #{to_s}>"
28
28
  end
29
29
 
30
- end# ColorSpace
30
+ end# Color
31
31
 
32
32
 
33
33
  end# Rays
@@ -12,10 +12,10 @@ module Rays
12
12
 
13
13
  extend Forwardable
14
14
 
15
- def_delegators :bitmap, :draw_string, :[], :[]=
15
+ def_delegators :bitmap, :[], :[]=
16
16
 
17
17
  def paint (&block)
18
- painter.begin self, &block
18
+ painter.paint self, &block
19
19
  self
20
20
  end
21
21
 
@@ -24,11 +24,7 @@ module Rays
24
24
  end
25
25
 
26
26
  def bounds ()
27
- Bounds.new 0, 0, *size
28
- end
29
-
30
- def self.load (path, alpha_only = false)
31
- load_image path, alpha_only
27
+ Bounds.new 0, 0, width, height
32
28
  end
33
29
 
34
30
  end# Image
@@ -0,0 +1,28 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'rays/ext'
5
+
6
+
7
+ module Rays
8
+
9
+
10
+ class Matrix
11
+
12
+ include Comparable
13
+ include Enumerable
14
+
15
+ def each (&block)
16
+ to_a.each &block
17
+ end
18
+
19
+ alias inspect_org inspect
20
+
21
+ def inspect ()
22
+ inspect_org.gsub(/\.?0+([^\.\d]|$)/) {$1}
23
+ end
24
+
25
+ end# Matrix
26
+
27
+
28
+ end# Rays
@@ -6,6 +6,8 @@ module Rays
6
6
 
7
7
  module Module
8
8
 
9
+ module_function
10
+
9
11
  def name ()
10
12
  super.split('::')[-2]
11
13
  end
@@ -15,10 +17,10 @@ module Rays
15
17
  end
16
18
 
17
19
  def root_dir (path = '')
18
- File.expand_path "../../../#{path}", __FILE__
20
+ File.expand_path "../../#{path}", __dir__
19
21
  end
20
22
 
21
- def include_dir ()
23
+ def inc_dir ()
22
24
  root_dir 'include'
23
25
  end
24
26
 
@@ -26,23 +28,6 @@ module Rays
26
28
  root_dir 'lib'
27
29
  end
28
30
 
29
- def task_dir ()
30
- root_dir 'task'
31
- end
32
-
33
- def load_tasks (*names)
34
- if names.empty?
35
- Dir["#{task_dir}/**/*.rake"].each {|path| load path}
36
- else
37
- names.each do |name|
38
- path = "#{task_dir}/#{name}.rake"
39
- load path if File.exist? path
40
- end
41
- end
42
- end
43
-
44
- extend self
45
-
46
31
  end# Module
47
32
 
48
33
 
@@ -1,9 +1,10 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
+ require 'xot/const_symbol_accessor'
5
+ require 'xot/universal_accessor'
4
6
  require 'xot/block_util'
5
7
  require 'rays/ext'
6
- require 'rays/color'
7
8
 
8
9
 
9
10
  module Rays
@@ -11,128 +12,112 @@ module Rays
11
12
 
12
13
  class Painter
13
14
 
14
- def background (*args, &block)
15
- set_or_get :background=, :get_background, args, block
16
- end
15
+ def push (*types, **attributes, &block)
16
+ each_type types do |type|
17
+ case type
18
+ when :state then push_state
19
+ when :matrix then push_matrix
20
+ else raise ArgumentError, "invalid push/pop type '#{type}'."
21
+ end
22
+ end
17
23
 
18
- def background= (*args)
19
- send_set :set_background, :get_background, :no_background, args, :color
20
- end
24
+ raise ArgumentError, 'missing block with pushing attributes.' if
25
+ !attributes.empty? && !block
21
26
 
22
- def fill (*args, &block)
23
- set_or_get :fill=, :get_fill, args, block
24
- end
27
+ if block
28
+ attributes.each do |key, value|
29
+ attributes[key] = __send__ key
30
+ __send__ key, *value
31
+ end
25
32
 
26
- def fill= (*args)
27
- send_set :set_fill, :get_fill, :no_fill, args, :color
28
- end
33
+ Xot::BlockUtil.instance_eval_or_block_call self, &block
29
34
 
30
- def stroke (*args, &block)
31
- set_or_get :stroke=, :get_stroke, args, block
32
- end
35
+ attributes.each do |key, value|
36
+ __send__ key, *value
37
+ end
33
38
 
34
- def stroke= (*args)
35
- send_set :set_stroke, :get_stroke, :no_stroke, args, :color
39
+ pop *types
40
+ end
36
41
  end
37
42
 
38
- def clip (*args, &block)
39
- set_or_get :clip=, :get_clip, args, block
43
+ def pop (*types)
44
+ each_type types, reverse: true do |type|
45
+ case type
46
+ when :state then pop_state
47
+ when :matrix then pop_matrix
48
+ else raise ArgumentError, "invalid push/pop type '#{type}'."
49
+ end
50
+ end
40
51
  end
41
52
 
42
- def clip= (*args)
43
- send_set :set_clip, :get_clip, :no_clip, args
53
+ def paint (*args, &block)
54
+ begin_paint
55
+ Xot::BlockUtil.instance_eval_or_block_call self, *args, &block
56
+ self
57
+ ensure
58
+ end_paint
44
59
  end
45
60
 
46
- def font (*args, &block)
47
- set_or_get :font=, :get_font, args, block
61
+ def line (*args, loop: false)
62
+ if args.first.kind_of?(Polyline)
63
+ draw_polyline args.first
64
+ else
65
+ draw_line args, loop
66
+ end
48
67
  end
49
68
 
50
- def font= (*args)
51
- send_set :set_font, :get_font, nil, args
69
+ def rect (*args, round: nil, lt: nil, rt: nil, lb: nil, rb: nil)
70
+ draw_rect args, round, lt, rt, lb, rb
52
71
  end
53
72
 
54
- def color (fill, stroke = nil, &block)
55
- org = [self.fill, self.stroke]
56
- self.fill, self.stroke = fill, stroke
57
- if block
58
- Xot::BlockUtil.instance_eval_or_block_call self, &block
59
- self.fill, self.stroke = org
60
- end
61
- org
73
+ def ellipse (*args, center: nil, radius: nil, hole: nil, from: nil, to: nil)
74
+ draw_ellipse args, center, radius, hole, from, to
62
75
  end
63
76
 
64
- def attach (shader, uniforms = {})
65
- shader =
66
- case shader
67
- when Shader then shader
68
- when String then Shader.new shader
69
- else raise ArgumentError
70
- end
71
- attach_shader shader
72
- uniforms.each {|name, args| set_uniform name, *args}
73
- shader
77
+ def curve (*args, loop: false)
78
+ draw_curve args, loop
74
79
  end
75
80
 
76
- alias detach detach_shader
77
-
78
- def push (&block)
79
- push_matrix
80
- push_attr
81
- push_shader
82
- if block
83
- Xot::BlockUtil.instance_eval_or_block_call self, &block
84
- pop
85
- end
81
+ def bezier (*args, loop: false)
82
+ draw_bezier args, loop
86
83
  end
87
84
 
88
- def pop ()
89
- pop_shader
90
- pop_attr
91
- pop_matrix
85
+ def color= (fill, stroke = nil)
86
+ self.fill fill
87
+ self.stroke stroke
92
88
  end
93
89
 
94
- def begin (*args, &block)
95
- begin_paint
96
- Xot::BlockUtil.instance_eval_or_block_call self, *args, &block
97
- end_paint
90
+ def color ()
91
+ return fill, stroke
98
92
  end
99
93
 
100
- private
94
+ def shader= (shader, **uniforms)
95
+ shader.uniform **uniforms if shader && !uniforms.empty?
96
+ set_shader shader
97
+ end
101
98
 
102
- NONES = [:no, :none, nil]
99
+ const_symbol_accessor :stroke_cap, {
100
+ butt: CAP_BUTT,
101
+ round: CAP_ROUND,
102
+ square: CAP_SQUARE
103
+ }
103
104
 
104
- def send_set (setter, getter, no, args, mode = nil)
105
- args = args[0] if args[0].kind_of? Array
106
- raise ArgumentError if args.empty?
105
+ const_symbol_accessor :stroke_join, {
106
+ miter: JOIN_MITER,
107
+ round: JOIN_ROUND,
108
+ square: JOIN_SQUARE
109
+ }
107
110
 
108
- arg0 = args[0]
109
- if args.size == 1 && NONES.include?(arg0)
110
- no ? send(no) : send(setter, nil)
111
- else
112
- case mode
113
- when :color then args = Color.color *args
114
- end
115
- send setter, *args
116
- end
117
- send getter
118
- end
111
+ universal_accessor :background, :fill, :stroke, :color,
112
+ :stroke_width, :stroke_cap, :stroke_join, :miter_limit,
113
+ :nsegment, :shader, :clip, :font
119
114
 
120
- def set_or_get (setter, getter, args, block)
121
- unless args.empty?
122
- set_or_push setter, getter, args, block
123
- else
124
- send getter
125
- end
126
- end
115
+ private
127
116
 
128
- def set_or_push (setter, getter, args, block)
129
- org = send getter
130
- send setter, *args
131
- if block
132
- Xot::BlockUtil.instance_eval_or_block_call self, &block
133
- send setter, org
134
- end
135
- org
117
+ def each_type (types, reverse: false, &block)
118
+ types = [:state, :matrix] if types.empty? || types.include?(:all)
119
+ types = types.reverse if reverse
120
+ types.each &block
136
121
  end
137
122
 
138
123
  end# Painter