if ($dist <= getdistance($pref->[$idx-1], $pref->[$idx], $pt))
1 2 3 4 5 6 7 8 9 10 11 12 13 14
$VAR1 = [ [ '0', '0' ], [ '3', '2' ], [ 1, 1 ] ];
1 2 3 4
my ($p0,$p1,$pt)=shift; print Dumper($p0); print Dumper($p1); print Dumper($pt);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#!c:\strawberry\perl\bin\perl.exe -w use diagnostics; use autodie; use Data::Dumper; use Getopt::Long; # We process long commandline options, better to read, longer time to think over it. use Config::Tiny; # simple configurations use Math::Polygon::Calc; use CAD::Calc; use strict; print "huhu\n"; #my $poly = Math::Polygon->new( [0, 0], [3, 2], [2, 3.5], [0.5, 6], [0, 8], [-0.5, 6], [-2, 3.5], [-3, 2], [0, 0]); my @apoly = ( [0, 0], [3, 2], [2, 3.5], [0.5, 6], [0, 8], [-0.5, 6], [-2, 3.5], [-3, 2], [0, 0]); my $bpoly=\@apoly; print "\n"; if (checkforoffset($bpoly,[0,1],0.1)) { print "1,1: drin\n"; } else { print "1,1: draußen\n"; } exit 0; sub checkforoffset { my $pref=shift; my $pt=shift; my $dist=shift; print "checkforoffset called:\n"; print Dumper($pref); for (my $idx=1; $idx < scalar(@$pref); ++$idx) { my $ldist=getdistance($pref->[$idx-1], $pref->[$idx], $pt); print "dist $ldist \n"; if ($dist >= $ldist) { return (1==0); } } return (1==1); } sub getdistance { print "getdistance called:\n"; print Dumper(\@_); my ($p0,$p1,$pt)=shift; print Dumper($p0); print Dumper($p1); print Dumper($pt); my $vx=$p1->[0]-$p0->[0]; my $vy=$p1->[1]-$p0->[0]; print "$vx $vy \n"; return ( abs($vy*$pt->[0] - $vx*$pt->[1] + $p1->[0]*$p0->[1] - $p1->[1]*$p0->[0]) / sqrt($vy**2 + $vx**2) ); }
my ($p0, $p1, $pt) = @_;
my ($p0,$p1,$pt)=shift;
my ($p0,$p1,$pt)=(shift,shift,shift);
my ($p0,$p1,$pt)=@_;
QuoteSeit wann schiebt denn shift alle drei übergebenen Parameter in die Variablen? Was für eine Perl-Version kann das?
Quotehttp://perldoc.perl.org/functions/shift.htmlshift
Shifts the first value of the array off and returns it, shortening the array by 1 and moving everything down. If there are no elements in the array, returns the undefined value. If ARRAY is omitted, shifts the @_ array within the lexical scope of subroutines and formats, and the @ARGV array outside a subroutine and also within the lexical scopes established by the eval STRING , BEGIN {} , INIT {} , CHECK {} , UNITCHECK {} , and END {} constructs.
Starting with Perl 5.14, an experimental feature allowed shift to take a scalar expression. This experiment has been deemed unsuccessful, and was removed as of Perl 5.24.
See also unshift, push, and pop. shift and unshift do the same thing to the left end of an array that pop and push do to the right end.