Module: FindBeads::BeadClumping

Defined in:
lib/find_beads/bead_clumps.rb

Defined Under Namespace

Classes: Edge, Graph, Vertex

Class Method Summary collapse

Class Method Details

.construct_adjacency_graph(points, distance_cutoff) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/find_beads/bead_clumps.rb', line 181

def self.construct_adjacency_graph(points, distance_cutoff)

	g = Graph.new

	points.each_with_index do |p, i|

		g.new_vertex(i+1)

	end

	points.each_with_index do |p, i|

		close = get_points_within_distance(p, points, distance_cutoff)

		close.each do |c|

			g.add_edge_between(i+1, points.index(c) + 1)

		end

	end

	g

end

.count_disjoint_subgraphs(graph) ⇒ Object



208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/find_beads/bead_clumps.rb', line 208

def self.count_disjoint_subgraphs(graph)

	subgraphs = Set.new

	graph.each do |l, vert|

		subgraphs << graph.get_connected_subgraph(l)

	end

	subgraphs.size

end

.get_points_within_distance(point, points_list, distance_cutoff) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/find_beads/bead_clumps.rb', line 161

def self.get_points_within_distance(point, points_list, distance_cutoff)

	close = []

	points_list.each do |p|

		next if point == p

		if (Vector[*point] - Vector[*p]).norm < distance_cutoff then

			close << p

		end

	end

	close

end