Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!decwrl!bacchus.pa.dec.com!decuac!haven!adm!news From: CDCKAB%EMUVM1.BITNET@cunyvm.cuny.edu ( Karl Brendel) Newsgroups: comp.lang.pascal Subject: (R)Text windows Message-ID: <25001@adm.brl.mil> Date: 14 Nov 90 15:12:05 GMT Sender: news@adm.brl.mil Lines: 50 In <7187@hub.ucsb.edu>, Boris Burtin <6600bori@ucsbuxa.ucsb.edu> writes: >I have been working on a text windowing program in Turbo Pascal, and >just have one question. I have a function that determines whether two >windows overlap. It currently does this by checking if one of the >corners of one of the windows is inside the other window. The problem >is that I have not truly optimized the coding. I have a long string and >and/or statements that works, but gives me a complex whenever I look at >it. Does anyone have an algorithm for this kind of problem? A simple one published in PC Techniques, v1n2, June/Jul 90, as "Hax 14", pg 60, from Bryan Flamig: if a rectangle is type rect = record xul,yul, {upper left corner x & y} xlr,ylr : integer; {lower right corner x & y} end; {rect} then two rectangles A & B intersect (or windows overlap) if A^.xul <= B^.xlr and A^.xlr >= B^.xul and A^.yul <= B^.ylr and A^.ylr >= B^.yul Flamig demonstrates this by drawing examples of the ways in which rectangles may intersect. You may want to do that also unless the truth of the statements leaps out at you. ;) PS--As I look at Albert Zhou's message <11473@j.cc.purdue.edu>: > Suppose two windows are defined as (xa1,ya1,xa2,ya2) and > (xb1,yb1,xb2,yb2), if (([xa1..xa2]*[xb1..xb2])=[]) or > ([ya1..ya2]*[yb1..yb2]=[]) then these two windows are not overlapping. it seems to me that Flamig's solution sort of "falls out" of Albert Zhou's, and thus may be considered something towards an optimization of that solution. +-------------------------------------------------------------------------+ | Karl Brendel Centers for Disease Control | | Internet: CDCKAB@EMUVM1.BITNET Epidemiology Program Office | | Bitnet: CDCKAB@EMUVM1 Atlanta, GA, USA | | ILink/RIME: KARL BRENDEL phone 404/639-2709 | | CIS : 73307,3101 fts 236-2709 | | GEnie: K.BRENDEL Home of Epi Info 5.0 | +-------------------------------------------------------------------------+