コード例 #1
0
        public void RectRayCasting_ShouldReturnNull_WhenInOppositeDirection()
        {
            // arrange
            MapRect rect = new MapRect(1, 0, 2, 2);
            Ray     ray  = new Ray(-3, 0, -1, 0);

            // act
            Trace trace = RayCast.CheckBulletTrace(ray, rect);

            // assert
            Assert.IsNull(trace);
        }
コード例 #2
0
        public void CircleRayCasting_ShouldReturnNull_WhenInOppositeDirection()
        {
            // arrange
            MapCircle circle = new MapCircle(1, 0, 1);
            Ray       ray    = new Ray(-3, 0, -1, 0);

            // act
            Trace trace = RayCast.CheckBulletTrace(ray, circle);

            // assert
            Assert.IsNull(trace);
        }
コード例 #3
0
        public void CircleRayCasting_ShouldReturnHitPosition_2()
        {
            // arrange
            MapCircle circle = new MapCircle(10, 10, 1);
            Ray       ray    = new Ray(20, 10, -1, 0);

            // act
            Trace trace = RayCast.CheckBulletTrace(ray, circle);

            // assert
            Assert.IsNotNull(trace);
            Assert.AreEqual(trace.Position, new Vector2(11, 10));
        }
コード例 #4
0
        public void RectRayCasting_ShouldReturnHitPosition_3()
        {
            // arrange
            MapRect rect = new MapRect(10, 10, 1, 1);
            Ray     ray  = new Ray(10, 12, 0, -1);

            // act
            Trace trace = RayCast.CheckBulletTrace(ray, rect);

            // assert
            Assert.IsNotNull(trace);
            Assert.AreEqual(trace.Position, new Vector2(10, 10.5));
        }
コード例 #5
0
        public void CircleRayCasting_ShouldReturnHitPosition_1()
        {
            // arrange
            MapCircle circle = new MapCircle(10, 10, 1);
            Ray       ray    = new Ray(0, 0, 1, 1);

            // act
            Trace trace = RayCast.CheckBulletTrace(ray, circle);

            // assert
            Assert.IsNotNull(trace);

            var     c = Math.Sqrt(2) / 2;
            Vector2 expectedPosition = circle.Position - new Vector2(c, c);

            Assert.AreEqual(expectedPosition.X, trace.Position.X, 1e-6);
            Assert.AreEqual(expectedPosition.Y, trace.Position.Y, 1e-6);
        }