#!/usr/bin/perl


unless ($ARGV[0] ne '') {
  print STDERR "Usage: $0 bldg-code < map.in > db.out\n" ;
  exit ;
}
$bldg = $ARGV[0] ; 

while (<STDIN>) {
  chomp ;
  if (!$_ || /^\s*#/) {
    next ; 
  }
#rect 222 436,81 520,171
  if (/^rect/) {
    tr/ / /s ;
    ($t,$url,$p1,$p2) = split(/ /) ;
    ($x1,$y1) = split(/,/,$p1) ;
    ($x2,$y2) = split(/,/,$p2) ;
    $x = int(($x1+$x2)/2) ;
    $y = int(($y1+$y2)/2) ;
    print "$bldg:$url         +$x+$y\n" ;
    next ;
  }
#poly 222 450,27 451,63 436,63 432,146 466,151 484,152 483,174 563,173 561,108 51
  if (/^poly/) {
    $sx = 0 ; $sy = 0 ;
    tr/ / /s ;
    ($t,$url,@p) = split(/ /) ;
    for ($i=0;$i<@p;$i++) {
      ($x,$y) = split(/,/,$p[$i]) ;
      $sx += $x ; $sy += $y ;
    }
    $sx /= @p ; $sy /= @p ; # get means
    $x = int($sx) ; $y - int($sy) ;
    print "$bldg:$url         +$x+$y\n" ; 
    next ;
  }
  print STDERR "Unimplemented $_\n" ;
}
