Esempio n. 1
0
        /// <summary>
        /// �ж�ָ����С�����������Ƿ��ཻ
        /// </summary>
        ///
        /// <param name="rectA"></param>
        /// <param name="dataA"></param>
        /// <param name="rectB"></param>
        /// <param name="dataB"></param>
        /// <returns></returns>
        public static bool Intersect(RectBox rectA, int[] dataA, RectBox rectB,
                int[] dataB)
        {
            int top = (int)Loon.Utils.MathUtils.Max(rectA.GetY(), rectB.GetY());
            int bottom = (int)Loon.Utils.MathUtils.Min(rectA.GetBottom(), rectB.GetBottom());
            int left = (int)Loon.Utils.MathUtils.Max(rectA.GetX(), rectB.GetX());
            int right = (int)Loon.Utils.MathUtils.Min(rectA.GetRight(), rectB.GetRight());

            for (int y = top; y < bottom; y++)
            {
                for (int x = left; x < right; x++)
                {

                    int colorA = dataA[(int)((x - rectA.x) + (y - rectA.y)
                            * rectA.width)];
                    int colorB = dataB[(int)((x - rectB.x) + (y - rectB.y)
                            * rectB.width)];
                    if ((int)(((uint)colorA) >> 24) != 0 && (int)(((uint)colorB) >> 24) != 0)
                    {
                        return true;
                    }
                }
            }

            return false;
        }
Esempio n. 2
0
 public static RectBox GetIntersection(RectBox a, RectBox b)
 {
     float a_x = a.GetX();
     float a_r = a.GetRight();
     float a_y = a.GetY();
     float a_t = a.GetBottom();
     float b_x = b.GetX();
     float b_r = b.GetRight();
     float b_y = b.GetY();
     float b_t = b.GetBottom();
     float i_x = MathUtils.Max(a_x, b_x);
     float i_r = MathUtils.Min(a_r, b_r);
     float i_y = MathUtils.Max(a_y, b_y);
     float i_t = MathUtils.Min(a_t, b_t);
     return (i_x < i_r && i_y < i_t) ? new RectBox(i_x, i_y, i_r - i_x, i_t
             - i_y) : null;
 }
Esempio n. 3
0
        public static RectBox GetIntersection(RectBox a, RectBox b)
        {
            float a_x = a.GetX();
            float a_r = a.GetRight();
            float a_y = a.GetY();
            float a_t = a.GetBottom();
            float b_x = b.GetX();
            float b_r = b.GetRight();
            float b_y = b.GetY();
            float b_t = b.GetBottom();
            float i_x = MathUtils.Max(a_x, b_x);
            float i_r = MathUtils.Min(a_r, b_r);
            float i_y = MathUtils.Max(a_y, b_y);
            float i_t = MathUtils.Min(a_t, b_t);

            return((i_x < i_r && i_y < i_t) ? new RectBox(i_x, i_y, i_r - i_x, i_t
                                                          - i_y) : null);
        }
Esempio n. 4
0
 public static RectBox GetIntersection(RectBox a, RectBox b, RectBox result)
 {
     float a_x = a.GetX();
     float a_r = a.GetRight();
     float a_y = a.GetY();
     float a_t = a.GetBottom();
     float b_x = b.GetX();
     float b_r = b.GetRight();
     float b_y = b.GetY();
     float b_t = b.GetBottom();
     float i_x = MathUtils.Max(a_x, b_x);
     float i_r = MathUtils.Min(a_r, b_r);
     float i_y = MathUtils.Max(a_y, b_y);
     float i_t = MathUtils.Min(a_t, b_t);
     if (i_x < i_r && i_y < i_t) {
         result.SetBounds(i_x, i_y, i_r - i_x, i_t - i_y);
         return result;
     }
     return null;
 }
Esempio n. 5
0
        public static RectBox GetIntersection(RectBox a, RectBox b, RectBox result)
        {
            float a_x = a.GetX();
            float a_r = a.GetRight();
            float a_y = a.GetY();
            float a_t = a.GetBottom();
            float b_x = b.GetX();
            float b_r = b.GetRight();
            float b_y = b.GetY();
            float b_t = b.GetBottom();
            float i_x = MathUtils.Max(a_x, b_x);
            float i_r = MathUtils.Min(a_r, b_r);
            float i_y = MathUtils.Max(a_y, b_y);
            float i_t = MathUtils.Min(a_t, b_t);

            if (i_x < i_r && i_y < i_t)
            {
                result.SetBounds(i_x, i_y, i_r - i_x, i_t - i_y);
                return(result);
            }
            return(null);
        }