Rectangle overlap X54942


Statement
 

pdf   zip

Using the definitions

class Point:
    """attributes: x, y"""

class Rectangle:
    """attributes: width, height, corner"""

and the function @point_in_rectangle@ from problem X53379 (Point in rectangle), write a function

rectangle_overlap(r1, r2)

that returns @True@ if a corner of a rectangle @r1@ falls inside or on the boundary of a rectangle @r2@ but the opposite corner of @r1@ falls outside @r2@ or, conversely, if a corner of @r2@ falls inside or on the boundary of @r1@ but the opposite corner of @r2@ falls outside @r1@, and @False@ otherwise. For example, a rectangle of width 5050, height 100100, and lower-left corner (0,0)(0, 0) and a rectangle of width 5050, height 100100, and lower-left corner (25,50)(25, 50) overlap, but a rectangle of width 5050, height 100100, and lower-left corner (0,0)(0, 0) and a rectangle of width 5050, height 100100, and lower-left corner (75,50)(75, 50) do not.

Input

The input consists of several pairs of rectangles (four non-negative integer numbers for each: the width, the height, and the coordinates of the lower-left corner).

Output

For each pair of rectangles, print whether or not they overlap.

Public test cases
  • Input

    50 100 0 0      50 100 25 50
    50 100 25 50    50 100 0 0
    50 100 0 0      50 100 75 50
    50 100 75 50    50 100 0 0
    50 100 0 0      25 50 0 0
    25 50 0 0       50 100 0 0
    

    Output

    True
    True
    False
    False
    True
    True
    
  • Information
    Author
    Gabriel Valiente
    Language
    English
    Official solutions
    Python
    User solutions
    C++ Python