From 19e1178b16fd27882c7834d66ad6597847e6baff Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 25 Sep 2016 05:54:08 +0100 Subject: Space rotates hints (to make hidden hints visible). It is common for link-hint markers to be close togother, and overlapping. Here, `` rotates hint markers such that hidden markers become visible. For filtered hints we additionally require a modifier (because `` on its own is already a token separator). The calculation of overlapping hints is quite expensive: O(n^2) in the best case and O(n^3) in the worst cast. The worst case is extraordinarily unlikely to arise in practice. --- tests/unit_tests/rect_test.coffee | 56 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'tests/unit_tests/rect_test.coffee') diff --git a/tests/unit_tests/rect_test.coffee b/tests/unit_tests/rect_test.coffee index cfb26b05..0773dbcf 100644 --- a/tests/unit_tests/rect_test.coffee +++ b/tests/unit_tests/rect_test.coffee @@ -230,3 +230,59 @@ context "Rect subtraction", if resultComplement.length == 1 complementRect = resultComplement[0] assert.isTrue Rect.contains subtractRect, complementRect + +context "Rect overlaps", + should "detect that a rect overlaps itself", -> + rect = Rect.create 2, 2, 4, 4 + assert.isTrue Rect.rectsOverlap rect, rect + + should "detect that non-overlapping rectangles do not overlap on the left", -> + rect1 = Rect.create 2, 2, 4, 4 + rect2 = Rect.create 0, 2, 1, 4 + assert.isFalse Rect.rectsOverlap rect1, rect2 + + should "detect that non-overlapping rectangles do not overlap on the right", -> + rect1 = Rect.create 2, 2, 4, 4 + rect2 = Rect.create 5, 2, 6, 4 + assert.isFalse Rect.rectsOverlap rect1, rect2 + + should "detect that non-overlapping rectangles do not overlap on the top", -> + rect1 = Rect.create 2, 2, 4, 4 + rect2 = Rect.create 2, 0, 2, 1 + assert.isFalse Rect.rectsOverlap rect1, rect2 + + should "detect that non-overlapping rectangles do not overlap on the bottom", -> + rect1 = Rect.create 2, 2, 4, 4 + rect2 = Rect.create 2, 5, 2, 6 + assert.isFalse Rect.rectsOverlap rect1, rect2 + + should "detect overlapping rectangles on the left", -> + rect1 = Rect.create 2, 2, 4, 4 + rect2 = Rect.create 0, 2, 2, 4 + assert.isTrue Rect.rectsOverlap rect1, rect2 + + should "detect overlapping rectangles on the right", -> + rect1 = Rect.create 2, 2, 4, 4 + rect2 = Rect.create 4, 2, 5, 4 + assert.isTrue Rect.rectsOverlap rect1, rect2 + + should "detect overlapping rectangles on the top", -> + rect1 = Rect.create 2, 2, 4, 4 + rect2 = Rect.create 2, 4, 4, 5 + assert.isTrue Rect.rectsOverlap rect1, rect2 + + should "detect overlapping rectangles on the bottom", -> + rect1 = Rect.create 2, 2, 4, 4 + rect2 = Rect.create 2, 0, 4, 2 + assert.isTrue Rect.rectsOverlap rect1, rect2 + + should "detect overlapping rectangles when second rectangle is contained in first", -> + rect1 = Rect.create 1, 1, 4, 4 + rect2 = Rect.create 2, 2, 3, 3 + assert.isTrue Rect.rectsOverlap rect1, rect2 + + should "detect overlapping rectangles when first rectangle is contained in second", -> + rect1 = Rect.create 1, 1, 4, 4 + rect2 = Rect.create 2, 2, 3, 3 + assert.isTrue Rect.rectsOverlap rect2, rect1 + -- cgit v1.2.3