Example #1
0
        internal int GetNearestWindow(Rectangle loc)
        {
            //precise center point
            var centerX = loc.X + loc.W / 2;
            var centerY = loc.Y + loc.H / 2;

            var nextIndexBase = 0;
            foreach (var winSz in WinSizes())
            {
                var indexBase = nextIndexBase;
                nextIndexBase = checked(indexBase + GetNumWindows(winSz));

                var offset = winSz >> _offsetExp;

                var xIndex = Clamp(GetIndex(centerX, winSz, offset), 0, GetNumWindows(winSz, _w) - 1);
                var yIndex = Clamp(GetIndex(centerY, winSz, offset), 0, GetNumWindows(winSz, _h) - 1);
                if (CheckContains(xIndex * offset, winSz, loc.X, loc.X + loc.W) && CheckContains(yIndex * offset, winSz, loc.Y, loc.Y + loc.H))
                {
                    return checked(indexBase + yIndex * GetNumWindows(winSz, _w) + xIndex);
                }
            }
            return -1;
        }
Example #2
0
 internal bool Overlaps(Rectangle r)
 {
     return ((X <= r.X && r.X < X + W) || (r.X <= X && X < r.X + r.W)) &&
            ((Y <= r.Y && r.Y < Y + H) || (r.Y <= Y && Y < r.Y + r.H));
 }