rays 0.1.13 → 0.1.18

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 (65) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/rays/camera.cpp +171 -0
  3. data/.doc/ext/rays/color.cpp +2 -3
  4. data/.doc/ext/rays/color_space.cpp +22 -14
  5. data/.doc/ext/rays/font.cpp +30 -0
  6. data/.doc/ext/rays/image.cpp +1 -1
  7. data/.doc/ext/rays/native.cpp +4 -4
  8. data/.doc/ext/rays/painter.cpp +83 -0
  9. data/.doc/ext/rays/point.cpp +14 -0
  10. data/.doc/ext/rays/polygon.cpp +33 -7
  11. data/.doc/ext/rays/polyline.cpp +12 -6
  12. data/.doc/ext/rays/rays.cpp +105 -1
  13. data/LICENSE +21 -0
  14. data/Rakefile +3 -0
  15. data/VERSION +1 -1
  16. data/ext/rays/bitmap.cpp +1 -1
  17. data/ext/rays/camera.cpp +186 -0
  18. data/ext/rays/color.cpp +2 -3
  19. data/ext/rays/color_space.cpp +22 -14
  20. data/ext/rays/extconf.rb +1 -1
  21. data/ext/rays/font.cpp +35 -2
  22. data/ext/rays/image.cpp +2 -2
  23. data/ext/rays/native.cpp +4 -4
  24. data/ext/rays/painter.cpp +94 -3
  25. data/ext/rays/point.cpp +16 -0
  26. data/ext/rays/polygon.cpp +34 -6
  27. data/ext/rays/polyline.cpp +11 -5
  28. data/ext/rays/rays.cpp +105 -1
  29. data/include/rays/camera.h +74 -0
  30. data/include/rays/color_space.h +4 -2
  31. data/include/rays/defs.h +33 -0
  32. data/include/rays/exception.h +6 -2
  33. data/include/rays/image.h +1 -1
  34. data/include/rays/painter.h +38 -0
  35. data/include/rays/polygon.h +35 -1
  36. data/include/rays/polyline.h +7 -1
  37. data/include/rays/ruby/camera.h +41 -0
  38. data/include/rays/ruby/rays.h +8 -0
  39. data/lib/rays.rb +2 -2
  40. data/lib/rays/camera.rb +24 -0
  41. data/lib/rays/image.rb +1 -1
  42. data/lib/rays/painter.rb +23 -1
  43. data/lib/rays/polygon.rb +8 -0
  44. data/rays.gemspec +2 -2
  45. data/src/color_space.cpp +2 -2
  46. data/src/image.cpp +1 -1
  47. data/src/ios/bitmap.h +23 -0
  48. data/src/ios/bitmap.mm +32 -11
  49. data/src/ios/camera.mm +517 -0
  50. data/src/ios/font.mm +2 -2
  51. data/src/ios/helper.h +2 -2
  52. data/src/osx/bitmap.h +23 -0
  53. data/src/osx/bitmap.mm +28 -10
  54. data/src/osx/camera.mm +452 -0
  55. data/src/osx/font.mm +2 -2
  56. data/src/painter.cpp +100 -10
  57. data/src/polygon.cpp +203 -37
  58. data/src/polyline.cpp +4 -2
  59. data/src/polyline.h +3 -1
  60. data/test/test_font.rb +5 -0
  61. data/test/test_painter.rb +65 -5
  62. data/test/test_painter_shape.rb +48 -3
  63. data/test/test_point.rb +8 -0
  64. data/test/test_polyline.rb +26 -0
  65. metadata +20 -9
@@ -89,9 +89,11 @@ namespace Rays
89
89
  }
90
90
 
91
91
  bool
92
- Polyline::expand (Polygon* result, coord width) const
92
+ Polyline::expand (
93
+ Polygon* result,
94
+ coord width, CapType cap, JoinType join, coord miter_limit) const
93
95
  {
94
- return Polyline_expand(result, *this, width);
96
+ return Polyline_expand(result, *this, width, cap, join, miter_limit);
95
97
  }
96
98
 
97
99
  Bounds
@@ -58,7 +58,9 @@ namespace Rays
58
58
  ClipperLib::Path* path, const Polyline& polyline,
59
59
  bool reverse = false);
60
60
 
61
- bool Polyline_expand (Polygon* result, const Polyline& polyline, coord width);
61
+ bool Polyline_expand (
62
+ Polygon* result, const Polyline& polyline,
63
+ coord width, CapType cap, JoinType join, coord miter_limit);
62
64
 
63
65
 
64
66
  }// Rays
@@ -25,4 +25,9 @@ class TestFont < Test::Unit::TestCase
25
25
  assert_equal w * 2, font.width('XX')
26
26
  end
27
27
 
28
+ def test_height ()
29
+ f = font
30
+ assert_equal f.height, f.ascent + f.descent + f.leading
31
+ end
32
+
28
33
  end# TestFont
@@ -28,7 +28,7 @@ class TestPainter < Test::Unit::TestCase
28
28
  assert_equal color(1, 1, 1, 1), pa.background
29
29
  pa.background = 0
30
30
  assert_equal color(0, 0, 0, 1), pa.background
31
- pa.background 1
31
+ pa.background 1
32
32
  assert_equal color(1, 1, 1, 1), pa.background
33
33
  pa.push background: 0 do |_|
34
34
  assert_equal color(0, 0, 0, 1), pa.background
@@ -42,7 +42,7 @@ class TestPainter < Test::Unit::TestCase
42
42
  assert_equal color(1, 1, 1, 1), pa.fill
43
43
  pa.fill = 0
44
44
  assert_equal color(0, 0, 0, 1), pa.fill
45
- pa.fill 1
45
+ pa.fill 1
46
46
  assert_equal color(1, 1, 1, 1), pa.fill
47
47
  pa.push fill: 0 do |_|
48
48
  assert_equal color(0, 0, 0, 1), pa.fill
@@ -56,7 +56,7 @@ class TestPainter < Test::Unit::TestCase
56
56
  assert_equal color(1, 1, 1, 1), pa.stroke
57
57
  pa.stroke = 0
58
58
  assert_equal color(0, 0, 0, 1), pa.stroke
59
- pa.stroke 1
59
+ pa.stroke 1
60
60
  assert_equal color(1, 1, 1, 1), pa.stroke
61
61
  pa.push stroke: 0 do |_|
62
62
  assert_equal color(0, 0, 0, 1), pa.stroke
@@ -64,13 +64,73 @@ class TestPainter < Test::Unit::TestCase
64
64
  assert_equal color(1, 1, 1, 1), pa.stroke
65
65
  end
66
66
 
67
+ def test_stroke_width_accessor ()
68
+ pa = painter
69
+ assert_equal 0, pa.stroke_width
70
+ pa.stroke_width = 1
71
+ assert_equal 1, pa.stroke_width
72
+ pa.stroke_width = 0
73
+ assert_equal 0, pa.stroke_width
74
+ pa.stroke_width 2
75
+ assert_equal 2, pa.stroke_width
76
+ pa.push stroke_width: 3 do |_|
77
+ assert_equal 3, pa.stroke_width
78
+ end
79
+ assert_equal 2, pa.stroke_width
80
+ end
81
+
82
+ def test_stroke_cap_accessor ()
83
+ pa = painter
84
+ assert_equal :butt, pa.stroke_cap
85
+ pa.stroke_cap = :round
86
+ assert_equal :round, pa.stroke_cap
87
+ pa.stroke_cap :square
88
+ assert_equal :square, pa.stroke_cap
89
+ pa.push stroke_cap: :butt do |_|
90
+ assert_equal :butt, pa.stroke_cap
91
+ end
92
+ assert_equal :square, pa.stroke_cap
93
+ assert_raise(ArgumentError) {pa.stroke_cap :foo}
94
+ assert_raise(ArgumentError) {pa.stroke_cap :BUTT}
95
+ assert_raise(ArgumentError) {pa.stroke_cap Rays::CAP_BUTT}# ToDo: accept this
96
+ end
97
+
98
+ def test_stroke_join_accessor ()
99
+ pa = painter
100
+ assert_equal :miter, pa.stroke_join
101
+ pa.stroke_join = :round
102
+ assert_equal :round, pa.stroke_join
103
+ pa.stroke_join :square
104
+ assert_equal :square, pa.stroke_join
105
+ pa.push stroke_join: :miter do |_|
106
+ assert_equal :miter, pa.stroke_join
107
+ end
108
+ assert_equal :square, pa.stroke_join
109
+ assert_raise(ArgumentError) {pa.stroke_join :foo}
110
+ assert_raise(ArgumentError) {pa.stroke_join :MITER}
111
+ assert_raise(ArgumentError) {pa.stroke_join Rays::JOIN_MITER}# ToDo: accept this
112
+ end
113
+
114
+ def test_miter_limit_accessor ()
115
+ pa = painter
116
+ assert_equal 2, pa.miter_limit
117
+ pa.miter_limit = 3
118
+ assert_equal 3, pa.miter_limit
119
+ pa.miter_limit 4
120
+ assert_equal 4, pa.miter_limit
121
+ pa.push miter_limit: 9 do |_|
122
+ assert_equal 9, pa.miter_limit
123
+ end
124
+ assert_equal 4, pa.miter_limit
125
+ end
126
+
67
127
  def test_clip_accessor ()
68
128
  pa = painter
69
129
  pa.clip = [1, 2, 3, 4]
70
130
  assert_equal [1, 2, 3, 4], pa.clip.to_a
71
131
  pa.clip = [5, 6, 7, 8]
72
132
  assert_equal [5, 6, 7, 8], pa.clip.to_a
73
- pa.clip 1, 2, 3, 4
133
+ pa.clip 1, 2, 3, 4
74
134
  assert_equal [1, 2, 3, 4], pa.clip.to_a
75
135
  pa.push clip: [5, 6, 7, 8] do |_|
76
136
  assert_equal [5, 6, 7, 8], pa.clip.to_a
@@ -85,7 +145,7 @@ class TestPainter < Test::Unit::TestCase
85
145
  assert_equal f10, pa.font
86
146
  pa.font = f20
87
147
  assert_equal f20, pa.font
88
- pa.font f10
148
+ pa.font f10
89
149
  assert_equal f10, pa.font
90
150
  pa.push font: f20 do |_|
91
151
  assert_equal f20, pa.font
@@ -11,7 +11,7 @@ class TestPainterShape < Test::Unit::TestCase
11
11
  end
12
12
 
13
13
  def image (fill = 1, stroke = 0, pixel_density = 1, &block)
14
- Rays::Image.new(100, 100, Rays::ColorSpace::RGBA, pixel_density).paint {|p|
14
+ Rays::Image.new(100, 100, Rays::RGBA, pixel_density).paint {|p|
15
15
  p.fill fill > 0 ? color(fill) : nil
16
16
  p.stroke stroke > 0 ? color(stroke) : nil
17
17
  p.instance_eval &block if block
@@ -22,11 +22,56 @@ class TestPainterShape < Test::Unit::TestCase
22
22
  img = image(0, 1) {line 1, 1, 98, 98}
23
23
  assert_equal 0, img[ 0, 0].a
24
24
  assert_equal 1, img[ 1, 1].a
25
- assert_equal 1, img[97, 97].a
26
- #assert_equal 1, img[98, 98].a
25
+ assert_equal 1, img[97, 97].a #img[98, 98].a
27
26
  assert_equal 0, img[99, 99].a
28
27
  end
29
28
 
29
+ def test_curve ()
30
+ =begin
31
+ img = image(0, 1) {curve 1, 1, 98, 1, 98, 98, 1, 98}
32
+ assert_equal 0, img[ 0, 0].a
33
+ assert_equal 1, img[ 1, 1].a
34
+ assert_equal 0, img[98, 1].a
35
+ assert_equal 0, img[98, 50].a
36
+ assert_equal 0, img[98, 98].a
37
+ assert_equal 1, img[ 1, 97].a #img[ 1, 98].a
38
+ assert_equal 0, img[99, 99].a
39
+ =end
40
+ assert_raise(ArgumentError) {image {curve}}
41
+ assert_raise(ArgumentError) {image {curve 0}}
42
+ assert_raise(ArgumentError) {image {curve 0, 1}}
43
+ assert_raise(ArgumentError) {image {curve 0, 1, 2}}
44
+ assert_raise(ArgumentError) {image {curve 0, 1, 2, 3}}
45
+ assert_raise(ArgumentError) {image {curve 0, 1, 2, 3, 4}}
46
+ assert_raise(ArgumentError) {image {curve 0, 1, 2, 3, 4, 5}}
47
+ assert_raise(ArgumentError) {image {curve 0, 1, 2, 3, 4, 5, 6}}
48
+ assert_nothing_raised {image {curve 0, 1, 2, 3, 4, 5, 6, 7}}
49
+ assert_raise(ArgumentError) {image {curve 0, 1, 2, 3, 4, 5, 6, 7, 8}}
50
+ end
51
+
52
+ def test_bezier ()
53
+ =begin
54
+ img = image(0, 1) {bezier 1, 1, 98, 1, 98, 98, 1, 98}
55
+ assert_equal 0, img[ 0, 0].a
56
+ assert_equal 1, img[ 1, 1].a
57
+ assert_equal 0, img[98, 1].a
58
+ assert_equal 0, img[98, 50].a
59
+ assert_equal 0, img[98, 98].a
60
+ assert_equal 1, img[ 1, 97].a #img[ 1, 98].a
61
+ assert_equal 0, img[99, 99].a
62
+ =end
63
+ assert_raise(ArgumentError) {image {bezier}}
64
+ assert_raise(ArgumentError) {image {bezier 0}}
65
+ assert_raise(ArgumentError) {image {bezier 0, 1}}
66
+ assert_raise(ArgumentError) {image {bezier 0, 1, 2}}
67
+ assert_raise(ArgumentError) {image {bezier 0, 1, 2, 3}}
68
+ assert_raise(ArgumentError) {image {bezier 0, 1, 2, 3, 4}}
69
+ assert_raise(ArgumentError) {image {bezier 0, 1, 2, 3, 4, 5}}
70
+ assert_raise(ArgumentError) {image {bezier 0, 1, 2, 3, 4, 5, 6}}
71
+ assert_nothing_raised {image {bezier 0, 1, 2, 3, 4, 5, 6, 7}}
72
+ assert_raise(ArgumentError) {image {bezier 0, 1, 2, 3, 4, 5, 6, 7, 8}}
73
+ end
74
+
30
75
  def test_rect ()
31
76
  img = image {rect 1, 1, 98, 98}
32
77
  assert_equal 0, img[ 0, 0].a
@@ -179,4 +179,12 @@ class TestPoint < Test::Unit::TestCase
179
179
  assert_equal "#<Rays::Point 1.0, 2.0, 3.0>", point(1, 2, 3).inspect
180
180
  end
181
181
 
182
+ def test_dot ()
183
+ assert_equal 1*4 + 2*5 + 3*6, Rays::Point::dot(point(1, 2, 3), point(4, 5, 6))
184
+ end
185
+
186
+ def test_cross ()
187
+ assert_equal point(0, 0, 1), Rays::Point::cross(point(1, 0, 0), point(0, 1, 0))
188
+ end
189
+
182
190
  end# TestPoint
@@ -68,6 +68,32 @@ class TestPolyline < Test::Unit::TestCase
68
68
  }
69
69
  end
70
70
 
71
+ def test_expand_with_cap ()
72
+ def pl; polyline [10,10], [20,20]; end
73
+ assert_nothing_raised {pl.expand 1, Rays::CAP_ROUND}
74
+ assert_nothing_raised {pl.expand 1, 'ROUND'}
75
+ assert_nothing_raised {pl.expand 1, :ROUND}
76
+ assert_nothing_raised {pl.expand 1, :round}
77
+ assert_nothing_raised {pl.expand 1, 1}
78
+ assert_raise(ArgumentError) {pl.expand 1, -1}
79
+ assert_raise(ArgumentError) {pl.expand 1, 99}
80
+ assert_raise(ArgumentError) {pl.expand 1, 'hoge'}
81
+ assert_raise(ArgumentError) {pl.expand 1, :hoge}
82
+ end
83
+
84
+ def test_expand_with_join ()
85
+ def pl; polyline [10,10], [20,20]; end
86
+ assert_nothing_raised {pl.expand 1, Rays::JOIN_ROUND}
87
+ assert_nothing_raised {pl.expand 1, 'ROUND'}
88
+ assert_nothing_raised {pl.expand 1, :ROUND}
89
+ assert_nothing_raised {pl.expand 1, :round}
90
+ assert_nothing_raised {pl.expand 1, 1}
91
+ assert_raise(ArgumentError) {pl.expand 1, 'hoge'}
92
+ assert_raise(ArgumentError) {pl.expand 1, :hoge}
93
+ assert_raise(ArgumentError) {pl.expand 1, -1}
94
+ assert_raise(ArgumentError) {pl.expand 1, 99}
95
+ end
96
+
71
97
  def test_transform_with_materix ()
72
98
  m = Rays::Matrix.translate 100, 200
73
99
  polyline([10,10], [20,20]).transform(m).tap {|o|
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.1.13
4
+ version: 0.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-23 00:00:00.000000000 Z
11
+ date: 2020-11-29 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.1'
19
+ version: 0.1.16
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.1'
26
+ version: 0.1.16
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.1'
33
+ version: 0.1.18
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.1'
40
+ version: 0.1.18
41
41
  description: This library helps you to develop graphics application with OpenGL.
42
42
  email: xordog@gmail.com
43
43
  executables: []
@@ -47,6 +47,7 @@ extra_rdoc_files:
47
47
  - ".doc/ext/rays/defs.cpp"
48
48
  - ".doc/ext/rays/image.cpp"
49
49
  - ".doc/ext/rays/bitmap.cpp"
50
+ - ".doc/ext/rays/camera.cpp"
50
51
  - ".doc/ext/rays/rays.cpp"
51
52
  - ".doc/ext/rays/font.cpp"
52
53
  - ".doc/ext/rays/color_space.cpp"
@@ -64,6 +65,7 @@ extra_rdoc_files:
64
65
  files:
65
66
  - ".doc/ext/rays/bitmap.cpp"
66
67
  - ".doc/ext/rays/bounds.cpp"
68
+ - ".doc/ext/rays/camera.cpp"
67
69
  - ".doc/ext/rays/color.cpp"
68
70
  - ".doc/ext/rays/color_space.cpp"
69
71
  - ".doc/ext/rays/defs.cpp"
@@ -79,11 +81,13 @@ files:
79
81
  - ".doc/ext/rays/polyline.cpp"
80
82
  - ".doc/ext/rays/rays.cpp"
81
83
  - ".doc/ext/rays/shader.cpp"
84
+ - LICENSE
82
85
  - README.md
83
86
  - Rakefile
84
87
  - VERSION
85
88
  - ext/rays/bitmap.cpp
86
89
  - ext/rays/bounds.cpp
90
+ - ext/rays/camera.cpp
87
91
  - ext/rays/color.cpp
88
92
  - ext/rays/color_space.cpp
89
93
  - ext/rays/defs.cpp
@@ -104,6 +108,7 @@ files:
104
108
  - include/rays.h
105
109
  - include/rays/bitmap.h
106
110
  - include/rays/bounds.h
111
+ - include/rays/camera.h
107
112
  - include/rays/color.h
108
113
  - include/rays/color_space.h
109
114
  - include/rays/coord.h
@@ -123,6 +128,7 @@ files:
123
128
  - include/rays/ruby.h
124
129
  - include/rays/ruby/bitmap.h
125
130
  - include/rays/ruby/bounds.h
131
+ - include/rays/ruby/camera.h
126
132
  - include/rays/ruby/color.h
127
133
  - include/rays/ruby/color_space.h
128
134
  - include/rays/ruby/font.h
@@ -139,6 +145,7 @@ files:
139
145
  - lib/rays/autoinit.rb
140
146
  - lib/rays/bitmap.rb
141
147
  - lib/rays/bounds.rb
148
+ - lib/rays/camera.rb
142
149
  - lib/rays/color.rb
143
150
  - lib/rays/color_space.rb
144
151
  - lib/rays/ext.rb
@@ -167,7 +174,9 @@ files:
167
174
  - src/frame_buffer.h
168
175
  - src/image.cpp
169
176
  - src/image.h
177
+ - src/ios/bitmap.h
170
178
  - src/ios/bitmap.mm
179
+ - src/ios/camera.mm
171
180
  - src/ios/font.mm
172
181
  - src/ios/helper.h
173
182
  - src/ios/helper.mm
@@ -178,7 +187,9 @@ files:
178
187
  - src/noise.cpp
179
188
  - src/opengl.cpp
180
189
  - src/opengl.h
190
+ - src/osx/bitmap.h
181
191
  - src/osx/bitmap.mm
192
+ - src/osx/camera.mm
182
193
  - src/osx/font.mm
183
194
  - src/osx/helper.h
184
195
  - src/osx/helper.mm
@@ -226,7 +237,7 @@ files:
226
237
  homepage: https://github.com/xord/rays
227
238
  licenses: []
228
239
  metadata: {}
229
- post_install_message:
240
+ post_install_message:
230
241
  rdoc_options: []
231
242
  require_paths:
232
243
  - lib
@@ -242,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
242
253
  version: '0'
243
254
  requirements: []
244
255
  rubygems_version: 3.0.3
245
- signing_key:
256
+ signing_key:
246
257
  specification_version: 4
247
258
  summary: A Drawing Engine using OpenGL.
248
259
  test_files: