Skip to content

How to Check if Rectangles are Disjoint

Jorj X. McKie edited this page Apr 15, 2017 · 7 revisions

Algebraic functions of rectangles and points can be used to check inclusion and intersection of such objects. Questions like "Are rectangles R1 and R2 disjoint?" or "Is point P outside or inside rectangle R?" can easily be answered.

  • r1.intersects(r2): This is True if rectangle r2 is contained in rectangle r1. Both may be of different rectangle types (IRect or Rect). For rectangles, points and matrices, the list() and tuple() functions will return sequences of their coordinates. This is used in this method - it simply returns tuple(r1 & r2) != (0, 0, 0, 0).

  • r1.contains(x): This is True if the rectangle or point x is contained in rectangle r1. This is equivalent to the expression x in r1.

Clone this wiki locally