Files
raytracing/tests/test_sphere.py
2019-04-01 16:02:59 +04:00

23 lines
401 B
Python

import numpy as np
from ray import Ray
from sphere import Sphere
from vector import Vector
def test_intersect():
sphere = Sphere(
r0=Vector.fromargs(0, 0),
radius=1,
)
assert sphere.intersect(Ray(
r0=Vector.fromargs(-2, 0),
e=Vector.fromargs(1, 0),
)) == 1
assert sphere.intersect(Ray(
r0=Vector.fromargs(-1, -1),
e=Vector.fromargs(1, 1),
)) == np.sqrt(2) - 1