Exemplo n.º 1
0
        public bool Overlaps(Rect r)
        {
            // pre-calculate left, bottom, right, top of this and right rect
            double tl = x, tb = y, tr = x+width, tt = y+height;
            double rl = r.x, rb = r.y, rr = r.x+r.width, rt = r.y+r.height;

            if ((tl > rr) || (tr < rl) || (tt < rb) || (tb > rt))
                return false;
            else return true;

            /*  stupid old code
            if (tl <= rl && tb <= rb && tr >= rr && tt >= rt) {
                // r is fully contained in this rectangle
                return true;
            }
            else if (tl >= rl && tb >= rb && tr <= rr && tt <= rt) {
                // this rectangle is fully contained in r
                return true;
            }
            else if (((rl >= tl && rl <= tr) || (rr >= tl && rr <= tr)) && ((rb >= tb && rb <= tt) || (rt >= tb && rt <= tt))) {
                return true;
            }

            return false;
             */
        }
Exemplo n.º 2
0
        public static Rect Union(Rect l, Rect r)
        {
            double left = Math.Min(l.x, r.x);
            double right = Math.Max(l.Right, r.Right);
            double bottom = Math.Min(l.y, r.y);
            double top = Math.Max(l.Top, r.Top);

            return new Rect(left, bottom, right-left, top-bottom);
        }