using System; namespace SquareFinder { /// /// Summary description for IGrid. /// /// interface IGrid { int CountBlocksSet(int x1, int x2, int y1, int y2); } enum Shape { Square, Rectangle, Unknown } class Grid : IGrid { int left; int right; int bottom; int top; public int TotalCalls = 0; public Grid(int left, int right, int bottom, int top) { this.left = left; this.right = right; this.bottom = bottom; this.top = top; } public int CountBlocksSet(int x1, int x2, int y1, int y2) { ++TotalCalls; int intersectRight = Math.Min(x2, this.right); int intersectLeft = Math.Max(x1, this.left); int intersectTop = Math.Min(y2, this.top); int intersectBottom = Math.Max(y1, this.bottom); if (intersectRight <= intersectLeft) return 0; if (intersectTop <= intersectBottom) return 0; return (intersectRight - intersectLeft) * (intersectTop - intersectBottom); } } }