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.
Files changed (155) 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/color.cpp +224 -45
  5. data/.doc/ext/rays/color_space.cpp +137 -45
  6. data/.doc/ext/rays/defs.cpp +183 -0
  7. data/.doc/ext/rays/font.cpp +39 -21
  8. data/.doc/ext/rays/image.cpp +26 -37
  9. data/.doc/ext/rays/matrix.cpp +186 -29
  10. data/.doc/ext/rays/native.cpp +12 -6
  11. data/.doc/ext/rays/noise.cpp +53 -0
  12. data/.doc/ext/rays/painter.cpp +120 -308
  13. data/.doc/ext/rays/point.cpp +82 -77
  14. data/.doc/ext/rays/polygon.cpp +287 -0
  15. data/.doc/ext/rays/polygon_line.cpp +96 -0
  16. data/.doc/ext/rays/polyline.cpp +161 -0
  17. data/.doc/ext/rays/rays.cpp +0 -13
  18. data/.doc/ext/rays/shader.cpp +83 -9
  19. data/README.md +1 -1
  20. data/Rakefile +21 -9
  21. data/VERSION +1 -1
  22. data/ext/rays/bitmap.cpp +22 -80
  23. data/ext/rays/bounds.cpp +100 -128
  24. data/ext/rays/color.cpp +232 -51
  25. data/ext/rays/color_space.cpp +140 -46
  26. data/ext/rays/defs.cpp +183 -0
  27. data/ext/rays/defs.h +26 -2
  28. data/ext/rays/extconf.rb +1 -2
  29. data/ext/rays/font.cpp +39 -22
  30. data/ext/rays/image.cpp +27 -39
  31. data/ext/rays/matrix.cpp +198 -30
  32. data/ext/rays/native.cpp +12 -6
  33. data/ext/rays/noise.cpp +55 -0
  34. data/ext/rays/painter.cpp +129 -315
  35. data/ext/rays/point.cpp +89 -81
  36. data/ext/rays/polygon.cpp +301 -0
  37. data/ext/rays/polygon_line.cpp +99 -0
  38. data/ext/rays/polyline.cpp +170 -0
  39. data/ext/rays/rays.cpp +0 -14
  40. data/ext/rays/shader.cpp +84 -9
  41. data/include/rays.h +10 -2
  42. data/include/rays/bitmap.h +14 -26
  43. data/include/rays/bounds.h +21 -4
  44. data/include/rays/color.h +25 -14
  45. data/include/rays/color_space.h +11 -8
  46. data/include/rays/coord.h +114 -0
  47. data/include/rays/debug.h +22 -0
  48. data/include/rays/defs.h +3 -0
  49. data/include/rays/font.h +4 -4
  50. data/include/rays/image.h +11 -17
  51. data/include/rays/matrix.h +50 -24
  52. data/include/rays/noise.h +42 -0
  53. data/include/rays/opengl.h +2 -50
  54. data/include/rays/painter.h +57 -99
  55. data/include/rays/point.h +44 -51
  56. data/include/rays/polygon.h +164 -0
  57. data/include/rays/polyline.h +65 -0
  58. data/include/rays/rays.h +3 -0
  59. data/include/rays/ruby.h +7 -1
  60. data/include/rays/ruby/bounds.h +1 -1
  61. data/include/rays/ruby/color.h +1 -1
  62. data/include/rays/ruby/color_space.h +1 -1
  63. data/include/rays/ruby/font.h +1 -1
  64. data/include/rays/ruby/matrix.h +1 -1
  65. data/include/rays/ruby/point.h +1 -1
  66. data/include/rays/ruby/polygon.h +52 -0
  67. data/include/rays/ruby/polyline.h +41 -0
  68. data/include/rays/ruby/shader.h +1 -1
  69. data/include/rays/shader.h +36 -8
  70. data/lib/rays.rb +6 -1
  71. data/lib/rays/bitmap.rb +0 -15
  72. data/lib/rays/bounds.rb +17 -23
  73. data/lib/rays/color.rb +20 -47
  74. data/lib/rays/color_space.rb +13 -13
  75. data/lib/rays/image.rb +2 -6
  76. data/lib/rays/matrix.rb +28 -0
  77. data/lib/rays/module.rb +4 -19
  78. data/lib/rays/painter.rb +60 -97
  79. data/lib/rays/point.rb +13 -21
  80. data/lib/rays/polygon.rb +50 -0
  81. data/lib/rays/polygon_line.rb +36 -0
  82. data/lib/rays/polyline.rb +32 -0
  83. data/lib/rays/shader.rb +20 -1
  84. data/rays.gemspec +5 -7
  85. data/src/bitmap.h +36 -0
  86. data/src/bounds.cpp +74 -11
  87. data/src/color.cpp +58 -23
  88. data/src/color_space.cpp +50 -32
  89. data/src/color_space.h +22 -0
  90. data/src/coord.cpp +170 -0
  91. data/src/coord.h +35 -0
  92. data/src/font.cpp +118 -0
  93. data/src/font.h +64 -0
  94. data/src/frame_buffer.cpp +37 -71
  95. data/src/frame_buffer.h +4 -4
  96. data/src/image.cpp +171 -97
  97. data/src/image.h +25 -0
  98. data/src/ios/bitmap.mm +107 -105
  99. data/src/ios/font.mm +48 -60
  100. data/src/ios/helper.h +2 -2
  101. data/src/ios/opengl.mm +19 -4
  102. data/src/ios/rays.mm +3 -0
  103. data/src/matrix.cpp +111 -26
  104. data/src/matrix.h +30 -0
  105. data/src/noise.cpp +74 -0
  106. data/src/opengl.cpp +9 -27
  107. data/src/opengl.h +37 -0
  108. data/src/osx/bitmap.mm +111 -106
  109. data/src/osx/font.mm +48 -61
  110. data/src/osx/helper.h +2 -2
  111. data/src/osx/opengl.mm +19 -83
  112. data/src/osx/rays.mm +3 -0
  113. data/src/painter.cpp +780 -696
  114. data/src/painter.h +24 -0
  115. data/src/point.cpp +140 -119
  116. data/src/polygon.cpp +1100 -0
  117. data/src/polygon.h +32 -0
  118. data/src/polyline.cpp +158 -0
  119. data/src/polyline.h +67 -0
  120. data/src/render_buffer.cpp +11 -4
  121. data/src/render_buffer.h +2 -2
  122. data/src/shader.cpp +163 -106
  123. data/src/shader.h +38 -0
  124. data/src/shader_program.cpp +533 -0
  125. data/src/{program.h → shader_program.h} +28 -16
  126. data/src/shader_source.cpp +140 -0
  127. data/src/shader_source.h +52 -0
  128. data/src/texture.cpp +136 -160
  129. data/src/texture.h +65 -0
  130. data/src/win32/bitmap.cpp +62 -52
  131. data/src/win32/font.cpp +11 -13
  132. data/src/win32/font.h +24 -0
  133. data/src/win32/gdi.h +6 -6
  134. data/test/helper.rb +0 -3
  135. data/test/test_bitmap.rb +31 -7
  136. data/test/test_bounds.rb +36 -0
  137. data/test/test_color.rb +59 -19
  138. data/test/test_color_space.rb +95 -0
  139. data/test/test_image.rb +24 -20
  140. data/test/test_matrix.rb +106 -0
  141. data/test/test_painter.rb +92 -46
  142. data/test/test_painter_shape.rb +57 -0
  143. data/test/test_point.rb +21 -0
  144. data/test/test_polygon.rb +234 -0
  145. data/test/test_polygon_line.rb +167 -0
  146. data/test/test_polyline.rb +145 -0
  147. data/test/test_shader.rb +9 -9
  148. metadata +88 -67
  149. data/.doc/ext/rays/texture.cpp +0 -138
  150. data/ext/rays/texture.cpp +0 -149
  151. data/include/rays/ruby/texture.h +0 -41
  152. data/include/rays/texture.h +0 -71
  153. data/lib/rays/texture.rb +0 -24
  154. data/src/program.cpp +0 -648
  155. data/test/test_texture.rb +0 -27
@@ -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
 
@@ -27,10 +27,6 @@ module Rays
27
27
  Bounds.new 0, 0, *size
28
28
  end
29
29
 
30
- def self.load (path, alpha_only = false)
31
- load_image path, alpha_only
32
- end
33
-
34
30
  end# Image
35
31
 
36
32
 
@@ -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,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
+ require 'xot/universal_accessor'
4
5
  require 'xot/block_util'
5
6
  require 'rays/ext'
6
- require 'rays/color'
7
7
 
8
8
 
9
9
  module Rays
@@ -11,128 +11,91 @@ module Rays
11
11
 
12
12
  class Painter
13
13
 
14
- def background (*args, &block)
15
- set_or_get :background=, :get_background, args, block
16
- end
14
+ def push (*types, **attributes, &block)
15
+ each_type types do |type|
16
+ case type
17
+ when :state then push_state
18
+ when :matrix then push_matrix
19
+ else raise ArgumentError, "invalid push/pop type '#{type}'."
20
+ end
21
+ end
17
22
 
18
- def background= (*args)
19
- send_set :set_background, :get_background, :no_background, args, :color
20
- end
23
+ raise ArgumentError, 'missing block with pushing attributes.' if
24
+ !attributes.empty? && !block
21
25
 
22
- def fill (*args, &block)
23
- set_or_get :fill=, :get_fill, args, block
24
- end
26
+ if block
27
+ attributes.each do |key, value|
28
+ attributes[key] = __send__ key
29
+ __send__ key, *value
30
+ end
25
31
 
26
- def fill= (*args)
27
- send_set :set_fill, :get_fill, :no_fill, args, :color
28
- end
32
+ Xot::BlockUtil.instance_eval_or_block_call self, &block
29
33
 
30
- def stroke (*args, &block)
31
- set_or_get :stroke=, :get_stroke, args, block
32
- end
34
+ attributes.each do |key, value|
35
+ __send__ key, *value
36
+ end
33
37
 
34
- def stroke= (*args)
35
- send_set :set_stroke, :get_stroke, :no_stroke, args, :color
38
+ pop *types
39
+ end
36
40
  end
37
41
 
38
- def clip (*args, &block)
39
- set_or_get :clip=, :get_clip, args, block
42
+ def pop (*types)
43
+ each_type types, reverse: true do |type|
44
+ case type
45
+ when :state then pop_state
46
+ when :matrix then pop_matrix
47
+ else raise ArgumentError, "invalid push/pop type '#{type}'."
48
+ end
49
+ end
40
50
  end
41
51
 
42
- def clip= (*args)
43
- send_set :set_clip, :get_clip, :no_clip, args
52
+ def paint (*args, &block)
53
+ begin_paint
54
+ Xot::BlockUtil.instance_eval_or_block_call self, *args, &block
55
+ self
56
+ ensure
57
+ end_paint
44
58
  end
45
59
 
46
- def font (*args, &block)
47
- set_or_get :font=, :get_font, args, block
60
+ def line (*args, loop: false)
61
+ if args.first.kind_of?(Polyline)
62
+ draw_polyline args.first
63
+ else
64
+ draw_line args, loop
65
+ end
48
66
  end
49
67
 
50
- def font= (*args)
51
- send_set :set_font, :get_font, nil, args
68
+ def rect (*args, round: nil, lt: nil, rt: nil, lb: nil, rb: nil)
69
+ draw_rect args, round, lt, rt, lb, rb
52
70
  end
53
71
 
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
72
+ def ellipse (*args, center: nil, radius: nil, hole: nil, from: nil, to: nil)
73
+ draw_ellipse args, center, radius, hole, from, to
62
74
  end
63
75
 
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
76
+ def color= (fill, stroke = nil)
77
+ self.fill fill
78
+ self.stroke stroke
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 color ()
82
+ return fill, stroke
86
83
  end
87
84
 
88
- def pop ()
89
- pop_shader
90
- pop_attr
91
- pop_matrix
85
+ def shader= (shader, **uniforms)
86
+ shader.uniform **uniforms if shader && !uniforms.empty?
87
+ set_shader shader
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
98
- end
90
+ universal_accessor :background, :fill, :stroke, :color,
91
+ :stroke_width, :nsegment, :shader, :clip, :font
99
92
 
100
93
  private
101
94
 
102
- NONES = [:no, :none, nil]
103
-
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?
107
-
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
119
-
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
127
-
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
95
+ def each_type (types, reverse: false, &block)
96
+ types = [:state, :matrix] if types.empty? || types.include?(:all)
97
+ types = types.reverse if reverse
98
+ types.each &block
136
99
  end
137
100
 
138
101
  end# Painter
@@ -10,6 +10,7 @@ module Rays
10
10
  class Point
11
11
 
12
12
  include Comparable
13
+ include Enumerable
13
14
 
14
15
  def move_to (*args)
15
16
  dup.move_to! *args
@@ -19,6 +20,14 @@ module Rays
19
20
  dup.move_by! *args
20
21
  end
21
22
 
23
+ def zero? ()
24
+ length == 0
25
+ end
26
+
27
+ def each (&block)
28
+ to_a.each &block
29
+ end
30
+
22
31
  def to_a (dimension = 2)
23
32
  case dimension
24
33
  when 1 then [x]
@@ -28,20 +37,8 @@ module Rays
28
37
  end
29
38
  end
30
39
 
31
- def + (*args)
32
- op_add Point.from(*args)
33
- end
34
-
35
- def - (*args)
36
- op_sub Point.from(*args)
37
- end
38
-
39
- def * (*args)
40
- op_mult Point.from(*args)
41
- end
42
-
43
- def / (*args)
44
- op_div Point.from(*args)
40
+ def to_s (dimension = 2)
41
+ to_a(dimension).to_s
45
42
  end
46
43
 
47
44
  def <=> (o)
@@ -50,13 +47,8 @@ module Rays
50
47
  z <=> o.z
51
48
  end
52
49
 
53
- def self.from (*args)
54
- case arg0 = args[0]
55
- when Point then arg0
56
- when Array then Point.new *arg0
57
- when Numeric then Point.new arg0, arg0, arg0
58
- else raise ArgumentError
59
- end
50
+ def inspect ()
51
+ "#<Rays::Point #{to_a(3).join ', '}>"
60
52
  end
61
53
 
62
54
  end# Point
@@ -0,0 +1,50 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'rays/ext'
5
+ require 'rays/polyline'
6
+
7
+
8
+ module Rays
9
+
10
+
11
+ class Polygon
12
+
13
+ include Enumerable
14
+
15
+ def initialize (*args, loop: true)
16
+ setup args, loop
17
+ end
18
+
19
+ def transform (matrix = nil, &block)
20
+ lines = to_a
21
+ lines = lines.map {|line| line.transform matrix} if matrix
22
+ lines = block.call lines if block
23
+ self.class.new *lines
24
+ end
25
+
26
+ def intersects (obj)
27
+ !(self & obj).empty?
28
+ end
29
+
30
+ def self.line (*args, loop: false)
31
+ new *args, loop: loop
32
+ end
33
+
34
+ def self.rect (
35
+ *args, round: nil, lt: nil, rt: nil, lb: nil, rb: nil, nsegment: nil)
36
+
37
+ create_rect args, round, lt, rt, lb, rb, nsegment
38
+ end
39
+
40
+ def self.ellipse (
41
+ *args, center: nil, radius: nil, hole: nil, from: nil, to: nil,
42
+ nsegment: nil)
43
+
44
+ create_ellipse args, center, radius, hole, from, to, nsegment
45
+ end
46
+
47
+ end# Polygon
48
+
49
+
50
+ end# Rays
@@ -0,0 +1,36 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'rays/ext'
5
+
6
+
7
+ module Rays
8
+
9
+
10
+ class Polygon
11
+
12
+
13
+ class Line < Polyline
14
+
15
+ def initialize (*points, loop: true, hole: false)
16
+ setup points, loop, hole
17
+ end
18
+
19
+ def transform (matrix = nil, loop: loop?, hole: hole?, &block)
20
+ points = to_a
21
+ points = points.map {|point| matrix * point} if matrix
22
+ points = block.call points if block
23
+ self.class.new *points, loop: loop, hole: hole
24
+ end
25
+
26
+ def inspect ()
27
+ "#<Rays::Polygon::Line #{to_a.join ', '}, loop: #{loop?}, hole: #{hole?}>"
28
+ end
29
+
30
+ end# Line
31
+
32
+
33
+ end# Polygon
34
+
35
+
36
+ end# Rays
@@ -0,0 +1,32 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'rays/ext'
5
+
6
+
7
+ module Rays
8
+
9
+
10
+ class Polyline
11
+
12
+ include Enumerable
13
+
14
+ def initialize (*points, loop: false)
15
+ setup points, loop
16
+ end
17
+
18
+ def transform (matrix = nil, loop: loop?, &block)
19
+ points = to_a
20
+ points = points.map {|point| matrix * point} if matrix
21
+ points = block.call points if block
22
+ self.class.new *points, loop: loop
23
+ end
24
+
25
+ def inspect ()
26
+ "#<Rays::Polyline #{to_a.join ', '}, loop: #{loop?}>"
27
+ end
28
+
29
+ end# Polyline
30
+
31
+
32
+ end# Rays