GraphUtils 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/graphutils.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5546eb7bfddd04c77a046375d54cc89a198fe925
|
4
|
+
data.tar.gz: df0070edc52ea607fb840943f81ee2b80b7b3ab7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfe48d61565dcbf68ea8e0cb25307c6f395f2365f825f507f5c3495edec075a26585a093a894601a16c4dac599ef95c3ae707440d1582489d80c59a39a6e8f7d
|
7
|
+
data.tar.gz: 328ed000ecbfdbbbafe76be2fd8deccdc3f8c010f25793ef6be4a7d46d8d4fe701dd8fee101523ad0a507d1ef25a21d533f4485c443a51526797230cb4e4338c
|
data/lib/graphutils.rb
CHANGED
@@ -8,6 +8,8 @@
|
|
8
8
|
|
9
9
|
module GraphUtils
|
10
10
|
|
11
|
+
# Find the coordinates of a target, returning the row and column indices as an array
|
12
|
+
|
11
13
|
def self.find_rc(two_dimensional_array, target)
|
12
14
|
column = nil
|
13
15
|
row = nil
|
@@ -25,12 +27,16 @@ module GraphUtils
|
|
25
27
|
[row, column]
|
26
28
|
end
|
27
29
|
|
30
|
+
# Find a value corresponding with the given [row,column] coordinates
|
31
|
+
|
28
32
|
def self.rc_lookup(two_dimensional_array, coordinates)
|
29
33
|
row = coordinates[0]
|
30
34
|
column = coordinates[1]
|
31
35
|
two_dimensional_array[row][column]
|
32
36
|
end
|
33
37
|
|
38
|
+
# Return an array of a column at a particular index.
|
39
|
+
|
34
40
|
def self.find_column(board, column_index)
|
35
41
|
column = []
|
36
42
|
row_index = 0
|
@@ -41,6 +47,8 @@ module GraphUtils
|
|
41
47
|
column
|
42
48
|
end
|
43
49
|
|
50
|
+
# Returns an array of adjacent coordinates for a given set of coordinates. An options hash is included to specify an inclusive or exclusive lookup, defaulting to inclusive.
|
51
|
+
|
44
52
|
def self.surrounding_coordinates(two_dimensional_array, coordinates, options = {} )
|
45
53
|
raise ArgumentError.new("Must include [row,column] coordinates") unless coordinates.is_a?(Array)
|
46
54
|
range = options[:range] || :inclusive
|
@@ -69,6 +77,8 @@ module GraphUtils
|
|
69
77
|
values
|
70
78
|
end
|
71
79
|
|
80
|
+
# Returns an array of adjacent targets for a given set of coordinates.
|
81
|
+
|
72
82
|
def self.surrounding_coordinates_to_values(two_dimensional_array, coordinates, options = {})
|
73
83
|
coordinates = GraphUtils.surrounding_coordinates(two_dimensional_array, coordinates, options)
|
74
84
|
|
@@ -81,6 +91,8 @@ module GraphUtils
|
|
81
91
|
values
|
82
92
|
end
|
83
93
|
|
94
|
+
# Deep iteration tools meant for manipulating N-D Array structures.
|
95
|
+
|
84
96
|
def self.deepmap!(array, &block)
|
85
97
|
array.map! do |elem|
|
86
98
|
elem.is_a?(Array) ? deepmap!(elem, &block) : yield(elem)
|