in reply to Permutation and comparison loop

You might find this a bit simpler:

#! perl -slw use strict; use enum qw[ IMAGENO MINLAT MAXLAT MINLON MAXLON ]; sub overlapLat { my( $a, $b ) = @_; return if $a->[MINLAT] > $b->[MAXLAT] or $a->[MAXLAT] < $b->[MINLAT]; return 1; } sub overlapLon { my( $a, $b ) = @_; return if $a->[MINLON] > $b->[MAXLON] or $a->[MAXLON] < $b->[MINLON]; return 1; } ##discard header <DATA>; my @rects = map[ split ',' ], <DATA>; my $m = 0; for my $first ( 0 .. $#rects ) { for my $second ( $first + 1 .. $#rects ) { if( overlapLat( @rects[ $first, $second ] ) and overlapLon( @rects[ $first, $second ] ) ) { print "@{$rects[ $first ] } overlaps \n@{ $rects[ $second +] }"; } } } __DATA__ "Image number","minlat","maxlat","minlon","maxlon" 1,0,30,20,50 2,10,30,70,90 3,70,80,40,50 4,40,70,20,50 5,20,75,40,80

Output:

C:\test>junk87 1 0 30 20 50 overlaps 5 20 75 40 80 2 10 30 70 90 overlaps 5 20 75 40 80 3 70 80 40 50 overlaps 4 40 70 20 50 3 70 80 40 50 overlaps 5 20 75 40 80 4 40 70 20 50 overlaps 5 20 75 40 80

One thing to watch for is whether to consider an image that ends at 70, overlaps with another that starts at 70 as with 3 & 4 above?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.