From d984019211dd7d2c1198943b29d2e20dc67c439b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 14 Mar 2009 21:08:40 +0100 Subject: [PATCH] SimpleNarrowPhase: Throw an exception is an unsupported shape type is inspected. --- src/net/habraun/sd/SimpleNarrowPhase.scala | 15 ++++++-- test/net/habraun/sd/SimpleNarrowPhaseTest.scala | 48 +++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/src/net/habraun/sd/SimpleNarrowPhase.scala b/src/net/habraun/sd/SimpleNarrowPhase.scala index 4e49e7e..91cecfa 100644 --- a/src/net/habraun/sd/SimpleNarrowPhase.scala +++ b/src/net/habraun/sd/SimpleNarrowPhase.scala @@ -61,8 +61,11 @@ class SimpleNarrowPhase extends NarrowPhase { Contact(b2, r.contact, -r.normal, b1)) } - case _ => + case NoShape => None + + case _ => + throw new IllegalArgumentException("Unsupported shape: " + b2.shape) } case s1: LineSegment => @@ -77,11 +80,17 @@ class SimpleNarrowPhase extends NarrowPhase { case s2: LineSegment => None - case _ => + case NoShape => None + + case _ => + throw new IllegalArgumentException("Unsupported shape: " + b2.shape) } - case _ => + case NoShape => None + + case _ => + throw new IllegalArgumentException("Unsupported shape: " + b1.shape) } } diff --git a/test/net/habraun/sd/SimpleNarrowPhaseTest.scala b/test/net/habraun/sd/SimpleNarrowPhaseTest.scala index 9d1b2f8..49c6510 100644 --- a/test/net/habraun/sd/SimpleNarrowPhaseTest.scala +++ b/test/net/habraun/sd/SimpleNarrowPhaseTest.scala @@ -84,6 +84,54 @@ class SimpleNarrowPhaseTest { @Test + def inspectLineSegmentAndNoShapeExpectNoCollision { + val b1 = new Body + val b2 = new Body + b1.shape = LineSegment(Vec2D(0, 0), Vec2D(1, 1)) + b2.shape = NoShape + + assertEquals(None, narrowPhase.inspectCollision(0.0, b1, b2)) + } + + + + @Test { val expected = classOf[IllegalArgumentException] } + def inspectUnsupportedShapeAndCircleExpectException { + val b1 = new Body + val b2 = new Body + b1.shape = new Shape {} + b2.shape = Circle(1) + + narrowPhase.inspectCollision(0.0, b1, b2) + } + + + + @Test { val expected = classOf[IllegalArgumentException] } + def inspectCircleAndUnsupportedShapeExpectException { + val b1 = new Body + val b2 = new Body + b1.shape = Circle(1) + b2.shape = new Shape {} + + narrowPhase.inspectCollision(0.0, b1, b2) + } + + + + @Test { val expected = classOf[IllegalArgumentException] } + def inspectLineSegmentAndUnsupportedShapeExpectException { + val b1 = new Body + val b2 = new Body + b1.shape = LineSegment(Vec2D(0, 0), Vec2D(1, 0)) + b2.shape = new Shape {} + + narrowPhase.inspectCollision(0.0, b1, b2) + } + + + + @Test def inspectTwoCirclesVerifyParametersArePassed { val test = new CircleCircleTest { var c1: Circle = null -- 2.11.4.GIT