Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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??


in reply to Detecting control placement constraints in dialog resources - rectangle overlap checking

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
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://535520]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (16)
As of 2014-12-22 13:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (118 votes), past polls