-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathnode_clusters.py
More file actions
30 lines (23 loc) · 850 Bytes
/
node_clusters.py
File metadata and controls
30 lines (23 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import math
import math_utils
class NodeClusters:
class Cluster:
def __init__(self, node):
self.pos = math_utils.Point(math.floor(node.position().x()), math.floor(node.position().y()))
self.nodes = [node]
def exists(self, node):
return math.floor(node.position().x()) == self.pos.x() and \
math.floor(node.position().y()) == self.pos.y()
def __init__(self):
self.clusters = []
def getNodes(self, node):
for cluster in self.clusters:
if cluster.exists(node):
return cluster.nodes
return []
def addNode(self, node):
for cluster in self.clusters:
if cluster.exists(node):
cluster.nodes.append(node)
return
self.clusters.append(self.Cluster(node))