Class: EdgeList

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby3mf/edge_list.rb

Instance Method Summary collapse

Constructor Details

#initializeEdgeList

Returns a new instance of EdgeList.



3
4
5
# File 'lib/ruby3mf/edge_list.rb', line 3

def initialize
  @edges = { }
end

Instance Method Details

#add_edge(first_vertex, second_vertex) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ruby3mf/edge_list.rb', line 7

def add_edge(first_vertex, second_vertex)
  if first_vertex < second_vertex
    edge = "#{first_vertex}:#{second_vertex}"
  else
    edge = "#{second_vertex}:#{first_vertex}"
  end

  (pos_count, neg_count) = @edges[edge]

  if pos_count == nil or neg_count == nil
    pos_count = 0
    neg_count = 0
  end

  pos_count += 1 if first_vertex < second_vertex
  neg_count += 1 if second_vertex < first_vertex

  @edges[edge] = [pos_count, neg_count]
end

#edge_count(first_vertex, second_vertex) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/ruby3mf/edge_list.rb', line 27

def edge_count(first_vertex, second_vertex)
  if first_vertex < second_vertex
    edge = "#{first_vertex}:#{second_vertex}"
  else
    edge = "#{second_vertex}:#{first_vertex}"
  end

  @edges[edge]
end


37
38
39
40
41
42
# File 'lib/ruby3mf/edge_list.rb', line 37

def print_list
  @edges.each do |key, value|
    (pos, neg) = value
    puts "#{pos} : #{neg}"
  end
end

#verify_edgesObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ruby3mf/edge_list.rb', line 44

def verify_edges
  @edges.each do |key, value|
    (pos, neg) = value

    if (pos > 1 and neg == 0) or (pos == 0 and neg > 1)
      return :bad_orientation
    elsif pos + neg == 1
      return :hole
    elsif pos != 1 or neg != 1
      return :nonmanifold
    end
  end

  :ok
end