rays 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +5 -5
  2. data/.doc/ext/rays/bitmap.cpp +22 -76
  3. data/.doc/ext/rays/bounds.cpp +95 -125
  4. data/.doc/ext/rays/color.cpp +224 -45
  5. data/.doc/ext/rays/color_space.cpp +137 -45
  6. data/.doc/ext/rays/defs.cpp +183 -0
  7. data/.doc/ext/rays/font.cpp +39 -21
  8. data/.doc/ext/rays/image.cpp +26 -37
  9. data/.doc/ext/rays/matrix.cpp +186 -29
  10. data/.doc/ext/rays/native.cpp +12 -6
  11. data/.doc/ext/rays/noise.cpp +53 -0
  12. data/.doc/ext/rays/painter.cpp +120 -308
  13. data/.doc/ext/rays/point.cpp +82 -77
  14. data/.doc/ext/rays/polygon.cpp +287 -0
  15. data/.doc/ext/rays/polygon_line.cpp +96 -0
  16. data/.doc/ext/rays/polyline.cpp +161 -0
  17. data/.doc/ext/rays/rays.cpp +0 -13
  18. data/.doc/ext/rays/shader.cpp +83 -9
  19. data/README.md +1 -1
  20. data/Rakefile +21 -9
  21. data/VERSION +1 -1
  22. data/ext/rays/bitmap.cpp +22 -80
  23. data/ext/rays/bounds.cpp +100 -128
  24. data/ext/rays/color.cpp +232 -51
  25. data/ext/rays/color_space.cpp +140 -46
  26. data/ext/rays/defs.cpp +183 -0
  27. data/ext/rays/defs.h +26 -2
  28. data/ext/rays/extconf.rb +1 -2
  29. data/ext/rays/font.cpp +39 -22
  30. data/ext/rays/image.cpp +27 -39
  31. data/ext/rays/matrix.cpp +198 -30
  32. data/ext/rays/native.cpp +12 -6
  33. data/ext/rays/noise.cpp +55 -0
  34. data/ext/rays/painter.cpp +129 -315
  35. data/ext/rays/point.cpp +89 -81
  36. data/ext/rays/polygon.cpp +301 -0
  37. data/ext/rays/polygon_line.cpp +99 -0
  38. data/ext/rays/polyline.cpp +170 -0
  39. data/ext/rays/rays.cpp +0 -14
  40. data/ext/rays/shader.cpp +84 -9
  41. data/include/rays.h +10 -2
  42. data/include/rays/bitmap.h +14 -26
  43. data/include/rays/bounds.h +21 -4
  44. data/include/rays/color.h +25 -14
  45. data/include/rays/color_space.h +11 -8
  46. data/include/rays/coord.h +114 -0
  47. data/include/rays/debug.h +22 -0
  48. data/include/rays/defs.h +3 -0
  49. data/include/rays/font.h +4 -4
  50. data/include/rays/image.h +11 -17
  51. data/include/rays/matrix.h +50 -24
  52. data/include/rays/noise.h +42 -0
  53. data/include/rays/opengl.h +2 -50
  54. data/include/rays/painter.h +57 -99
  55. data/include/rays/point.h +44 -51
  56. data/include/rays/polygon.h +164 -0
  57. data/include/rays/polyline.h +65 -0
  58. data/include/rays/rays.h +3 -0
  59. data/include/rays/ruby.h +7 -1
  60. data/include/rays/ruby/bounds.h +1 -1
  61. data/include/rays/ruby/color.h +1 -1
  62. data/include/rays/ruby/color_space.h +1 -1
  63. data/include/rays/ruby/font.h +1 -1
  64. data/include/rays/ruby/matrix.h +1 -1
  65. data/include/rays/ruby/point.h +1 -1
  66. data/include/rays/ruby/polygon.h +52 -0
  67. data/include/rays/ruby/polyline.h +41 -0
  68. data/include/rays/ruby/shader.h +1 -1
  69. data/include/rays/shader.h +36 -8
  70. data/lib/rays.rb +6 -1
  71. data/lib/rays/bitmap.rb +0 -15
  72. data/lib/rays/bounds.rb +17 -23
  73. data/lib/rays/color.rb +20 -47
  74. data/lib/rays/color_space.rb +13 -13
  75. data/lib/rays/image.rb +2 -6
  76. data/lib/rays/matrix.rb +28 -0
  77. data/lib/rays/module.rb +4 -19
  78. data/lib/rays/painter.rb +60 -97
  79. data/lib/rays/point.rb +13 -21
  80. data/lib/rays/polygon.rb +50 -0
  81. data/lib/rays/polygon_line.rb +36 -0
  82. data/lib/rays/polyline.rb +32 -0
  83. data/lib/rays/shader.rb +20 -1
  84. data/rays.gemspec +5 -7
  85. data/src/bitmap.h +36 -0
  86. data/src/bounds.cpp +74 -11
  87. data/src/color.cpp +58 -23
  88. data/src/color_space.cpp +50 -32
  89. data/src/color_space.h +22 -0
  90. data/src/coord.cpp +170 -0
  91. data/src/coord.h +35 -0
  92. data/src/font.cpp +118 -0
  93. data/src/font.h +64 -0
  94. data/src/frame_buffer.cpp +37 -71
  95. data/src/frame_buffer.h +4 -4
  96. data/src/image.cpp +171 -97
  97. data/src/image.h +25 -0
  98. data/src/ios/bitmap.mm +107 -105
  99. data/src/ios/font.mm +48 -60
  100. data/src/ios/helper.h +2 -2
  101. data/src/ios/opengl.mm +19 -4
  102. data/src/ios/rays.mm +3 -0
  103. data/src/matrix.cpp +111 -26
  104. data/src/matrix.h +30 -0
  105. data/src/noise.cpp +74 -0
  106. data/src/opengl.cpp +9 -27
  107. data/src/opengl.h +37 -0
  108. data/src/osx/bitmap.mm +111 -106
  109. data/src/osx/font.mm +48 -61
  110. data/src/osx/helper.h +2 -2
  111. data/src/osx/opengl.mm +19 -83
  112. data/src/osx/rays.mm +3 -0
  113. data/src/painter.cpp +780 -696
  114. data/src/painter.h +24 -0
  115. data/src/point.cpp +140 -119
  116. data/src/polygon.cpp +1100 -0
  117. data/src/polygon.h +32 -0
  118. data/src/polyline.cpp +158 -0
  119. data/src/polyline.h +67 -0
  120. data/src/render_buffer.cpp +11 -4
  121. data/src/render_buffer.h +2 -2
  122. data/src/shader.cpp +163 -106
  123. data/src/shader.h +38 -0
  124. data/src/shader_program.cpp +533 -0
  125. data/src/{program.h → shader_program.h} +28 -16
  126. data/src/shader_source.cpp +140 -0
  127. data/src/shader_source.h +52 -0
  128. data/src/texture.cpp +136 -160
  129. data/src/texture.h +65 -0
  130. data/src/win32/bitmap.cpp +62 -52
  131. data/src/win32/font.cpp +11 -13
  132. data/src/win32/font.h +24 -0
  133. data/src/win32/gdi.h +6 -6
  134. data/test/helper.rb +0 -3
  135. data/test/test_bitmap.rb +31 -7
  136. data/test/test_bounds.rb +36 -0
  137. data/test/test_color.rb +59 -19
  138. data/test/test_color_space.rb +95 -0
  139. data/test/test_image.rb +24 -20
  140. data/test/test_matrix.rb +106 -0
  141. data/test/test_painter.rb +92 -46
  142. data/test/test_painter_shape.rb +57 -0
  143. data/test/test_point.rb +21 -0
  144. data/test/test_polygon.rb +234 -0
  145. data/test/test_polygon_line.rb +167 -0
  146. data/test/test_polyline.rb +145 -0
  147. data/test/test_shader.rb +9 -9
  148. metadata +88 -67
  149. data/.doc/ext/rays/texture.cpp +0 -138
  150. data/ext/rays/texture.cpp +0 -149
  151. data/include/rays/ruby/texture.h +0 -41
  152. data/include/rays/texture.h +0 -71
  153. data/lib/rays/texture.rb +0 -24
  154. data/src/program.cpp +0 -648
  155. data/test/test_texture.rb +0 -27
@@ -0,0 +1,57 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require_relative 'helper'
5
+
6
+
7
+ class TestPainterShape < Test::Unit::TestCase
8
+
9
+ def color (*args)
10
+ Rays::Color.new *args
11
+ end
12
+
13
+ def image (fill = 1, stroke = 0, pixel_density = 1, &block)
14
+ Rays::Image.new(100, 100, Rays::ColorSpace::RGBA, pixel_density).paint {|p|
15
+ p.fill fill > 0 ? color(fill) : nil
16
+ p.stroke stroke > 0 ? color(stroke) : nil
17
+ p.instance_eval &block if block
18
+ }
19
+ end
20
+
21
+ def test_line ()
22
+ img = image(0, 1) {line 1, 1, 98, 98}
23
+ assert_equal 0, img[ 0, 0].a
24
+ assert_equal 1, img[ 1, 1].a
25
+ assert_equal 1, img[97, 97].a
26
+ #assert_equal 1, img[98, 98].a
27
+ assert_equal 0, img[99, 99].a
28
+ end
29
+
30
+ def test_rect ()
31
+ img = image {rect 1, 1, 98, 98}
32
+ assert_equal 0, img[ 0, 0].a
33
+ assert_equal 1, img[ 1, 1].a
34
+ assert_equal 1, img[98, 98].a
35
+ assert_equal 0, img[99, 99].a
36
+ end
37
+
38
+ def test_rect_rounded ()
39
+ img = image {rect 1, 1, 98, 98, 10, 10, 10, 10}
40
+ assert_equal 0, img[ 0, 0].a
41
+ assert_equal 0, img[ 1, 1].a
42
+ assert_equal 1, img[10, 10].a
43
+ assert_equal 1, img[89, 89].a
44
+ assert_equal 0, img[98, 98].a
45
+ assert_equal 0, img[99, 99].a
46
+ end
47
+
48
+ def test_ellipse ()
49
+ img = image {ellipse 1, 1, 98, 98}
50
+ assert_equal 0, img[ 0, 0].a
51
+ assert_equal 1, img[50, 1].a
52
+ assert_equal 1, img[50, 50].a
53
+ assert_equal 1, img[ 1, 50].a
54
+ assert_equal 0, img[99, 99].a
55
+ end
56
+
57
+ end# TestPainter
@@ -18,6 +18,18 @@ class TestPoint < Test::Unit::TestCase
18
18
  assert_raise(ArgumentError) {point(1, 2, 3, 4)}
19
19
  end
20
20
 
21
+ def test_dup ()
22
+ o = point
23
+ assert_equal point(0, 0, 0), o
24
+ o.x = 1
25
+ assert_equal point(1, 0, 0), o
26
+ x = o.dup
27
+ assert_equal point(1, 0, 0), x
28
+ x.x = 2
29
+ assert_equal point(2, 0, 0), x
30
+ assert_equal point(1, 0, 0), o
31
+ end
32
+
21
33
  def test_get_xyz ()
22
34
  o = point 1, 2, 3
23
35
  assert_equal 1, o.x
@@ -95,6 +107,7 @@ class TestPoint < Test::Unit::TestCase
95
107
 
96
108
  def test_normal ()
97
109
  assert_equal point(1, 2, 3).normalize, point(1, 2, 3).normal
110
+ assert_raise(Rucy::NativeError) {point(0).normal}
98
111
  end
99
112
 
100
113
  def test_to_a ()
@@ -143,6 +156,10 @@ class TestPoint < Test::Unit::TestCase
143
156
  assert o > point(1, 2, 2)
144
157
  end
145
158
 
159
+ def test_negate ()
160
+ assert_equal point(-1, 2, -3), -point(1, -2, 3)
161
+ end
162
+
146
163
  def test_arithmetic_operations ()
147
164
  assert_equal point(11, 22, 33), point(10, 20, 30) + point(1, 2, 3)
148
165
  assert_equal point( 9, 18, 27), point(10, 20, 30) - point(1, 2, 3)
@@ -158,4 +175,8 @@ class TestPoint < Test::Unit::TestCase
158
175
  assert_equal point( 5, 10, 15), point(10, 20, 30) / 2
159
176
  end
160
177
 
178
+ def test_inspect ()
179
+ assert_equal "#<Rays::Point 1.0, 2.0, 3.0>", point(1, 2, 3).inspect
180
+ end
181
+
161
182
  end# TestPoint
@@ -0,0 +1,234 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require_relative 'helper'
5
+
6
+
7
+ class TestPolygon < Test::Unit::TestCase
8
+
9
+ class Rays::Polygon
10
+ def dump ()
11
+ map {|l| l.map &:to_a}
12
+ end
13
+ end
14
+
15
+ def polygon (*args)
16
+ Rays::Polygon.new *args
17
+ end
18
+
19
+ def line (*args)
20
+ Rays::Polygon::Line.new *args
21
+ end
22
+
23
+ def polyline (*args)
24
+ Rays::Polyline.new *args
25
+ end
26
+
27
+ def point (*args)
28
+ Rays::Point.new *args
29
+ end
30
+
31
+ def bounds (*args)
32
+ Rays::Bounds.new *args
33
+ end
34
+
35
+ def rect (*args)
36
+ Rays::Polygon.rect *args
37
+ end
38
+
39
+ def assert_equal_polygon (poly1, poly2)
40
+ assert_equal *[poly1, poly2].map {|poly|
41
+ poly.dump.map {|l| l.map {|p| p.map &:round}}.map(&:sort).sort.flatten
42
+ }
43
+ end
44
+
45
+ def test_initialize ()
46
+ assert_equal [[[1, 2], [3, 4]]], polygon( 1, 2, 3, 4, loop: false).dump
47
+ assert_equal [[[5, 6], [7, 8]]], polygon( [5, 6], [7, 8], loop: false).dump
48
+ assert_equal [[[1, 1], [2, 2]]], polygon( [1], [2], loop: false).dump
49
+ assert_equal [[[3, 3], [4, 4]]], polygon(point(3), point(4), loop: false).dump
50
+ assert_nothing_raised {polygon( loop: true)}
51
+ assert_nothing_raised {polygon( loop: false)}
52
+ assert_raise(ArgumentError) {polygon(1, loop: true)}
53
+ assert_raise(ArgumentError) {polygon(1, loop: false)}
54
+ assert_raise(ArgumentError) {polygon(1, 2, loop: true)}
55
+ assert_nothing_raised {polygon(1, 2, loop: false)}
56
+ assert_raise(ArgumentError) {polygon(1, 2, 3, loop: true)}
57
+ assert_raise(ArgumentError) {polygon(1, 2, 3, loop: false)}
58
+ assert_raise(ArgumentError) {polygon(1, 2, 3, 4, loop: true)}
59
+ assert_nothing_raised {polygon(1, 2, 3, 4, loop: false)}
60
+ assert_raise(ArgumentError) {polygon(1, 2, 3, 4, 5, loop: true)}
61
+ assert_raise(ArgumentError) {polygon(1, 2, 3, 4, 5, loop: false)}
62
+ assert_nothing_raised {polygon(1, 2, 3, 4, 5, 6, loop: true)}
63
+ assert_nothing_raised {polygon(1, 2, 3, 4, 5, 6, loop: false)}
64
+ end
65
+
66
+ def test_expand ()
67
+ polygon([10,10], [20,10], [30,20], loop: false).expand(1).tap {|o|
68
+ assert_equal 1, o .size
69
+ assert_equal 6, o[0].size
70
+ }
71
+ polygon([10,10], [20,10], [20,20], [10,20], loop: true) .expand(1).tap {|o|
72
+ assert_equal 1, o .size
73
+ assert_equal 4, o[0].size
74
+ }
75
+ end
76
+
77
+ def test_transform_with_matrix ()
78
+ m = Rays::Matrix.translate 10, 10
79
+ assert_equal_polygon rect(20, 20, 50, 50), rect(10, 10, 50, 50).transform(m)
80
+
81
+ m = Rays::Matrix.scale 2
82
+ assert_equal_polygon rect(20, 20, 40, 40), rect(10, 10, 20, 20).transform(m)
83
+
84
+ m = Rays::Matrix.rotate 90
85
+ assert_equal_polygon rect(-10, 0, 10, 10), rect(0, 0, 10, 10).transform(m)
86
+ end
87
+
88
+ def test_transform_block ()
89
+ o = rect(0, 0, 100, 100) - rect(10, 10, 50, 50)
90
+ assert_equal 2, o.size
91
+
92
+ o.transform {|lines|
93
+ lines.map {|l| l.transform Rays::Matrix.translate 10, 10}
94
+ }.tap {|x|
95
+ assert_equal_polygon (rect(10, 10, 100, 100) - rect(20, 20, 50, 50)), x
96
+ }
97
+
98
+ o.transform {|lines|
99
+ lines.reject {|l| l.to_a.include? point(10, 10)}
100
+ }.tap {|x|
101
+ assert_equal 1, x.size
102
+ assert_equal 2, o.size
103
+ }
104
+
105
+ o.transform {|lines|
106
+ lines.reject {|l| l.to_a.include? point(10, 10)}
107
+ }.tap {|x|
108
+ assert_equal 1, x.size
109
+ assert_equal 2, o.size
110
+ }
111
+
112
+ o.transform {|lines|
113
+ lines + [line(1, 2, 3, 4, 5, 6)]
114
+ }.tap {|x|
115
+ assert_equal 3, x.size
116
+ assert_equal 2, o.size
117
+ }
118
+ end
119
+
120
+ def test_intersects ()
121
+ assert rect(10, 10, 20, 20).intersects(rect 20, 20, 20, 20)
122
+ assert_not rect(10, 10, 20, 20).intersects(rect 40, 40, 20, 20)
123
+ end
124
+
125
+ def test_bounds ()
126
+ assert_equal bounds(10, 20, 0, 20, 10, 0), polygon(10, 20, 30, 20, 20, 30).bounds
127
+
128
+ assert polygon(10, 20, 30, 20, 20, 30).bounds.valid?
129
+ assert_not polygon() .bounds.valid?
130
+ end
131
+
132
+ def test_loop ()
133
+ assert_equal true, polygon(1, 2, 3, 4, 5, 6 ).first.loop?
134
+ assert_equal true, polygon(1, 2, 3, 4, 5, 6, loop: true ).first.loop?
135
+ assert_equal false, polygon(1, 2, 3, 4, 5, 6, loop: false).first.loop?
136
+ end
137
+
138
+ def test_size ()
139
+ assert_equal 0, polygon( ).size
140
+ assert_equal 1, polygon(1, 2, 3, 4, loop: false).size
141
+ assert_equal 1, polygon(1, 2, 3, 4, 5, 6, loop: false).size
142
+ assert_equal 2, (rect(0, 0, 5, 5) | rect(10, 0, 5, 5)).size
143
+ end
144
+
145
+ def test_empty? ()
146
+ assert_equal true, polygon( ).empty?
147
+ assert_equal false, polygon(1, 2, 3, 4, 5, 6).empty?
148
+ end
149
+
150
+ def test_index ()
151
+ o1 = rect 0, 0, 10, 10
152
+ o2 = rect 20, 0, 10, 10
153
+ o3 = rect 40, 0, 10, 10
154
+ o = o1 | o2 | o3
155
+ assert_not_nil o[ 0]
156
+ assert_not_nil o[ 1]
157
+ assert_not_nil o[-1]
158
+ assert_raise(IndexError) {o[ 3]}
159
+ assert_raise(IndexError) {o[-4]}
160
+ end
161
+
162
+ def test_sub ()
163
+ rect10 = rect 0, 0, 10, 10
164
+
165
+ o = rect10 - rect(5, 0, 10, 10)
166
+ assert_equal_polygon rect(0, 0, 5, 10), o
167
+
168
+ o = rect10 - rect(5, 0, 10, 10) - rect(0, 0, 2, 10)
169
+ assert_equal_polygon rect(2, 0, 3, 10), o
170
+
171
+ o = rect10 - [rect(5, 0, 10, 10), rect(0, 0, 3, 10)]
172
+ assert_equal_polygon rect(3, 0, 2, 10), o
173
+
174
+ assert_equal_polygon rect10, rect10 - polygon()
175
+ assert_equal_polygon polygon(), polygon() - rect10
176
+ assert_equal_polygon rect10, rect10 - []
177
+ assert_equal_polygon polygon(), rect10 - rect10
178
+ end
179
+
180
+ def test_and ()
181
+ rect10 = rect 0, 0, 10, 10
182
+
183
+ o = rect10 & rect(5, 0, 10, 10)
184
+ assert_equal_polygon rect(5, 0, 5, 10), o
185
+
186
+ o = rect10 & rect(5, 0, 10, 10) & rect(0, 5, 10, 10)
187
+ assert_equal_polygon rect(5, 5, 5, 5), o
188
+
189
+ o = rect10 & [rect(5, 0, 10, 10), rect(0, 6, 10, 10)]
190
+ assert_equal_polygon rect(5, 6, 5, 4), o
191
+
192
+ assert_equal_polygon polygon(), rect10 & polygon()
193
+ assert_equal_polygon polygon(), polygon() & rect10
194
+ assert_equal_polygon rect10, rect10 & []
195
+ assert_equal_polygon rect10, rect10 & rect10
196
+ end
197
+
198
+ def test_or ()
199
+ rect10 = rect 0, 0, 10, 10
200
+
201
+ o = rect10 | rect(5, 0, 10, 10)
202
+ assert_equal_polygon rect(0, 0, 15, 10), o
203
+
204
+ o = rect10 | rect(5, 0, 10, 10) | rect(-5, 0, 10, 10)
205
+ assert_equal_polygon rect(-5, 0, 20, 10), o
206
+
207
+ o = rect10 | [rect(5, 0, 10, 10), rect(-6, 0, 10, 10)]
208
+ assert_equal_polygon rect(-6, 0, 21, 10), o
209
+
210
+ assert_equal_polygon rect10, rect10 | polygon()
211
+ assert_equal_polygon rect10, polygon() | rect10
212
+ assert_equal_polygon rect10, rect10 | []
213
+ assert_equal_polygon rect10, rect10 | rect10
214
+ end
215
+
216
+ def test_xor ()
217
+ rect10 = rect 0, 0, 10, 10
218
+
219
+ o = rect10 ^ rect(5, 0, 10, 10)
220
+ assert_equal_polygon rect(0, 0, 5, 10) | rect(10, 0, 5, 10), o
221
+
222
+ o = rect10 ^ rect(5, 0, 10, 10) ^ rect(0, 0, 15, 5)
223
+ assert_equal_polygon rect(0, 5, 5, 5) | rect(5, 0, 5, 5) | rect(10, 5, 5, 5), o
224
+
225
+ o = rect10 ^ [rect(5, 0, 10, 10), rect(0, 0, 15, 6)]
226
+ assert_equal_polygon rect(0, 6, 5, 4) | rect(5, 0, 5, 6) | rect(10, 6, 5, 4), o
227
+
228
+ assert_equal_polygon rect10, rect10 ^ polygon()
229
+ assert_equal_polygon rect10, polygon() ^ rect10
230
+ assert_equal_polygon rect10, rect10 ^ []
231
+ assert_equal_polygon polygon(), rect10 ^ rect10
232
+ end
233
+
234
+ end# TestPolygon
@@ -0,0 +1,167 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require_relative 'helper'
5
+
6
+
7
+ class TestPolygonLine < Test::Unit::TestCase
8
+
9
+ class Rays::Polygon::Line
10
+ def dump ()
11
+ map &:to_a
12
+ end
13
+
14
+ def loop_hole ()
15
+ [loop?, hole?]
16
+ end
17
+ end
18
+
19
+ def line (*args)
20
+ Rays::Polygon::Line.new *args
21
+ end
22
+
23
+ def point (*args)
24
+ Rays::Point.new *args
25
+ end
26
+
27
+ def rect (*args)
28
+ Rays::Polygon.rect *args
29
+ end
30
+
31
+ def test_initialize ()
32
+ assert_equal [[1, 2], [3, 4], [5, 6]], line( 1, 2, 3, 4 , 5, 6 ).dump
33
+ assert_equal [[1, 2], [3, 4], [5, 6]], line( [1, 2], [3, 4], [5, 6]).dump
34
+ assert_equal [[1, 1], [2, 2], [3, 3]], line( [1], [2], [3]).dump
35
+ assert_equal [[1, 1], [2, 2], [3, 3]], line(point(1), point(2), point(3)).dump
36
+
37
+ assert_equal [true, false], line(1, 2, 3, 4, 5, 6 ).loop_hole
38
+ assert_equal [true, false], line(1, 2, 3, 4, 5, 6, loop: true ).loop_hole
39
+ assert_equal [false, false], line(1, 2, 3, 4, 5, 6, loop: false ).loop_hole
40
+ assert_equal [true, true ], line(1, 2, 3, 4, 5, 6, hole: true ).loop_hole
41
+ assert_equal [true, false], line(1, 2, 3, 4, 5, 6, hole: false).loop_hole
42
+ assert_equal [true, true ], line(1, 2, 3, 4, 5, 6, loop: true, hole: true ).loop_hole
43
+ assert_equal [true, false], line(1, 2, 3, 4, 5, 6, loop: true, hole: false).loop_hole
44
+ assert_raise(ArgumentError) {line(1, 2, 3, 4, 5, 6, loop: false, hole: true ).loop_hole}
45
+ assert_equal [false, false], line(1, 2, 3, 4, 5, 6, loop: false, hole: false).loop_hole
46
+
47
+ assert_raise(ArgumentError) {line( loop: true, hole: true )}
48
+ assert_nothing_raised {line( loop: true, hole: false)}
49
+ assert_raise(ArgumentError) {line( loop: false, hole: true )}
50
+ assert_nothing_raised {line( loop: false, hole: false)}
51
+ assert_raise(ArgumentError) {line(1, loop: true, hole: true )}
52
+ assert_raise(ArgumentError) {line(1, loop: true, hole: false)}
53
+ assert_raise(ArgumentError) {line(1, loop: false, hole: true )}
54
+ assert_raise(ArgumentError) {line(1, loop: false, hole: false)}
55
+ assert_raise(ArgumentError) {line(1, 2, loop: true, hole: true )}
56
+ assert_raise(ArgumentError) {line(1, 2, loop: true, hole: false)}
57
+ assert_raise(ArgumentError) {line(1, 2, loop: false, hole: true )}
58
+ assert_nothing_raised {line(1, 2, loop: false, hole: false)}
59
+ assert_raise(ArgumentError) {line(1, 2, 3, loop: true, hole: true )}
60
+ assert_raise(ArgumentError) {line(1, 2, 3, loop: true, hole: false)}
61
+ assert_raise(ArgumentError) {line(1, 2, 3, loop: false, hole: true )}
62
+ assert_raise(ArgumentError) {line(1, 2, 3, loop: false, hole: false)}
63
+ assert_raise(ArgumentError) {line(1, 2, 3, 4, loop: true, hole: true )}
64
+ assert_raise(ArgumentError) {line(1, 2, 3, 4, loop: true, hole: false)}
65
+ assert_raise(ArgumentError) {line(1, 2, 3, 4, loop: false, hole: true )}
66
+ assert_nothing_raised {line(1, 2, 3, 4, loop: false, hole: false)}
67
+ assert_raise(ArgumentError) {line(1, 2, 3, 4, 5, loop: true, hole: true )}
68
+ assert_raise(ArgumentError) {line(1, 2, 3, 4, 5, loop: true, hole: false)}
69
+ assert_raise(ArgumentError) {line(1, 2, 3, 4, 5, loop: false, hole: true )}
70
+ assert_raise(ArgumentError) {line(1, 2, 3, 4, 5, loop: false, hole: false)}
71
+ assert_nothing_raised {line(1, 2, 3, 4, 5, 6, loop: true, hole: true )}
72
+ assert_nothing_raised {line(1, 2, 3, 4, 5, 6, loop: true, hole: false)}
73
+ assert_raise(ArgumentError) {line(1, 2, 3, 4, 5, 6, loop: false, hole: true )}
74
+ assert_nothing_raised {line(1, 2, 3, 4, 5, 6, loop: false, hole: false)}
75
+ end
76
+
77
+ def test_transform_with_materix ()
78
+ m = Rays::Matrix.translate 100, 200
79
+ line([10,10], [20,20], loop: false).transform(m).tap {|o|
80
+ assert_equal [[110,210], [120,220]], o.dump
81
+ }
82
+
83
+ m = Rays::Matrix.scale 2
84
+ line([10,10], [20,20], loop: false).transform(m).tap {|o|
85
+ assert_equal [[20,20], [40,40]], o.dump
86
+ }
87
+
88
+ m = Rays::Matrix.rotate 90
89
+ line([10,10], [20,20], loop: false).transform(m).tap {|o|
90
+ assert_equal [[-10,10], [-20,20]], o.dump
91
+ }
92
+ end
93
+
94
+ def test_transform_with_block ()
95
+ line([10,10], [20,20], loop: false).transform {|points|
96
+ points.map {|p| p + [10, 20]}
97
+ }.tap {|o|
98
+ assert_equal [[20,30], [30,40]], o.dump
99
+ }
100
+
101
+ line([10,10], [20,20], [30,30], loop: false).transform {|points|
102
+ points.reject {|p| p == point(20, 20)}
103
+ }.tap {|o|
104
+ assert_equal [[10,10], [30,30]], o.dump
105
+ }
106
+
107
+ line([10,10], [20,20], loop: false).transform {|points|
108
+ points + [[30, 30]]
109
+ }.tap {|o|
110
+ assert_equal [[10,10], [20,20], [30,30]], o.dump
111
+ }
112
+
113
+ points = [1, 2, 3, 4, 5, 6]
114
+ line(*points, loop: false, hole: false).transform(loop: true ).tap {|o|
115
+ assert_equal points, o.dump.flatten
116
+ assert_equal [true, false], o.loop_hole
117
+ }
118
+ assert_raise(ArgumentError) {
119
+ line(*points, loop: false, hole: false).transform( hole: true )
120
+ }
121
+ assert_raise(ArgumentError) {
122
+ line(*points, loop: false, hole: false).transform(loop: false, hole: true )
123
+ }
124
+ line(*points, loop: false, hole: false).transform(loop: true, hole: true ).tap {|o|
125
+ assert_equal points, o.dump.flatten
126
+ assert_equal [true, true ], o.loop_hole
127
+ }
128
+ line(*points, loop: true, hole: false).transform(loop: false ).tap {|o|
129
+ assert_equal points, o.dump.flatten
130
+ assert_equal [false, false], o.loop_hole
131
+ }
132
+ line(*points, loop: true, hole: false).transform( hole: true ).tap {|o|
133
+ assert_equal points, o.dump.flatten
134
+ assert_equal [true, true ], o.loop_hole
135
+ }
136
+ assert_raise(ArgumentError) {
137
+ line(*points, loop: true, hole: false).transform(loop: false, hole: true )
138
+ }
139
+ assert_raise(ArgumentError) {
140
+ line(*points, loop: true, hole: true ).transform(loop: false )
141
+ }
142
+ line(*points, loop: true, hole: true ).transform( hole: false).tap {|o|
143
+ assert_equal points, o.dump.flatten
144
+ assert_equal [true, false], o.loop_hole
145
+ }
146
+ line(*points, loop: true, hole: true ).transform(loop: false, hole: false).tap {|o|
147
+ assert_equal points, o.dump.flatten
148
+ assert_equal [false, false], o.loop_hole
149
+ }
150
+ end
151
+
152
+ def test_hole ()
153
+ (rect(0, 0, 10, 10) - rect(1, 1, 2, 2)).tap {|o|
154
+ assert_equal 1, o.select {|line| line.hole?}.size
155
+ }
156
+ (rect(0, 0, 10, 10) - rect(100, 1, 2, 2)).tap {|o|
157
+ assert_equal 0, o.select {|line| line.hole?}.size
158
+ }
159
+ end
160
+
161
+ def test_inspect ()
162
+ assert_equal(
163
+ "#<Rays::Polygon::Line [1.0, 2.0], [3.0, 4.0], [5.0, 6.0], loop: true, hole: false>",
164
+ line(1, 2, 3, 4, 5, 6).inspect)
165
+ end
166
+
167
+ end# TestPolygonLine