[comp.lang.pascal] Text windows

6600bori@ucsbuxa.ucsb.edu (Boris Burtin) (11/14/90)

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?
	- Boris Burtin
	(6600bori@ucsbuxa.ucsb.edu)

bobb@vice.ICO.TEK.COM (Bob Beauchaine) (11/14/90)

In article <7187@hub.ucsb.edu> 6600bori@ucsbuxa.ucsb.edu (Boris Burtin) 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?
>	- Boris Burtin
>	(6600bori@ucsbuxa.ucsb.edu)

  This seems to me another variation on the containment problem; i.e., how
  to decide if a given point lies within the boundary of a polygon whose
  vertices are known.

  I don't have my source for such algorithms with me, but I have seen several
  solutions to this problem.  The book I like is _Fundamental_Algorithms_for_
  Raster_Graphics (sorry, author unknown).  You will need to know a bit 
  about linear algebra, though, and may find the solution more trouble than
  it's worth.

  Bob Beauchaine
  bobb@vice.ICO.TEK.COM

zhou@brazil.psych.purdue.edu (Albert Zhou) (11/14/90)

I don't really get it. If your window information is stored in variables,
it is really simple.  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. I don't
know it can be called optimized, but I couldn't think of anything simpler.

I don't undertand the author's writing after "My problem is.." until the end
of the article.


([ya1..ya2]*[yb1..yb2] 

milne@ics.uci.edu (Alastair Milne) (11/16/90)

In <7187@hub.ucsb.edu> 6600bori@ucsbuxa.ucsb.edu (Boris Burtin) 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?

   This sounds as if it would be easily handled by the Cohen-Sutherland
   clipping algorithm.  You'd probably have to apply it to up to all 
   four sides of one window, though, using the other as a basis; 
   but it's reasonably fast.

   The reference I used to have for this was Newman and Sproull, but I can't
   remember their title; it may also be in Foley and Van Dam's book 
   -- something like "Fundamentals of Interactive Computer Graphics".  
   The fact that it's described for graphics doesn't matter, since you 
   still need to compare coordinate pairs.  You're just applying them
   to rather large points, i.e. text fonts.


   Alastair Milne