typegraph/scripts/blocks/getBlockCluster.gml

42 lines
1003 B
Plaintext
Raw Permalink Normal View History

///getBlockCluster(block)
/**
* getBlockCluster :: Block -> Set Block
*
* Returns a set of all blocks in the connected component.
*
* @param block a block within the cluster
*/
var discovered = ds_set_create();
var visited = ds_set_create();
ds_set_add(discovered, argument0);
while (!ds_set_empty(discovered)) {
var block = ds_set_first(discovered);
ds_set_delete(discovered, block);
ds_set_add(visited, block);
for (var i = 0; i < ds_list_size(block.children); i++)
with (block.children[|i]) {
var otherEnd = noone;
if (instanceof(id, OutputAnchor))
if (self.line != noone)
var otherEnd = self.line.drain;
if (instanceof(id, InputAnchor))
if (self.line != noone)
var otherEnd = self.line.source;
with (otherEnd)
if (self.target != noone)
if (!ds_set_exists(visited, self.target.parent))
ds_set_add(discovered, self.target.parent);
}
}
ds_set_destroy(discovered);
return visited;