Welcome to MSDN Blogs Sign in | Join | Help

Mock Grid Implementation

 
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 + 1) * (intersectTop - intersectBottom + 1);
    }
}
Published Friday, May 20, 2005 6:56 PM by Jomo Fisher

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker