コード例 #1
0
        public void WhenMeasuringDistanceToPointsOnAllSidesResultsAreValid()
        {
            var someAabb        = new BoundingRectangle(100, 100, 120, 120);
            var diagonalPoint   = new Vector2(121, 121);
            var topSidePoint    = new Vector2(110, 99);
            var rightSidePoint  = new Vector2(121, 110);
            var bottomSidePoint = new Vector2(110, 121);
            var leftSidePoint   = new Vector2(99, 110);
            var farAwayPoint    = new Vector2(-100000000, 0);
            var containedPoint  = new Vector2(110, 110);
            var edgePoint       = new Vector2(100, 110);

            Assert.That(someAabb.DistanceTo(diagonalPoint), Is.EqualTo(1.41421354f));
            Assert.That(someAabb.DistanceTo(topSidePoint), Is.EqualTo(1f));
            Assert.That(someAabb.DistanceTo(rightSidePoint), Is.EqualTo(1f));
            Assert.That(someAabb.DistanceTo(bottomSidePoint), Is.EqualTo(1f));
            Assert.That(someAabb.DistanceTo(leftSidePoint), Is.EqualTo(1f));
            Assert.That(someAabb.DistanceTo(farAwayPoint), Is.EqualTo(100000104f));
            Assert.That(someAabb.DistanceTo(containedPoint), Is.EqualTo(-10f));
            Assert.That(someAabb.DistanceTo(edgePoint), Is.EqualTo(0f));
        }