rays 0.1.12 → 0.1.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.doc/ext/rays/bitmap.cpp +22 -76
- data/.doc/ext/rays/bounds.cpp +95 -125
- data/.doc/ext/rays/camera.cpp +171 -0
- data/.doc/ext/rays/color.cpp +223 -45
- data/.doc/ext/rays/color_space.cpp +146 -46
- data/.doc/ext/rays/defs.cpp +183 -0
- data/.doc/ext/rays/font.cpp +69 -21
- data/.doc/ext/rays/image.cpp +26 -37
- data/.doc/ext/rays/matrix.cpp +186 -29
- data/.doc/ext/rays/native.cpp +14 -8
- data/.doc/ext/rays/noise.cpp +53 -0
- data/.doc/ext/rays/painter.cpp +187 -292
- data/.doc/ext/rays/point.cpp +96 -77
- data/.doc/ext/rays/polygon.cpp +313 -0
- data/.doc/ext/rays/polygon_line.cpp +96 -0
- data/.doc/ext/rays/polyline.cpp +167 -0
- data/.doc/ext/rays/rays.cpp +103 -12
- data/.doc/ext/rays/shader.cpp +83 -9
- data/LICENSE +21 -0
- data/README.md +1 -1
- data/Rakefile +24 -9
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +23 -81
- data/ext/rays/bounds.cpp +100 -128
- data/ext/rays/camera.cpp +186 -0
- data/ext/rays/color.cpp +231 -51
- data/ext/rays/color_space.cpp +149 -47
- data/ext/rays/defs.cpp +183 -0
- data/ext/rays/defs.h +26 -2
- data/ext/rays/extconf.rb +2 -3
- data/ext/rays/font.cpp +74 -24
- data/ext/rays/image.cpp +28 -40
- data/ext/rays/matrix.cpp +198 -30
- data/ext/rays/native.cpp +14 -8
- data/ext/rays/noise.cpp +55 -0
- data/ext/rays/painter.cpp +203 -298
- data/ext/rays/point.cpp +105 -81
- data/ext/rays/polygon.cpp +329 -0
- data/ext/rays/polygon_line.cpp +99 -0
- data/ext/rays/polyline.cpp +176 -0
- data/ext/rays/rays.cpp +103 -13
- 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/camera.h +74 -0
- data/include/rays/color.h +25 -14
- data/include/rays/color_space.h +15 -10
- data/include/rays/coord.h +114 -0
- data/include/rays/debug.h +22 -0
- data/include/rays/defs.h +36 -0
- data/include/rays/exception.h +6 -2
- data/include/rays/font.h +4 -4
- data/include/rays/image.h +12 -18
- 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 +89 -93
- data/include/rays/point.h +44 -51
- data/include/rays/polygon.h +198 -0
- data/include/rays/polyline.h +71 -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/camera.h +41 -0
- 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/rays.h +8 -0
- data/include/rays/ruby/shader.h +1 -1
- data/include/rays/shader.h +36 -8
- data/lib/rays.rb +7 -2
- data/lib/rays/bitmap.rb +0 -15
- data/lib/rays/bounds.rb +17 -23
- data/lib/rays/camera.rb +24 -0
- data/lib/rays/color.rb +20 -47
- data/lib/rays/color_space.rb +13 -13
- data/lib/rays/image.rb +3 -7
- data/lib/rays/matrix.rb +28 -0
- data/lib/rays/module.rb +4 -19
- data/lib/rays/painter.rb +78 -93
- data/lib/rays/point.rb +13 -21
- data/lib/rays/polygon.rb +58 -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 +52 -34
- 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 +172 -98
- data/src/image.h +25 -0
- data/src/ios/bitmap.h +23 -0
- data/src/ios/bitmap.mm +133 -110
- data/src/ios/camera.mm +510 -0
- data/src/ios/font.mm +50 -62
- data/src/ios/helper.h +4 -4
- 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.h +23 -0
- data/src/osx/bitmap.mm +133 -110
- data/src/osx/camera.mm +451 -0
- data/src/osx/font.mm +49 -62
- 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 +845 -671
- data/src/painter.h +24 -0
- data/src/point.cpp +140 -119
- data/src/polygon.cpp +1266 -0
- data/src/polygon.h +32 -0
- data/src/polyline.cpp +160 -0
- data/src/polyline.h +69 -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_font.rb +5 -0
- data/test/test_image.rb +24 -20
- data/test/test_matrix.rb +106 -0
- data/test/test_painter.rb +157 -51
- data/test/test_painter_shape.rb +102 -0
- data/test/test_point.rb +29 -0
- data/test/test_polygon.rb +234 -0
- data/test/test_polygon_line.rb +167 -0
- data/test/test_polyline.rb +171 -0
- data/test/test_shader.rb +9 -9
- metadata +102 -70
- 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
data/lib/rays/color.rb
CHANGED
@@ -10,24 +10,19 @@ module Rays
|
|
10
10
|
class Color
|
11
11
|
|
12
12
|
include Comparable
|
13
|
+
include Enumerable
|
13
14
|
|
14
|
-
|
15
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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.
|
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
|
|
data/lib/rays/color_space.rb
CHANGED
@@ -9,25 +9,25 @@ module Rays
|
|
9
9
|
|
10
10
|
class ColorSpace
|
11
11
|
|
12
|
-
|
13
|
-
|
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
|
17
|
-
|
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
|
27
|
-
|
26
|
+
def inspect ()
|
27
|
+
"#<#{self.class.name} #{to_s}>"
|
28
28
|
end
|
29
29
|
|
30
|
-
end#
|
30
|
+
end# Color
|
31
31
|
|
32
32
|
|
33
33
|
end# Rays
|
data/lib/rays/image.rb
CHANGED
@@ -12,10 +12,10 @@ module Rays
|
|
12
12
|
|
13
13
|
extend Forwardable
|
14
14
|
|
15
|
-
def_delegators :bitmap, :
|
15
|
+
def_delegators :bitmap, :[], :[]=
|
16
16
|
|
17
17
|
def paint (&block)
|
18
|
-
painter.
|
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,
|
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
|
data/lib/rays/matrix.rb
ADDED
@@ -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
|
data/lib/rays/module.rb
CHANGED
@@ -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 "
|
20
|
+
File.expand_path "../../#{path}", __dir__
|
19
21
|
end
|
20
22
|
|
21
|
-
def
|
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
|
|
data/lib/rays/painter.rb
CHANGED
@@ -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
|
15
|
-
|
16
|
-
|
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
|
-
|
19
|
-
|
20
|
-
end
|
24
|
+
raise ArgumentError, 'missing block with pushing attributes.' if
|
25
|
+
!attributes.empty? && !block
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
|
27
|
+
if block
|
28
|
+
attributes.each do |key, value|
|
29
|
+
attributes[key] = __send__ key
|
30
|
+
__send__ key, *value
|
31
|
+
end
|
25
32
|
|
26
|
-
|
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
|
-
|
31
|
-
|
32
|
-
|
35
|
+
attributes.each do |key, value|
|
36
|
+
__send__ key, *value
|
37
|
+
end
|
33
38
|
|
34
|
-
|
35
|
-
|
39
|
+
pop *types
|
40
|
+
end
|
36
41
|
end
|
37
42
|
|
38
|
-
def
|
39
|
-
|
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
|
43
|
-
|
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
|
47
|
-
|
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
|
51
|
-
|
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
|
55
|
-
|
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
|
65
|
-
|
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
|
-
|
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
|
89
|
-
|
90
|
-
|
91
|
-
pop_matrix
|
85
|
+
def color= (fill, stroke = nil)
|
86
|
+
self.fill fill
|
87
|
+
self.stroke stroke
|
92
88
|
end
|
93
89
|
|
94
|
-
def
|
95
|
-
|
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
|
-
|
94
|
+
def shader= (shader, **uniforms)
|
95
|
+
shader.uniform **uniforms if shader && !uniforms.empty?
|
96
|
+
set_shader shader
|
97
|
+
end
|
101
98
|
|
102
|
-
|
99
|
+
const_symbol_accessor :stroke_cap, {
|
100
|
+
butt: CAP_BUTT,
|
101
|
+
round: CAP_ROUND,
|
102
|
+
square: CAP_SQUARE
|
103
|
+
}
|
103
104
|
|
104
|
-
|
105
|
-
|
106
|
-
|
105
|
+
const_symbol_accessor :stroke_join, {
|
106
|
+
miter: JOIN_MITER,
|
107
|
+
round: JOIN_ROUND,
|
108
|
+
square: JOIN_SQUARE
|
109
|
+
}
|
107
110
|
|
108
|
-
|
109
|
-
|
110
|
-
|
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
|
-
|
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
|
129
|
-
|
130
|
-
|
131
|
-
|
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
|