Some cosmetic changes

parent 284a1d12
...@@ -68,7 +68,7 @@ class Vec ...@@ -68,7 +68,7 @@ class Vec
def vnormalize def vnormalize
len = vlength len = vlength
v = Vec.new(@x, @y, @z) v = Vec.new(@x, @y, @z)
if len > 1.0e-17 then if len > 1.0e-17
v.x = v.x / len v.x = v.x / len
v.y = v.y / len v.y = v.y / len
v.z = v.z / len v.z = v.z / len
...@@ -92,10 +92,10 @@ class Sphere ...@@ -92,10 +92,10 @@ class Sphere
b = rs.vdot(ray.dir) b = rs.vdot(ray.dir)
c = rs.vdot(rs) - (@radius * @radius) c = rs.vdot(rs) - (@radius * @radius)
d = b * b - c d = b * b - c
if d > 0.0 then if d > 0.0
t = - b - Math.sqrt(d) t = - b - Math.sqrt(d)
if t > 0.0 and t < isect.t then if t > 0.0 and t < isect.t
isect.t = t isect.t = t
isect.hit = true isect.hit = true
isect.pl = Vec.new(ray.org.x + ray.dir.x * t, isect.pl = Vec.new(ray.org.x + ray.dir.x * t,
...@@ -118,16 +118,16 @@ class Plane ...@@ -118,16 +118,16 @@ class Plane
d = -@p.vdot(@n) d = -@p.vdot(@n)
v = ray.dir.vdot(@n) v = ray.dir.vdot(@n)
v0 = v v0 = v
if v < 0.0 then if v < 0.0
v0 = -v v0 = -v
end end
if v0 < 1.0e-17 then if v0 < 1.0e-17
return return
end end
t = -(ray.org.vdot(@n) + d) / v t = -(ray.org.vdot(@n) + d) / v
if t > 0.0 and t < isect.t then if t > 0.0 and t < isect.t
isect.hit = true isect.hit = true
isect.t = t isect.t = t
isect.n = @n isect.n = @n
...@@ -170,10 +170,10 @@ end ...@@ -170,10 +170,10 @@ end
def clamp(f) def clamp(f)
i = f * 255.5 i = f * 255.5
if i > 255.0 then if i > 255.0
i = 255.0 i = 255.0
end end
if i < 0.0 then if i < 0.0
i = 0.0 i = 0.0
end end
i.to_i i.to_i
...@@ -183,11 +183,11 @@ def otherBasis(basis, n) ...@@ -183,11 +183,11 @@ def otherBasis(basis, n)
basis[2] = Vec.new(n.x, n.y, n.z) basis[2] = Vec.new(n.x, n.y, n.z)
basis[1] = Vec.new(0.0, 0.0, 0.0) basis[1] = Vec.new(0.0, 0.0, 0.0)
if n.x < 0.6 and n.x > -0.6 then if n.x < 0.6 and n.x > -0.6
basis[1].x = 1.0 basis[1].x = 1.0
elsif n.y < 0.6 and n.y > -0.6 then elsif n.y < 0.6 and n.y > -0.6
basis[1].y = 1.0 basis[1].y = 1.0
elsif n.z < 0.6 and n.z > -0.6 then elsif n.z < 0.6 and n.z > -0.6
basis[1].z = 1.0 basis[1].z = 1.0
else else
basis[1].x = 1.0 basis[1].x = 1.0
...@@ -221,8 +221,8 @@ class Scene ...@@ -221,8 +221,8 @@ class Scene
p0 = Vec.new(isect.pl.x + eps * isect.n.x, p0 = Vec.new(isect.pl.x + eps * isect.n.x,
isect.pl.y + eps * isect.n.y, isect.pl.y + eps * isect.n.y,
isect.pl.z + eps * isect.n.z) isect.pl.z + eps * isect.n.z)
nphi.times do |j| nphi.times do
ntheta.times do |i| ntheta.times do
r = Rand::rand r = Rand::rand
phi = 2.0 * 3.14159265 * Rand::rand phi = 2.0 * 3.14159265 * Rand::rand
x = Math.cos(phi) * Math.sqrt(1.0 - r) x = Math.cos(phi) * Math.sqrt(1.0 - r)
...@@ -241,7 +241,7 @@ class Scene ...@@ -241,7 +241,7 @@ class Scene
@spheres[1].intersect(ray, occisect) @spheres[1].intersect(ray, occisect)
@spheres[2].intersect(ray, occisect) @spheres[2].intersect(ray, occisect)
@plane.intersect(ray, occisect) @plane.intersect(ray, occisect)
if occisect.hit then if occisect.hit
occlusion = occlusion + 1.0 occlusion = occlusion + 1.0
else else
0.0 0.0
...@@ -283,7 +283,7 @@ class Scene ...@@ -283,7 +283,7 @@ class Scene
@spheres[1].intersect(ray, isect) @spheres[1].intersect(ray, isect)
@spheres[2].intersect(ray, isect) @spheres[2].intersect(ray, isect)
@plane.intersect(ray, isect) @plane.intersect(ray, isect)
if isect.hit then if isect.hit
col = ambient_occlusion(isect) col = ambient_occlusion(isect)
rad.x = rad.x + col.x rad.x = rad.x + col.x
rad.y = rad.y + col.y rad.y = rad.y + col.y
......
...@@ -17,19 +17,19 @@ def test_lists() ...@@ -17,19 +17,19 @@ def test_lists()
# li2 must now be empty # li2 must now be empty
# remove each individual item from right side of li3 and # remove each individual item from right side of li3 and
# append to right side of li2 (reversing list) # append to right side of li2 (reversing list)
while (not li3.empty?) until li3.empty?
li2.push(li3.pop) li2.push(li3.pop)
end end
# li3 must now be empty # li3 must now be empty
# reverse li1 in place # reverse li1 in place
li1.reverse! li1.reverse!
# check that first item is now SIZE # check that first item is now SIZE
if li1[0] != SIZE then if li1[0] != SIZE
p "not SIZE" p "not SIZE"
0 0
else else
# compare li1 and li2 for equality # compare li1 and li2 for equality
if li1 != li2 then if li1 != li2
return(0) return(0)
else else
# return the length of the list # return the length of the list
......
...@@ -509,28 +509,28 @@ end ...@@ -509,28 +509,28 @@ end
assert 'Hash#select' do assert 'Hash#select' do
h = {1=>2,3=>4,5=>6} h = {1=>2,3=>4,5=>6}
hret = h.select.with_index {|a,b| a[1] == 4} hret = h.select.with_index {|a,_b| a[1] == 4}
assert_equal({3=>4}, hret) assert_equal({3=>4}, hret)
assert_equal({1=>2,3=>4,5=>6}, h) assert_equal({1=>2,3=>4,5=>6}, h)
end end
assert 'Hash#select!' do assert 'Hash#select!' do
h = {1=>2,3=>4,5=>6} h = {1=>2,3=>4,5=>6}
hret = h.select!.with_index {|a,b| a[1] == 4} hret = h.select!.with_index {|a,_b| a[1] == 4}
assert_equal h, hret assert_equal h, hret
assert_equal({3=>4}, h) assert_equal({3=>4}, h)
end end
assert 'Hash#reject' do assert 'Hash#reject' do
h = {1=>2,3=>4,5=>6} h = {1=>2,3=>4,5=>6}
hret = h.reject.with_index {|a,b| a[1] == 4} hret = h.reject.with_index {|a,_b| a[1] == 4}
assert_equal({1=>2,5=>6}, hret) assert_equal({1=>2,5=>6}, hret)
assert_equal({1=>2,3=>4,5=>6}, h) assert_equal({1=>2,3=>4,5=>6}, h)
end end
assert 'Hash#reject!' do assert 'Hash#reject!' do
h = {1=>2,3=>4,5=>6} h = {1=>2,3=>4,5=>6}
hret = h.reject!.with_index {|a,b| a[1] == 4} hret = h.reject!.with_index {|a,_b| a[1] == 4}
assert_equal h, hret assert_equal h, hret
assert_equal({1=>2,5=>6}, h) assert_equal({1=>2,5=>6}, h)
end end
......
...@@ -336,7 +336,7 @@ end ...@@ -336,7 +336,7 @@ end
assert('BS Block 28') do assert('BS Block 28') do
assert_equal(10) do assert_equal(10) do
3.times{|bl| 3.times{
break 10 break 10
} }
end end
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
# #
# For example, the following mruby code: # For example, the following mruby code:
# #
# if i > 0 and i < 10 then # if i > 0 and i < 10
# #
# compiles to the following byte code: # compiles to the following byte code:
# #
...@@ -27,21 +27,21 @@ ...@@ -27,21 +27,21 @@
assert('and', '11.2.3') do assert('and', '11.2.3') do
a = 1 a = 1
if a > 0 and a < 10 then if a > 0 and a < 10
b = 1 b = 1
else else
b = 0 b = 0
end end
assert_equal 1, b assert_equal 1, b
if a < 0 and a < 10 then if a < 0 and a < 10
b = 1 b = 1
else else
b = 0 b = 0
end end
assert_equal 0, b assert_equal 0, b
if a < 0 and a > 10 then if a < 0 and a > 10
b = 1 b = 1
else else
b = 0 b = 0
...@@ -51,21 +51,21 @@ end ...@@ -51,21 +51,21 @@ end
assert('or','11.2.4') do assert('or','11.2.4') do
a = 1 a = 1
if a > 0 or a < 10 then if a > 0 or a < 10
b = 1 b = 1
else else
b = 0 b = 0
end end
assert_equal 1, b assert_equal 1, b
if a < 0 or a < 10 then if a < 0 or a < 10
b = 1 b = 1
else else
b = 0 b = 0
end end
assert_equal 1, b assert_equal 1, b
if a < 0 or a > 10 then if a < 0 or a > 10
b = 1 b = 1
else else
b = 0 b = 0
......
...@@ -367,9 +367,9 @@ assert('String#gsub', '15.2.10.5.18') do ...@@ -367,9 +367,9 @@ assert('String#gsub', '15.2.10.5.18') do
assert_equal('aBcaBc', 'abcabc'.gsub('b', 'B'), 'gsub without block') assert_equal('aBcaBc', 'abcabc'.gsub('b', 'B'), 'gsub without block')
assert_equal('aBcaBc', 'abcabc'.gsub('b'){|w| w.capitalize }, 'gsub with block') assert_equal('aBcaBc', 'abcabc'.gsub('b'){|w| w.capitalize }, 'gsub with block')
assert_equal('$a$a$', '#a#a#'.gsub('#', '$'), 'mruby/mruby#847') assert_equal('$a$a$', '#a#a#'.gsub('#', '$'), 'mruby/mruby#847')
assert_equal('$a$a$', '#a#a#'.gsub('#'){|w| '$' }, 'mruby/mruby#847 with block') assert_equal('$a$a$', '#a#a#'.gsub('#'){|_w| '$' }, 'mruby/mruby#847 with block')
assert_equal('$$a$$', '##a##'.gsub('##', '$$'), 'mruby/mruby#847 another case') assert_equal('$$a$$', '##a##'.gsub('##', '$$'), 'mruby/mruby#847 another case')
assert_equal('$$a$$', '##a##'.gsub('##'){|w| '$$' }, 'mruby/mruby#847 another case with block') assert_equal('$$a$$', '##a##'.gsub('##'){|_w| '$$' }, 'mruby/mruby#847 another case with block')
assert_equal('A', 'a'.gsub('a', 'A')) assert_equal('A', 'a'.gsub('a', 'A'))
assert_equal('A', 'a'.gsub('a'){|w| w.capitalize }) assert_equal('A', 'a'.gsub('a'){|w| w.capitalize })
assert_equal("<a><><>", 'a'.gsub('a', '<\0><\1><\2>')) assert_equal("<a><><>", 'a'.gsub('a', '<\0><\1><\2>'))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment