init
This commit is contained in:
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
30
tests/test_intersections.py
Normal file
30
tests/test_intersections.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import numpy as np
|
||||
|
||||
from intersections import intersect_plane_ray
|
||||
from plane import Plane
|
||||
from ray import Ray
|
||||
from vector import Vector
|
||||
|
||||
|
||||
def test_intersections():
|
||||
r = Ray(
|
||||
Vector.fromargs(0, 0, 1),
|
||||
Vector.fromargs(-1, -1, -1),
|
||||
)
|
||||
p = Plane(
|
||||
Vector.fromargs(0, 0, 0),
|
||||
Vector.fromargs(0, 0, 1),
|
||||
)
|
||||
|
||||
assert intersect_plane_ray(p, r) == Vector.fromargs(-1, -1, 0)
|
||||
|
||||
np.random.seed(0)
|
||||
for i in range(10):
|
||||
p = Plane(Vector.random(), Vector.random())
|
||||
r = Ray(Vector.random(), Vector.random())
|
||||
|
||||
intersection = intersect_plane_ray(p, r)
|
||||
|
||||
print(p, r, intersection)
|
||||
|
||||
assert p & intersection
|
37
tests/test_plane.py
Normal file
37
tests/test_plane.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import numpy as np
|
||||
|
||||
from plane import Plane
|
||||
from ray import Ray
|
||||
from vector import Vector
|
||||
|
||||
|
||||
def test_plane():
|
||||
p = Plane(
|
||||
Vector.fromargs(0, 0, 0),
|
||||
Vector.fromargs(0, 0, 1),
|
||||
)
|
||||
assert (p & Vector.fromargs(0, 0, 0))
|
||||
assert (p & Vector.fromargs(1, 1, 0))
|
||||
assert not (p & Vector.fromargs(0, 0, -1))
|
||||
|
||||
p = Plane(
|
||||
Vector.fromargs(1, 1),
|
||||
Vector.fromargs(1, 1),
|
||||
)
|
||||
|
||||
assert not (p & Vector.fromargs(0, 0))
|
||||
assert (p & Vector.fromargs(2, 0))
|
||||
|
||||
|
||||
def test_reflection():
|
||||
p = Plane(
|
||||
Vector.fromargs(0, 0),
|
||||
Vector.fromargs(0, 1),
|
||||
)
|
||||
|
||||
r = Ray(
|
||||
Vector.fromargs(-1, 1),
|
||||
Vector.fromargs(1, -1),
|
||||
)
|
||||
|
||||
assert p.intersect(r) == np.sqrt(2)
|
22
tests/test_sphere.py
Normal file
22
tests/test_sphere.py
Normal file
@@ -0,0 +1,22 @@
|
||||
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
|
7
tests/test_vector.py
Normal file
7
tests/test_vector.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from vector import Vector
|
||||
|
||||
|
||||
def test_vector():
|
||||
v = Vector.fromargs(1, 2)
|
||||
print(v)
|
||||
print(-v)
|
Reference in New Issue
Block a user