in reply to Re^2: Permutation and comparison loop
in thread Permutation and comparison loop
Provided that your images do not cross the North or South poles. If they do, then things get real weird and you need to move to an alternative coordinates system.
#! perl -slw use strict; use enum qw[ IMAGENO MINLAT MAXLAT MINLON MAXLON ]; sub overlapLat { my( $a, $b ) = @_; return if $a->[MINLAT]+90 > $b->[MAXLAT]+90 or $a->[MAXLAT]+90 < $b->[MINLAT]+90; return 1; } sub overlapLon { my( $a, $b ) = @_; return if $a->[MINLON]+360 > $b->[MAXLON]+360 or $a->[MAXLON]+360 < $b->[MINLON]+360; return 1; } ##discard header <DATA>; my @rects = map[ split ',' ], <DATA>; 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" ...
|
|---|