Advertisement
dkanavis

Untitled

Nov 21st, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.77 KB | None | 0 0
  1. my @rect1 = ([1, 3], [3, 3], [3, 1], [1, 1]);
  2. my @rect2 = ([3, 5], [5, 5], [5, 3], [3, 3]);
  3.  
  4. sub check_rect_intersection {
  5.     my @rect1 = @_[0..3];
  6.     my @rect2 = @_[4..7];
  7.  
  8.     sub rect_bounds {
  9.         my @rect = @_;
  10.  
  11.         my @res;
  12.         for my $axis (0,1) {
  13.             my $max;
  14.             my $min;
  15.             for my $point (@rect) {
  16.                 if (!defined $max || $max < $point->[$axis]) {
  17.                     $max = $point->[$axis];
  18.                 }
  19.                 if (!defined $min || $min > $point->[$axis]) {
  20.                     $min = $point->[$axis];
  21.                 }
  22.             }
  23.             $res[$axis]
  24.         }
  25.     }
  26.  
  27.     my @bounds = (rect_bounds(@rect1), rect_bounds(@rect2);
  28. }
  29.  
  30. check_rect_intersection(@rect1, @rect2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement