Class: Zadt::FaceGraph
- Defined in:
- lib/zadt/AbstractDataTypes/Graph/face_graph.rb
Instance Attribute Summary collapse
-
#faces ⇒ Object
readonly
Made up of.
Attributes inherited from Graph
Class Method Summary collapse
Instance Method Summary collapse
-
#add_attached_face(vertex_array, num_edges) ⇒ Object
This adds a face that will be attached to the given vertices Make sure the vertices are connected, or it will raise an error All new vertices and edges will be created This will automatically make_neighbors with any faces that share a vertex with the new face.
- #add_face(edges_array) ⇒ Object
-
#find_face_neighbors(face) ⇒ Object
Neighbor is defined as sharing a vertex, not necessarily sharing an edge.
-
#find_neighbors(vertex_array) ⇒ Object
Return all faces containing the given vertices.
- #help ⇒ Object
-
#initialize ⇒ FaceGraph
constructor
Contains attr_accessor :value.
-
#make_original_face(num_edges) ⇒ Object
Makes a face with num_edges edges, which will be attached to nothing.
- #methods ⇒ Object
Methods inherited from Graph
#add_vertex, #break_connection, #find_connection, #is_connected?, #make_connection, #remove_vertex
Constructor Details
#initialize ⇒ FaceGraph
Contains attr_accessor :value
13 14 15 16 17 |
# File 'lib/zadt/AbstractDataTypes/Graph/face_graph.rb', line 13 def initialize #@faces is ALL faces on the graph @faces = [] super end |
Instance Attribute Details
#faces ⇒ Object (readonly)
Made up of
7 8 9 |
# File 'lib/zadt/AbstractDataTypes/Graph/face_graph.rb', line 7 def faces @faces end |
Class Method Details
.help ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/zadt/AbstractDataTypes/Graph/face_graph.rb', line 133 def self.help puts "Here are the functions for FaceGraph:" puts "#add_face(edges_array), makes a face with the given edges (must be cyclicly connected)" puts "#make_original_face(num_edges), which makes a standard disconnected face" puts "#add_attached_face(vertex_array, num_edges), which adds a face connected to the vertex_array" puts "#find_neighbors(vertex_array), lists all faces containing the given vertices" puts "#find_face_neighbors(vertex_array), which finds all neighbors of the given face" puts "--a neighbor of a face is defined as one that shares a vertex (not necessarily an edge)" puts "#make_vertex_line(vertex_array), reorders a list of connected vertices by connection sequence" puts "" puts "FaceGraph also inherits the following functions from Graph:" puts "#add_vertex" puts "#remove_vertex(vertex)" puts "#make_connection(v1,v2), adds an edge between two vertices" puts "#break_connection(v1,v2)" puts "#find_connection(v1,v2), returns edge connecting two given vertices" puts "#is_connected?(v1,v2)" end |
.methods ⇒ Object
19 20 21 |
# File 'lib/zadt/AbstractDataTypes/Graph/face_graph.rb', line 19 def self.methods self.help end |
Instance Method Details
#add_attached_face(vertex_array, num_edges) ⇒ Object
This adds a face that will be attached to the given vertices
Make sure the vertices are connected, or it will raise an error
All new vertices and edges will be created This will automatically make_neighbors with any faces that share
a vertex with the new face
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 |
# File 'lib/zadt/AbstractDataTypes/Graph/face_graph.rb', line 56 def add_attached_face(vertex_array, num_edges) # Make the vertices into a line vertex_line = make_vertex_line(vertex_array) # This finds the "ends" of the vertex line end_vertices = [vertex_line.first, vertex_line.last] # Find the neighbors that will be added later new_neighbors = find_neighbors(vertex_array) # How many vertices and edges to be made vertices_to_make = num_edges - vertex_array.length edges_to_make = vertices_to_make + 1 # Make new vertices vert_ref = Array.new(vertices_to_make) {Vertex.new} edge_ref = [] # Connect new vertices in a line (edges_to_make - 2).times do |vert_id| # Connect each vertex to the one after it edge_ref << make_connection(vert_ref[vert_id], vert_ref[vert_id + 1]) end # Connect "ends" of new vertices to "ends" of vertex line (making a circuit) # Connect "first" of new vertices to "last end" of old ones edge_ref << make_connection(vert_ref.first, end_vertices.last) # Connect "last" of new vertices to "first end" of old ones edge_ref << make_connection(vert_ref.last, end_vertices.first) # Add edges from vertex_line to edge_ref (vertex_line.length - 1).times do |vert_id| edge_ref << find_connection(vertex_line[vert_id], vertex_line[vert_id + 1]) end face_border = edge_ref # Make a face out of the new circuit, and store it face = add_face(face_border) # Store the new vertices @vertices += vert_ref # Store the new edges @edges += edge_ref new_neighbors.each do |neighbor| # Add all the new_neighbors face.add_neighbor(neighbor) # Make this a neighbor to all new_neighbors neighbor.add_neighbor(face) end face end |
#add_face(edges_array) ⇒ Object
23 24 25 26 27 |
# File 'lib/zadt/AbstractDataTypes/Graph/face_graph.rb', line 23 def add_face(edges_array) face = Face.new(edges_array) @faces << face face end |
#find_face_neighbors(face) ⇒ Object
Neighbor is defined as sharing a vertex, not necessarily sharing an edge.
118 119 120 121 |
# File 'lib/zadt/AbstractDataTypes/Graph/face_graph.rb', line 118 def find_face_neighbors(face) neighbors = find_neighbors(face.vertices) neighbors - [face] end |
#find_neighbors(vertex_array) ⇒ Object
Return all faces containing the given vertices
105 106 107 108 109 110 111 112 113 |
# File 'lib/zadt/AbstractDataTypes/Graph/face_graph.rb', line 105 def find_neighbors(vertex_array) neighbors = [] vertex_array.each do |vertex| @faces.each do |face| neighbors << face if face.vertices.include?(vertex) end end neighbors.uniq end |
#help ⇒ Object
123 124 125 |
# File 'lib/zadt/AbstractDataTypes/Graph/face_graph.rb', line 123 def help FaceGraph.help end |
#make_original_face(num_edges) ⇒ Object
Makes a face with num_edges edges, which will be attached to nothing.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/zadt/AbstractDataTypes/Graph/face_graph.rb', line 30 def make_original_face(num_edges) # Make the vertices vert_ref = Array.new(num_edges) {Vertex.new} edge_ref = [] # Connect each vertex to the one before it (including the first one :) (num_edges).times do |vert_id| edge_ref << make_connection(vert_ref[vert_id - 1], vert_ref[vert_id]) end # Make the face and store it face = add_face(edge_ref) # Store the new vertices @vertices += vert_ref # Store the new edges @edges += edge_ref face end |
#methods ⇒ Object
127 128 129 |
# File 'lib/zadt/AbstractDataTypes/Graph/face_graph.rb', line 127 def methods help end |