File: Wire.pm

package info (click to toggle)
polymake 3.0r2-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 19,752 kB
  • ctags: 30,928
  • sloc: cpp: 151,785; perl: 32,510; ansic: 3,597; java: 2,654; python: 278; makefile: 181; xml: 103; sh: 79
file content (108 lines) | stat: -rw-r--r-- 3,272 bytes parent folder | download
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#  Copyright (c) 1997-2015
#  Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
#  http://www.polymake.org
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version: http://www.gnu.org/licenses/gpl.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#-------------------------------------------------------------------------------

###############################################################################
#
#  Common base for Visual::Wire and Visual::Graph

package Visual::WireBase;

use Polymake::Struct (
   [ '@ISA' => 'PointSet' ],
   [ '$EdgeColor' => 'unify_edge_decor(#%)', merge => 'unify_edge_decor(#%)', default => '$Visual::Color::edges' ],
   [ '$EdgeThickness' => 'unify_edge_decor(#%)', merge => 'unify_edge_decor(#%)', default => 'undef' ],
   [ '$EdgeLabels' => 'unify_edge_labels(#%)', default => '"hidden"' ],
   [ '$EdgeStyle' => 'unify_edge_decor(#%)', merge => 'unify_edge_decor(#%)', default => 'undef' ],
);

#  the same as Visual::unify_decor, but with extra dereferencing
#  in the cases of array and hash access.

sub unify_edge_decor {
   my ($name, $decor, $default)=@_;
   my $unified;
   if (is_container($decor)) {
      $unified=&unify_decor;
      sub { $unified->(${$_[0]}) }
   } elsif (is_hash($decor)) {
      if (is_code($default)) {
         # assuming that $default was already filtered thru unify_edge_decor,
         # we must avoid repeated dereferencing
         $unified=unify_decor($name,$decor);
         sub { $unified->(${$_[0]}) // &$default }
      } else {
         $unified=&unify_decor;
         sub { $unified->(${$_[0]}) }
      }
   } else {
      &unify_decor
   }
}

sub unify_edge_labels {
   my ($name, $labels)=@_;
   if (is_code($labels)) {
      $labels
   } else {
      $labels=&unify_labels
      and sub { $labels->(${$_[0]}) }
   }
}

sub ArrowStyle { undef }

###############################################################################

package Visual::Wire::EdgeIterator;
use Polymake::Struct (
   [ new => '$' ],
   [ '@edges' => '#1' ],
   [ '$index' => '0' ],
   [ '$end' => '$#{ #1 }' ],
);

use overload
   bool => sub { my $self=shift; $self->index <= $self->end },
   '++' => sub { $_[0]->index++ },
   '""' => sub { $_[0]->index },
   '${}' => sub { \($_[0]->index) },
   '@{}' => sub { my $self=shift; $self->edges->[$self->index] },
   '=' => sub { bless [ @{(shift)} ] },
   falback => 0;


package Visual::Wire;
use Polymake::Struct (
   [ '@ISA' => 'WireBase' ],
   [ '$Edges' => 'check_edges(#%)', default => 'croak("Edges missing")' ],
);

sub check_edges {
   my ($name, $edges)=@_;
   is_array($edges) ? $edges : croak( "$name is not an array" );
}

sub n_nodes { scalar(@{(shift)->Vertices}) }
sub n_edges { scalar(@{(shift)->Edges}) }

sub all_edges { new EdgeIterator((shift)->Edges) }


1

# Local Variables:
# cperl-indent-level:3
# indent-tabs-mode:nil
# End: