zadt 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14d5d23662aa56e1c863e096a68657364b276574
4
- data.tar.gz: 10f4b9da70a96defbe4c75c2c4920b09a3dab714
3
+ metadata.gz: 8895ef5d94147f877d0ca9d14fe2a2cadd2a159c
4
+ data.tar.gz: f28233fd6801797e5f304cb54bdeadbc056f94d0
5
5
  SHA512:
6
- metadata.gz: 40eb3b8f4ab8ae3fa098838ba4416ef035c1f1bedd8bd5fa7aefb77f7fccc5dbe4d4853446c9f9a2569e8624cd361944f07f0b8c721dad03385d88d1646358f6
7
- data.tar.gz: cf59f864501efdc60b3388e337afddfcf4cc0bb0abac48127871715785590cbd81591899cb807b80b8f0571da69ad9df4b6e06c5cab9366f3cdd14451d418788
6
+ metadata.gz: 7cc9788cc828d6a52c1ed4bb9e3b47ba883450db9f953f607a96440e4a7e2c92febc4a2186d6c458f30cc8495283055884dbab3403dd970086b456ea9f57a39e
7
+ data.tar.gz: ac0158200268b0973ecbb8f1444bfc5c552fd371b922e8cb0d5d0be884f06ddb4f3282fae3c5a88c5679539d102bf5cb0701bd84e720b543c384c7f2dddebb1b
data/.DS_Store CHANGED
Binary file
data/README.md CHANGED
@@ -26,13 +26,63 @@ I also made a "help" function for each Data Type. Type Zadt::StackQueue.help ge
26
26
 
27
27
  And don't forget to require 'zadt' at the top!
28
28
 
29
- ### MinMaxStackQueue
29
+ ### Stacks and Queues
30
+
31
+ If you've never heard of a Stack or a Queue before, click [here](https://en.wikibooks.org/wiki/Data_Structures/Stacks_and_Queues) for an introduction.
30
32
 
31
33
  A MinMaxStackQueue is an Queue object that allows the minimum and maximum values to be found in constant time. It's built by making a Queue out of a Stack, which has that same min/max ability.
32
34
 
33
35
  Since it is made out of Queues and Stacks, those data types are also available. I also provided StackQueue (functionally the same as a Queue), and a MinMaxStack, which is a Stack version of MinMaxStackQueue.
34
36
 
35
- ### Graphs
37
+ #### Stack
38
+
39
+ My Stack has the following methods:
40
+ * show, returns the entire stack
41
+ * push(value), adds a value to the top of the stack
42
+ * pop, returns the value at the top of the stack, and removes it
43
+ * peek, returns the value at the top of the stack, but doesn't remove it
44
+ * length, number of values in the stack
45
+ * empty?, whether or not the stack is empty
46
+
47
+ #### Queue
48
+
49
+ My Queue has the following methods:
50
+ * show, returns the entire queue
51
+ * enqueue(value), adds a value to the back of the queue
52
+ * dequeue, returns the value at the front of the queue, and removes it
53
+ * peek, returns the value at the front of the queue, but doesn't remove it
54
+ * length, number of values in the queue
55
+ * empty?, whether or not the queue is empty
56
+
57
+ #### StackQueue
58
+
59
+ StackQueue has the same methodology as Queue
60
+
61
+ #### MinMaxStack
62
+
63
+ My MinMaxStack has the following methods:
64
+ * show, returns the entire stack
65
+ * push(value), adds a value to the top of the stack
66
+ * pop, returns the value at the top of the stack, and removes it
67
+ * peek, returns the value at the top of the stack, but doesn't remove it
68
+ * min, returns the lowest value of the stack. Works in constant time.
69
+ * max, returns the highest value of the stack. Works in constant time.
70
+ * length, number of values in the stack
71
+ * empty?, whether or not the stack is empty
72
+
73
+ #### MinMaxStackQueue
74
+
75
+ My MinMaxStackQueue has the following methods:
76
+ * show, returns the entire queue
77
+ * enqueue(value), adds a value to the back of the queue
78
+ * dequeue, returns the value at the front of the queue, and removes it
79
+ * peek, returns the value at the front of the queue, but doesn't remove it
80
+ * min, returns the lowest value of the queue. Works in constant time.
81
+ * max, returns the highest value of the queue. Works in constant time.
82
+ * length, number of values in the queue
83
+ * empty?, whether or not the queue is empty
84
+
85
+ ### Graph Objects
36
86
 
37
87
  A Graph is a data type that consists of Vertices, which are connected by Edges. In addition, a FaceGraph is a Graph which also consists of Faces: the space defined inside a set of cyclic edges.
38
88
 
@@ -55,10 +105,38 @@ A Graph has the following methods
55
105
  A FaceGraph has the following methods, in addition to its inheritance from Graph
56
106
  * add_face(edges_array), makes a face with the given edges (must be cyclicly connected)
57
107
  * make_original_face(num_edges), which makes a standard disconnected face
58
- * add_attached_face(vertex_array, num_edges), which adds a face connected to the vertex_array
108
+ * add_attached_face(vertex_array, num_edges), which adds a face connected to the vertex_array specified. Face will consist of the number of edges specified.
59
109
  * find_neighbors(vertex_array), lists all faces containing the given vertices
60
110
  * find_face_neighbors(face), which finds all neighbors of the given face. A neighbor of a face is defined as one that shares a vertex (not necessarily an edge)
61
- * make_vertex_line(vertex_array), reorders a list of connected vertices by connection sequence
111
+
112
+ ### Geometrics
113
+
114
+ Geometric objects, contained within a universe.
115
+
116
+
117
+ #### Universe
118
+
119
+ An universe is a Euclidean coordinate system that can be any number of dimensions. When initialized, you can specify how many dimensions you want it, or you can leave it blank to have infinite dimensions. Once a dimension is set, all objects in it are limited to that many dimensions. A universe of infinite dimensions has no restrictions, and can hold objects of any number of dimensions.
120
+
121
+ Within the universe, you can create Points and Spheres (though the more proper term is HyperSphere, more on that later). The only two functions are #add_point(coordinates) and #add_sphere(radius, center). Both will check to ensure that the number of dimensions matches the universe (if the universe has a finite number of dimensions).
122
+
123
+ In addition, the universe has the class method Universe.distance(pointA, pointB), which will tell you the distance between any two points. This will work for points in any number of dimensions, so long as the two points are of the same.
124
+
125
+ #### Sphere
126
+
127
+ A Sphere is a set of points within a certain number of dimensions that are equidistant (equal distance) from a given point. The number of dimensions is defined by the number of coordinates in its center. For example, a two-dimensional sphere (called a Circle) has a center of (x,y). This leads to the more proper term of HyperSphere, though that is not used in syntax.
128
+
129
+ Upon creation, a sphere is given a radius and a center (default is the 3-dimensional Unit Sphere, of radius 1 and center [0,0,0]). Spheres are immutable, as of yet, and though the number of dimensions is limitless certain functionalities will only apply to a 3-dimensional sphere.
130
+
131
+ A Sphere has the following methods
132
+ * on_sphere?(point) will return if a point is on the sphere.
133
+ * in_sphere?(point) will return if a point is within the boundaries of the sphere.
134
+ * how_far_from_sphere(point) will return how far a point is from the boundaries of the sphere.
135
+
136
+ The following methods are available exclusively for 3-dimensional spheres.
137
+ * volume, returns the volume of the sphere
138
+ * surface_area, returns the surface area of the sphere
139
+ * equation, returns a string of the standard equation of the sphere. For example, a sphere with Radius 2 and Center [0,1,-2] will return "x^2 + (y - 1)^2 + (z + 2)^2 = 4".
62
140
 
63
141
  ## Development
64
142
 
@@ -1,12 +1,20 @@
1
- require_relative 'zadt/AbstractDataTypes/ADT.rb'
2
- require_relative 'zadt/AbstractDataTypes/MinMaxStackQueue/Stack.rb'
3
- require_relative 'zadt/AbstractDataTypes/MinMaxStackQueue/Queue.rb'
4
- require_relative 'zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb'
5
- require_relative 'zadt/AbstractDataTypes/MinMaxStackQueue/MinMaxStack.rb'
6
- require_relative 'zadt/AbstractDataTypes/MinMaxStackQueue/MinMaxStackQueue.rb'
7
-
8
- require_relative 'zadt/AbstractDataTypes/Graph/vertex.rb'
9
- require_relative 'zadt/AbstractDataTypes/Graph/edge.rb'
1
+ # Note that we only require those that are included in the gem, not their dependancies.
2
+ # This is so the client does not have access to these private classes
3
+ # Ex. A client cannot make an edge other than within a graph.
4
+
5
+ require_relative 'zadt/HelpModules/adt_help.rb'
6
+ require_relative 'zadt/HelpModules/adt_stackqueue_help.rb'
7
+ require_relative 'zadt/HelpModules/adt_graph_help.rb'
8
+ require_relative 'zadt/HelpModules/adt_geometrics_help.rb'
9
+
10
+ require_relative 'zadt/AbstractDataTypes/StackQueue/Stack.rb'
11
+ require_relative 'zadt/AbstractDataTypes/StackQueue/Queue.rb'
12
+ require_relative 'zadt/AbstractDataTypes/StackQueue/StackQueue.rb'
13
+ require_relative 'zadt/AbstractDataTypes/StackQueue/MinMaxStack.rb'
14
+ require_relative 'zadt/AbstractDataTypes/StackQueue/MinMaxStackQueue.rb'
15
+
10
16
  require_relative 'zadt/AbstractDataTypes/Graph/graph.rb'
11
17
  require_relative 'zadt/AbstractDataTypes/Graph/face.rb'
12
18
  require_relative 'zadt/AbstractDataTypes/Graph/face_graph.rb'
19
+
20
+ require_relative 'zadt/AbstractDataTypes/Geometrics/universe.rb'
@@ -0,0 +1,7 @@
1
+ class Point
2
+ attr_reader :coords, :dims
3
+ def initialize(coordinates)
4
+ @coords = coordinates
5
+ @dims = @coords.length
6
+ end
7
+ end
@@ -0,0 +1,81 @@
1
+ require_relative 'point.rb'
2
+
3
+ class Sphere
4
+
5
+ attr_reader :radius, :center
6
+ attr_accessor :pct_error
7
+
8
+ def initialize(radius = 1, center = [0,0,0], pct_error = 1)
9
+ @radius = radius
10
+ @center = Point.new(center)
11
+ @pct_error = pct_error
12
+ end
13
+
14
+ def self.help
15
+ Sphere.show_help_message
16
+ end
17
+
18
+ def help
19
+ Sphere.help
20
+ end
21
+
22
+ def on_sphere?(point)
23
+ Zadt::Universe.distance(@center, point).round(2) == radius.round(2)
24
+ end
25
+
26
+ def in_sphere?(point)
27
+ Zadt::Universe.distance(@center, point) <= @radius
28
+ end
29
+
30
+ def how_far_from_sphere(point)
31
+ (@radius - Zadt::Universe.distance(@center, point)).abs
32
+ end
33
+
34
+ def volume
35
+ dim_check(3)
36
+ Math::PI * (@radius ** 3) * 4.0 / 3.0
37
+ end
38
+
39
+ def surface_area
40
+ dim_check(3)
41
+ 4.0 * Math::PI * (@radius ** 2)
42
+ end
43
+
44
+ def equation
45
+ dim_check(3)
46
+ center_point = @center.dup
47
+ coord_names = ["x", "y", "z"]
48
+ center_point.coords.each_with_index do |center_coord, index|
49
+ if center_coord == 0
50
+ # coord_name is fine
51
+ elsif center_coord < 0
52
+ coord_names[index] = "(#{coord_names[index]} + #{-center_coord})"
53
+ else
54
+ coord_names[index] = "(#{coord_names[index]} - #{center_coord})"
55
+ end
56
+ end
57
+ "#{coord_names[0]}^2 + #{coord_names[1]}^2 + #{coord_names[2]}^2 = #{@radius ** 2}"
58
+ end
59
+
60
+ def inspect
61
+ "Sphere: #{equation}"
62
+ end
63
+
64
+ private
65
+
66
+ def self.show_help_message
67
+ Zadt::ADT::show_sphere_help_message
68
+ end
69
+
70
+ def close_enough(guess, exact)
71
+ range = Array.new
72
+ range[0] = exact *(100.0 - @pct_error)/100.0
73
+ range[1] = exact * (100.0 + @pct_error)/100.0
74
+ guess.between?(range[0], range[1])
75
+ end
76
+
77
+ def dim_check(num)
78
+ raise "dimension error" unless num == @center.dims
79
+ end
80
+
81
+ end
@@ -0,0 +1,54 @@
1
+ require_relative 'point.rb'
2
+ require_relative 'sphere.rb'
3
+
4
+ module Zadt
5
+ class Universe
6
+ attr_reader :points, :objects
7
+ def initialize(num_dim = nil)
8
+ @num_dim = num_dim
9
+ @points = []
10
+ @objects = []
11
+ end
12
+
13
+ def self.help
14
+ Universe.show_help_message
15
+ end
16
+
17
+ def help
18
+ Universe.help
19
+ end
20
+
21
+ def self.distance(pointa, pointb)
22
+ raise "different dimensions" if pointa.dims != pointb.dims
23
+ coordinate_distances = Array.new
24
+ pointa.dims.times {|coord| coordinate_distances[coord] = pointa.coords[coord] - pointb.coords[coord]}
25
+ sum_of_squares = coordinate_distances.inject(0) {|sum, coord| sum += coord ** 2}
26
+ return Math.sqrt(sum_of_squares)
27
+ end
28
+
29
+ def add_point(coords)
30
+ point = Point.new(coords)
31
+ dim_check(point)
32
+ @points << point
33
+ point
34
+ end
35
+
36
+ def add_sphere(radius, center)
37
+ sphere = Sphere.new(radius, center)
38
+ dim_check(sphere.center)
39
+ @objects << sphere
40
+ sphere
41
+ end
42
+
43
+ private
44
+
45
+ def dim_check(point)
46
+ return if !@num_dim
47
+ raise "Wrong number of dimensions" if point.dims != @num_dim
48
+ end
49
+
50
+ def self.show_help_message
51
+ Zadt::ADT::show_universe_help_message
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ module Zadt
2
+ class DiGraph < Graph
3
+
4
+ end
5
+ end
@@ -1,44 +1,19 @@
1
1
  # require_relative 'vertex.rb'
2
2
  # require_relative 'edge.rb'
3
3
  class Face
4
- attr_reader :edges, :vertices, :neighboring_faces
4
+ attr_reader :edges, :vertices
5
5
  # Contains
6
6
  attr_accessor :value
7
- def initialize(edges_array, neighboring_faces = {}, value = Hash.new)
8
- raise "Not enough edges" if edges_array.length < 3
7
+
8
+ def initialize(edges_array, value = Hash.new)
9
+ raise "not enough edges" if edges_array.length < 3
10
+ edges_array.each {|edge| raise "not an edge" unless edge.is_a?(Edge)}
9
11
  @edges = edges_array
10
12
  vertices = edges_array.map{ |edge| edge.connection}.inject(:+).uniq
11
13
  @vertices = ensure_cyclic(vertices)
12
- @neighboring_faces = neighboring_faces
13
- @neighbor_id = @neighboring_faces.length
14
14
  @value = value
15
15
  end
16
16
 
17
- # TODO: Neighbors shouldn't be stored in Face, as FaceGraph takes care of this
18
-
19
- def add_neighbor(face)
20
- # face_info is a catalog of information about the face's neighbor
21
- # It has three properties: face, which is the neighbor face itself,
22
- # as well as "shared_vertices" and "shared_edges".
23
- face_info = {}
24
- face_info["face"] = face
25
- face_info["shared_vertices"] = @vertices.select{|vertex| face.vertices.include?(vertex)}
26
- face_info["shared_edges"] = @edges.select{|edge| face.edges.include?(edge)}
27
- raise "No connecting edges or vertices" if face_info["shared_vertices"].empty? && face_info["shared_edges"].empty?
28
- @neighboring_faces[@neighbor_id] = face_info
29
- @neighbor_id += 1
30
- end
31
-
32
- def remove_neighbor(neighbor)
33
- id_of_neighbor = -1
34
- @neighboring_faces.each do |id, face_info|
35
- id_of_neighbor = id if face_info["face"] == neighbor
36
- end
37
- raise "Not a neighbor" if id_of_neighbor == -1
38
- @neighboring_faces.delete(id_of_neighbor)
39
- end
40
-
41
-
42
17
  def inspect
43
18
  output = "This face contains the following vertices:"
44
19
  output += @vertices.to_s
@@ -7,7 +7,7 @@ module Zadt
7
7
  attr_reader :faces
8
8
  # in addition to its parent's :vertices and :edges
9
9
 
10
- # Contains
10
+ # Contains (inherits)
11
11
  # attr_accessor :value
12
12
 
13
13
  def initialize
@@ -26,6 +26,7 @@ module Zadt
26
26
 
27
27
 
28
28
  def add_face(edges_array)
29
+ edge_array_check(edges_array)
29
30
  face = Face.new(edges_array)
30
31
  @faces << face
31
32
  face
@@ -33,7 +34,7 @@ module Zadt
33
34
 
34
35
  # Makes a face with num_edges edges, which will be attached to nothing.
35
36
  def make_original_face(num_edges)
36
-
37
+ num_edges_check(num_edges)
37
38
  # Make the vertices
38
39
  vert_ref = Array.new(num_edges) {Vertex.new}
39
40
  edge_ref = []
@@ -59,8 +60,10 @@ module Zadt
59
60
  # This will automatically make_neighbors with any faces that share
60
61
  # a vertex with the new face
61
62
  def add_attached_face(vertex_array, num_edges)
63
+ vertex_array_check(vertex_array)
64
+ num_edges_check(num_edges)
62
65
  # Make the vertices into a line
63
- vertex_line = make_vertex_line(vertex_array)
66
+ vertex_line = confirm_vertex_line(vertex_array)
64
67
  # This finds the "ends" of the vertex line
65
68
  end_vertices = [vertex_line.first, vertex_line.last]
66
69
  # Find the neighbors that will be added later
@@ -97,17 +100,12 @@ module Zadt
97
100
  # Store the new edges
98
101
  @edges += edge_ref
99
102
 
100
- new_neighbors.each do |neighbor|
101
- # Add all the new_neighbors
102
- face.add_neighbor(neighbor)
103
- # Make this a neighbor to all new_neighbors
104
- neighbor.add_neighbor(face)
105
- end
106
103
  face
107
104
  end
108
105
 
109
106
  # Return all faces containing the given vertices
110
107
  def find_neighbors(vertex_array)
108
+ vertex_array_check(vertex_array)
111
109
  neighbors = []
112
110
  vertex_array.each do |vertex|
113
111
  @faces.each do |face|
@@ -121,28 +119,33 @@ module Zadt
121
119
  # Neighbor is defined as sharing a vertex,
122
120
  # not necessarily sharing an edge.
123
121
  def find_face_neighbors(face)
122
+ raise "not a face" unless face.is_a?(Face)
124
123
  neighbors = find_neighbors(face.vertices)
125
124
  neighbors - [face]
126
125
  end
127
126
 
128
-
129
127
  private
130
128
 
131
- def make_vertex_line(vertex_array)
132
- connection_line = []
133
- connection_line << vertex_array.first
134
- continue = true
135
- until connection_line.length == vertex_array.length || !continue
136
- continue = false
137
- vertex_array.each do |vertex|
138
- if vertex.is_connected?(connection_line.last) && !connection_line.include?(vertex)
139
- continue = true
140
- connection_line << vertex
141
- end
142
- end
143
- raise "Vertices not connected" if continue == false
129
+ def vertex_array_check(vertex_array)
130
+ raise "invalid vertex array" unless vertex_array.is_a?(Array)
131
+ vertex_array.each {|vertex| raise "not a vertex" unless vertex.is_a?(Vertex)}
132
+ end
133
+
134
+ def edge_array_check(edges_array)
135
+ raise "not an array" unless edges_array.is_a?(Array)
136
+ edges_array.each {|edge| raise "not an edge" unless edge.is_a?(Edge)}
137
+ end
138
+
139
+ def num_edges_check(num_edges)
140
+ raise "invalid number of edges" unless num_edges.is_a?(Integer)
141
+ raise "need 3 or more edgesto make a face" unless num_edges > 2
142
+ end
143
+
144
+ def confirm_vertex_line(vertex_array)
145
+ (vertex_array.length - 1).times do |i|
146
+ raise "Vertices not connected" unless vertex_array[i].is_connected?(vertex_array[i+1])
144
147
  end
145
- connection_line
148
+ vertex_array
146
149
  end
147
150
 
148
151
  def make_neighbors(face1, face2)
@@ -156,22 +159,7 @@ module Zadt
156
159
  end
157
160
 
158
161
  def self.show_help_message
159
- puts "Here are the methods for FaceGraph:"
160
- puts "#add_face(edges_array), makes a face with the given edges (must be cyclicly connected)"
161
- puts "#make_original_face(num_edges), which makes a standard disconnected face"
162
- puts "#add_attached_face(vertex_array, num_edges), which adds a face connected to the vertex_array"
163
- puts "#find_neighbors(vertex_array), lists all faces containing the given vertices"
164
- puts "#find_face_neighbors(face), which finds all neighbors of the given face"
165
- puts "--a neighbor of a face is defined as one that shares a vertex (not necessarily an edge)"
166
- puts "#make_vertex_line(vertex_array), reorders a list of connected vertices by connection sequence"
167
- puts ""
168
- puts "FaceGraph also inherits the following functions from Graph:"
169
- puts "#add_vertex"
170
- puts "#remove_vertex(vertex)"
171
- puts "#make_connection(v1,v2), adds an edge between two vertices"
172
- puts "#break_connection(v1,v2)"
173
- puts "#find_connection(v1,v2), returns edge connecting two given vertices"
174
- puts "#is_connected?(v1,v2)"
162
+ Zadt::ADT::show_face_graph_help_message
175
163
  end
176
164
  end
177
165
  end
@@ -38,6 +38,7 @@ module Zadt
38
38
  # Remove a vertex
39
39
  def remove_vertex(vertex)
40
40
  # The vertex must exist
41
+ raise "not a vertex" unless vertex.is_a?(Vertex)
41
42
  if !vertex
42
43
  raise "Vertex does not exist"
43
44
  # The vertex must not be connected to anything
@@ -51,6 +52,7 @@ module Zadt
51
52
 
52
53
  # Make an edge between two vertices
53
54
  def make_connection(v1, v2)
55
+ raise "not a vertex" unless v1.is_a?(Vertex) && v2.is_a?(Vertex)
54
56
  raise "already connected" if is_connected?(v1, v2)
55
57
  # Make new edge
56
58
  edge = Edge.new(v1, v2)
@@ -65,12 +67,16 @@ module Zadt
65
67
 
66
68
  # Find the edge connecting two vertices
67
69
  def find_connection(v1, v2)
70
+ raise "not a vertex" unless v1.is_a?(Vertex) && v2.is_a?(Vertex)
71
+ raise "Vertices not connected" if !is_connected?(v1, v2)
68
72
  connection = v1.edges.select {|edge| edge.connection.include?(v2)}
73
+ raise "Error finding connection" if connection.length > 1
69
74
  connection.first
70
75
  end
71
76
 
72
77
  # Returns whether two vertices are connected
73
78
  def is_connected?(v1, v2)
79
+ raise "not a vertex" unless v1.is_a?(Vertex) && v2.is_a?(Vertex)
74
80
  v1.connections.include?(v2)
75
81
  end
76
82
 
@@ -96,13 +102,7 @@ module Zadt
96
102
  private
97
103
 
98
104
  def self.show_help_message
99
- puts "Here are the methods for Graph:"
100
- puts "#add_vertex"
101
- puts "#remove_vertex(vertex)"
102
- puts "#make_connection(v1,v2), adds an edge between two vertices"
103
- puts "#break_connection(v1,v2)"
104
- puts "#find_connection(v1,v2), returns edge connecting two given vertices"
105
- puts "#is_connected?(v1,v2)"
105
+ Zadt::ADT::show_graph_help_message
106
106
  end
107
107
  end
108
108
  end
@@ -19,7 +19,9 @@
19
19
 
20
20
  # Make an edge between this vertex and another
21
21
  def connect(other_vertex, edge)
22
- return nil if !other_vertex.is_a?(Vertex) || other_vertex == self
22
+ raise "not a vertex" unless other_vertex.is_a?(Vertex)
23
+ raise "cannot connect vertex to self" if other_vertex == self
24
+ raise "not an edge" unless edge.is_a?(Edge)
23
25
  raise "already connected" if is_connected?(other_vertex)
24
26
  # Store connection info in this vertex
25
27
  @edges << edge
@@ -29,6 +31,7 @@
29
31
 
30
32
  # Returns if another vertex is "connected" to this one
31
33
  def is_connected?(other_vertex)
34
+ raise "not a vertex" unless other_vertex.is_a?(Vertex)
32
35
  @connections.include?(other_vertex)
33
36
  end
34
37
 
@@ -8,27 +8,11 @@ module Zadt
8
8
  end
9
9
 
10
10
  def self.help
11
- puts "Here are the functions for MinMaxStack:"
12
- puts "#push(value)"
13
- puts "#pop"
14
- puts "#peek"
15
- puts "#min"
16
- puts "#max"
17
- puts "#length"
18
- puts "#show"
19
- puts "#empty?"
20
- end
21
-
22
- def self.methods
23
- self.help
11
+ Zadt::ADT::show_minmaxstack_help_message
24
12
  end
25
13
 
26
14
  def help
27
- self.help
28
- end
29
-
30
- def methods
31
- help
15
+ MinMaxStack.help
32
16
  end
33
17
 
34
18
  def push(val)
@@ -11,28 +11,13 @@ module Zadt
11
11
  end
12
12
 
13
13
  def self.help
14
- puts "Here are the functions for MinMaxStackQueue:"
15
- puts "#show"
16
- puts "#enqueue(value)"
17
- puts "#dequeue"
18
- puts "#min"
19
- puts "#max"
20
- puts "#length"
21
- puts "#empty?"
22
- end
23
-
24
- def self.methods
25
- self.help
14
+ Zadt::ADT::show_minmaxstackqueue_help_message
26
15
  end
27
16
 
28
17
  def help
29
18
  MinMaxStackQueue.help
30
19
  end
31
20
 
32
- def methods
33
- help
34
- end
35
-
36
21
  def show
37
22
  @out.show.reverse + @in.show
38
23
  end
@@ -50,6 +35,15 @@ module Zadt
50
35
  @out.pop
51
36
  end
52
37
 
38
+ def peek
39
+ if @out.empty?
40
+ @in.length.times do
41
+ @out.push(@in.pop)
42
+ end
43
+ end
44
+ @out.peek
45
+ end
46
+
53
47
  def min
54
48
  if @in.empty?
55
49
  @out.min
@@ -5,26 +5,13 @@ module Zadt
5
5
  end
6
6
 
7
7
  def self.help
8
- puts "Here are the functions for Queue:"
9
- puts "#show"
10
- puts "#enqueue(value)"
11
- puts "#dequeue"
12
- puts "#length"
13
- puts "#empty?"
14
- end
15
-
16
- def self.methods
17
- self.help
8
+ Zadt::ADT::show_queue_help_message
18
9
  end
19
10
 
20
11
  def help
21
12
  Queue.help
22
13
  end
23
14
 
24
- def methods
25
- help
26
- end
27
-
28
15
  def show
29
16
  @values
30
17
  end
@@ -38,6 +25,10 @@ module Zadt
38
25
  @values.shift
39
26
  end
40
27
 
28
+ def peek
29
+ @values.first
30
+ end
31
+
41
32
  def length
42
33
  @values.length
43
34
  end
@@ -5,26 +5,13 @@ module Zadt
5
5
  end
6
6
 
7
7
  def self.help
8
- puts "Here are the functions for Stack:"
9
- puts "#show"
10
- puts "#push(value)"
11
- puts "#pop"
12
- puts "#length"
13
- puts "#empty?"
14
- end
15
-
16
- def self.methods
17
- self.help
8
+ Zadt::ADT::show_stack_help_message
18
9
  end
19
10
 
20
11
  def help
21
12
  Stack.help
22
13
  end
23
14
 
24
- def methods
25
- help
26
- end
27
-
28
15
  def show
29
16
  @values
30
17
  end
@@ -38,6 +25,10 @@ module Zadt
38
25
  @values.pop
39
26
  end
40
27
 
28
+ def peek
29
+ @values.last
30
+ end
31
+
41
32
  def length
42
33
  @values.length
43
34
  end
@@ -10,26 +10,13 @@ module Zadt
10
10
  end
11
11
 
12
12
  def self.help
13
- puts "Here are the functions for StackQueue:"
14
- puts "#show"
15
- puts "#enqueue(value)"
16
- puts "#dequeue"
17
- puts "#length"
18
- puts "#empty?"
19
- end
20
-
21
- def self.methods
22
- self.help
13
+ Zadt::ADT::show_stackqueue_help_message
23
14
  end
24
15
 
25
16
  def help
26
17
  StackQueue.help
27
18
  end
28
19
 
29
- def methods
30
- help
31
- end
32
-
33
20
  def show
34
21
  @out.show.reverse + @in.show
35
22
  end
@@ -47,12 +34,21 @@ module Zadt
47
34
  @out.pop
48
35
  end
49
36
 
37
+ def peek
38
+ if @out.empty?
39
+ @in.length.times do
40
+ @out.push(@in.pop)
41
+ end
42
+ end
43
+ @out.peek
44
+ end
45
+
50
46
  def length
51
47
  @in.length + @out.length
52
48
  end
53
49
 
54
50
  def empty?
55
- @values.empty?
51
+ @in.empty? && @out.empty?
56
52
  end
57
53
  end
58
54
  end
@@ -0,0 +1,21 @@
1
+ module Zadt
2
+ class ADT
3
+ def self.show_universe_help_message
4
+ puts "Here are the methods for Universe:"
5
+ puts "#add_point(coordinates)"
6
+ puts "#add_sphere(radius, center)"
7
+ puts "#self.distance(pointA, pointB)"
8
+ end
9
+
10
+ def self.show_sphere_help_message
11
+ puts "Here are the methods for Sphere:"
12
+ puts "#on_sphere(point)"
13
+ puts "#in_sphere(point)"
14
+ puts "#how_far_from_sphere(point)"
15
+ puts "The following methods are also included in a 3-dimensional sphere:"
16
+ puts "#volume"
17
+ puts "#surface_area"
18
+ puts "#equation, which returns a string in the form of (x-a)^2 + (y-b)^2 + (z-c)^2 = r^2"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ module Zadt
2
+ class ADT
3
+ def self.show_graph_help_message
4
+ puts "Here are the methods for Graph:"
5
+ puts "#add_vertex"
6
+ puts "#remove_vertex(vertex)"
7
+ puts "#make_connection(v1,v2), adds an edge between two vertices"
8
+ puts "#break_connection(v1,v2)"
9
+ puts "#find_connection(v1,v2), returns edge connecting two given vertices"
10
+ puts "#is_connected?(v1,v2)"
11
+ end
12
+
13
+ def self.show_face_graph_help_message
14
+ puts "Here are the methods for FaceGraph:"
15
+ puts "#add_face(edges_array), makes a face with the given edges (must be cyclicly connected)"
16
+ puts "#make_original_face(num_edges), which makes a standard disconnected face"
17
+ puts "#add_attached_face(vertex_array, num_edges), which adds a face connected to the vertex_array"
18
+ puts "#find_neighbors(vertex_array), lists all faces containing the given vertices"
19
+ puts "#find_face_neighbors(face), which finds all neighbors of the given face"
20
+ puts "--a neighbor of a face is defined as one that shares a vertex (not necessarily an edge)"
21
+ puts ""
22
+ puts "FaceGraph also inherits the following methods from Graph:"
23
+ puts "#add_vertex"
24
+ puts "#remove_vertex(vertex)"
25
+ puts "#make_connection(v1,v2), adds an edge between two vertices"
26
+ puts "#break_connection(v1,v2)"
27
+ puts "#find_connection(v1,v2), returns edge connecting two given vertices"
28
+ puts "#is_connected?(v1,v2)"
29
+ end
30
+ end
31
+ end
@@ -3,18 +3,26 @@ module Zadt
3
3
  def self.help
4
4
  puts "Thank you for using Zagorski Advanced Data Types!"
5
5
  puts "This package contains the following Data Types:"
6
+
6
7
  puts "Array-Like Data Types"
7
8
  puts "-Stack, a LIFO array with functions push and pop"
8
9
  puts "-Queue, a FIFO array with functions enqueue and dequeue"
9
10
  puts "-StackQueue, a Queue that is Stack-based (no real difference)"
10
11
  puts "-MinMaxStack, a Stack that can return Min and Max in constant time"
11
12
  puts "-MinMaxStackQueue, a Queue that can return Min and Max in constant time"
13
+
12
14
  puts "Graph Data Types"
13
15
  puts "-Graph, consisting of Vertices connected by Edges"
14
16
  puts "--Vertex, a 'spot' on the graph"
15
17
  puts "--Edge, connects two vertices"
16
18
  puts "-FaceGraph, a sub-class of Graph which includes Faces"
17
19
  puts "--Face, a space surrounded by a cycle of Edges. Consists of Vertices and the Edges connecting them"
20
+
21
+ puts "Geometrics"
22
+ puts "-Universe, consisting of Points and Spheres"
23
+ puts "--Point, a 'spot' in the universe"
24
+ puts "--Sphere, a set of points in a certain number of dimensions that is equidistant from a given point, called the Center"
25
+
18
26
  puts ""
19
27
  puts "Each data type also has a help function. Type Zadt::Stack::help for a list of Stack methods, and so on for each data type."
20
28
  end
@@ -0,0 +1,57 @@
1
+ module Zadt
2
+ class ADT
3
+ def self.show_stack_help_message
4
+ puts "Here are the functions for Stack:"
5
+ puts "#show"
6
+ puts "#push(value)"
7
+ puts "#pop"
8
+ puts "#peek"
9
+ puts "#length"
10
+ puts "#empty?"
11
+ end
12
+
13
+ def self.show_queue_help_message
14
+ puts "Here are the functions for Queue:"
15
+ puts "#show"
16
+ puts "#enqueue(value)"
17
+ puts "#dequeue"
18
+ puts "#peek"
19
+ puts "#length"
20
+ puts "#empty?"
21
+ end
22
+
23
+ def self.show_stackqueue_help_message
24
+ puts "Here are the functions for StackQueue:"
25
+ puts "#show"
26
+ puts "#enqueue(value)"
27
+ puts "#dequeue"
28
+ puts "#peek"
29
+ puts "#length"
30
+ puts "#empty?"
31
+ end
32
+
33
+ def self.show_minmaxstack_help_message
34
+ puts "Here are the functions for MinMaxStack:"
35
+ puts "#show"
36
+ puts "#push(value)"
37
+ puts "#pop"
38
+ puts "#peek"
39
+ puts "#min"
40
+ puts "#max"
41
+ puts "#length"
42
+ puts "#empty?"
43
+ end
44
+
45
+ def self.show_minmaxstackqueue_help_message
46
+ puts "Here are the functions for MinMaxStackQueue:"
47
+ puts "#show"
48
+ puts "#enqueue(value)"
49
+ puts "#dequeue"
50
+ puts "#peek"
51
+ puts "#min"
52
+ puts "#max"
53
+ puts "#length"
54
+ puts "#empty?"
55
+ end
56
+ end
57
+ end
@@ -1,3 +1,3 @@
1
1
  module Zadt
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
@@ -10,9 +10,10 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["benj@zagorski.com"]
11
11
 
12
12
  spec.summary = %q{Zagorski ADT is a collection of advanced data types that are not included in the standard Ruby library.}
13
- spec.description = %q{Includes two different categories of Advanced Data Types: Array-Based, and Graphs.
13
+ spec.description = %q{Includes three different categories of Advanced Data Types: Array-Based, Graphs, and Geometrics.
14
14
  Array-Based Data Types include Stack, Queue, StackQueue, MinMaxStack, and MinMaxStackQueue.
15
15
  Graph Data Types include Graph, which consists of Vertices and Edges, and FaceGraph, which includes Faces.
16
+ Geometrics includes Universe, which currently consists of Points and Spheres (work in progress).
16
17
  Once installed, type "Zadt::ADT::help" for a list of datatypes
17
18
  and basic functionality.}
18
19
  spec.homepage = "https://github.com/MrMicrowaveOven/zadt.git"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zadt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Zagorski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-22 00:00:00.000000000 Z
11
+ date: 2016-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,9 +53,10 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  description: |-
56
- Includes two different categories of Advanced Data Types: Array-Based, and Graphs.
56
+ Includes three different categories of Advanced Data Types: Array-Based, Graphs, and Geometrics.
57
57
  Array-Based Data Types include Stack, Queue, StackQueue, MinMaxStack, and MinMaxStackQueue.
58
58
  Graph Data Types include Graph, which consists of Vertices and Edges, and FaceGraph, which includes Faces.
59
+ Geometrics includes Universe, which currently consists of Points and Spheres (work in progress).
59
60
  Once installed, type "Zadt::ADT::help" for a list of datatypes
60
61
  and basic functionality.
61
62
  email:
@@ -78,17 +79,24 @@ files:
78
79
  - lib/ADT_requireables.rb
79
80
  - lib/helper_functions.rb
80
81
  - lib/zadt.rb
81
- - lib/zadt/AbstractDataTypes/ADT.rb
82
+ - lib/zadt/AbstractDataTypes/Geometrics/point.rb
83
+ - lib/zadt/AbstractDataTypes/Geometrics/sphere.rb
84
+ - lib/zadt/AbstractDataTypes/Geometrics/universe.rb
85
+ - lib/zadt/AbstractDataTypes/Graph/di_graph.rb
82
86
  - lib/zadt/AbstractDataTypes/Graph/edge.rb
83
87
  - lib/zadt/AbstractDataTypes/Graph/face.rb
84
88
  - lib/zadt/AbstractDataTypes/Graph/face_graph.rb
85
89
  - lib/zadt/AbstractDataTypes/Graph/graph.rb
86
90
  - lib/zadt/AbstractDataTypes/Graph/vertex.rb
87
- - lib/zadt/AbstractDataTypes/MinMaxStackQueue/MinMaxStack.rb
88
- - lib/zadt/AbstractDataTypes/MinMaxStackQueue/MinMaxStackQueue.rb
89
- - lib/zadt/AbstractDataTypes/MinMaxStackQueue/Queue.rb
90
- - lib/zadt/AbstractDataTypes/MinMaxStackQueue/Stack.rb
91
- - lib/zadt/AbstractDataTypes/MinMaxStackQueue/StackQueue.rb
91
+ - lib/zadt/AbstractDataTypes/StackQueue/MinMaxStack.rb
92
+ - lib/zadt/AbstractDataTypes/StackQueue/MinMaxStackQueue.rb
93
+ - lib/zadt/AbstractDataTypes/StackQueue/Queue.rb
94
+ - lib/zadt/AbstractDataTypes/StackQueue/Stack.rb
95
+ - lib/zadt/AbstractDataTypes/StackQueue/StackQueue.rb
96
+ - lib/zadt/HelpModules/adt_geometrics_help.rb
97
+ - lib/zadt/HelpModules/adt_graph_help.rb
98
+ - lib/zadt/HelpModules/adt_help.rb
99
+ - lib/zadt/HelpModules/adt_stackqueue_help.rb
92
100
  - lib/zadt/version.rb
93
101
  - zadt.gemspec
94
102
  homepage: https://github.com/MrMicrowaveOven/zadt.git