-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_parser.py
More file actions
131 lines (103 loc) · 2.69 KB
/
Copy pathtest_parser.py
File metadata and controls
131 lines (103 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from .context import raytracer
from raytracer.ray_tracer import Sphere, LightSource, Plane
from raytracer.sceneparser import parse_scene
from raytracer.vector import Vector3
"""
Need :
scene
objects
lights
camera
screen distance
"""
def test_scene_one_sphere():
scene_str = """
surfaces:
s1:
color: [0,0,253]
ka: [0.1, 0.2, 0.3]
kd: [0.4, 0.5, 0.6]
ks: [0.7, 0.8, 0.9]
objects:
sphere1:
type: sphere
position: [10, 10, 10]
radius: 5
surface: s1
lights: {}
camera:
position: [0, 0, 0]
direction: [1,-0.45,0]
up: [1,1,0]
"""
scene, _ = parse_scene(scene_str)
assert len(scene.objects) == 1
assert isinstance(scene.objects[0], Sphere)
assert scene.objects[0].radius == 5
assert scene.objects[0].position == Vector3(10, 10, 10)
assert scene.objects[0].surface.diffuse
assert not scene.objects[0].surface.mirror_reflection
assert not scene.objects[0].surface.kr
assert scene.objects[0].surface.ka == Vector3(0.1, 0.2, 0.3)
assert scene.objects[0].surface.kd == Vector3(0.4, 0.5, 0.6)
assert scene.objects[0].surface.ks == Vector3(0.7, 0.8, 0.9)
assert scene.objects[0].surface.color == Vector3(0, 0, 253)
def test_one_plane():
scene_str = """
surfaces:
s1:
color: [0,0,253]
objects:
ground:
type: plane
point: [0, 0, 0]
normal: [0, 1, 0]
surface: s1
lights: {}
camera:
position: [0, 0, 0]
direction: [1,-0.45,0]
up: [1,1,0]
"""
scene, _ = parse_scene(scene_str)
assert len(scene.objects) == 1
assert isinstance(scene.objects[0], Plane)
assert scene.objects[0].point == Vector3(0, 0, 0)
assert scene.objects[0].normal == Vector3(0, 1, 0)
assert scene.objects[0].surface.color == Vector3(0, 0, 253)
def test_scene_one_light_source():
scene_str = """
surfaces: {}
objects: {}
lights:
light1:
position: [20,50,30]
power: [1000, 1000, 1000]
camera:
position: [0, 0, 0]
direction: [1,-0.45,0]
up: [1,1,0]
"""
scene, _ = parse_scene(scene_str)
assert len(scene.light_sources) == 1
assert isinstance(scene.light_sources[0], LightSource)
assert scene.light_sources[0].position == Vector3(20, 50, 30)
assert scene.light_sources[0].power == Vector3(1000, 1000, 1000)
def test_camera():
scene_str = """
surfaces: {}
objects: {}
lights: {}
camera:
position: [0, 0, 0]
direction: [1,-0.45,0]
up: [1,1,0]
field_of_view: 2.3
screen_distance: 11
"""
_, camera = parse_scene(scene_str)
assert camera.position == Vector3(0, 0, 0)
assert camera.direction == Vector3(1, -0.45, 0)
assert camera.up == Vector3(1, 1, 0)
assert camera.field_of_view == 2.3
assert camera.screen_distance == 11