laziness, impatience, and hubris PerlMonks

### Re: Detecting control placement constraints in dialog resources - rectangle overlap checking

by shotgunefx (Parson)
 on Mar 09, 2006 at 21:31 UTC ( #535520=note: print w/replies, xml ) Need Help??

You want to double check my work here (though some use of rand() and Tk could make quick work of testing visually). I'm assuming X1 < X2 , Y1 < Y2
```my @box = (
{ name => "Box 1", x1 => 0,   y1 => 0,   x2 => 320, y2 => 100 },
{ name => "Box 2", x1 => 100, y1 => 10,  x2 => 510, y2 => 500 },
{ name => "Box 3", x1 => 20,  y1 => 300, x2 => 120, y2 => 600 },
{ name => "Box 4", x1 => 300, y1 => 301, x2 => 310, y2 => 600 },
);

sub bounding_box {
my @box = sort { \$a->{x1} <=> \$b->{x1} } @_;    # Sort on X axis
for ( my \$i = 0 ; \$i < \$#box ; \$i++ ) {
for ( my \$j = \$i + 1 ; \$j < @box ; \$j++ ) {
warn "Checking \$box[\$i]->{name} against \$box[\$j]->{name}\n
+";
if ( \$box[\$i]->{x2} > \$box[\$j]->{x1} ) {
if ( \$box[\$i]->{y2} > \$box[\$j]->{y1}
&& \$box[\$i]->{y1} < \$box[\$j]->{y2} )
{
warn " \$box[\$i]->{name} overlaps \$box[\$j]->{name}\
+n";
# Do something here
}
else {
warn
" \$box[\$i]->{name} doesn't overlap \$box[\$j]->{na
+me}\n";
}
}
else {
last;
}
}

}
}
update My spaceship <=> was half missing. Whoops.

-Lee
"To be civilized is to deny one's nature."
• Comment on Re: Detecting control placement constraints in dialog resources - rectangle overlap checking

Create A New User
Node Status?
node history
Node Type: note [id://535520]
help
Chatterbox?
 [LanX]: Oh I see, userDict should have been declared in n outer scope ... [LanX]: an [LanX]: strange python accepts this? [LanX]: no previous userDict?

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2018-03-20 18:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When I think of a mole I think of:

Results (257 votes). Check out past polls.

Notices?