typeprof 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +26 -0
- data/.gitignore +7 -0
- data/.gitmodules +6 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +41 -0
- data/README.md +53 -0
- data/Rakefile +10 -0
- data/doc/doc.ja.md +415 -0
- data/doc/doc.md +429 -0
- data/doc/ppl2019.pdf +0 -0
- data/exe/typeprof +5 -0
- data/lib/typeprof.rb +13 -0
- data/lib/typeprof/analyzer.rb +1911 -0
- data/lib/typeprof/builtin.rb +554 -0
- data/lib/typeprof/cli.rb +110 -0
- data/lib/typeprof/container-type.rb +626 -0
- data/lib/typeprof/export.rb +203 -0
- data/lib/typeprof/import.rb +546 -0
- data/lib/typeprof/insns-def.rb +61 -0
- data/lib/typeprof/iseq.rb +387 -0
- data/lib/typeprof/method.rb +267 -0
- data/lib/typeprof/type.rb +1092 -0
- data/lib/typeprof/utils.rb +209 -0
- data/run.sh +3 -0
- data/smoke/alias.rb +30 -0
- data/smoke/alias2.rb +19 -0
- data/smoke/any-cbase.rb +5 -0
- data/smoke/any1.rb +15 -0
- data/smoke/any2.rb +17 -0
- data/smoke/arguments.rb +16 -0
- data/smoke/array-each.rb +14 -0
- data/smoke/array-each2.rb +15 -0
- data/smoke/array-each3.rb +15 -0
- data/smoke/array-ltlt.rb +13 -0
- data/smoke/array-ltlt2.rb +16 -0
- data/smoke/array-map.rb +11 -0
- data/smoke/array-map2.rb +10 -0
- data/smoke/array-map3.rb +22 -0
- data/smoke/array-mul.rb +17 -0
- data/smoke/array-plus1.rb +10 -0
- data/smoke/array-plus2.rb +15 -0
- data/smoke/array-pop.rb +11 -0
- data/smoke/array-replace.rb +12 -0
- data/smoke/array-s-aref.rb +11 -0
- data/smoke/array1.rb +26 -0
- data/smoke/array10.rb +14 -0
- data/smoke/array11.rb +13 -0
- data/smoke/array12.rb +24 -0
- data/smoke/array13.rb +30 -0
- data/smoke/array14.rb +13 -0
- data/smoke/array2.rb +27 -0
- data/smoke/array3.rb +25 -0
- data/smoke/array4.rb +14 -0
- data/smoke/array5.rb +13 -0
- data/smoke/array6.rb +14 -0
- data/smoke/array7.rb +13 -0
- data/smoke/array8.rb +13 -0
- data/smoke/array9.rb +12 -0
- data/smoke/attr.rb +28 -0
- data/smoke/backtrace.rb +32 -0
- data/smoke/block1.rb +22 -0
- data/smoke/block10.rb +14 -0
- data/smoke/block11.rb +39 -0
- data/smoke/block12.rb +22 -0
- data/smoke/block2.rb +14 -0
- data/smoke/block3.rb +38 -0
- data/smoke/block4.rb +18 -0
- data/smoke/block5.rb +18 -0
- data/smoke/block6.rb +20 -0
- data/smoke/block7.rb +20 -0
- data/smoke/block8.rb +27 -0
- data/smoke/block9.rb +12 -0
- data/smoke/blown.rb +12 -0
- data/smoke/break1.rb +18 -0
- data/smoke/break2.rb +15 -0
- data/smoke/case.rb +16 -0
- data/smoke/case2.rb +17 -0
- data/smoke/class.rb +5 -0
- data/smoke/class_instance_var.rb +9 -0
- data/smoke/class_method.rb +25 -0
- data/smoke/class_method2.rb +21 -0
- data/smoke/class_method3.rb +27 -0
- data/smoke/constant1.rb +38 -0
- data/smoke/constant2.rb +33 -0
- data/smoke/constant3.rb +9 -0
- data/smoke/constant4.rb +11 -0
- data/smoke/context-sensitive1.rb +12 -0
- data/smoke/cvar.rb +28 -0
- data/smoke/cvar2.rb +17 -0
- data/smoke/demo.rb +80 -0
- data/smoke/demo1.rb +16 -0
- data/smoke/demo10.rb +20 -0
- data/smoke/demo11.rb +11 -0
- data/smoke/demo2.rb +14 -0
- data/smoke/demo3.rb +16 -0
- data/smoke/demo4.rb +27 -0
- data/smoke/demo5.rb +13 -0
- data/smoke/demo6.rb +21 -0
- data/smoke/demo7.rb +14 -0
- data/smoke/demo8.rb +18 -0
- data/smoke/demo9.rb +18 -0
- data/smoke/dummy-execution1.rb +14 -0
- data/smoke/dummy-execution2.rb +16 -0
- data/smoke/ensure1.rb +20 -0
- data/smoke/enumerator.rb +15 -0
- data/smoke/expandarray1.rb +22 -0
- data/smoke/expandarray2.rb +23 -0
- data/smoke/fib.rb +28 -0
- data/smoke/flow1.rb +16 -0
- data/smoke/flow2.rb +14 -0
- data/smoke/flow3.rb +14 -0
- data/smoke/flow4.rb +5 -0
- data/smoke/flow5.rb +19 -0
- data/smoke/flow6.rb +19 -0
- data/smoke/flow7.rb +26 -0
- data/smoke/for.rb +9 -0
- data/smoke/freeze.rb +11 -0
- data/smoke/function.rb +16 -0
- data/smoke/gvar.rb +13 -0
- data/smoke/hash-fetch.rb +27 -0
- data/smoke/hash1.rb +18 -0
- data/smoke/hash2.rb +12 -0
- data/smoke/hash3.rb +13 -0
- data/smoke/hash4.rb +10 -0
- data/smoke/hash5.rb +14 -0
- data/smoke/inheritance.rb +34 -0
- data/smoke/inheritance2.rb +29 -0
- data/smoke/initialize.rb +26 -0
- data/smoke/instance_eval.rb +18 -0
- data/smoke/int_times.rb +14 -0
- data/smoke/integer.rb +10 -0
- data/smoke/ivar.rb +29 -0
- data/smoke/ivar2.rb +30 -0
- data/smoke/kernel-class.rb +12 -0
- data/smoke/keyword1.rb +11 -0
- data/smoke/keyword2.rb +11 -0
- data/smoke/keyword3.rb +12 -0
- data/smoke/keyword4.rb +11 -0
- data/smoke/keyword5.rb +15 -0
- data/smoke/kwsplat1.rb +42 -0
- data/smoke/kwsplat2.rb +12 -0
- data/smoke/manual-rbs.rb +27 -0
- data/smoke/manual-rbs.rbs +3 -0
- data/smoke/manual-rbs2.rb +20 -0
- data/smoke/manual-rbs2.rbs +8 -0
- data/smoke/masgn1.rb +13 -0
- data/smoke/masgn2.rb +17 -0
- data/smoke/masgn3.rb +12 -0
- data/smoke/method_in_branch.rb +22 -0
- data/smoke/module1.rb +29 -0
- data/smoke/module2.rb +28 -0
- data/smoke/module3.rb +33 -0
- data/smoke/module4.rb +29 -0
- data/smoke/module_function1.rb +28 -0
- data/smoke/module_function2.rb +28 -0
- data/smoke/multiple-include.rb +14 -0
- data/smoke/multiple-superclass.rb +16 -0
- data/smoke/next1.rb +20 -0
- data/smoke/next2.rb +16 -0
- data/smoke/object-send1.rb +22 -0
- data/smoke/once.rb +12 -0
- data/smoke/optional1.rb +13 -0
- data/smoke/optional2.rb +15 -0
- data/smoke/parameterizedd-self.rb +18 -0
- data/smoke/pathname1.rb +13 -0
- data/smoke/pathname2.rb +13 -0
- data/smoke/printf.rb +20 -0
- data/smoke/proc.rb +19 -0
- data/smoke/proc2.rb +16 -0
- data/smoke/proc3.rb +14 -0
- data/smoke/proc4.rb +11 -0
- data/smoke/range.rb +13 -0
- data/smoke/redo1.rb +21 -0
- data/smoke/redo2.rb +22 -0
- data/smoke/req-keyword.rb +12 -0
- data/smoke/rescue1.rb +20 -0
- data/smoke/rescue2.rb +22 -0
- data/smoke/respond_to.rb +22 -0
- data/smoke/rest-farg.rb +10 -0
- data/smoke/rest1.rb +25 -0
- data/smoke/rest2.rb +30 -0
- data/smoke/rest3.rb +36 -0
- data/smoke/rest4.rb +18 -0
- data/smoke/rest5.rb +10 -0
- data/smoke/rest6.rb +11 -0
- data/smoke/retry1.rb +20 -0
- data/smoke/return.rb +13 -0
- data/smoke/reveal.rb +13 -0
- data/smoke/singleton_class.rb +8 -0
- data/smoke/singleton_method.rb +9 -0
- data/smoke/step.rb +17 -0
- data/smoke/string-split.rb +11 -0
- data/smoke/struct.rb +9 -0
- data/smoke/struct2.rb +24 -0
- data/smoke/super1.rb +50 -0
- data/smoke/super2.rb +16 -0
- data/smoke/super3.rb +19 -0
- data/smoke/svar1.rb +12 -0
- data/smoke/tap1.rb +17 -0
- data/smoke/toplevel.rb +12 -0
- data/smoke/two-map.rb +17 -0
- data/smoke/type_var.rb +10 -0
- data/smoke/typed_method.rb +15 -0
- data/smoke/union-recv.rb +29 -0
- data/smoke/variadic1.rb.notyet +5 -0
- data/smoke/wrong-extend.rb +25 -0
- data/smoke/wrong-include.rb +26 -0
- data/smoke/wrong-rbs.rb +15 -0
- data/smoke/wrong-rbs.rbs +7 -0
- data/testbed/ao.rb +297 -0
- data/testbed/diff-lcs-entrypoint.rb +4 -0
- data/testbed/goodcheck-Gemfile.lock +51 -0
- data/tools/coverage.rb +14 -0
- data/tools/setup-insns-def.rb +30 -0
- data/tools/stackprof-wrapper.rb +10 -0
- data/typeprof.gemspec +24 -0
- metadata +262 -0
data/smoke/svar1.rb
ADDED
data/smoke/tap1.rb
ADDED
data/smoke/toplevel.rb
ADDED
data/smoke/two-map.rb
ADDED
data/smoke/type_var.rb
ADDED
data/smoke/union-recv.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
class SuperBase
|
2
|
+
def self.foo
|
3
|
+
self
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class Base < SuperBase
|
8
|
+
def self.foo
|
9
|
+
super
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class A < Base
|
14
|
+
foo
|
15
|
+
end
|
16
|
+
|
17
|
+
class B < Base
|
18
|
+
foo
|
19
|
+
end
|
20
|
+
|
21
|
+
__END__
|
22
|
+
# Classes
|
23
|
+
class SuperBase
|
24
|
+
def self.foo : -> (A.class | B.class)
|
25
|
+
end
|
26
|
+
|
27
|
+
class Base < SuperBase
|
28
|
+
def self.foo : -> (A.class | B.class)
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Bar
|
2
|
+
def bar
|
3
|
+
:bar
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
module Foo
|
8
|
+
mod = rand < 0.5 ? Bar : "Not module"
|
9
|
+
|
10
|
+
extend mod
|
11
|
+
|
12
|
+
def foo
|
13
|
+
:foo
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
__END__
|
18
|
+
# Classes
|
19
|
+
module Bar
|
20
|
+
def bar : -> :bar
|
21
|
+
end
|
22
|
+
|
23
|
+
module Foo
|
24
|
+
def foo : -> :foo
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Bar
|
2
|
+
def bar
|
3
|
+
:bar
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
module Foo
|
8
|
+
mod = rand < 0.5 ? Bar : "Not module"
|
9
|
+
|
10
|
+
include mod
|
11
|
+
|
12
|
+
def foo
|
13
|
+
:foo
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
__END__
|
18
|
+
# Classes
|
19
|
+
module Bar
|
20
|
+
def bar : -> :bar
|
21
|
+
end
|
22
|
+
|
23
|
+
module Foo
|
24
|
+
include Bar
|
25
|
+
def foo : -> :foo
|
26
|
+
end
|
data/smoke/wrong-rbs.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
def foo
|
2
|
+
end
|
3
|
+
def bar(n)
|
4
|
+
end
|
5
|
+
def baz(n=1)
|
6
|
+
end
|
7
|
+
def qux(a,n=1)
|
8
|
+
end
|
9
|
+
|
10
|
+
__END__
|
11
|
+
# Errors
|
12
|
+
smoke/wrong-rbs.rb:1: [error] RBS says that the arity may be 1, but the method definition requires at most 0 arguments
|
13
|
+
smoke/wrong-rbs.rb:3: [error] RBS says that the arity may be 0, but the method definition requires at least 1 arguments
|
14
|
+
|
15
|
+
# Classes
|
data/smoke/wrong-rbs.rbs
ADDED
data/testbed/ao.rb
ADDED
@@ -0,0 +1,297 @@
|
|
1
|
+
# AO render benchmark
|
2
|
+
# Original program (C) Syoyo Fujita in Javascript (and other languages)
|
3
|
+
# https://code.google.com/p/aobench/
|
4
|
+
# Ruby(yarv2llvm) version by Hideki Miura
|
5
|
+
# mruby version by Hideki Miura
|
6
|
+
#
|
7
|
+
|
8
|
+
IMAGE_WIDTH = 64
|
9
|
+
IMAGE_HEIGHT = 64
|
10
|
+
NSUBSAMPLES = 2
|
11
|
+
NAO_SAMPLES = 8
|
12
|
+
|
13
|
+
class Vec
|
14
|
+
# include Inline
|
15
|
+
def initialize(x, y, z)
|
16
|
+
@x = x
|
17
|
+
@y = y
|
18
|
+
@z = z
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_accessor :x, :y, :z
|
22
|
+
|
23
|
+
def vadd(b)
|
24
|
+
Vec.new(@x + b.x, @y + b.y, @z + b.z)
|
25
|
+
end
|
26
|
+
|
27
|
+
def vsub(b)
|
28
|
+
Vec.new(@x - b.x, @y - b.y, @z - b.z)
|
29
|
+
end
|
30
|
+
# make_inline_method :vsub
|
31
|
+
|
32
|
+
def vcross(b)
|
33
|
+
Vec.new(@y * b.z - @z * b.y,
|
34
|
+
@z * b.x - @x * b.z,
|
35
|
+
@x * b.y - @y * b.x)
|
36
|
+
end
|
37
|
+
# make_inline_method :vcross
|
38
|
+
|
39
|
+
def vdot(b)
|
40
|
+
r = @x * b.x + @y * b.y + @z * b.z
|
41
|
+
r
|
42
|
+
end
|
43
|
+
# make_inline_method :vdot
|
44
|
+
|
45
|
+
def vlength
|
46
|
+
Math.sqrt(@x * @x + @y * @y + @z * @z)
|
47
|
+
end
|
48
|
+
# make_inline_method :vlength
|
49
|
+
|
50
|
+
def vnormalize
|
51
|
+
len = vlength
|
52
|
+
v = Vec.new(@x, @y, @z)
|
53
|
+
if len > 1.0e-17
|
54
|
+
v.x = v.x / len
|
55
|
+
v.y = v.y / len
|
56
|
+
v.z = v.z / len
|
57
|
+
end
|
58
|
+
v
|
59
|
+
end
|
60
|
+
# make_inline_method :vnormalize
|
61
|
+
end
|
62
|
+
|
63
|
+
class Sphere
|
64
|
+
def initialize(center, radius)
|
65
|
+
@center = center
|
66
|
+
@radius = radius
|
67
|
+
end
|
68
|
+
|
69
|
+
attr_reader :center, :radius
|
70
|
+
|
71
|
+
def intersect(ray, isect)
|
72
|
+
rs = ray.org.vsub(@center)
|
73
|
+
b = rs.vdot(ray.dir)
|
74
|
+
c = rs.vdot(rs) - (@radius * @radius)
|
75
|
+
d = b * b - c
|
76
|
+
if d > 0.0
|
77
|
+
t = - b - Math.sqrt(d)
|
78
|
+
|
79
|
+
if t > 0.0 and t < isect.t
|
80
|
+
isect.t = t
|
81
|
+
isect.hit = true
|
82
|
+
isect.pl = Vec.new(ray.org.x + ray.dir.x * t,
|
83
|
+
ray.org.y + ray.dir.y * t,
|
84
|
+
ray.org.z + ray.dir.z * t)
|
85
|
+
n = isect.pl.vsub(@center)
|
86
|
+
isect.n = n.vnormalize
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
class Plane
|
93
|
+
def initialize(p, n)
|
94
|
+
@p = p
|
95
|
+
@n = n
|
96
|
+
end
|
97
|
+
|
98
|
+
def intersect(ray, isect)
|
99
|
+
d = -@p.vdot(@n)
|
100
|
+
v = ray.dir.vdot(@n)
|
101
|
+
v0 = v
|
102
|
+
if v < 0.0
|
103
|
+
v0 = -v
|
104
|
+
end
|
105
|
+
if v0 < 1.0e-17
|
106
|
+
return
|
107
|
+
end
|
108
|
+
|
109
|
+
t = -(ray.org.vdot(@n) + d) / v
|
110
|
+
|
111
|
+
if t > 0.0 and t < isect.t
|
112
|
+
isect.hit = true
|
113
|
+
isect.t = t
|
114
|
+
isect.n = @n
|
115
|
+
isect.pl = Vec.new(ray.org.x + t * ray.dir.x,
|
116
|
+
ray.org.y + t * ray.dir.y,
|
117
|
+
ray.org.z + t * ray.dir.z)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
class Ray
|
123
|
+
def initialize(org, dir)
|
124
|
+
@org = org
|
125
|
+
@dir = dir
|
126
|
+
end
|
127
|
+
|
128
|
+
attr_accessor :org, :dir
|
129
|
+
end
|
130
|
+
|
131
|
+
class Isect
|
132
|
+
def initialize
|
133
|
+
@t = 10000000.0
|
134
|
+
@hit = false
|
135
|
+
@pl = Vec.new(0.0, 0.0, 0.0)
|
136
|
+
@n = Vec.new(0.0, 0.0, 0.0)
|
137
|
+
end
|
138
|
+
|
139
|
+
attr_accessor :t, :hit, :pl, :n
|
140
|
+
end
|
141
|
+
|
142
|
+
def clamp(f)
|
143
|
+
i = f * 255.5
|
144
|
+
if i > 255.0
|
145
|
+
i = 255.0
|
146
|
+
end
|
147
|
+
if i < 0.0
|
148
|
+
i = 0.0
|
149
|
+
end
|
150
|
+
i.to_i
|
151
|
+
end
|
152
|
+
|
153
|
+
def otherBasis(n)
|
154
|
+
zero = Vec.new(0.0, 0.0, 0.0)
|
155
|
+
basis = [zero, zero, zero]
|
156
|
+
basis[2] = Vec.new(n.x, n.y, n.z)
|
157
|
+
basis[1] = Vec.new(0.0, 0.0, 0.0)
|
158
|
+
|
159
|
+
if n.x < 0.6 and n.x > -0.6
|
160
|
+
basis[1].x = 1.0
|
161
|
+
elsif n.y < 0.6 and n.y > -0.6
|
162
|
+
basis[1].y = 1.0
|
163
|
+
elsif n.z < 0.6 and n.z > -0.6
|
164
|
+
basis[1].z = 1.0
|
165
|
+
else
|
166
|
+
basis[1].x = 1.0
|
167
|
+
end
|
168
|
+
|
169
|
+
basis[0] = basis[1].vcross(basis[2])
|
170
|
+
basis[0] = basis[0].vnormalize
|
171
|
+
|
172
|
+
basis[1] = basis[2].vcross(basis[0])
|
173
|
+
basis[1] = basis[1].vnormalize
|
174
|
+
|
175
|
+
basis
|
176
|
+
end
|
177
|
+
|
178
|
+
class Scene
|
179
|
+
def initialize
|
180
|
+
@spheres = [
|
181
|
+
Sphere.new(Vec.new(-2.0, 0.0, -3.5), 0.5),
|
182
|
+
Sphere.new(Vec.new(-0.5, 0.0, -3.0), 0.5),
|
183
|
+
Sphere.new(Vec.new(1.0, 0.0, -2.2), 0.5),
|
184
|
+
]
|
185
|
+
@plane = Plane.new(Vec.new(0.0, -0.5, 0.0), Vec.new(0.0, 1.0, 0.0))
|
186
|
+
end
|
187
|
+
|
188
|
+
def ambient_occlusion(isect)
|
189
|
+
basis = otherBasis(isect.n)
|
190
|
+
|
191
|
+
ntheta = NAO_SAMPLES
|
192
|
+
nphi = NAO_SAMPLES
|
193
|
+
eps = 0.0001
|
194
|
+
occlusion = 0.0
|
195
|
+
|
196
|
+
p0 = Vec.new(isect.pl.x + eps * isect.n.x,
|
197
|
+
isect.pl.y + eps * isect.n.y,
|
198
|
+
isect.pl.z + eps * isect.n.z)
|
199
|
+
nphi.times do |j|
|
200
|
+
ntheta.times do |i|
|
201
|
+
r = rand
|
202
|
+
# r = $rand.rand
|
203
|
+
phi = 2.0 * 3.14159265 * rand
|
204
|
+
# phi = 2.0 * 3.14159265 * $rand.rand
|
205
|
+
x = Math.cos(phi) * Math.sqrt(1.0 - r)
|
206
|
+
y = Math.sin(phi) * Math.sqrt(1.0 - r)
|
207
|
+
z = Math.sqrt(r)
|
208
|
+
|
209
|
+
rx = x * basis[0].x + y * basis[1].x + z * basis[2].x
|
210
|
+
ry = x * basis[0].y + y * basis[1].y + z * basis[2].y
|
211
|
+
rz = x * basis[0].z + y * basis[1].z + z * basis[2].z
|
212
|
+
|
213
|
+
raydir = Vec.new(rx, ry, rz)
|
214
|
+
ray = Ray.new(p0, raydir)
|
215
|
+
|
216
|
+
occisect = Isect.new
|
217
|
+
@spheres[0].intersect(ray, occisect)
|
218
|
+
@spheres[1].intersect(ray, occisect)
|
219
|
+
@spheres[2].intersect(ray, occisect)
|
220
|
+
@plane.intersect(ray, occisect)
|
221
|
+
if occisect.hit
|
222
|
+
occlusion = occlusion + 1.0
|
223
|
+
else
|
224
|
+
0.0
|
225
|
+
end
|
226
|
+
1.0
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
occlusion = (ntheta.to_f * nphi.to_f - occlusion) / (ntheta.to_f * nphi.to_f)
|
231
|
+
Vec.new(occlusion, occlusion, occlusion)
|
232
|
+
end
|
233
|
+
|
234
|
+
def render(w, h, nsubsamples)
|
235
|
+
cnt = 0
|
236
|
+
nsf = nsubsamples.to_f
|
237
|
+
h.times do |y|
|
238
|
+
w.times do |x|
|
239
|
+
rad = Vec.new(0.0, 0.0, 0.0)
|
240
|
+
|
241
|
+
# Subsmpling
|
242
|
+
nsubsamples.times do |v|
|
243
|
+
nsubsamples.times do |u|
|
244
|
+
cnt = cnt + 1
|
245
|
+
wf = w.to_f
|
246
|
+
hf = h.to_f
|
247
|
+
xf = x.to_f
|
248
|
+
yf = y.to_f
|
249
|
+
uf = u.to_f
|
250
|
+
vf = v.to_f
|
251
|
+
|
252
|
+
px = (xf + (uf / nsf) - (wf / 2.0)) / (wf / 2.0)
|
253
|
+
py = -(yf + (vf / nsf) - (hf / 2.0)) / (hf / 2.0)
|
254
|
+
|
255
|
+
eye = Vec.new(px, py, -1.0).vnormalize
|
256
|
+
|
257
|
+
ray = Ray.new(Vec.new(0.0, 0.0, 0.0), eye)
|
258
|
+
|
259
|
+
isect = Isect.new
|
260
|
+
@spheres[0].intersect(ray, isect)
|
261
|
+
@spheres[1].intersect(ray, isect)
|
262
|
+
@spheres[2].intersect(ray, isect)
|
263
|
+
@plane.intersect(ray, isect)
|
264
|
+
if isect.hit
|
265
|
+
col = ambient_occlusion(isect)
|
266
|
+
rad.x = rad.x + col.x
|
267
|
+
rad.y = rad.y + col.y
|
268
|
+
rad.z = rad.z + col.z
|
269
|
+
else
|
270
|
+
0.0
|
271
|
+
end
|
272
|
+
1
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
r = rad.x / (nsf * nsf)
|
277
|
+
g = rad.y / (nsf * nsf)
|
278
|
+
b = rad.z / (nsf * nsf)
|
279
|
+
printf("%c", clamp(r))
|
280
|
+
printf("%c", clamp(g))
|
281
|
+
printf("%c", clamp(b))
|
282
|
+
1
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
def top
|
289
|
+
Scene.new.render(IMAGE_WIDTH, IMAGE_HEIGHT, NSUBSAMPLES)
|
290
|
+
end
|
291
|
+
|
292
|
+
top
|
293
|
+
|
294
|
+
if _dummy = false
|
295
|
+
v = Vec.new(0.0, 0.0, 0.0)
|
296
|
+
v.vadd(v)
|
297
|
+
end
|