1
#region File Description
2 //-----------------------------------------------------------------------------
5 // Microsoft XNA Community Game Platform
6 // Copyright (C) Microsoft Corporation. All rights reserved.
7 //-----------------------------------------------------------------------------
11 using Microsoft
.Xna
.Framework
;
13 namespace Platformer2D
16 /// Represents a 2D circle.
21 /// Center position of the circle.
23 public Vector2 Center
;
26 /// Radius of the circle.
31 /// Constructs a new circle.
33 public Circle(Vector2 position
, float radius
)
40 /// Determines if a circle intersects a rectangle.
42 /// <returns>True if the circle and rectangle overlap. False otherwise.</returns>
43 public bool Intersects(Rectangle rectangle
)
45 Vector2 v
= new Vector2(MathHelper
.Clamp(Center
.X
, rectangle
.Left
, rectangle
.Right
),
46 MathHelper
.Clamp(Center
.Y
, rectangle
.Top
, rectangle
.Bottom
));
48 Vector2 direction
= Center
- v
;
49 float distanceSquared
= direction
.LengthSquared();
51 return ((distanceSquared
> 0) && (distanceSquared
< Radius
* Radius
));