Schrift
[thread]3251[/thread]

perl highlight

Leser: 1


<< |< 1 2 3 >| >> 26 Einträge, 3 Seiten
esskar
 2003-08-11 16:32
#31699 #31699
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
Code (perl): (dl )
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use strict;

my @x = (0, 2, 4);
my @y = (0, 2, 0);

my &#36polygon =  { x=>\@x, y=>\@y };
my &#36point1 =  { x=>2, y=>1 };
my &#36point2 =  { x=>5, y=>5 };
my &#36point3 =  { x=>1, y=>1 };

sub min
{
    return &#36_[0] < &#36_[1] ? &#36_[0] : &#36_[1];
}

sub max
{
    return &#36_[0] > &#36_[1] ? &#36_[0] : &#36_[1];
}

sub isInside
{
    # return values: -1 == draussen, 0 == auf Kante , 1 == innerhalb
   my &#36polygon = shift;
   my &#36point = shift;

   my &#36nPPoints = 0;
      
   return -1 if((&#36nPPoints = scalar(@{&#36polygon->{x}})) != scalar(@{&#36polygon->{y}}));   
   return -1 unless &#36nPPoints;
   
   my &#36x = &#36point->{x};
   my &#36y = &#36point->{y};
   my &#36ax = &#36polygon->{x}->[&#36nPPoints-1];
   my &#36ay = &#36polygon->{y}->[&#36nPPoints-1];
   my &#36lx = &#36ax;
   my(&#36bx, &#36by) = (0, 0);
   my(&#36count, &#36ignore, &#36zx) = (0, 0, 0);

   for my &#36i (0..&#36nPPoints-1)
   {
      &#36bx = &#36polygon->{x}->[&#36i];
      &#36by = &#36polygon->{y}->[&#36i];
      
      if(!&#36ignore)
      {
         if(&#36by == &#36y and &#36bx>=&#36x)
         {
            return 0 if &#36bx == &#36x;
            &#36ignore = 1;
         }
         else
         {
            if((&#36ay < &#36y) == (&#36y < &#36by))
            {
               if(&#36x < min(&#36ax, &#36bx)) { &#36count++; }
               elsif(&#36x > max(&#36ax, &#36bx)) {}
               elsif(&#36x < (&#36zx = ((&#36bx-&#36ax)*(&#36y-&#36ay)/(&#36by-&#36ay))+&#36ax)) { &#36count++; }
               elsif(&#36zx == &#36x) { return 0; }               
 
            }
            &#36ax = &#36bx; &#36ay = &#36by;
         }
      }
      else
      {
          if(&#36by == &#36y)
          {
              return 0 if(((&#36lx < &#36x) == (&#36x<&#36bx)) or &#36bx == &#36x);
          }
          else
          {
              &#36count++ if((&#36ay < &#36y) == (&#36y < &#36by));
              &#36ignore = 0;
              &#36ax = &#36bx; &#36ay = &#36by;
          }                    
      }
      &#36lx = &#36bx;
   }    
   
   return (&#36count & 1) ? 1 : -1;
}

print "Point1: ", isInside(&#36polygon, &#36point1),"\n"; 
print "Point2: ", isInside(&#36polygon, &#36point2),"\n";
print "Point3: ", isInside(&#36polygon, &#36point3),"\n";
\n\n

<!--EDIT|esskar|1060617662-->
Robby
 2003-08-11 17:11
#31700 #31700
User since
2003-08-11
409 Artikel
BenutzerIn
[default_avatar]
*schick* gefällt mir was ihr hier mit dem Forum macht!
Weiter so! 8)
Kaum macht man es richtig - schon funktioniert es!
esskar
 2003-08-11 16:45
#31701 #31701
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
naja...
ist noch nicht vollendet...
aber ich arbeite dran! ;)
pq
 2003-08-11 17:40
#31702 #31702
User since
2003-08-04
12208 Artikel
Admin1
[Homepage]
user image
ups... eingegeben:
Code: (dl )
1
2
print abs / 0; # is this a comment?/;
print time / 1; # is this a comment?/;

heraus kommt:
Code (perl): (dl )
1
2
print abs / 0; # is this a comment?/;
print time / 1; # is this a comment?/;


:ghostface:

Edit: ah, schon okay, in der vorschau war da noch ein
color:red oder so drin.
ist trotzdem verkehrt gehighlighted =)\n\n

<!--EDIT|esskar|1060617697-->
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem
esskar
 2003-08-11 17:45
#31703 #31703
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
@pq: ich arbeite dran!
pq
 2003-08-11 18:08
#31704 #31704
User since
2003-08-04
12208 Artikel
Admin1
[Homepage]
user image
[quote=esskar,11.08.2003, 15:45]@pq: ich arbeite dran![/quote]
ich glaub, besser kannst du's nicht machen. welchen
highlighter benutzt du denn?

(dass es in der vorschau falsch erscheint, ist ja nicht so schlimm.)\n\n

<!--EDIT|pq|1060610968-->
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem
esskar
 2003-08-11 18:13
#31705 #31705
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
[quote=pq,11.08.2003, 16:08]ich glaub, besser kannst du's nicht machen. welchen
highlighter benutzt du denn?[/quote]
- oh doch...
- meinen
Ishka
 2003-08-11 18:15
#31706 #31706
User since
2003-08-04
771 Artikel
HausmeisterIn
[Homepage] [default_avatar]
den ausm Perled?
sub z{if(@_){1while$x[$k=rand 10];t($t=$x[$k]=1)}print map"$z[$x[$_]]$_".($_%3?
"":"\n"),1..9}sub t{$j=0;$x[$_+1]==$t&&($j+=2**$_)for 0..8;z,die"Gewinner $z[$t]
"if grep$_==($j&$_),7,56,73,84,146,273,292,448;z,die"Gleichstand\n"if@x>9&&!grep
!$_,@x}@x=4;@z=qw{. [ (};z$^T&1;while(<>){next if$_>9||$x[$_];t$t=$x[$_]=2;z 1}
esskar
 2003-08-11 18:19
#31707 #31707
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
[quote=Ishka,11.08.2003, 16:15]den ausm Perled?[/quote]
neee...
der wär zu langsam!
pq
 2003-08-11 18:20
#31708 #31708
User since
2003-08-04
12208 Artikel
Admin1
[Homepage]
user image
[quote=esskar,11.08.2003, 16:13][quote=pq,11.08.2003, 16:08]ich glaub, besser kannst du's nicht machen. [/quote]
- oh doch...[/quote]
wenn du es schaffst, obiges snippet korrekt zu highlighten (also
eine zeile hat einen kommentar, die andere nicht), kriegst
du 'nen preis =)
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem
<< |< 1 2 3 >| >> 26 Einträge, 3 Seiten



View all threads created 2003-08-11 16:32.