Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • The rectangles _don't_ overlap when one is either completely to the left of the other, or completely below the other.

    A rectangle can be defined by the coordinates of its top-left and bottom-right points:

    So let's say A = (x1,y1,x2,y2) and B = (u1,v1,u2,v2).

    (x1,y1)                 (u1,v1)
      +-------------+           +-----------+
      |             |           |           |
      |     A       |           |     B     |
      |             |           |           |
      +-------------+           +-----------+
                  (x2,y2)                 (u2,v2)
    Then A does not overlap B if one of these four tests pass:

    # A left of B
    x2 < u1
    # A right of B
    x1 > u2
    # A above B
    y2 > v1
    # A below B
    y1 < v2
    So A overlaps B if none of the above hold:

      not ( x2 < u1 or x1 > u2 or y2 > v1 or y1 < v2 )
    or equivalently ( !(a or b) <=> !a and !b )

      x2 >= u1 and x1 <= u2 and y2 <= v1 and y1 >= v2
    That's too simple to be a module :-)