Exemple #1
0
        public void TestCheckContact()
        {
            Assert.IsTrue(
                AabbAabbCollider.CheckContact(
                    testRectangle.Min, testRectangle.Max,
                    new Vector2(14.0f, 14.0f), new Vector2(16.0f, 16.0f)
                    ),
                "Fully enclosed box"
                );

            Assert.IsTrue(
                AabbAabbCollider.CheckContact(
                    testRectangle.Min, testRectangle.Max,
                    new Vector2(5.0f, 5.0f), new Vector2(25.0f, 25.0f)
                    ),
                "Fully containing box"
                );

            TestPoint[] testPoints =
            {
                new TestPoint(
                    new Vector2(5.0f,                                                                       5.0f), new Vector2(10.0f - Specifications.MaximumDeviation,                                   25.0f),
                    "Close miss on X axis, left side"
                    ),
                new TestPoint(
                    new Vector2(20.0f + Specifications.MaximumDeviation,                                    5.0f), new Vector2(25.0f,                                                                     25.0f),
                    "Close miss on X axis, right side"
                    ),
                new TestPoint(
                    new Vector2(5.0f,                                                                       5.0f), new Vector2(25.0f,                                   10.0f - Specifications.MaximumDeviation),
                    "Close miss on Y axis, upper side"
                    ),
                new TestPoint(
                    new Vector2(5.0f,                                    20.0f + Specifications.MaximumDeviation), new Vector2(25.0f,                                                                     25.0f),
                    "Close miss on Y axis, lower side"
                    )
            };

            foreach (TestPoint testPoint in testPoints)
            {
                Assert.IsFalse(
                    AabbAabbCollider.CheckContact(
                        testRectangle.Min, testRectangle.Max, testPoint.Min, testPoint.Max
                        ),
                    testPoint.Name
                    );
                Assert.IsFalse(
                    AabbAabbCollider.CheckContact(
                        testRectangle.Min, testRectangle.Max, testPoint.Min, testPoint.Max
                        ),
                    testPoint.Name
                    );
            }
        }
Exemple #2
0
        public void TestFindDynamicContact()
        {
            float?impactTime = AabbAabbCollider.FindContact(
                testRectangle.Min,
                testRectangle.Max,
                new Vector2(0.0f, 10.0f),
                new Vector2(5.0f, 5.0f),
                new Vector2(10.0f, 0.0f)
                );

            Assert.IsTrue(impactTime.HasValue);
            Assert.AreEqual(0.5f, impactTime.Value);
        }