Dear Monks,
I am stumped. What am I doing wrong here.
#!/usr/bin/perl -w
use lib ( '../Vector2D' );
use Vector2D;
my $POLYGONS_MAX_Y = 11;
my $A = new Vector2D( 2, 3 );
my $B = new Vector2D( 7, 1 );
my $C = new Vector2D( 13, 5 );
my $D = new Vector2D( 13, 11 );
my $E = new Vector2D( 7, 7 );
my $F = new Vector2D( 2, 9 );
my @AB = [ $A, $B ];
my @BC = [ $B, $C ];
my @CD = [ $C, $D ];
my @DE = [ $D, $E ];
my @EF = [ $E, $F ];
my @FA = [ $F, $A ];
my @polygon = ( @AB, @BC, @CD, @DE, @EF, @FA );
my @ET; # global Edge Table
# each entry in the ET contains the Ymax coordinate of the edge,
# the x cooridnate of the bottom endpoint Xbot and the x increment
# used in the stepping from one scan lime to the next 1/m
for my $edge (@polygon) {
my $y = ( @{$edge}->[0]->gety() < @{$edge}->[1]->gety() )
+? @{$edge}->[0]->gety() : @{$edge}->[1]->gety() ;
my $Ymax = ( @{$edge}->[0]->gety() >= @{$edge}->[1]->gety() )
+? @{$edge}->[0]->gety() : @{$edge}->[1]->gety() ;
my $Xbot = ( @{$edge}->[0]->gety() < @{$edge}->[1]->gety() )
+? @{$edge}->[0]->getx() : @{$edge}->[1]->getx() ;
my $invSlope = &calcOneOverSlope($edge);
my $rec = {
Ymax => $Ymax,
Xbot => $Xbot,
invSlope => $invSlope
};
print "$y -> $Ymax | $Xbot | $invSlope\n";
push( @{$ET[$y]}, $rec );
}
for my $i (1..$POLYGONS_MAX_Y) {
if ( $ET[$i] ) {
print "ET[$i] = ";
for my $r ( ${ET[$i]} ) {
print "{" . $r->{Ymax} . "|" . $r->{Xbot} . "|
+" . $r->{invSlope} . "}" ;
}
print "\n";
} else {
print "ET[$i] = NULL\n";
}
}
sub calcOneOverSlope {
my $edge = shift;
my $y = @{$edge}->[0]->gety()-@{$edge}->[1]->gety();
my $x = @{$edge}->[0]->getx()-@{$edge}->[1]->getx();
if ( $y == 0 ) { return undef; }
return $x/$y;
}
When I execute this I get the following output and error message.
$ ./buildET.pl
1 -> 3 | 7 | -2.5
1 -> 5 | 7 | 1.5
5 -> 11 | 13 | 0
7 -> 11 | 7 | 1.5
7 -> 9 | 7 | -2.5
3 -> 9 | 2 | 0
Use of uninitialized value in concatenation (.) or string at ./buildET.pl line 49.
Use of uninitialized value in concatenation (.) or string at ./buildET.pl line 49.
Bad index while coercing array into hash at ./buildET.pl line 49.
ET(1] =
I had hoped that the output would look like this ...
ET(1] = {3 | 7 | -2.5} {5 | 7 | 1.5}
ET(2] = NULL
ET(3] = {9 | 2 | 0}
ET(4] = NULL
ET(5] = {11 | 13 | 0}
ET(6] = NULL
ET(7] = {11 | 7 | 1.5} {7 -> 9 | 7 | -2.5}
ET(8] = NULL
...
ET(20] = NULL
Line 49 is this line ...
print "{" . $r->{Ymax} . "|" . $r->{Xbot} . "|" . $r->{invSlope} . "}" ;
Thanks
Edited:
~Fri Sep 27 15:05:17 2002 (GMT)
by footpad: s/<PRE>/<CODE>/; in last code line, per Consideration.