tests: add more collision unit tests

Closes #609
This commit is contained in:
hecris 2019-04-05 16:18:24 -04:00 committed by rdb
parent 552916efea
commit ac451d79ef
5 changed files with 55 additions and 3 deletions

View File

@ -1,8 +1,9 @@
from panda3d.core import CollisionNode, NodePath
from panda3d.core import CollisionTraverser, CollisionHandlerQueue
from panda3d.core import CollisionSphere, CollisionBox, CollisionPolygon
from panda3d.core import CollisionCapsule, CollisionSegment
from panda3d.core import Point3, Vec3
from panda3d.core import CollisionSphere, CollisionBox, CollisionPolygon, CollisionCapsule
from panda3d.core import CollisionLine, CollisionRay, CollisionSegment, CollisionParabola
from panda3d.core import CollisionPlane
from panda3d.core import Point3, Vec3, Plane, LParabola
def make_collision(solid_from, solid_into):

View File

@ -17,3 +17,12 @@ def test_sphere_into_box():
# No collision
entry = make_collision(CollisionSphere(100, 100, 100, 100), box)[0]
assert entry is None
def test_plane_into_box():
# CollisionPlane is not a 'from' object
plane = CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0, 0, 0)))
box = CollisionBox((0, 0, 0), 2, 3, 4)
entry = make_collision(plane, box)[0]
assert entry is None

View File

@ -0,0 +1,24 @@
# Testing that all variants of CollisionLine
# cannot be used as "into" objects
from collisions import *
def test_sphere_into_line():
entry = make_collision(CollisionSphere(0, 0, 0, 3), CollisionLine(0, 0, 0, 1, 0, 0))[0]
assert entry is None
def test_sphere_into_ray():
entry = make_collision(CollisionSphere(0, 0, 0, 3), CollisionRay(0, 0, 0, 3, 3, 3))[0]
assert entry is None
def test_sphere_into_segment():
entry = make_collision(CollisionSphere(0, 0, 0, 3), CollisionSegment(0, 0, 0, 3, 3, 3))[0]
assert entry is None
def test_sphere_into_parabola():
parabola = LParabola((1, 0, 0), (0, 1, 0), (0, 0, 1))
entry = make_collision(CollisionSphere(0, 0, 0, 3), CollisionParabola(parabola, 1, 2))[0]
assert entry is None

View File

@ -37,3 +37,12 @@ def test_sphere_into_poly():
# No collision
entry = make_collision(CollisionSphere(100, 100, 100, 100), poly)[0]
assert entry is None
def test_plane_into_poly():
# CollisionPlane is not a 'from' object
plane = CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0, 0, 0)))
poly = CollisionPolygon(Point3(0, 0, 0), Point3(0, 0, 1), Point3(0, 1, 1), Point3(0, 1, 0))
entry = make_collision(plane, poly)[0]
assert entry is None

View File

@ -78,3 +78,12 @@ def test_segment_into_sphere():
# No collision
entry = make_collision(CollisionSegment((0, 0, 0), (3, 0, 0)), sphere)[0]
assert entry is None
def test_plane_into_sphere():
# CollisionPlane is not a 'from' object
plane = CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0, 0, 0)))
sphere = CollisionSphere(0, 0, 0, 1)
entry = make_collision(plane, sphere)[0]
assert entry is None