D
Daniel T.
Edward Gregor said:Hi!
I've written this code as a part of my program and I
wonder if you would mind looking at the
try_subtract_region and tell me if it well written.
Thankful for help!
So I went ahead and ran your code though some tests. I was a little
surprised at the results, I thought of "subtraction" of rectangles more
like a set-intersection than a union... However I was especially
surprised at this particular result:
void failUnlessEqual( int a, int b ) {
assert( a == b );
}
void test_top_bottom_intersecting() {
region r1 = { 1, 3, 5, 7 };
region r2 = { 1, 3, 6, 8 };
int result = try_subtract_region( &r1, &r2 );
failUnlessEqual( 1, result );
failUnlessEqual( 1, r1.left );
failUnlessEqual( 3, r1.right );
failUnlessEqual( 5, r1.top );
failUnlessEqual( 6, r1.bottom );
failUnlessEqual( 1, r2.left );
failUnlessEqual( 3, r2.right );
failUnlessEqual( 6, r2.top );
failUnlessEqual( 8, r2.bottom );
}
Why is r1.bottom == 6 in this test?