missing files from the previous merge
[pyRayTrace.git] / test / test_camera.py
blobdc0f5f0c37d5d15152112dc618e1873a66be7ca6
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 # Copyright 2009 Tuukka Turto
6 # This file is part of pyRayTrace.
8 # pyRayTrace is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # pyRayTrace is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with pyRayTrace. If not, see <http://www.gnu.org/licenses/>.
21 from camera import Camera
22 from camera import GridViewPort
23 from camera import Ray
24 from vector import Vector
26 def test_camera_creation():
27 """
28 Just a simple camera creation test to ensure that testing environment is working
29 """
30 camera = Camera()
31 assert not (camera is None)
33 def test_get_viewport_grid():
34 """
35 Test that a camera can return a list of coordinates defining grid of viewport.
36 """
37 camera = Camera()
38 viewport = GridViewPort()
40 camera.location = Vector(0, 0, 0)
41 viewport.point0 = Vector(10, 10, 10)
42 viewport.point1 = Vector(0, 0, 10)
43 viewport.resolution = (11, 11)
44 camera.viewport = viewport
46 points = camera.get_viewport_grid()
47 assert (10, 10, 10) in points
48 assert (0, 0, 10) in points
49 assert (5, 2, 10) in points
51 def test_get_viewport_rays():
52 """
53 Test that a camera can return a list of rays, originating from camera location and going through
54 the grid
55 """
56 camera = Camera()
57 viewport = GridViewPort()
58 ray = Ray((0, 0, 0), (0.0, 0.0, 1.0))
60 camera.location = Vector(0, 0, 0)
61 viewport.point0 = Vector(10, 10, 10)
62 viewport.point1 = Vector(0, 0, 10)
63 viewport.resolution = (11, 11)
64 camera.viewport = viewport
66 rays = camera.get_viewport_rays()
67 assert ray in rays
69 def test_ray_normalization():
70 ray = Ray((0, 0, 0), (10, 0, 0))
71 normalized = ray.normalize()
72 assert normalized.origin == (0, 0, 0)
73 assert normalized.direction == (1.0, 0.0, 0.0)
75 def test_ray_normalization_off_origo():
76 ray = Ray((2, 4, -2), (0, 5, 0))
77 normalized = ray.normalize()
78 assert normalized.origin == (2, 4, -2)
79 print normalized.direction.vector
80 assert normalized.direction == (0.0, 1.0, 0.0)
82 def test_ray_equality():
83 ray1 = Ray((0, 0, 0), (5, 5, 5))
84 ray2 = Ray((0, 0, 0), (5, 5, 5))
86 assert ray1 == ray2