/// <summary>
        ///   Checks whether the specified rectangle intersects the passed circle.
        /// </summary>
        /// <param name="rectangle">
        ///   Rectangle to check.
        /// </param>
        /// <param name="circle">
        ///   Circle to check.
        /// </param>
        /// <returns>
        ///   <c>true</c>, if rectangle and circle intersect each other, and <c>false</c> otherwise.
        /// </returns>
        public static bool Intersects(this RectangleF rectangle, CircleF circle)
        {
            // Check if rectangle contains center.
            if (rectangle.Contains(circle.Center))
            {
                return(true);
            }

            // Check each edge.
            var topLeft     = new Vector2F(rectangle.X, rectangle.Y);
            var bottomLeft  = new Vector2F(rectangle.X, rectangle.MaxY);
            var topRight    = new Vector2F(rectangle.MaxX, rectangle.Y);
            var bottomRight = new Vector2F(rectangle.MaxX, rectangle.MaxY);

            var left   = new LineSegment2F(topLeft, bottomLeft);
            var right  = new LineSegment2F(topRight, bottomRight);
            var top    = new LineSegment2F(topLeft, topRight);
            var bottom = new LineSegment2F(bottomLeft, bottomRight);

            return(left.Intersects(circle) || right.Intersects(circle) || top.Intersects(circle) ||
                   bottom.Intersects(circle));
        }
Exemplo n.º 2
0
 /// <summary>
 ///   Checks whether the specified line intersects the passed circle.
 /// </summary>
 /// <param name="line">
 ///   Line to check.
 /// </param>
 /// <param name="circle">
 ///   Circle to check.
 /// </param>
 /// <returns>
 ///   <c>true</c>, if line and circle intersect each other, and <c>false</c> otherwise.
 /// </returns>
 public static bool Intersects(this LineSegment2F line, CircleF circle)
 {
     return(line.GetDistance(circle.Center) < circle.Radius);
 }
Exemplo n.º 3
0
 /// <summary>
 ///   Checks whether the specified circle intersects the passed rectangle.
 /// </summary>
 /// <param name="circle">
 ///   Circle to check.
 /// </param>
 /// <param name="rectangle">
 ///   Rectangle to check.
 /// </param>
 /// <returns>
 ///   <c>true</c>, if circle and rectangle intersect each other, and <c>false</c> otherwise.
 /// </returns>
 public static bool Intersects(this CircleF circle, RectangleF rectangle)
 {
     return(rectangle.Intersects(circle));
 }
Exemplo n.º 4
0
 /// <summary>
 ///   Checks whether the specified circle intersects the passed line.
 /// </summary>
 /// <param name="circle">
 ///   Circle to check.
 /// </param>
 /// <param name="line">
 ///   Line to check.
 /// </param>
 /// <returns>
 ///   <c>true</c>, if circle and line intersect each other, and <c>false</c> otherwise.
 /// </returns>
 public static bool Intersects(this CircleF circle, LineSegment2F line)
 {
     return(line.Intersects(circle));
 }