GimelStudio / GimelStudio

Non-destructive, node based 2D image editor with an API for custom nodes

Home Page:https://gimelstudio.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add check to prevent nodes from connecting to nodes in their own upstream

Correct-Syntax opened this issue · comments

Implement a check that prevents nodes from connecting to nodes that are in their own upstream, so that tangled messes are not allowed:

Check that the node you are connecting to is not an upstream node of yours. The way you do it is you walk up the node graph with a recursive function until you can't find any more upstream nodes. That means you are at the root of the graph/tree. Then you walk the same path downwards and collect all the nodes on the way

Pseudo-code:

def getAllUpstreamNodes(nodes):
    if (upstreamNode == getUpstreamNode()):
        upstreamNode.getAllUpstreamNodes(nodes)
    nodes.append(self)

def getUpstreamNode():
    # return upstream node if present