/// <summary> /// Determines whether a certain area lies within the box. /// </summary> /// <param name="area">The area to check for collision in entity space.</param> /// <param name="rotation">How the box shall be rotated before performing the collision test.</param> /// <returns><c>true</c> if <paramref name="area"/> does collide with the box, <c>false</c>.</returns> public override bool CollisionTest(Quadrangle area, float rotation) { // ReSharper disable once CompareOfFloatsByEqualityOperator if (rotation == 0) { // Perform simple test if no rotation is to be performed return(area.IntersectWith(Area)); } // Perform rotation before intersection test var rotatedBox = new Quadrangle(Area).Rotate(rotation); return(rotatedBox.IntersectWith(area)); }
/// <summary> /// Determines whether a certain point lies within the box. /// </summary> /// <param name="point">The point to check for collision in entity space.</param> /// <param name="rotation">How the box shall be rotated before performing the collision test.</param> /// <returns><c>true</c> if <paramref name="point"/> does collide with the box, <c>false</c> otherwise.</returns> public override bool CollisionTest(Vector2 point, float rotation) { // ReSharper disable once CompareOfFloatsByEqualityOperator if (rotation == 0) { // Perform simple test if no rotation is to be performed return(point.X >= Minimum.X && point.X <= Maximum.X && point.Y >= Minimum.Y && point.Y <= Maximum.Y); } // Empty boxes can never intersect if (Minimum == Maximum) { return(false); } // Perform rotation before intersection test var rotatedBox = new Quadrangle(Area).Rotate(rotation); return(rotatedBox.IntersectWith(point)); }