rubysketch 0.3.15 → 0.3.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +2 -2
- data/.github/workflows/test.yml +2 -2
- data/ChangeLog.md +23 -0
- data/VERSION +1 -1
- data/lib/rubysketch/app.rb +13 -0
- data/lib/rubysketch/glsl.rb +2 -2
- data/lib/rubysketch/module.rb +3 -3
- data/lib/rubysketch/processing.rb +406 -257
- data/lib/rubysketch/window.rb +81 -58
- data/lib/rubysketch-processing.rb +1 -1
- data/lib/rubysketch.rb +2 -0
- data/rubysketch.gemspec +2 -2
- data/test/helper.rb +1 -1
- data/test/processing/test_utility.rb +3 -7
- data/test/processing/test_vector.rb +43 -46
- metadata +8 -7
data/lib/rubysketch/window.rb
CHANGED
@@ -4,99 +4,116 @@ module RubySketch
|
|
4
4
|
class Window < Reflex::Window
|
5
5
|
|
6
6
|
attr_accessor :setup, :update, :draw, :before_draw, :after_draw, :resize,
|
7
|
+
:key_down, :key_up,
|
7
8
|
:pointer_down, :pointer_up, :pointer_move, :pointer_drag,
|
8
|
-
:
|
9
|
+
:motion
|
9
10
|
|
10
11
|
attr_accessor :auto_resize
|
11
12
|
|
12
|
-
attr_reader :
|
13
|
+
attr_reader :canvas_image, :canvas_painter
|
13
14
|
|
14
|
-
def initialize
|
15
|
-
|
16
|
-
|
17
|
-
@
|
15
|
+
def initialize(width = 500, height = 500, *args, **kwargs, &block)
|
16
|
+
RubySketch.instance_variable_set :@window, self
|
17
|
+
|
18
|
+
@canvas_image =
|
19
|
+
@canvas_painter = nil
|
20
|
+
@events = []
|
21
|
+
@auto_resize = true
|
22
|
+
@error = nil
|
18
23
|
|
19
24
|
painter.miter_limit = 10
|
20
25
|
resize_canvas 1, 1
|
21
26
|
|
22
|
-
|
27
|
+
@canvas_view = add Reflex::View.new(name: :canvas) {|v|
|
28
|
+
v.on(:update) {|e| on_canvas_update e}
|
29
|
+
v.on(:draw) {|e| on_canvas_draw e}
|
30
|
+
v.on(:pointer) {|e| on_canvas_pointer e}
|
31
|
+
v.on(:resize) {|e| on_canvas_resize e}
|
32
|
+
}
|
33
|
+
|
34
|
+
super(*args, size: [width, height], **kwargs, &block)
|
23
35
|
end
|
24
36
|
|
25
|
-
def start
|
37
|
+
def start(&block)
|
26
38
|
draw_canvas do
|
27
39
|
block.call if block
|
28
40
|
on_setup
|
29
41
|
end
|
30
42
|
end
|
31
43
|
|
32
|
-
def event
|
44
|
+
def event()
|
33
45
|
@events.last
|
34
46
|
end
|
35
47
|
|
36
|
-
def on_setup
|
48
|
+
def on_setup()
|
37
49
|
call_block @setup, nil
|
38
50
|
end
|
39
51
|
|
40
|
-
def
|
41
|
-
|
42
|
-
redraw
|
43
|
-
end
|
44
|
-
|
45
|
-
def on_draw (e)
|
46
|
-
draw_canvas {call_block @draw, e} if @draw
|
47
|
-
|
48
|
-
x, y, w, h = coord_converter
|
49
|
-
e.painter.image @canvas, x, y, @canvas.width * w, @canvas.height * h
|
52
|
+
def on_resize(e)
|
53
|
+
on_canvas_resize e
|
50
54
|
end
|
51
55
|
|
52
|
-
def
|
53
|
-
|
56
|
+
def on_draw(e)
|
57
|
+
update_canvas_view
|
54
58
|
end
|
55
59
|
|
56
|
-
def
|
57
|
-
block = case e.
|
58
|
-
when :down then @
|
59
|
-
when :up then @
|
60
|
-
when :move then e.drag? ? @pointer_drag : @pointer_move
|
60
|
+
def on_key(e)
|
61
|
+
block = case e.action
|
62
|
+
when :down then @key_down
|
63
|
+
when :up then @key_up
|
61
64
|
end
|
62
65
|
draw_canvas {call_block block, e} if block
|
63
66
|
end
|
64
67
|
|
65
|
-
def on_motion
|
68
|
+
def on_motion(e)
|
66
69
|
draw_canvas {call_block @motion, e} if @motion
|
67
70
|
end
|
68
71
|
|
69
|
-
def
|
70
|
-
|
71
|
-
|
72
|
+
def on_canvas_update(e)
|
73
|
+
call_block @update, e
|
74
|
+
@canvas_view.redraw
|
72
75
|
end
|
73
76
|
|
74
|
-
def
|
75
|
-
|
76
|
-
|
77
|
+
def on_canvas_draw(e)
|
78
|
+
draw_canvas {call_block @draw, e} if @draw
|
79
|
+
e.painter.image @canvas_image
|
80
|
+
end
|
81
|
+
|
82
|
+
def on_canvas_pointer(e)
|
83
|
+
block = case e.action
|
84
|
+
when :down then @pointer_down
|
85
|
+
when :up, :cancel then @pointer_up
|
86
|
+
when :move then e.drag? ? @pointer_drag : @pointer_move
|
87
|
+
end
|
88
|
+
draw_canvas {call_block block, e} if block
|
89
|
+
end
|
90
|
+
|
91
|
+
def on_canvas_resize(e)
|
92
|
+
resize_canvas e.width, e.height if @auto_resize
|
93
|
+
draw_canvas {call_block @resize, e} if @resize
|
77
94
|
end
|
78
95
|
|
79
96
|
private
|
80
97
|
|
81
|
-
def resize_canvas
|
98
|
+
def resize_canvas(width, height, pixel_density = nil)
|
82
99
|
return nil if width * height == 0
|
83
100
|
|
84
|
-
unless width == @
|
85
|
-
height == @
|
101
|
+
unless width == @canvas_image&.width &&
|
102
|
+
height == @canvas_image&.height &&
|
86
103
|
pixel_density == @canvas_painter&.pixel_density
|
87
104
|
|
88
|
-
|
105
|
+
old_image = @canvas_image
|
89
106
|
old_painter = @canvas_painter
|
90
|
-
cs =
|
107
|
+
cs = old_image&.color_space || Rays::RGBA
|
91
108
|
pd = pixel_density ||
|
92
109
|
old_painter&.pixel_density ||
|
93
110
|
painter .pixel_density
|
94
111
|
|
95
|
-
@
|
96
|
-
@canvas_painter = @
|
112
|
+
@canvas_image = Rays::Image.new width, height, cs, pd
|
113
|
+
@canvas_painter = @canvas_image.painter
|
97
114
|
|
98
|
-
if
|
99
|
-
@canvas_painter.paint {image
|
115
|
+
if old_image
|
116
|
+
@canvas_painter.paint {image old_image}
|
100
117
|
copy_painter_attributes old_painter, @canvas_painter
|
101
118
|
end
|
102
119
|
|
@@ -106,11 +123,7 @@ module RubySketch
|
|
106
123
|
@canvas_painter
|
107
124
|
end
|
108
125
|
|
109
|
-
def
|
110
|
-
size width, height
|
111
|
-
end
|
112
|
-
|
113
|
-
def copy_painter_attributes (from, to)
|
126
|
+
def copy_painter_attributes(from, to)
|
114
127
|
to.fill = from.fill
|
115
128
|
to.stroke = from.stroke
|
116
129
|
to.stroke_width = from.stroke_width
|
@@ -120,39 +133,49 @@ module RubySketch
|
|
120
133
|
to.font = from.font
|
121
134
|
end
|
122
135
|
|
123
|
-
def
|
124
|
-
|
125
|
-
|
126
|
-
|
136
|
+
def resize_window(width, height)
|
137
|
+
size width, height
|
138
|
+
end
|
139
|
+
|
140
|
+
def update_canvas_view()
|
141
|
+
scrollx, scrolly, zoom = get_scroll_and_zoom
|
142
|
+
@canvas_view.scroll_to scrollx, scrolly
|
143
|
+
@canvas_view.zoom zoom
|
144
|
+
end
|
145
|
+
|
146
|
+
def get_scroll_and_zoom()
|
147
|
+
ww, wh = width.to_f, height.to_f
|
148
|
+
cw, ch = @canvas_image.width.to_f, @canvas_image.height.to_f
|
149
|
+
return [0, 0, 1] if ww == 0 || wh == 0 || cw == 0 || ch == 0
|
127
150
|
|
128
151
|
wratio, cratio = ww / wh, cw / ch
|
129
152
|
if wratio >= cratio
|
130
153
|
scaled_w = wh * cratio
|
131
|
-
return (ww - scaled_w) / 2, 0, scaled_w / cw
|
154
|
+
return (ww - scaled_w) / 2, 0, scaled_w / cw
|
132
155
|
else
|
133
156
|
scaled_h = ww / cratio
|
134
|
-
return 0, (wh - scaled_h) / 2, ww / cw
|
157
|
+
return 0, (wh - scaled_h) / 2, ww / cw
|
135
158
|
end
|
136
159
|
end
|
137
160
|
|
138
|
-
def draw_canvas
|
161
|
+
def draw_canvas(&block)
|
139
162
|
begin_draw
|
140
163
|
block.call
|
141
164
|
ensure
|
142
165
|
end_draw
|
143
166
|
end
|
144
167
|
|
145
|
-
def begin_draw
|
168
|
+
def begin_draw()
|
146
169
|
@canvas_painter.__send__ :begin_paint
|
147
170
|
@before_draw&.call
|
148
171
|
end
|
149
172
|
|
150
|
-
def end_draw
|
173
|
+
def end_draw()
|
151
174
|
@after_draw&.call
|
152
175
|
@canvas_painter.__send__ :end_paint
|
153
176
|
end
|
154
177
|
|
155
|
-
def call_block
|
178
|
+
def call_block(block, event, *args)
|
156
179
|
@events.push event
|
157
180
|
block.call event, *args if block && !@error
|
158
181
|
rescue Exception => e
|
data/lib/rubysketch.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'set'
|
1
2
|
require 'digest/sha1'
|
2
3
|
require 'pathname'
|
3
4
|
require 'tmpdir'
|
@@ -5,6 +6,7 @@ require 'open-uri'
|
|
5
6
|
|
6
7
|
require 'reflex'
|
7
8
|
require 'rubysketch/module'
|
9
|
+
require 'rubysketch/app'
|
8
10
|
require 'rubysketch/window'
|
9
11
|
require 'rubysketch/processing'
|
10
12
|
require 'rubysketch/glsl'
|
data/rubysketch.gemspec
CHANGED
@@ -26,9 +26,9 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.homepage = "https://github.com/xord/rubysketch"
|
27
27
|
|
28
28
|
s.platform = Gem::Platform::RUBY
|
29
|
-
s.required_ruby_version = '
|
29
|
+
s.required_ruby_version = '>= 2.6.0'
|
30
30
|
|
31
|
-
s.add_runtime_dependency 'reflexion', '~> 0.1'
|
31
|
+
s.add_runtime_dependency 'reflexion', '~> 0.1.25'
|
32
32
|
|
33
33
|
s.files = `git ls-files`.split $/
|
34
34
|
s.test_files = s.files.grep %r{^(test|spec|features)/}
|
data/test/helper.rb
CHANGED
@@ -12,7 +12,7 @@ require 'rubysketch'
|
|
12
12
|
include Xot::Test
|
13
13
|
|
14
14
|
|
15
|
-
def assert_equal_vector
|
15
|
+
def assert_equal_vector(v1, v2, delta = 0.000001)
|
16
16
|
assert_in_delta v1.x, v2.x, delta
|
17
17
|
assert_in_delta v1.y, v2.y, delta
|
18
18
|
assert_in_delta v1.z, v2.z, delta
|
@@ -6,15 +6,11 @@ require_relative '../helper'
|
|
6
6
|
|
7
7
|
class TestProcessingUtility < Test::Unit::TestCase
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
def context()
|
10
|
+
RubySketch::Processing::Context.new RubySketch::Window.new
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
Context.new
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_random ()
|
13
|
+
def test_random()
|
18
14
|
c = context
|
19
15
|
|
20
16
|
assert_equal Float, c.random(1).class
|
@@ -6,23 +6,20 @@ require_relative '../helper'
|
|
6
6
|
|
7
7
|
class TestProcessingVector < Test::Unit::TestCase
|
8
8
|
|
9
|
-
P
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
M = Math
|
14
|
-
|
9
|
+
P = RubySketch::Processing
|
10
|
+
V = P::Vector
|
11
|
+
M = Math
|
15
12
|
PI = M::PI
|
16
13
|
|
17
|
-
def vec
|
18
|
-
V.new
|
14
|
+
def vec(*args, **kwargs)
|
15
|
+
V.new(*args, **kwargs)
|
19
16
|
end
|
20
17
|
|
21
|
-
def point
|
22
|
-
Rays::Point.new
|
18
|
+
def point(*args, **kwargs)
|
19
|
+
Rays::Point.new(*args, **kwargs)
|
23
20
|
end
|
24
21
|
|
25
|
-
def test_initialize
|
22
|
+
def test_initialize()
|
26
23
|
assert_equal_vector vec(0, 0, 0), vec()
|
27
24
|
assert_equal_vector vec(1, 0, 0), vec(1)
|
28
25
|
assert_equal_vector vec(1, 2, 0), vec(1, 2)
|
@@ -37,7 +34,7 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
37
34
|
assert_equal_vector vec(1, 2, 3), vec(point 1, 2, 3)
|
38
35
|
end
|
39
36
|
|
40
|
-
def test_set
|
37
|
+
def test_set()
|
41
38
|
v0 = vec 9, 9, 9
|
42
39
|
|
43
40
|
v = v0.dup; v.set; assert_equal_vector vec(0, 0, 0), v
|
@@ -54,7 +51,7 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
54
51
|
v = v0.dup; v.set point(1, 2, 3); assert_equal_vector vec(1, 2, 3), v
|
55
52
|
end
|
56
53
|
|
57
|
-
def test_dup
|
54
|
+
def test_dup()
|
58
55
|
v1 = vec 1, 2, 3
|
59
56
|
assert_equal_vector vec(1, 2, 3), v1
|
60
57
|
|
@@ -67,7 +64,7 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
67
64
|
assert_equal_vector vec(1, 2, 3), v2
|
68
65
|
end
|
69
66
|
|
70
|
-
def test_copy
|
67
|
+
def test_copy()
|
71
68
|
v1 = vec 1, 2, 3
|
72
69
|
assert_equal_vector vec(1, 2, 3), v1
|
73
70
|
|
@@ -80,7 +77,7 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
80
77
|
assert_equal_vector vec(1, 2, 3), v2
|
81
78
|
end
|
82
79
|
|
83
|
-
def test_xyz
|
80
|
+
def test_xyz()
|
84
81
|
v = vec 1, 2, 3
|
85
82
|
assert_equal_vector vec(1, 2, 3), v
|
86
83
|
assert_equal [1, 2, 3], [v.x, v.y, v.z]
|
@@ -95,11 +92,11 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
95
92
|
assert_equal_vector vec(7, 8, 9), v
|
96
93
|
end
|
97
94
|
|
98
|
-
def test_array
|
95
|
+
def test_array()
|
99
96
|
assert_equal [1, 2, 3], vec(1, 2, 3).array
|
100
97
|
end
|
101
98
|
|
102
|
-
def test_add
|
99
|
+
def test_add()
|
103
100
|
v = vec 1, 2, 3
|
104
101
|
v.add 4, 5, 6
|
105
102
|
assert_equal_vector vec(5, 7, 9), v
|
@@ -118,7 +115,7 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
118
115
|
assert_equal_vector vec(5, 7, 9), vec(1, 2, 3).add(point(4, 5, 6))
|
119
116
|
end
|
120
117
|
|
121
|
-
def test_sub
|
118
|
+
def test_sub()
|
122
119
|
v = vec 9, 8, 7
|
123
120
|
v.sub 1, 2, 3
|
124
121
|
assert_equal_vector vec(8, 6, 4), v
|
@@ -137,19 +134,19 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
137
134
|
assert_equal_vector vec(8, 6, 4), vec(9, 8, 7).sub(point(1, 2, 3))
|
138
135
|
end
|
139
136
|
|
140
|
-
def test_mult
|
137
|
+
def test_mult()
|
141
138
|
v = vec 1, 2, 3
|
142
139
|
v.mult 2
|
143
140
|
assert_equal_vector vec(2, 4, 6), v
|
144
141
|
end
|
145
142
|
|
146
|
-
def test_div
|
143
|
+
def test_div()
|
147
144
|
v = vec 2, 4, 6
|
148
145
|
v.div 2
|
149
146
|
assert_equal_vector vec(1, 2, 3), v
|
150
147
|
end
|
151
148
|
|
152
|
-
def test_op_add
|
149
|
+
def test_op_add()
|
153
150
|
v1 = vec 1, 2, 3
|
154
151
|
v2 = vec 4, 5, 6
|
155
152
|
assert_equal_vector vec(5, 7, 9), v1 + v2
|
@@ -167,7 +164,7 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
167
164
|
assert_equal_vector vec(5, 7, 9), vec(1, 2, 3) + point(4, 5, 6)
|
168
165
|
end
|
169
166
|
|
170
|
-
def test_op_sub
|
167
|
+
def test_op_sub()
|
171
168
|
v1 = vec 9, 8, 7
|
172
169
|
v2 = vec 1, 2, 3
|
173
170
|
assert_equal_vector vec(8, 6, 4), v1 - v2
|
@@ -185,19 +182,19 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
185
182
|
assert_equal_vector vec(8, 6, 4), vec(9, 8, 7) - point(1, 2, 3)
|
186
183
|
end
|
187
184
|
|
188
|
-
def test_op_mult
|
185
|
+
def test_op_mult()
|
189
186
|
v = vec 1, 2, 3
|
190
187
|
assert_equal_vector vec(2, 4, 6), v * 2
|
191
188
|
assert_equal_vector vec(1, 2, 3), v
|
192
189
|
end
|
193
190
|
|
194
|
-
def test_op_div
|
191
|
+
def test_op_div()
|
195
192
|
v = vec 2, 4, 6
|
196
193
|
assert_equal_vector vec(1, 2, 3), v / 2
|
197
194
|
assert_equal_vector vec(2, 4, 6), v
|
198
195
|
end
|
199
196
|
|
200
|
-
def test_fun_add
|
197
|
+
def test_fun_add()
|
201
198
|
v1 = vec 1, 2, 3
|
202
199
|
v2 = vec 4, 5, 6
|
203
200
|
result = vec
|
@@ -207,7 +204,7 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
207
204
|
assert_equal_vector vec(5, 7, 9), result
|
208
205
|
end
|
209
206
|
|
210
|
-
def test_fun_sub
|
207
|
+
def test_fun_sub()
|
211
208
|
v1 = vec 9, 8, 7
|
212
209
|
v2 = vec 1, 2, 3
|
213
210
|
result = vec
|
@@ -217,7 +214,7 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
217
214
|
assert_equal_vector vec(8, 6, 4), result
|
218
215
|
end
|
219
216
|
|
220
|
-
def test_fun_mult
|
217
|
+
def test_fun_mult()
|
221
218
|
v1 = vec 1, 2, 3
|
222
219
|
result = vec
|
223
220
|
assert_equal_vector vec(2, 4, 6), V.mult(v1, 2, result)
|
@@ -225,7 +222,7 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
225
222
|
assert_equal_vector vec(2, 4, 6), result
|
226
223
|
end
|
227
224
|
|
228
|
-
def test_fun_div
|
225
|
+
def test_fun_div()
|
229
226
|
v1 = vec 2, 4, 6
|
230
227
|
result = vec
|
231
228
|
assert_equal_vector vec(1, 2, 3), V.div(v1, 2, result)
|
@@ -233,17 +230,17 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
233
230
|
assert_equal_vector vec(1, 2, 3), result
|
234
231
|
end
|
235
232
|
|
236
|
-
def test_mag
|
233
|
+
def test_mag()
|
237
234
|
assert_in_delta M.sqrt(5), vec(1, 2) .mag, 0.000001
|
238
235
|
assert_in_delta M.sqrt(14), vec(1, 2, 3).mag, 0.000001
|
239
236
|
end
|
240
237
|
|
241
|
-
def test_magSq
|
238
|
+
def test_magSq()
|
242
239
|
assert_equal 5, vec(1, 2) .magSq
|
243
240
|
assert_equal 14, vec(1, 2, 3).magSq
|
244
241
|
end
|
245
242
|
|
246
|
-
def test_setMag
|
243
|
+
def test_setMag()
|
247
244
|
v = vec 3, 4, 0
|
248
245
|
assert_equal_vector vec(6, 8, 0), v.setMag(10)
|
249
246
|
assert_equal_vector vec(6, 8, 0), v
|
@@ -255,7 +252,7 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
255
252
|
assert_equal_vector vec(6, 8, 0), result
|
256
253
|
end
|
257
254
|
|
258
|
-
def test_normalize
|
255
|
+
def test_normalize()
|
259
256
|
v = vec 1, 2, 3
|
260
257
|
normal = v / v.mag
|
261
258
|
assert_equal_vector normal, v.normalize
|
@@ -268,7 +265,7 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
268
265
|
assert_equal_vector normal, result
|
269
266
|
end
|
270
267
|
|
271
|
-
def test_limit
|
268
|
+
def test_limit()
|
272
269
|
v = vec 1, 2, 3
|
273
270
|
assert_in_delta 1, v.limit(1).mag, 0.000001
|
274
271
|
assert_in_delta 1, v .mag, 0.000001
|
@@ -279,7 +276,7 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
279
276
|
assert_in_delta vec(1, 2, 3).mag, vec(1, 2, 3).limit(4).mag, 0.000001
|
280
277
|
end
|
281
278
|
|
282
|
-
def test_dist
|
279
|
+
def test_dist()
|
283
280
|
v1 = vec 1, 2, 3
|
284
281
|
v2 = vec 4, 5, 6
|
285
282
|
|
@@ -292,7 +289,7 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
292
289
|
assert_equal_vector vec(4, 5, 6), v2
|
293
290
|
end
|
294
291
|
|
295
|
-
def test_dot
|
292
|
+
def test_dot()
|
296
293
|
v1 = vec 1, 2, 3
|
297
294
|
v2 = vec 4, 5, 6
|
298
295
|
|
@@ -308,7 +305,7 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
308
305
|
assert_equal_vector vec(4, 5, 6), v2
|
309
306
|
end
|
310
307
|
|
311
|
-
def test_cross
|
308
|
+
def test_cross()
|
312
309
|
v1 = vec 1, 0, 0
|
313
310
|
v2 = vec 0, 1, 0
|
314
311
|
|
@@ -328,9 +325,9 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
328
325
|
assert_equal_vector vec(0, 0, 1), result
|
329
326
|
end
|
330
327
|
|
331
|
-
def test_rotate
|
328
|
+
def test_rotate()
|
332
329
|
angle = PI * 2 * 0.1
|
333
|
-
context = Object.new.tap {|o| def o.toAngle__
|
330
|
+
context = Object.new.tap {|o| def o.toAngle__(a); a * 2 * P::RAD2DEG__; end}
|
334
331
|
|
335
332
|
v = vec 1, 0, 0
|
336
333
|
assert_equal_vector vec(M.cos(angle), M.sin(angle), 0), v.rotate(angle)
|
@@ -340,7 +337,7 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
340
337
|
assert_equal_vector vec(M.cos(angle * 2), M.sin(angle * 2), 0), v.rotate(angle)
|
341
338
|
end
|
342
339
|
|
343
|
-
def test_fromAngle
|
340
|
+
def test_fromAngle()
|
344
341
|
angle = PI * 2 * 0.1
|
345
342
|
result = vec
|
346
343
|
assert_equal_vector vec(M.cos(angle), M.sin(angle), 0), V.fromAngle(angle)
|
@@ -348,25 +345,25 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
348
345
|
assert_equal_vector vec(M.cos(angle), M.sin(angle), 0), result
|
349
346
|
end
|
350
347
|
|
351
|
-
def test_heading
|
348
|
+
def test_heading()
|
352
349
|
angle = PI * 1 * 0.1
|
353
|
-
assert_in_delta
|
354
|
-
assert_in_delta
|
350
|
+
assert_in_delta( angle, V.fromAngle( angle).heading, 0.000001)
|
351
|
+
assert_in_delta(-angle, V.fromAngle(-angle).heading, 0.000001)
|
355
352
|
end
|
356
353
|
|
357
|
-
def test_angleBetween
|
354
|
+
def test_angleBetween()
|
358
355
|
v1 = V.fromAngle PI * 0.25
|
359
356
|
v2 = V.fromAngle PI * 0.75
|
360
357
|
assert_in_delta PI / 2, V.angleBetween(v1, v2), 0.000001
|
361
358
|
end
|
362
359
|
|
363
|
-
def test_lerp
|
360
|
+
def test_lerp()
|
364
361
|
assert_equal_vector vec(0.5, 0.5, 0.5), vec(0, 0, 0).lerp(vec(1, 1, 1), 0.5)
|
365
362
|
assert_equal_vector vec(0.5, 0.5, 0.5), vec(0, 0, 0).lerp( 1, 1, 1, 0.5)
|
366
363
|
assert_equal_vector vec(0.5, 0.5, 0.5), V.lerp(vec(0, 0, 0), vec(1, 1, 1), 0.5)
|
367
364
|
end
|
368
365
|
|
369
|
-
def test_random2D
|
366
|
+
def test_random2D()
|
370
367
|
v1 = V.random2D
|
371
368
|
v2 = V.random2D
|
372
369
|
assert v1.x != 0
|
@@ -380,7 +377,7 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
380
377
|
assert_in_delta 1, v2.mag, 0.000001
|
381
378
|
end
|
382
379
|
|
383
|
-
def test_random3D
|
380
|
+
def test_random3D()
|
384
381
|
v1 = V.random3D
|
385
382
|
v2 = V.random3D
|
386
383
|
assert v1.x != 0
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubysketch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xordog
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: reflexion
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.1.25
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.1.25
|
27
27
|
description: Creative Coding Framework have API compatible to Processing API or p5.js.
|
28
28
|
email: xordog@gmail.com
|
29
29
|
executables: []
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- examples/shapes.rb
|
51
51
|
- lib/rubysketch-processing.rb
|
52
52
|
- lib/rubysketch.rb
|
53
|
+
- lib/rubysketch/app.rb
|
53
54
|
- lib/rubysketch/glsl.rb
|
54
55
|
- lib/rubysketch/module.rb
|
55
56
|
- lib/rubysketch/processing.rb
|
@@ -67,16 +68,16 @@ require_paths:
|
|
67
68
|
- lib
|
68
69
|
required_ruby_version: !ruby/object:Gem::Requirement
|
69
70
|
requirements:
|
70
|
-
- - "
|
71
|
+
- - ">="
|
71
72
|
- !ruby/object:Gem::Version
|
72
|
-
version:
|
73
|
+
version: 2.6.0
|
73
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
75
|
requirements:
|
75
76
|
- - ">="
|
76
77
|
- !ruby/object:Gem::Version
|
77
78
|
version: '0'
|
78
79
|
requirements: []
|
79
|
-
rubygems_version: 3.
|
80
|
+
rubygems_version: 3.1.6
|
80
81
|
signing_key:
|
81
82
|
specification_version: 4
|
82
83
|
summary: Processing like Creative Coding Framework.
|