Skip to content

Commit

Permalink
Rectangle_tests.h:
Browse files Browse the repository at this point in the history
* Adding additional Rectangle tests.
  • Loading branch information
razterizer committed Sep 27, 2024
1 parent c9e4dc0 commit 1c2e027
Showing 1 changed file with 139 additions and 0 deletions.
139 changes: 139 additions & 0 deletions Tests/Rectangle_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,151 @@ namespace ttl
assert(rec.pos() == RC(0, 0));
assert(rec.size() == RC(0, 0));

// No need to replicate these two tests for rectangles of other dimensions:
auto rec_tmp = rec;
rec_tmp.set_pos({ 2, -1 });
rec_tmp.set_size({ 4, 4 });
assert(rec_tmp.pos() == RC(2, -1));
assert(rec_tmp.size() == RC(4, 4));
}

{
Rectangle rec { -1, +1, 2, 1}; // [-1..0, 1]

assert(rec.r == -1);
assert(rec.c == +1);
assert(rec.r_len == 2);
assert(rec.c_len == 1);

assert(!rec.is_inside(0, 0));
assert(!rec.is_inside(1, 0));
assert(rec.is_inside(0, 1));
assert(!rec.is_inside(-1, 0));
assert(!rec.is_inside(0, -1));
assert(!rec.is_inside(pt0));
assert(!rec.is_inside(pt1));
assert(rec.is_inside(pt2));
assert(!rec.is_inside(pt3));
assert(!rec.is_inside(pt4));

assert(!rec.is_inside_offs(0, 0, -1));
assert(rec.is_inside_offs(0, 0, +1));
assert(!rec.is_inside_offs(1, 0, -1));
assert(rec.is_inside_offs(1, 0, +1));
assert(!rec.is_inside_offs(0, 1, -1));
assert(rec.is_inside_offs(0, 1, +1));
assert(!rec.is_inside_offs(-1, 0, -1));
assert(rec.is_inside_offs(-1, 0, +1));
assert(!rec.is_inside_offs(0, -1, -1));
assert(!rec.is_inside_offs(0, -1, +1));
assert(rec.is_inside_offs(0, -1, +2));
assert(!rec.is_inside_offs(pt0, -1));
assert(rec.is_inside_offs(pt0, +1));
assert(!rec.is_inside_offs(pt1, -1));
assert(rec.is_inside_offs(pt1, +1));
assert(!rec.is_inside_offs(pt2, -1));
assert(rec.is_inside_offs(pt2, +1));
assert(!rec.is_inside_offs(pt3, -1));
assert(rec.is_inside_offs(pt3, +1));
assert(!rec.is_inside_offs(pt4, -1));
assert(!rec.is_inside_offs(pt4, +1));
assert(rec.is_inside_offs(pt4, +2));

assert(rec.is_inside_offs(pt0, +1, +2));
assert(rec.is_inside_offs(pt1, +1, +2));
assert(rec.is_inside_offs(pt2, +1, +2));
assert(rec.is_inside_offs(pt3, +1, +2));
assert(rec.is_inside_offs(pt4, +1, +2));

assert(!rec.is_inside_offs(pt0, +1, +2, 0, +1));
assert(rec.is_inside_offs(pt0, +1, +2, +1, 0));
assert(!rec.is_inside_offs(pt0, +2, 0, 0, +1));
assert(rec.is_inside_offs(pt0, 0, +1, +1, +1));
assert(!rec.is_inside_offs(pt0, 0, +1, -1, +1));
assert(!rec.is_inside_offs(pt0, -1, +1, -1, +1));
assert(!rec.is_inside_offs(pt0, +1, -1, +1, -1));
assert(rec.is_inside_offs(pt0, +1, +1, +1, +1));
assert(rec.is_inside_offs(pt0, +2, +2, +2, +2));

assert(!rec.is_inside_offs(pt1, +1, +2, 0, +1));
assert(rec.is_inside_offs(pt1, +1, +2, +1, 0));
assert(!rec.is_inside_offs(pt1, +2, 0, 0, +1));
assert(rec.is_inside_offs(pt1, 0, +1, +1, +1));
assert(!rec.is_inside_offs(pt1, 0, +1, -1, +1));
assert(!rec.is_inside_offs(pt1, -1, +1, -1, +1));
assert(!rec.is_inside_offs(pt1, +1, -1, +1, -1));
assert(rec.is_inside_offs(pt1, +1, +1, +1, +1));
assert(rec.is_inside_offs(pt1, +2, +2, +2, +2));

assert(rec.is_inside_offs(pt2, +1, +2, 0, +1));
assert(rec.is_inside_offs(pt2, +1, +2, +1, 0));
assert(rec.is_inside_offs(pt2, +2, 0, 0, +1));
assert(rec.is_inside_offs(pt2, 0, +1, +1, +1));
assert(!rec.is_inside_offs(pt2, 0, +1, -1, +1));
assert(!rec.is_inside_offs(pt2, -1, +1, -1, +1));
assert(!rec.is_inside_offs(pt2, +1, -1, +1, -1));
assert(rec.is_inside_offs(pt2, +1, +1, +1, +1));
assert(rec.is_inside_offs(pt2, +2, +2, +2, +2));

assert(!rec.is_inside_offs(pt3, +1, +2, 0, +1));
assert(rec.is_inside_offs(pt3, +1, +2, +1, 0));
assert(!rec.is_inside_offs(pt3, +2, 0, 0, +1));
assert(rec.is_inside_offs(pt3, 0, +1, +1, +1));
assert(!rec.is_inside_offs(pt3, 0, +1, -1, +1));
assert(!rec.is_inside_offs(pt3, -1, +1, -1, +1));
assert(rec.is_inside_offs(pt3, +1, -1, +1, -1));
assert(rec.is_inside_offs(pt3, +1, +1, +1, +1));
assert(rec.is_inside_offs(pt3, +2, +2, +2, +2));

assert(!rec.is_inside_offs(pt4, +1, +2, 0, +1));
assert(!rec.is_inside_offs(pt4, +1, +2, +1, 0));
assert(!rec.is_inside_offs(pt4, +2, 0, 0, +1));
assert(!rec.is_inside_offs(pt4, 0, +1, +1, +1));
assert(!rec.is_inside_offs(pt4, 0, +1, -1, +1));
assert(!rec.is_inside_offs(pt4, -1, +1, -1, +1));
assert(!rec.is_inside_offs(pt4, +1, -1, +1, -1));
assert(!rec.is_inside_offs(pt4, +1, +1, +1, +1));
assert(rec.is_inside_offs(pt4, +2, +2, +2, +2));

assert(rec.is_on_border(pt0));
assert(!rec.is_on_border(pt1));
assert(rec.is_on_border(pt2));
assert(rec.is_on_border(pt3));
assert(rec.is_on_border(pt4));

assert(rec.find_location(pt0) == BBLocation::OutsideLeft);
assert(rec.find_location(pt1) == BBLocation::OutsideBottomLeft);
assert(rec.find_location(pt2) == BBLocation::Inside); // rec:[-1..0, 1], pt2:[0, 1]
assert(rec.find_location(pt3) == BBLocation::OutsideLeft);
assert(rec.find_location(pt4) == BBLocation::OutsideLeft);

assert(rec.find_location_offs(pt0, 0, +1, 0, +1) == BBLocation::OutsideLeft);
assert(rec.find_location_offs(pt0, -1, +1, 0, +1) == BBLocation::OutsideLeft);
assert(rec.find_location_offs(pt1, 0, +1, 0, +1) == BBLocation::OutsideLeft);
assert(rec.find_location_offs(pt1, 0, +2, 0, +1) == BBLocation::OutsideLeft);
assert(rec.find_location_offs(pt2, 0, +1, 0, +1) == BBLocation::Inside);
assert(rec.find_location_offs(pt2, 0, +1, 0, +2) == BBLocation::Inside);
assert(rec.find_location_offs(pt3, 0, +1, 0, +1) == BBLocation::OutsideLeft);
assert(rec.find_location_offs(pt3, +1, 0, 0, +1) == BBLocation::OutsideLeft);
assert(rec.find_location_offs(pt4, 0, +1, 0, +1) == BBLocation::OutsideLeft);
assert(rec.find_location_offs(pt4, 0, +1, +1, +1) == BBLocation::OutsideLeft);
assert(rec.find_location_offs(pt4, -1, 0, -1, 0) == BBLocation::None); // rec:[-1..0, 1] -> [0, .], pt4:[0, -1]

assert(!rec.is_empty());
assert(!rec.is_inverted());
assert(!rec.is_collapsed());
assert(rec.is_valid());

assert(rec.center() == RC(0, 1)); // rec:[-1..0, 1], { -1, +1, 2, 1}/2 = -1+1, 1+0.5
assert(rec.r_mid() == 0);
assert(rec.c_mid() == 1);
assert(rec.top() == -1);
assert(rec.bottom() == 0);
assert(rec.left() == 1);
assert(rec.right() == 1);
assert(rec.pos() == RC(-1, +1));
assert(rec.size() == RC(2, 1));
}
}

}

0 comments on commit 1c2e027

Please sign in to comment.