tests: add capsule-into-sphere and segment-into-sphere tests

This commit is contained in:
rdb 2019-03-29 13:45:06 +01:00
parent e98fbc7633
commit e0d6e07a93
2 changed files with 42 additions and 0 deletions

View File

@ -1,6 +1,7 @@
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

View File

@ -37,3 +37,44 @@ def test_box_into_sphere():
# No collision
entry = make_collision(CollisionBox((0, 0, 10), 6, 6, 6), sphere)[0]
assert entry is None
def test_capsule_into_sphere():
# First test a sphere that is fully touching the inner line of the capsule
capsule = CollisionCapsule((0, 0, 1.0), (10, 0, 1.0), 1.0)
sphere = CollisionSphere(5, 0, 1.5, 1.0)
entry = make_collision(capsule, sphere)[0]
assert entry is not None
assert entry.get_from() == capsule
assert entry.get_into() == sphere
# Now test one that merely grazes.
entry = make_collision(CollisionCapsule((0, 0, 0), (10, 0, 0), 1.0), sphere)[0]
assert entry is not None
# No collision
entry = make_collision(CollisionCapsule((0, 0, 0), (10, 0, 0), 0.25), sphere)[0]
assert entry is None
# Degenerate case: capsule is actually a sphere.
entry = make_collision(CollisionCapsule((5, 0, 0), (5, 0, 0), 1.0), sphere)[0]
assert entry is not None
# Degenerate case, but not colliding.
entry = make_collision(CollisionCapsule((5, 0, 0), (5, 0, 0), 0.25), sphere)[0]
assert entry is None
def test_segment_into_sphere():
segment = CollisionSegment((0, 0, 0), (10, 0, 0))
sphere = CollisionSphere(5, 0, 0.5, 1.0)
entry = make_collision(segment, sphere)[0]
assert entry is not None
assert entry.get_from() == segment
assert entry.get_into() == sphere
# No collision
entry = make_collision(CollisionSegment((0, 0, 0), (3, 0, 0)), sphere)[0]
assert entry is None