示例#1
0
        public bool CollidesWith(IVector2D movement, Rectangle rectangle)
        {
            IVector2D envelopeOrigin = Origin.Add(movement);
            var envelope = new Rectangle(envelopeOrigin, Size);
            envelope = envelope.EnlargeRectangleRectangle(this);

            if (envelope.CollidesWith(rectangle))
            {
                float min = Size.X.Minimum(Size.Y) / 4.0f;
                float minimumMoveDistance = min.Maximum(Helper.Epsilon);

                if (movement.Length() < minimumMoveDistance)
                {
                    return true;
                }

                IVector2D halfMovement = movement.Divide(2.0f);

                envelope = new Rectangle(Origin.Add(halfMovement), Size);

                return CollidesWith(halfMovement, rectangle) ||
                       envelope.CollidesWith(halfMovement, rectangle);
            }

            return false;
        }