rays 0.1.21 → 0.1.22

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_point.rb CHANGED
@@ -6,11 +6,11 @@ require_relative 'helper'
6
6
 
7
7
  class TestPoint < Test::Unit::TestCase
8
8
 
9
- def point (*args)
10
- Rays::Point.new *args
9
+ def point(*args)
10
+ Rays::Point.new(*args)
11
11
  end
12
12
 
13
- def test_initialize ()
13
+ def test_initialize()
14
14
  assert_equal point(0, 0, 0), point()
15
15
  assert_equal point(1, 1, 0), point(1)
16
16
  assert_equal point(1, 2, 0), point(1, 2)
@@ -18,7 +18,7 @@ class TestPoint < Test::Unit::TestCase
18
18
  assert_raise(ArgumentError) {point(1, 2, 3, 4)}
19
19
  end
20
20
 
21
- def test_dup ()
21
+ def test_dup()
22
22
  o = point
23
23
  assert_equal point(0, 0, 0), o
24
24
  o.x = 1
@@ -30,14 +30,14 @@ class TestPoint < Test::Unit::TestCase
30
30
  assert_equal point(1, 0, 0), o
31
31
  end
32
32
 
33
- def test_get_xyz ()
33
+ def test_get_xyz()
34
34
  o = point 1, 2, 3
35
35
  assert_equal 1, o.x
36
36
  assert_equal 2, o.y
37
37
  assert_equal 3, o.z
38
38
  end
39
39
 
40
- def test_set_xyz ()
40
+ def test_set_xyz()
41
41
  o = point
42
42
  o.x = 1
43
43
  assert_equal [1, 0, 0], o.to_a(3)
@@ -47,7 +47,7 @@ class TestPoint < Test::Unit::TestCase
47
47
  assert_equal [1, 2, 3], o.to_a(3)
48
48
  end
49
49
 
50
- def test_move_to ()
50
+ def test_move_to()
51
51
  o = point 1, 2, 3
52
52
  assert_equal point(4, 2, 3), o.move_to( 4)
53
53
  assert_equal point(4, 5, 3), o.move_to( 4, 5)
@@ -67,7 +67,7 @@ class TestPoint < Test::Unit::TestCase
67
67
  assert_equal point(4, 5, 6), o1
68
68
  end
69
69
 
70
- def test_move_by ()
70
+ def test_move_by()
71
71
  o = point 1, 2, 3
72
72
  assert_equal point( 5, 2, 3), o.move_by( 4)
73
73
  assert_equal point( 5, 7, 3), o.move_by( 4, 5)
@@ -90,13 +90,13 @@ class TestPoint < Test::Unit::TestCase
90
90
  assert_equal point(5, 7, 9), o1
91
91
  end
92
92
 
93
- def test_length ()
93
+ def test_length()
94
94
  assert_in_delta 0, point(0).length
95
95
  assert_in_delta 1, point(1, 0, 0).length
96
96
  assert_in_delta Math.sqrt(2), point(1, 1, 0).length
97
97
  end
98
98
 
99
- def test_normalize ()
99
+ def test_normalize()
100
100
  assert_in_delta 1, point( 1, 0, 0) .normalize.length
101
101
  assert_in_delta 1, point( 1, 1, 0) .normalize.length
102
102
  assert_in_delta 1, point( 1, 1, 1) .normalize.length
@@ -105,12 +105,12 @@ class TestPoint < Test::Unit::TestCase
105
105
  assert_raise(Rucy::NativeError) {point(0).normalize}
106
106
  end
107
107
 
108
- def test_normal ()
108
+ def test_normal()
109
109
  assert_equal point(1, 2, 3).normalize, point(1, 2, 3).normal
110
110
  assert_raise(Rucy::NativeError) {point(0).normal}
111
111
  end
112
112
 
113
- def test_to_a ()
113
+ def test_to_a()
114
114
  o = point 1, 2, 3
115
115
  assert_equal [1, 2], o.to_a
116
116
  assert_equal [1], o.to_a(1)
@@ -121,7 +121,7 @@ class TestPoint < Test::Unit::TestCase
121
121
  assert_raise(ArgumentError) {o.to_a(4)}
122
122
  end
123
123
 
124
- def test_index ()
124
+ def test_index()
125
125
  o = point 1, 2, 3
126
126
  assert_equal 1, o[0]
127
127
  assert_equal 2, o[1]
@@ -130,7 +130,7 @@ class TestPoint < Test::Unit::TestCase
130
130
  assert_raise(IndexError) {point[3]}
131
131
  end
132
132
 
133
- def test_index_assign ()
133
+ def test_index_assign()
134
134
  o = point 1, 2, 3
135
135
  o[0] = 4
136
136
  assert_equal [4, 2, 3], o.to_a(3)
@@ -142,7 +142,7 @@ class TestPoint < Test::Unit::TestCase
142
142
  assert_raise(IndexError) {point[ 3] = 7}
143
143
  end
144
144
 
145
- def test_compare ()
145
+ def test_compare()
146
146
  o = point 1, 2, 3
147
147
  assert o == point(1, 2, 3)
148
148
  assert_not o != point(1, 2, 3)
@@ -156,11 +156,11 @@ class TestPoint < Test::Unit::TestCase
156
156
  assert o > point(1, 2, 2)
157
157
  end
158
158
 
159
- def test_negate ()
159
+ def test_negate()
160
160
  assert_equal point(-1, 2, -3), -point(1, -2, 3)
161
161
  end
162
162
 
163
- def test_arithmetic_operations ()
163
+ def test_arithmetic_operations()
164
164
  assert_equal point(11, 22, 33), point(10, 20, 30) + point(1, 2, 3)
165
165
  assert_equal point( 9, 18, 27), point(10, 20, 30) - point(1, 2, 3)
166
166
  assert_equal point(10, 40, 90), point(10, 20, 30) * point(1, 2, 3)
@@ -175,15 +175,15 @@ class TestPoint < Test::Unit::TestCase
175
175
  assert_equal point( 5, 10, 15), point(10, 20, 30) / 2
176
176
  end
177
177
 
178
- def test_inspect ()
178
+ def test_inspect()
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 ()
182
+ def test_dot()
183
183
  assert_equal 1*4 + 2*5 + 3*6, Rays::Point::dot(point(1, 2, 3), point(4, 5, 6))
184
184
  end
185
185
 
186
- def test_cross ()
186
+ def test_cross()
187
187
  assert_equal point(0, 0, 1), Rays::Point::cross(point(1, 0, 0), point(0, 1, 0))
188
188
  end
189
189
 
data/test/test_polygon.rb CHANGED
@@ -7,42 +7,42 @@ require_relative 'helper'
7
7
  class TestPolygon < Test::Unit::TestCase
8
8
 
9
9
  class Rays::Polygon
10
- def dump ()
10
+ def dump()
11
11
  map {|l| l.map &:to_a}
12
12
  end
13
13
  end
14
14
 
15
- def polygon (*args)
16
- Rays::Polygon.new *args
15
+ def polygon(*args, **kwargs)
16
+ Rays::Polygon.new(*args, **kwargs)
17
17
  end
18
18
 
19
- def line (*args)
20
- Rays::Polygon::Line.new *args
19
+ def line(*args)
20
+ Rays::Polygon::Line.new(*args)
21
21
  end
22
22
 
23
- def polyline (*args)
24
- Rays::Polyline.new *args
23
+ def polyline(*args)
24
+ Rays::Polyline.new(*args)
25
25
  end
26
26
 
27
- def point (*args)
28
- Rays::Point.new *args
27
+ def point(*args)
28
+ Rays::Point.new(*args)
29
29
  end
30
30
 
31
- def bounds (*args)
32
- Rays::Bounds.new *args
31
+ def bounds(*args)
32
+ Rays::Bounds.new(*args)
33
33
  end
34
34
 
35
- def rect (*args)
36
- Rays::Polygon.rect *args
35
+ def rect(*args)
36
+ Rays::Polygon.rect(*args)
37
37
  end
38
38
 
39
- def assert_equal_polygon (poly1, poly2)
40
- assert_equal *[poly1, poly2].map {|poly|
39
+ def assert_equal_polygon(poly1, poly2)
40
+ assert_equal(*[poly1, poly2].map {|poly|
41
41
  poly.dump.map {|l| l.map {|p| p.map &:round}}.map(&:sort).sort.flatten
42
- }
42
+ })
43
43
  end
44
44
 
45
- def test_initialize ()
45
+ def test_initialize()
46
46
  assert_equal [[[1, 2], [3, 4]]], polygon( 1, 2, 3, 4, loop: false).dump
47
47
  assert_equal [[[5, 6], [7, 8]]], polygon( [5, 6], [7, 8], loop: false).dump
48
48
  assert_equal [[[1, 1], [2, 2]]], polygon( [1], [2], loop: false).dump
@@ -63,7 +63,7 @@ class TestPolygon < Test::Unit::TestCase
63
63
  assert_nothing_raised {polygon(1, 2, 3, 4, 5, 6, loop: false)}
64
64
  end
65
65
 
66
- def test_expand ()
66
+ def test_expand()
67
67
  polygon([10,10], [20,10], [30,20], loop: false).expand(1).tap {|o|
68
68
  assert_equal 1, o .size
69
69
  assert_equal 6, o[0].size
@@ -74,7 +74,7 @@ class TestPolygon < Test::Unit::TestCase
74
74
  }
75
75
  end
76
76
 
77
- def test_transform_with_matrix ()
77
+ def test_transform_with_matrix()
78
78
  m = Rays::Matrix.translate 10, 10
79
79
  assert_equal_polygon rect(20, 20, 50, 50), rect(10, 10, 50, 50).transform(m)
80
80
 
@@ -85,7 +85,7 @@ class TestPolygon < Test::Unit::TestCase
85
85
  assert_equal_polygon rect(-10, 0, 10, 10), rect(0, 0, 10, 10).transform(m)
86
86
  end
87
87
 
88
- def test_transform_block ()
88
+ def test_transform_block()
89
89
  o = rect(0, 0, 100, 100) - rect(10, 10, 50, 50)
90
90
  assert_equal 2, o.size
91
91
 
@@ -117,37 +117,37 @@ class TestPolygon < Test::Unit::TestCase
117
117
  }
118
118
  end
119
119
 
120
- def test_intersects ()
120
+ def test_intersects()
121
121
  assert rect(10, 10, 20, 20).intersects(rect 20, 20, 20, 20)
122
122
  assert_not rect(10, 10, 20, 20).intersects(rect 40, 40, 20, 20)
123
123
  end
124
124
 
125
- def test_bounds ()
125
+ def test_bounds()
126
126
  assert_equal bounds(10, 20, 0, 20, 10, 0), polygon(10, 20, 30, 20, 20, 30).bounds
127
127
 
128
128
  assert polygon(10, 20, 30, 20, 20, 30).bounds.valid?
129
129
  assert_not polygon() .bounds.valid?
130
130
  end
131
131
 
132
- def test_loop ()
132
+ def test_loop()
133
133
  assert_equal true, polygon(1, 2, 3, 4, 5, 6 ).first.loop?
134
134
  assert_equal true, polygon(1, 2, 3, 4, 5, 6, loop: true ).first.loop?
135
135
  assert_equal false, polygon(1, 2, 3, 4, 5, 6, loop: false).first.loop?
136
136
  end
137
137
 
138
- def test_size ()
138
+ def test_size()
139
139
  assert_equal 0, polygon( ).size
140
140
  assert_equal 1, polygon(1, 2, 3, 4, loop: false).size
141
141
  assert_equal 1, polygon(1, 2, 3, 4, 5, 6, loop: false).size
142
142
  assert_equal 2, (rect(0, 0, 5, 5) | rect(10, 0, 5, 5)).size
143
143
  end
144
144
 
145
- def test_empty? ()
145
+ def test_empty?()
146
146
  assert_equal true, polygon( ).empty?
147
147
  assert_equal false, polygon(1, 2, 3, 4, 5, 6).empty?
148
148
  end
149
149
 
150
- def test_index ()
150
+ def test_index()
151
151
  o1 = rect 0, 0, 10, 10
152
152
  o2 = rect 20, 0, 10, 10
153
153
  o3 = rect 40, 0, 10, 10
@@ -159,7 +159,7 @@ class TestPolygon < Test::Unit::TestCase
159
159
  assert_raise(IndexError) {o[-4]}
160
160
  end
161
161
 
162
- def test_sub ()
162
+ def test_sub()
163
163
  rect10 = rect 0, 0, 10, 10
164
164
 
165
165
  o = rect10 - rect(5, 0, 10, 10)
@@ -177,7 +177,7 @@ class TestPolygon < Test::Unit::TestCase
177
177
  assert_equal_polygon polygon(), rect10 - rect10
178
178
  end
179
179
 
180
- def test_and ()
180
+ def test_and()
181
181
  rect10 = rect 0, 0, 10, 10
182
182
 
183
183
  o = rect10 & rect(5, 0, 10, 10)
@@ -195,7 +195,7 @@ class TestPolygon < Test::Unit::TestCase
195
195
  assert_equal_polygon rect10, rect10 & rect10
196
196
  end
197
197
 
198
- def test_or ()
198
+ def test_or()
199
199
  rect10 = rect 0, 0, 10, 10
200
200
 
201
201
  o = rect10 | rect(5, 0, 10, 10)
@@ -213,7 +213,7 @@ class TestPolygon < Test::Unit::TestCase
213
213
  assert_equal_polygon rect10, rect10 | rect10
214
214
  end
215
215
 
216
- def test_xor ()
216
+ def test_xor()
217
217
  rect10 = rect 0, 0, 10, 10
218
218
 
219
219
  o = rect10 ^ rect(5, 0, 10, 10)
@@ -7,28 +7,28 @@ require_relative 'helper'
7
7
  class TestPolygonLine < Test::Unit::TestCase
8
8
 
9
9
  class Rays::Polygon::Line
10
- def dump ()
10
+ def dump()
11
11
  map &:to_a
12
12
  end
13
13
 
14
- def loop_hole ()
14
+ def loop_hole()
15
15
  [loop?, hole?]
16
16
  end
17
17
  end
18
18
 
19
- def line (*args)
20
- Rays::Polygon::Line.new *args
19
+ def line(*args, **kwargs)
20
+ Rays::Polygon::Line.new(*args, **kwargs)
21
21
  end
22
22
 
23
- def point (*args)
24
- Rays::Point.new *args
23
+ def point(*args)
24
+ Rays::Point.new(*args)
25
25
  end
26
26
 
27
- def rect (*args)
28
- Rays::Polygon.rect *args
27
+ def rect(*args)
28
+ Rays::Polygon.rect(*args)
29
29
  end
30
30
 
31
- def test_initialize ()
31
+ def test_initialize()
32
32
  assert_equal [[1, 2], [3, 4], [5, 6]], line( 1, 2, 3, 4 , 5, 6 ).dump
33
33
  assert_equal [[1, 2], [3, 4], [5, 6]], line( [1, 2], [3, 4], [5, 6]).dump
34
34
  assert_equal [[1, 1], [2, 2], [3, 3]], line( [1], [2], [3]).dump
@@ -74,7 +74,7 @@ class TestPolygonLine < Test::Unit::TestCase
74
74
  assert_nothing_raised {line(1, 2, 3, 4, 5, 6, loop: false, hole: false)}
75
75
  end
76
76
 
77
- def test_transform_with_materix ()
77
+ def test_transform_with_materix()
78
78
  m = Rays::Matrix.translate 100, 200
79
79
  line([10,10], [20,20], loop: false).transform(m).tap {|o|
80
80
  assert_equal [[110,210], [120,220]], o.dump
@@ -91,7 +91,7 @@ class TestPolygonLine < Test::Unit::TestCase
91
91
  }
92
92
  end
93
93
 
94
- def test_transform_with_block ()
94
+ def test_transform_with_block()
95
95
  line([10,10], [20,20], loop: false).transform {|points|
96
96
  points.map {|p| p + [10, 20]}
97
97
  }.tap {|o|
@@ -149,7 +149,7 @@ class TestPolygonLine < Test::Unit::TestCase
149
149
  }
150
150
  end
151
151
 
152
- def test_hole ()
152
+ def test_hole()
153
153
  (rect(0, 0, 10, 10) - rect(1, 1, 2, 2)).tap {|o|
154
154
  assert_equal 1, o.select {|line| line.hole?}.size
155
155
  }
@@ -158,7 +158,7 @@ class TestPolygonLine < Test::Unit::TestCase
158
158
  }
159
159
  end
160
160
 
161
- def test_inspect ()
161
+ def test_inspect()
162
162
  assert_equal(
163
163
  "#<Rays::Polygon::Line [1.0, 2.0], [3.0, 4.0], [5.0, 6.0], loop: true, hole: false>",
164
164
  line(1, 2, 3, 4, 5, 6).inspect)
@@ -7,24 +7,24 @@ require_relative 'helper'
7
7
  class TestPolyline < Test::Unit::TestCase
8
8
 
9
9
  class Rays::Polyline
10
- def dump ()
10
+ def dump()
11
11
  map &:to_a
12
12
  end
13
13
  end
14
14
 
15
- def polyline (*args)
16
- Rays::Polyline.new *args
15
+ def polyline(*args, **kwargs)
16
+ Rays::Polyline.new(*args, **kwargs)
17
17
  end
18
18
 
19
- def point (*args)
20
- Rays::Point.new *args
19
+ def point(*args)
20
+ Rays::Point.new(*args)
21
21
  end
22
22
 
23
- def bounds (*args)
24
- Rays::Bounds.new *args
23
+ def bounds(*args)
24
+ Rays::Bounds.new(*args)
25
25
  end
26
26
 
27
- def test_initialize ()
27
+ def test_initialize()
28
28
  assert_equal [[1, 2], [3, 4]], polyline( 1, 2, 3, 4 ).dump
29
29
  assert_equal [[1, 2], [3, 4]], polyline( [1, 2], [3, 4]).dump
30
30
  assert_equal [[1, 1], [2, 2]], polyline( [1], [2]).dump
@@ -52,7 +52,7 @@ class TestPolyline < Test::Unit::TestCase
52
52
  assert_nothing_raised {polyline(1, 2, 3, 4, 5, 6, loop: false)}
53
53
  end
54
54
 
55
- def test_expand ()
55
+ def test_expand()
56
56
  polyline([10,10], [20,20], loop: false).expand(1).tap {|o|
57
57
  assert_equal 1, o .size
58
58
  assert_equal 4, o[0].size
@@ -68,33 +68,33 @@ 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}
71
+ def test_expand_with_cap()
72
+ pl = -> {polyline [10,10], [20,20]}
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
82
  end
83
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}
84
+ def test_expand_with_join()
85
+ pl = -> {polyline [10,10], [20,20]}
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
95
  end
96
96
 
97
- def test_transform_with_materix ()
97
+ def test_transform_with_materix()
98
98
  m = Rays::Matrix.translate 100, 200
99
99
  polyline([10,10], [20,20]).transform(m).tap {|o|
100
100
  assert_equal [[110,210], [120,220]], o.dump
@@ -111,7 +111,7 @@ class TestPolyline < Test::Unit::TestCase
111
111
  }
112
112
  end
113
113
 
114
- def test_transform_with_block ()
114
+ def test_transform_with_block()
115
115
  polyline([10,10], [20,20] ).transform {|points|
116
116
  points.map {|p| p + [10, 20]}
117
117
  }.tap {|o|
@@ -136,24 +136,24 @@ class TestPolyline < Test::Unit::TestCase
136
136
  }
137
137
  end
138
138
 
139
- def test_bounds ()
139
+ def test_bounds()
140
140
  assert_equal bounds(10, 20, 0, 20, 10, 0), polyline(10, 20, 30, 20, 20, 30).bounds
141
141
 
142
142
  assert polyline(10, 20, 30, 20, 20, 30).bounds.valid?
143
143
  assert_not polyline() .bounds.valid?
144
144
  end
145
145
 
146
- def test_size ()
146
+ def test_size()
147
147
  assert_equal 2, polyline(1, 2, 3, 4, ).size
148
148
  assert_equal 3, polyline(1, 2, 3, 4, 5, 6).size
149
149
  end
150
150
 
151
- def test_empty? ()
151
+ def test_empty?()
152
152
  assert_equal true, polyline( ).empty?
153
153
  assert_equal false, polyline(1, 2, 3, 4).empty?
154
154
  end
155
155
 
156
- def test_index ()
156
+ def test_index()
157
157
  o = polyline 1, 2, 3, 4, 5, 6
158
158
  assert_equal [1, 2], o[ 0].to_a
159
159
  assert_equal [3, 4], o[ 1].to_a
@@ -162,7 +162,7 @@ class TestPolyline < Test::Unit::TestCase
162
162
  assert_raise(IndexError) {o[-4]}
163
163
  end
164
164
 
165
- def test_inspect ()
165
+ def test_inspect()
166
166
  assert_equal(
167
167
  "#<Rays::Polyline [1.0, 2.0], [3.0, 4.0], loop: false>",
168
168
  polyline(1, 2, 3, 4).inspect)