rays 0.1.12 → 0.1.13
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/color.cpp +224 -45
- data/.doc/ext/rays/color_space.cpp +137 -45
- data/.doc/ext/rays/defs.cpp +183 -0
- data/.doc/ext/rays/font.cpp +39 -21
- data/.doc/ext/rays/image.cpp +26 -37
- data/.doc/ext/rays/matrix.cpp +186 -29
- data/.doc/ext/rays/native.cpp +12 -6
- data/.doc/ext/rays/noise.cpp +53 -0
- data/.doc/ext/rays/painter.cpp +120 -308
- data/.doc/ext/rays/point.cpp +82 -77
- data/.doc/ext/rays/polygon.cpp +287 -0
- data/.doc/ext/rays/polygon_line.cpp +96 -0
- data/.doc/ext/rays/polyline.cpp +161 -0
- data/.doc/ext/rays/rays.cpp +0 -13
- data/.doc/ext/rays/shader.cpp +83 -9
- data/README.md +1 -1
- data/Rakefile +21 -9
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +22 -80
- data/ext/rays/bounds.cpp +100 -128
- data/ext/rays/color.cpp +232 -51
- data/ext/rays/color_space.cpp +140 -46
- data/ext/rays/defs.cpp +183 -0
- data/ext/rays/defs.h +26 -2
- data/ext/rays/extconf.rb +1 -2
- data/ext/rays/font.cpp +39 -22
- data/ext/rays/image.cpp +27 -39
- data/ext/rays/matrix.cpp +198 -30
- data/ext/rays/native.cpp +12 -6
- data/ext/rays/noise.cpp +55 -0
- data/ext/rays/painter.cpp +129 -315
- data/ext/rays/point.cpp +89 -81
- data/ext/rays/polygon.cpp +301 -0
- data/ext/rays/polygon_line.cpp +99 -0
- data/ext/rays/polyline.cpp +170 -0
- data/ext/rays/rays.cpp +0 -14
- 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/color.h +25 -14
- data/include/rays/color_space.h +11 -8
- data/include/rays/coord.h +114 -0
- data/include/rays/debug.h +22 -0
- data/include/rays/defs.h +3 -0
- data/include/rays/font.h +4 -4
- data/include/rays/image.h +11 -17
- 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 +57 -99
- data/include/rays/point.h +44 -51
- data/include/rays/polygon.h +164 -0
- data/include/rays/polyline.h +65 -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/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/shader.h +1 -1
- data/include/rays/shader.h +36 -8
- data/lib/rays.rb +6 -1
- data/lib/rays/bitmap.rb +0 -15
- data/lib/rays/bounds.rb +17 -23
- data/lib/rays/color.rb +20 -47
- data/lib/rays/color_space.rb +13 -13
- data/lib/rays/image.rb +2 -6
- data/lib/rays/matrix.rb +28 -0
- data/lib/rays/module.rb +4 -19
- data/lib/rays/painter.rb +60 -97
- data/lib/rays/point.rb +13 -21
- data/lib/rays/polygon.rb +50 -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 +50 -32
- 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 +171 -97
- data/src/image.h +25 -0
- data/src/ios/bitmap.mm +107 -105
- data/src/ios/font.mm +48 -60
- data/src/ios/helper.h +2 -2
- 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.mm +111 -106
- data/src/osx/font.mm +48 -61
- 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 +780 -696
- data/src/painter.h +24 -0
- data/src/point.cpp +140 -119
- data/src/polygon.cpp +1100 -0
- data/src/polygon.h +32 -0
- data/src/polyline.cpp +158 -0
- data/src/polyline.h +67 -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_image.rb +24 -20
- data/test/test_matrix.rb +106 -0
- data/test/test_painter.rb +92 -46
- data/test/test_painter_shape.rb +57 -0
- data/test/test_point.rb +21 -0
- data/test/test_polygon.rb +234 -0
- data/test/test_polygon_line.rb +167 -0
- data/test/test_polyline.rb +145 -0
- data/test/test_shader.rb +9 -9
- metadata +88 -67
- 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/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
|
|
@@ -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
|
|
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,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
|
15
|
-
|
16
|
-
|
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
|
-
|
19
|
-
|
20
|
-
end
|
23
|
+
raise ArgumentError, 'missing block with pushing attributes.' if
|
24
|
+
!attributes.empty? && !block
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
if block
|
27
|
+
attributes.each do |key, value|
|
28
|
+
attributes[key] = __send__ key
|
29
|
+
__send__ key, *value
|
30
|
+
end
|
25
31
|
|
26
|
-
|
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
|
-
|
31
|
-
|
32
|
-
|
34
|
+
attributes.each do |key, value|
|
35
|
+
__send__ key, *value
|
36
|
+
end
|
33
37
|
|
34
|
-
|
35
|
-
|
38
|
+
pop *types
|
39
|
+
end
|
36
40
|
end
|
37
41
|
|
38
|
-
def
|
39
|
-
|
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
|
43
|
-
|
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
|
47
|
-
|
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
|
51
|
-
|
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
|
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
|
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
|
65
|
-
|
66
|
-
|
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
|
-
|
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
|
89
|
-
|
90
|
-
|
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
|
-
|
95
|
-
|
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
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
data/lib/rays/point.rb
CHANGED
@@ -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
|
32
|
-
|
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
|
54
|
-
|
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
|
data/lib/rays/polygon.rb
ADDED
@@ -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
|