rays 0.3.11 → 0.3.12

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.
data/src/sdl/rays.cpp CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
 
4
4
  #include <SDL.h>
5
+ #include <SDL_ttf.h>
5
6
  #include "rays/exception.h"
6
7
  #include "rays/debug.h"
7
8
  #include "../renderer.h"
@@ -28,6 +29,9 @@ namespace Rays
28
29
  if (SDL_Init(SDL_INIT_VIDEO) < 0)
29
30
  rays_error(__FILE__, __LINE__, SDL_GetError());
30
31
 
32
+ if (TTF_Init() < 0)
33
+ rays_error(__FILE__, __LINE__, "TTF_Init failed: %s", TTF_GetError());
34
+
31
35
  Renderer_init();
32
36
 
33
37
  global::initialized = true;
@@ -41,6 +45,7 @@ namespace Rays
41
45
 
42
46
  Renderer_fin();
43
47
 
48
+ //TTF_Quit();
44
49
  SDL_Quit();
45
50
 
46
51
  global::initialized = false;
data/src/texture.h CHANGED
@@ -19,6 +19,8 @@ namespace Rays
19
19
  class Texture
20
20
  {
21
21
 
22
+ typedef Texture This;
23
+
22
24
  public:
23
25
 
24
26
  Texture ();
@@ -53,6 +55,10 @@ namespace Rays
53
55
 
54
56
  bool operator ! () const;
55
57
 
58
+ friend bool operator == (const This& lhs, const This& rhs);
59
+
60
+ friend bool operator != (const This& lhs, const This& rhs);
61
+
56
62
  struct Data;
57
63
 
58
64
  Xot::PSharedImpl<Data> self;
data/test/test_painter.rb CHANGED
@@ -193,43 +193,54 @@ class TestPainter < Test::Unit::TestCase
193
193
  end
194
194
 
195
195
  def test_clip_accessor()
196
- pa = painter
197
- pa.clip = [1, 2, 3, 4]
198
- assert_equal [1, 2, 3, 4], pa.clip.to_a
199
- pa.clip = [5, 6, 7, 8]
200
- assert_equal [5, 6, 7, 8], pa.clip.to_a
201
- pa.clip 1, 2, 3, 4
202
- assert_equal [1, 2, 3, 4], pa.clip.to_a
203
- pa.push clip: [5, 6, 7, 8] do |_|
196
+ pa = painter
197
+ pa.clip = [1, 2, 3, 4]
198
+ assert_equal [1, 2, 3, 4], pa.clip.to_a
199
+ pa.clip = [5, 6, 7, 8]
200
+ assert_equal [5, 6, 7, 8], pa.clip.to_a
201
+ pa.clip 1, 2, 3, 4
202
+ assert_equal [1, 2, 3, 4], pa.clip.to_a
203
+ pa.push clip: [5, 6, 7, 8] do |_|
204
204
  assert_equal [5, 6, 7, 8], pa.clip.to_a
205
205
  end
206
- assert_equal [1, 2, 3, 4], pa.clip.to_a
206
+ assert_equal [1, 2, 3, 4], pa.clip.to_a
207
207
  end
208
208
 
209
209
  def test_font_accessor()
210
- pa = painter
210
+ pa = painter
211
211
  f10, f20 = font(nil, 10), font(nil, 20)
212
- pa.font = f10
213
- assert_equal f10, pa.font
214
- pa.font = f20
215
- assert_equal f20, pa.font
216
- pa.font f10
217
- assert_equal f10, pa.font
218
- pa.push font: f20 do |_|
212
+ pa.font = f10
213
+ assert_equal f10, pa.font
214
+ pa.font = f20
215
+ assert_equal f20, pa.font
216
+ pa.font f10
217
+ assert_equal f10, pa.font
218
+ pa.push font: f20 do |_|
219
219
  assert_equal f20, pa.font
220
220
  end
221
- assert_equal f10, pa.font
221
+ assert_equal f10, pa.font
222
222
  end
223
223
 
224
224
  def test_font_name_size()
225
225
  pa = painter
226
- pa.font "Arial", 10
227
- assert_equal "Arial", pa.font.name
228
- assert_equal 10, pa.font.size
229
- pa.font nil
230
- assert_not_equal "Arial", pa.font.name
231
- pa.font nil, 20
232
- assert_equal 20, pa.font.size
226
+ pa.font "Arial", 10
227
+ assert_equal "Arial", pa.font.name
228
+ assert_equal 10, pa.font.size
229
+ pa.font nil
230
+ assert_not_equal "Arial", pa.font.name
231
+ assert_not_equal 10, pa.font.size
232
+ pa.font nil, 20
233
+ assert_not_equal "Arial", pa.font.name
234
+ assert_equal 20, pa.font.size
235
+ end
236
+
237
+ def test_debug_accessor()
238
+ pa = painter
239
+ assert_false pa.debug?
240
+ pa.debug = true
241
+ assert_true pa.debug?
242
+ pa.debug = false
243
+ assert_false pa.debug?
233
244
  end
234
245
 
235
246
  def test_color_by_name()
@@ -0,0 +1,254 @@
1
+ require_relative 'helper'
2
+
3
+
4
+ class TestPainterBatch < Test::Unit::TestCase
5
+
6
+ def image(w = 16, h = 16, bg: 0, &block)
7
+ Rays::Image.new(w, h)
8
+ .paint {background bg}
9
+ .tap {|img| img.paint {stroke nil; instance_eval(&block)} if block}
10
+ end
11
+
12
+ def assert_gray(expected, actual, message = nil)
13
+ assert_in_epsilon expected, actual, 0.02, message
14
+ end
15
+
16
+ def assert_rgb(expected, actual)
17
+ (0..2).each do |i|
18
+ assert_gray expected[i], actual[i], "Expected: #{expected}, Actual: #{actual}"
19
+ end
20
+ end
21
+
22
+ def assert_equal_batched_and_unbatched(w, h, &block)
23
+ batched = image(w, h, bg: 0, &block)
24
+ unbatched = image(w, h, bg: 0) {|p| p.debug = true; p.instance_eval(&block)}
25
+ assert_equal unbatched.bitmap.pixels, batched.bitmap.pixels, "Pixel mismatch"
26
+ end
27
+
28
+ def test_match_fill_rects()
29
+ assert_equal_batched_and_unbatched(16, 16) do
30
+ fill 1, 0, 0
31
+ rect 0, 0, 8, 16
32
+ fill 0, 1, 0
33
+ rect 8, 0, 8, 16
34
+ end
35
+ end
36
+
37
+ def test_match_stroke_rects()
38
+ assert_equal_batched_and_unbatched(16, 16) do
39
+ no_fill
40
+ stroke 1, 0, 0
41
+ rect 0, 0, 8, 16
42
+ stroke 0, 1, 0
43
+ rect 8, 0, 8, 16
44
+ end
45
+ end
46
+
47
+ def test_match_translated_rects()
48
+ assert_equal_batched_and_unbatched(16, 16) do
49
+ fill 1, 0, 0
50
+ rect 0, 0, 8, 16
51
+ translate 8, 0
52
+ fill 0, 1, 0
53
+ rect 0, 0, 8, 16
54
+ end
55
+ end
56
+
57
+ def test_match_scaled_rects()
58
+ assert_equal_batched_and_unbatched(16, 16) do
59
+ scale 2, 1
60
+ fill 1, 0, 0
61
+ rect 0, 0, 4, 16
62
+ fill 0, 1, 0
63
+ rect 4, 0, 4, 16
64
+ end
65
+ end
66
+
67
+ def test_match_rotated_rects()
68
+ assert_equal_batched_and_unbatched(16, 16) do
69
+ fill 1, 0, 0
70
+ rect 0, 0, 16, 8
71
+ translate 8, 8
72
+ rotate 180
73
+ translate(-8, -8)
74
+ fill 0, 1, 0
75
+ rect 0, 0, 16, 8
76
+ end
77
+ end
78
+
79
+ def test_match_many_rects()
80
+ assert_equal_batched_and_unbatched(16, 16) do
81
+ 8.times do |x|
82
+ fill x / 7.0, 0, 0
83
+ rect x * 2, 0, 2, 16
84
+ end
85
+ end
86
+ end
87
+
88
+ def test_match_image_draw()
89
+ img = image(4, 4) {fill 1, 0, 0; rect 0, 0, 4, 4}
90
+ assert_equal_batched_and_unbatched(8, 8) do
91
+ fill 1
92
+ image img, 2, 2, 4, 4
93
+ end
94
+ end
95
+
96
+ def test_match_image_partial_draw()
97
+ img = image(4, 4) {
98
+ fill 1, 0, 0; rect 0, 0, 2, 4
99
+ fill 0, 1, 0; rect 2, 0, 2, 4
100
+ }
101
+ assert_equal_batched_and_unbatched(2, 4) do
102
+ fill 1
103
+ image img, 0, 0, 2, 4, 0, 0, 2, 4
104
+ end
105
+ end
106
+
107
+ def test_match_image_multiple()
108
+ r = image(4, 4) {fill 1, 0, 0; rect 0, 0, 4, 4}
109
+ g = image(4, 4) {fill 0, 1, 0; rect 0, 0, 4, 4}
110
+ assert_equal_batched_and_unbatched(8, 4) do
111
+ fill 1
112
+ image r, 0, 0
113
+ image g, 4, 0
114
+ end
115
+ end
116
+
117
+ def test_match_image_translated()
118
+ img = image(4, 4) {fill 1, 0, 0; rect 0, 0, 4, 4}
119
+ assert_equal_batched_and_unbatched(8, 8) do
120
+ fill 1
121
+ translate 4, 0
122
+ image img, 0, 0
123
+ end
124
+ end
125
+
126
+ def test_match_atlas_sub_regions()
127
+ atlas = image(8, 4) do
128
+ fill 1, 0, 0; rect 0, 0, 4, 4
129
+ fill 0, 1, 0; rect 4, 0, 4, 4
130
+ end
131
+ assert_equal_batched_and_unbatched(8, 4) do
132
+ fill 1
133
+ image atlas, 0, 0, 4, 4, 0, 0, 4, 4
134
+ image atlas, 4, 0, 4, 4, 4, 0, 4, 4
135
+ end
136
+ end
137
+
138
+ def test_match_atlas_sub_regions_reversed_order()
139
+ atlas = image(8, 4) do
140
+ fill 1, 0, 0; rect 0, 0, 4, 4
141
+ fill 0, 1, 0; rect 4, 0, 4, 4
142
+ end
143
+ assert_equal_batched_and_unbatched(8, 4) do
144
+ fill 1
145
+ image atlas, 4, 0, 4, 4, 0, 0, 4, 4
146
+ image atlas, 0, 0, 4, 4, 4, 0, 4, 4
147
+ end
148
+ end
149
+
150
+ def test_match_atlas_four_regions()
151
+ atlas = image(4, 4) do
152
+ fill 1, 0, 0; rect 0, 0, 2, 2
153
+ fill 0, 1, 0; rect 2, 0, 2, 2
154
+ fill 0, 0, 1; rect 0, 2, 2, 2
155
+ fill 1, 1, 0; rect 2, 2, 2, 2
156
+ end
157
+ assert_equal_batched_and_unbatched(8, 8) do
158
+ fill 1
159
+ image atlas, 0, 0, 2, 2, 0, 0, 4, 4
160
+ image atlas, 2, 0, 2, 2, 4, 0, 4, 4
161
+ image atlas, 0, 2, 2, 2, 0, 4, 4, 4
162
+ image atlas, 2, 2, 2, 2, 4, 4, 4, 4
163
+ end
164
+ end
165
+
166
+ def test_match_atlas_scaled_draw()
167
+ atlas = image(4, 4) do
168
+ fill 1, 0, 0; rect 0, 0, 2, 4
169
+ fill 0, 1, 0; rect 2, 0, 2, 4
170
+ end
171
+ assert_equal_batched_and_unbatched(16, 8) do
172
+ fill 1
173
+ image atlas, 0, 0, 2, 4, 0, 0, 8, 8
174
+ image atlas, 2, 0, 2, 4, 8, 0, 8, 8
175
+ end
176
+ end
177
+
178
+ def test_match_atlas_with_translate()
179
+ atlas = image(8, 4) do
180
+ fill 1, 0, 0; rect 0, 0, 4, 4
181
+ fill 0, 1, 0; rect 4, 0, 4, 4
182
+ end
183
+ assert_equal_batched_and_unbatched(8, 4) do
184
+ fill 1
185
+ translate 4, 0
186
+ image atlas, 0, 0, 4, 4, 0, 0, 4, 4
187
+ end
188
+ end
189
+
190
+ def test_match_rects_and_images_interleaved()
191
+ img = image(4, 4) {fill 0, 0, 1; rect 0, 0, 4, 4}
192
+ assert_equal_batched_and_unbatched(16, 4) do
193
+ fill 1, 0, 0
194
+ rect 0, 0, 4, 4
195
+ fill 1
196
+ image img, 4, 0
197
+ fill 0, 1, 0
198
+ rect 8, 0, 4, 4
199
+ end
200
+ end
201
+
202
+ def test_match_blend_mode()
203
+ assert_equal_batched_and_unbatched(16, 16) do
204
+ fill 0.5
205
+ rect 0, 0, 16, 16
206
+ blend_mode :add
207
+ fill 0.2
208
+ rect 0, 0, 8, 16
209
+ end
210
+ end
211
+
212
+ def test_match_clip()
213
+ assert_equal_batched_and_unbatched(16, 16) do
214
+ fill 1, 0, 0
215
+ clip 0, 0, 8, 16
216
+ rect 0, 0, 16, 16
217
+ end
218
+ end
219
+
220
+ def test_match_push_pop_state()
221
+ assert_equal_batched_and_unbatched(16, 16) do
222
+ fill 1, 0, 0
223
+ rect 0, 0, 8, 16
224
+ push fill: [0, 1, 0] do
225
+ rect 8, 0, 8, 16
226
+ end
227
+ end
228
+ end
229
+
230
+ def test_match_shader()
231
+ assert_equal_batched_and_unbatched(16, 16) do
232
+ fill 1, 0, 0
233
+ rect 0, 0, 8, 16
234
+ shader "void main() {gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);}"
235
+ fill 1
236
+ rect 8, 0, 8, 16
237
+ end
238
+ end
239
+
240
+ def test_atlas_no_bleed()
241
+ atlas = image(4, 2) do
242
+ fill 1, 0, 0; rect 0, 0, 2, 2
243
+ fill 0, 0, 1; rect 2, 0, 2, 2
244
+ end
245
+ img = image(8, 8, bg: 0) do
246
+ fill 1
247
+ image atlas, 0, 0, 2, 2, 0, 0, 8, 8
248
+ end
249
+ assert_rgb [1, 0, 0], img[1, 1]
250
+ assert_rgb [1, 0, 0], img[6, 4]
251
+ assert_rgb [1, 0, 0], img[7, 7]
252
+ end
253
+
254
+ end# TestPainterBatch
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rays
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.11
4
+ version: 0.3.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-17 00:00:00.000000000 Z
11
+ date: 2026-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xot
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.11
19
+ version: 0.3.12
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: 0.3.11
26
+ version: 0.3.12
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rucy
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.3.11
33
+ version: 0.3.12
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.3.11
40
+ version: 0.3.12
41
41
  description: This library helps you to develop graphics application with OpenGL.
42
42
  email: xordog@gmail.com
43
43
  executables: []
@@ -245,6 +245,7 @@ files:
245
245
  - test/test_image.rb
246
246
  - test/test_matrix.rb
247
247
  - test/test_painter.rb
248
+ - test/test_painter_batch.rb
248
249
  - test/test_painter_shape.rb
249
250
  - test/test_point.rb
250
251
  - test/test_polygon.rb
@@ -285,6 +286,7 @@ test_files:
285
286
  - test/test_image.rb
286
287
  - test/test_matrix.rb
287
288
  - test/test_painter.rb
289
+ - test/test_painter_batch.rb
288
290
  - test/test_painter_shape.rb
289
291
  - test/test_point.rb
290
292
  - test/test_polygon.rb