chiark / gitweb /
wip break out edge_id_to_other_id
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 14 Jan 2019 15:51:47 +0000 (15:51 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 14 Jan 2019 15:51:47 +0000 (15:51 +0000)
parse-input-graph

index 69dc87ef7febb94113a13fef7d91775c41d1372e..e65df4156e811902ad3bffcdfc4c9a618395b4c0 100755 (executable)
@@ -146,6 +146,20 @@ sub adjacencies () {
   print STDERR "total $ndikes dikes\n";
 }
 
+sub edge_id_to_other_id ($$) {
+  my ($ra, $adjia) = @_;
+  my $adjsa = $region{$ra}{Adj};
+  my $adja = $adjsa->[$adjia];
+  my $rb = $adja->{Name};
+  my $adjsb = $region{$rb}{Adj};
+  foreach my $adjib (0..$#$adjsb) {
+    my $adjb = $adjsb->[$adjib];
+    next unless $adjb->{Name} eq $ra;
+    return ($rb, $adjib);
+  }
+  confess "$ra $adjia ?";
+}
+
 sub dual () {
   # We want to turn the graph from a graph on the regions, to
   # one where the nodes are the vertices of region boundaries.
@@ -165,27 +179,23 @@ sub dual () {
   foreach my $ra (sort keys %region) {
     my $adjsa = $region{$ra}{Adj};
     foreach my $adjia (0..$#$adjsa) {
+      my ($rb, $adjib) = edge_id_to_other_id($ra, $adjia);
       my $adja = $adjsa->[$adjia];
       my $va = "$ra # $adjia";
       # $va is the vertex at the anticlockwise end
       # of edge no.$adjia of region $ra
-      my $rb = $adja->{Name};
       next if ($rb eq 'L' or $rb eq 'NZ') and
              ($ra eq 'L' or $ra eq 'NZ');
       # $rb is the region on the other side of that edge
       my $adjsb = $region{$rb}{Adj};
-      foreach my $adjib (0..$#$adjsb) {
-       my $adjb = $adjsb->[$adjib];
-       next unless $adjb->{Name} eq $ra;
-       # $adjb is the same edge seen from the other side
-       my $adjibc = ($adjib + 1) % @$adjsb;
-       my $vb = "$rb # $adjibc";
-       # $vb is the vertex at the *clockwise* end
-       # of that same edge, which is edge no $adjib of region $rb
-       print STDERR "vertex $va = $vb\n";
-       $g->add_edge($va,$vb);
-       last;
-      }
+      # $adjb is the same edge seen from the other side
+      my $adjibc = ($adjib + 1) % @$adjsb;
+      my $vb = "$rb # $adjibc";
+      # $vb is the vertex at the *clockwise* end
+      # of that same edge, which is edge no $adjib of region $rb
+      print STDERR "vertex $va = $vb\n";
+      $g->add_edge($va,$vb);
+      last;
     }
   }
   my %edgeid2vi;