Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.


In reply to Bad index while coercing array into hash by rbc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-03-29 15:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found