Skip to content

Commit

Permalink
[arrayTools] fix sectRect boundary case
Browse files Browse the repository at this point in the history
use '>' instead of '>=' when comparing intersection of two rectangles, so we don't skip boundary case when the two touch

Fixes #3352
  • Loading branch information
anthrotype committed Nov 28, 2023
1 parent abd34de commit ebb5e27
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/fontTools/misc/arrayTools.py
Expand Up @@ -208,7 +208,7 @@ def sectRect(rect1, rect2):
min(xMax1, xMax2),
min(yMax1, yMax2),
)
if xMin >= xMax or yMin >= yMax:
if xMin > xMax or yMin > yMax:
return False, (0, 0, 0, 0)
return True, (xMin, yMin, xMax, yMax)

Expand Down
7 changes: 7 additions & 0 deletions Tests/misc/arrayTools_test.py
Expand Up @@ -89,6 +89,13 @@ def test_sectRect():
assert rect == (5, 20, 20, 30)


def test_sectRect_perpendicular():
# https://github.com/fonttools/fonttools/issues/3352
intersects, rect = sectRect((0.0, 0.0, 0.0, 1.0), (0.0, 0.5, 1.0, 0.5))
assert intersects
assert rect == (0.0, 0.5, 0.0, 0.5)


def test_unionRect():
assert unionRect((0, 10, 20, 30), (0, 40, 20, 50)) == (0, 10, 20, 50)

Expand Down

0 comments on commit ebb5e27

Please sign in to comment.