Exemplo n.º 1
0
        /// <summary>
        /// Distance between two rectangles
        /// </summary>
        /// <param name="r">first rectangle</param>
        /// <param name="q">second rectangle</param>
        /// <returns>distance between two rectangles</returns>
        ///
        public static int distance(Rectangle r, Rectangle q)
        {
            if (r.overlaps(q))
            {
                return(0);
            }
            int d = 0;

            if (r.x0 > q.x1)
            {
                d += (r.x0 - q.x1) * (r.x0 - q.x1);
            }
            else if (q.x0 > r.x1)
            {
                d += (q.x0 - r.x1) * (q.x0 - r.x1);
            }
            if (r.y0 > q.y1)
            {
                d += (r.y0 - q.y1) * (r.y0 - q.y1);
            }
            else if (q.y0 > r.y1)
            {
                d += (q.y0 - r.y1) * (q.y0 - r.y1);
            }
            return((int)Math.Sqrt((double)d));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Distance between two rectangles
 /// </summary>
 /// <param name="r">first rectangle</param>
 /// <param name="q">second rectangle</param>
 /// <returns>distance between two rectangles</returns>
 ///
 public static int distance(Rectangle r, Rectangle q)
 {
     if (r.overlaps(q)) {
     return 0;
     }
     int d = 0;
     if (r.x0 > q.x1) {
     d += (r.x0 - q.x1)*(r.x0 - q.x1);
     } else if (q.x0 > r.x1) {
     d += (q.x0 - r.x1)*(q.x0 - r.x1);
     }
     if (r.y0 > q.y1) {
     d += (r.y0 - q.y1)*(r.y0 - q.y1);
     } else if (q.y0 > r.y1) {
     d += (q.y0 - r.y1)*(q.y0 - r.y1);
     }
     return (int)Math.Sqrt((double)d);
 }