[program-l] Re: detecting overlapping controls

  • From: Jamal Mazrui <empower@xxxxxxxxx>
  • To: program-l@xxxxxxxxxxxxx
  • Date: Sat, 29 Jul 2006 11:35:51 -0400 (EDT)

Hi David,
You're right --the algorithm I proposed would not detect overlap if the
primary control completely contained a secondary control.  I think it
would if their roles were reversed, that is, the primary was inside the
secondary.  Thus, a correct answer would result if tests were done
both ways at each iteration, which, of course, would also be more
inefficient.  In either the Visual Basic 6 or the JAWS scripting language,
it may not be practical to calculate overlapping conditions displayed on
the status bar in real time as one navigates among controls because of the
computational delay.  So, a better implementation might be a hot key that
does this upon request.

Regards,
Jamal
 On Sat, 29 Jul 2006, David Lant wrote:

> Date: Sat, 29 Jul 2006 09:56:28 +0100
> From: David Lant <david.lant1@xxxxxxxxxxxxxx>
> Reply-To: program-l@xxxxxxxxxxxxx
> To: program-l@xxxxxxxxxxxxx
> Subject: [program-l] Re: detecting overlapping controls
>
> Hi Jamal,
>
> That's certainly an improvement.  However, it still wouldn't detect the
> situation where the primary control is larger than the secondary, but
> completely overlays it.  I.e. all the bounding sides of the primary control
> are outside the area contained by the bounding controls of the secondary,
> such as with two concentric squares.
>
> For those who are used to using Visual Basic 6 with JAWS, you will soon
> realise how slow this test can become.  Therefore, I would also recommend
> some culling techniques to eliminate certain controls from the two-way
> testing that is required.  For example, any control whose Y2 property is
> less than the Y1 property of the primary control can safely be ignored,
> since it must be entirely above the primary control.  Similarly, any control
> whose X2 coordinate is less than the X1 coordinate can be eliminated, as it
> must be entirely to the left of the primary control.  Continue this for the
> other two directions, and hopefully you will be left with a small set of
> controls who have any possibility of being in an overlapping state.  Indeed,
> one could use this technique to simply eliminate all controls that cannot be
> overlapping, and thus proclaim that any controls left *must* be touching or
> overlapping.  You could either leave it at that, or proceed to perform
> further calculations in order to describe in what way the remaining controls
> overlap.
>
> Some efficient sorting techniques could help speed up the process too.  E.g.
> if you keep 4 arrays, each representing all the controls on the form.  Sort
> one list according to the X1 coordinate, the second according to the X2, the
> third according to the Y1 and the last according to the Y2.  You could then
> simply chop off the entire block which falls beyond the bounds of the
> current control, saving the need to iterate through every control to do a
> comparison.  I.e. you simply iterate out from the primary control in the
> array, until you reach one that must be outside it.  Any further controls in
> the array in that direction must also be outside, so can be ignored.
>
> Those with a more mathematical bent could possibly come up with some faster
> techniques than this.  Perhaps some form of matrix processing is available
> that could present an even quicker way to arrive at the subset of
> overlapping controls.  Maybe using the vector classes in DirectX? <smile>
>
> All the best,
>
> David
>
>
> -----Original Message-----
> From: program-l-bounce@xxxxxxxxxxxxx [mailto:program-l-bounce@xxxxxxxxxxxxx]
> On Behalf Of Jamal Mazrui
> Sent: 28 July 2006 10:10
> To: program-l@xxxxxxxxxxxxx
> Subject: [program-l] Re: detecting overlapping controls
>
>
> Perhaps I'm misunderstanding this.  Does x1,y1 refer to the coordinates
> of the left, top corner of a control (or bounding rectangle of a shape)
> and x2,y2 refer to the right, bottom?  If so, then I think more
> comparisons are needed to determine overlap.  Just comparing x
> coordinates (horizontal position) cannot conclude overlap because one
> control could be completely below the other, with no shared screen area.
>
> I suggest an algorithm like the following to determine if a control is
> overlapped by others:
>
> Save the top left and bottom right coordinates of a control being tested
> for overlap.  Call this the primary control.
>
> Iterate through the other controls in the window, and for each one, save
> its coordinates to another set of variables.  Call this the secondary
> control.
>
> When comparing primary and secondary controls, test whether either the
> primary's left is between the left and right of the secondary, or its
> right is between the left and right of the secondary.  Between is
> defined inclusively, e.g., a <= rather than < comparison.
>
> If one of the two previous conditions holds, do a similar test in the
> other dimension.  Specifically, if either the top or bottom of the
> primary is between the top and bottom of the secondary, then this means
> that the pair of controls share at least some overlapping area.
>
> Regards,
> Jamal
>
> -----Original Message-----
> From: program-l-bounce@xxxxxxxxxxxxx
> [mailto:program-l-bounce@xxxxxxxxxxxxx] On Behalf Of Will Pearson
> Sent: Friday, July 28, 2006 11:22 AM
> To: program-l@xxxxxxxxxxxxx
> Subject: [program-l] Re: detecting overlapping controls
>
>
> Hi Pranav,
>
> I think the easiest way to do this is by simple comparison.  Assuming an
>
> origin of 0, 0 is the top left corner, then if the x1 of a UI element is
>
> less than the x2 of another UI element then the two overlap, equally if
> the
> y1 of a UI element overlaps the Y2 of another UI element then the two
> overlap.  You would need to cycle through each object on the drawing
> surface
> and check them against all other objects on the drawing surface.  You
> shouldn't need to check for overlap on the right or bottom edges of an
> object, as if it overlaps on the right side then the control it overlaps
>
> with will overlap it on the left side and be detected, the same is true
> for
> the top/bottom distinction.
>
> You could probably do it other ways, such as caching the area occupied
> by a
> drawing object.  However, these are likely more complex solutions and
> would
> therefore require more work.
>
> Will
> ----- Original Message -----
> From: "Pranav Lal" <pranav.lal@xxxxxxxxx>
> To: "Program-L-Freelists. Org" <program-l@xxxxxxxxxxxxx>
> Sent: Friday, July 28, 2006 1:52 AM
> Subject: [program-l] detecting overlapping controls
>
>
> > Hi all,
> >
> > How do I programmatically detect overlapping controls? In Microsoft
> Visio
> > 2003, I have the x1, y1, x2 and y2 coordinates for every shape.
> >
> > I know this is possible since I have seen it done in the
> configurations
> > for
> > Visual Basic.
> >
> > Pranav
> >
> > ** To leave the list, click on the immediately-following link:-
> > ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
> > ** If this link doesn't work then send a message to:
> > ** program-l-request@xxxxxxxxxxxxx
> > ** and in the Subject line type
> > ** unsubscribe
> > ** For other list commands such as vacation mode, click on the
> > ** immediately-following link:-
> > ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
> > ** or send a message, to
> > ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq
>
>
> ** To leave the list, click on the immediately-following link:-
> ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
> ** If this link doesn't work then send a message to:
> ** program-l-request@xxxxxxxxxxxxx
> ** and in the Subject line type
> ** unsubscribe
> ** For other list commands such as vacation mode, click on the
> ** immediately-following link:-
> ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
> ** or send a message, to
> ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq
> ** To leave the list, click on the immediately-following link:-
> ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
> ** If this link doesn't work then send a message to:
> ** program-l-request@xxxxxxxxxxxxx
> ** and in the Subject line type
> ** unsubscribe
> ** For other list commands such as vacation mode, click on the
> ** immediately-following link:-
> ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
> ** or send a message, to
> ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq
>
> ** To leave the list, click on the immediately-following link:-
> ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
> ** If this link doesn't work then send a message to:
> ** program-l-request@xxxxxxxxxxxxx
> ** and in the Subject line type
> ** unsubscribe
> ** For other list commands such as vacation mode, click on the
> ** immediately-following link:-
> ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
> ** or send a message, to
> ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq
>
** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

Other related posts: