stu96art has asked for the wisdom of the Perl Monks concerning the following question:
the list comes in going clockwise, but my algorithm changes it because the next x-value after the greatest y-value is less than the x-value of the greatest y-value. Any help would be much appreciated. Thanks| ^ | / / | / | | --- ---------
my ($highest, $hv, $xclock, $negx); my @backwards; # MAKE CLOCKWISE ************************************* CLK: for $i (0..$#blocks) { $highest = 0; for $j (0..$#{$blocks[$i]}) { if ($blocks[$i][$j][2] > $highest) { $highest = $blocks[$i][$j][2]; $hv = $j; } } if ($hv == 0) { print "zero [$i][$i][$i][$i][$i]\n"; $xclock = $blocks[$i][($hv + 1)][1] - $blocks[$i][$hv][1]; if ($xclock == 0) { $xclock = $blocks[$i][($hv + 2)][1] - $blocks[$i][$hv][1]; } $negx = $blocks[$i][$hv][1] - $blocks[$i][($#{$blocks[$i]} - 1 +)][1]; print "00000 blk [$i][$hv] clkwise [$xclock], [$negx]\n"; if ($xclock == 0) { print "xclock 0 \n"; if ($negx < 0) { print "change xclock 000\n"; @backwards = reverse @{$blocks[$i]}; for $k (0..$#backwards) { print "xcl0000 [$k][1] $backwards[$k][1]\n"; print "xcl0000 [$k][2] $backwards[$k][2]\n"; } @{$blocks[$i]} = @backwards; next CLK; } } if (($xclock < 0) ) { print "change 000\n"; @backwards = reverse @{$blocks[$i]}; for $k (0..$#backwards) { print "0000 [$k][1] $backwards[$k][1]\n"; print "0000 [$k][2] $backwards[$k][2]\n"; } @{$blocks[$i]} = @backwards; next CLK; } } $xclock = $blocks[$i][($hv + 1)][1] - $blocks[$i][$hv][1]; if ($xclock == 0) { $xclock = $blocks[$i][($hv + 2)][1] - $blocks[$i][$hv][1]; } $negx = $blocks[$i][$hv][1] - $blocks[$i][($hv - 1)][1]; print "BBBBBBBBBB [$i][$i][$i]\n"; print "blk [$i][$hv] clkwise [$xclock], [$negx]\n"; if (($xclock < 0) || ($negx < 0)) { print "change reg\n"; @backwards = reverse @{$blocks[$i]}; for $k (0..$#backwards) { print "[$k][1] $backwards[$k][1]\n"; print "[$k][2] $backwards[$k][2]\n"; } @{$blocks[$i]} = @backwards; next CLK; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Making CLOCKWISE work (off by one)
by tye (Sage) on Feb 21, 2003 at 20:53 UTC | |
|
Re: Making CLOCKWISE work
by BrowserUk (Patriarch) on Feb 21, 2003 at 23:15 UTC | |
|
Re: Making CLOCKWISE work
by atcroft (Abbot) on Feb 21, 2003 at 20:17 UTC | |
|
Re: Making CLOCKWISE work
by tall_man (Parson) on Feb 21, 2003 at 21:51 UTC | |
|
Re: Making CLOCKWISE work
by Thelonius (Priest) on Feb 21, 2003 at 20:30 UTC | |
|
Re: Making CLOCKWISE work
by extremely (Priest) on Feb 21, 2003 at 23:43 UTC |