]> granicus.if.org Git - graphviz/commitdiff
Add opp() helper function to make it simpler to get the "other side" of
authorEmden Gansner <erg@research.att.com>
Wed, 5 Sep 2012 19:07:48 +0000 (15:07 -0400)
committerEmden Gansner <erg@research.att.com>
Wed, 5 Sep 2012 19:07:48 +0000 (15:07 -0400)
an edge.

cmd/gvpr/gvpr.1
lib/gvpr/compile.c
lib/gvpr/gprdata

index 7833480a361b987e6f32bce72687cfdbb49d4ae0..cb7b8f65e7a10080250119655882504a804edc8c 100644 (file)
@@ -471,6 +471,12 @@ returns the next edge after \fIe\fP in the root graph.
 .TP
 \fBnxtedge_sg\fP(\fIsg\fP : \fBgraph_t\fP, \fIe\fP : \fBedge_t\fP, \fBnode_t\fP) : \fBedge_t\fP
 returns the next edge after \fIe\fP in the graph \fIsg\fP.
+.TP
+\fBopp\fP(\fIe\fP : \fBedge_t\fP, \fBnode_t\fP) : \fBnode_t\fP
+returns the node on the edge \fIe\fP not equal to \fIn\fP.
+Returns NULL if \fIn\fP is not a node of \fIe\fP.
+This can be useful when using \fBfstedge\fP and \fBnxtedge\fP
+to enumerate the neighbors of \fIn\fP.
 .SS "Graph I/O"
 .TP
 \fBwrite\fP(\fIg\fP : \fBgraph_t\fP) : \fBvoid\fP
index 73041c8390ae3dbeece294e13ef65ef92c4bfbff..18cd13eaa109e25a5529974db7f1b9f5609172d0 100644 (file)
@@ -888,6 +888,23 @@ getval(Expr_t * pgm, Exnode_t * node, Exid_t * sym, Exref_t * ref,
            } else
                v.integer = PTR2INT(addEdge(gp, ep, 1));
            break;
+       case F_opp:
+           ep = INT2PTR(Agedge_t *, args[0].integer);
+           np = INT2PTR(Agnode_t *, args[1].integer);
+           if (!ep) {
+               error(ERROR_WARNING, "NULL edge passed to opp()");
+               v.integer = 0;
+           } else if (!np) {
+               error(ERROR_WARNING, "NULL node passed to opp()");
+               v.integer = 0;
+           } else {
+               if (aghead(ep) == np)
+                   np = agtail(ep);
+               else
+                   np = aghead(ep);
+               v.integer = PTR2INT(np);
+           }
+           break;
        case F_isedge:
            key = args[2].string;
            if (*key == '\0')
index 595a7729e6868ed571c478853ee592b0bf5f4d17..b02fc39f472c9882589386bdd7e0742cd8934450 100644 (file)
@@ -47,6 +47,7 @@ F_isin      "isIn"         FUNCTION I|A(1,G)|A(2,O)
 F_edge      "edge"         FUNCTION E|A(1,V)|A(2,V)|A(3,S)
 F_edgesg    "edge_sg"      FUNCTION E|A(1,G)|A(2,V)|A(3,V)|A(4,S)
 F_addedge   "subedge"      FUNCTION E|A(1,G)|A(2,E)
+F_opp       "opp"          FUNCTION V|A(1,E)|A(2,V)
 F_fstout    "fstout"       FUNCTION E|A(1,V)
 F_nxtout    "nxtout"       FUNCTION E|A(1,E)
 F_fstin     "fstin"        FUNCTION E|A(1,V)