Class: LemonGraph::Graph::Edge

Inherits:
LemonGraph::GraphItem show all
Defined in:
ext/lemongraph/graph_edge.cc,
ext/lemongraph/lemongraph.cc

Overview

Edge of a LemonGraph::Graph, between two Nodes u and v.

Instance Attribute Summary

Attributes inherited from LemonGraph::GraphItem

#graph, #id

Instance Method Summary collapse

Methods inherited from LemonGraph::GraphItem

#!=, #<=>, #==

Instance Method Details

#arc1Arc

Returns the Arc that represents the edge and whose direction is the same as the inherent orientation of self (from u to v).

Returns:



134
135
136
137
138
139
# File 'ext/lemongraph/graph_edge.cc', line 134

VALUE lemongraph_unedge_arc1(VALUE self)
{
  VALUE g = rb_iv_get(self, "@graph");
  lemon::ListGraph::Arc a = lemongraph_graph_rb2ref(g).direct(lemongraph_rbunedge2unedge(self), true);
  return lemongraph_make_unarc(a, g);
}

#arc2Arc

Returns the Arc that represents the edge and whose direction is the opposite as the inherent orientation of self (so, from v to u).

Returns:



146
147
148
149
150
151
# File 'ext/lemongraph/graph_edge.cc', line 146

VALUE lemongraph_unedge_arc2(VALUE self)
{
  VALUE g = rb_iv_get(self, "@graph");
  lemon::ListGraph::Arc a = lemongraph_graph_rb2ref(g).direct(lemongraph_rbunedge2unedge(self), false);
  return lemongraph_make_unarc(a, g);
}

#eraseself

Erases the edge from the graph it belongs to.

Returns:

  • (self)


56
57
58
59
60
# File 'ext/lemongraph/graph_edge.cc', line 56

VALUE lemongraph_unedge_erase(VALUE self)
{
  lemongraph_graph_rb2ref(rb_iv_get(self, "@graph")).erase(lemongraph_rbunedge2unedge(self));
  return self;
}

#uNode

Returns the first node of the edge.

Returns:



75
76
77
78
79
80
# File 'ext/lemongraph/graph_edge.cc', line 75

VALUE lemongraph_unedge_u(VALUE self)
{
  VALUE g = rb_iv_get(self, "@graph");
  lemon::ListGraph::Node n = lemongraph_graph_rb2ref(g).u(lemongraph_rbunedge2unedge(self));
  return lemongraph_make_unnode(n, g);
}

#u=(node) ⇒ node

Changes the first node of the edge to node.

Parameters:

  • node (Node)

    the edge's new u node

Returns:

  • (node)


98
99
100
101
102
103
104
105
106
107
108
109
# File 'ext/lemongraph/graph_edge.cc', line 98

VALUE lemongraph_unedge_change_u(VALUE self, VALUE node)
{
  if (rb_class_of(node) != c_UnNode) {
    rb_raise(rb_eTypeError, "expecting a %" PRIsVALUE ", not a %s",
        rb_class_name(c_UnNode), rb_obj_classname(node));
  }
  VALUE graph = rb_iv_get(self, "@graph");
  if (rb_iv_get(node, "@graph") != graph)
    rb_raise(rb_eRuntimeError, "edge and node not from the sams graph");
  lemongraph_graph_rb2ref(graph).changeU(lemongraph_rbunedge2unedge(self), lemongraph_rbunnode2unnode(node));
  return self;
}

#vNode

Returns the second node of the edge.

Returns:



86
87
88
89
90
91
# File 'ext/lemongraph/graph_edge.cc', line 86

VALUE lemongraph_unedge_v(VALUE self)
{
  VALUE g = rb_iv_get(self, "@graph");
  lemon::ListGraph::Node n = lemongraph_graph_rb2ref(g).v(lemongraph_rbunedge2unedge(self));
  return lemongraph_make_unnode(n, g);
}

#v=(node) ⇒ node

Changes the second node of the edge to node.

Parameters:

  • node (Node)

    the edge's new v node

Returns:

  • (node)


116
117
118
119
120
121
122
123
124
125
126
127
# File 'ext/lemongraph/graph_edge.cc', line 116

VALUE lemongraph_unedge_change_v(VALUE self, VALUE node)
{
  if (rb_class_of(node) != c_UnNode) {
    rb_raise(rb_eTypeError, "expecting a %" PRIsVALUE ", not a %s",
        rb_class_name(c_UnNode), rb_obj_classname(node));
  }
  VALUE graph = rb_iv_get(self, "@graph");
  if (rb_iv_get(node, "@graph") != graph)
    rb_raise(rb_eRuntimeError, "edge and node not from the sams graph");
  lemongraph_graph_rb2ref(graph).changeV(lemongraph_rbunedge2unedge(self), lemongraph_rbunnode2unnode(node));
  return self;
}

#valid?Boolean

Test if the edge is valid, i.e. it is a real edge of the graph it belons to.

Returns:

  • (Boolean)


66
67
68
69
# File 'ext/lemongraph/graph_edge.cc', line 66

VALUE lemongraph_unedge_is_valid(VALUE self)
{
  return lemongraph_graph_rb2ref(rb_iv_get(self, "@graph")).valid(lemongraph_rbunedge2unedge(self)) ? Qtrue : Qfalse;
}