Skip to content

How to Check if Rectangles are Disjoint

Jorj X. McKie edited this page Mar 28, 2017 · 7 revisions

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

For rectangles, points and matrices, the list() and tuple() functions will return sequences of the coordinates. Therefore:

tuple(r1 & r2) == (0, 0, 0, 0)

means that r1 and r2 are disjoint (have nothing in common). Rectangles need not be of same type (IRect or Rect). There also is a new method for IRect/Rect doing the same thing: r1.intersects(r2) delivers (the negation of) the bool above.

tuple(r1 | x) == tuple(r1)

means that x is completely contained in r1. x can be any rectangle or point in this case. There also is a new method for Rect/IRect doing the same: r1.contains(x) delivers the bool of above.

Clone this wiki locally