Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
734 B
5
Indexable
def transform(tree, dest_node, point):
    path = []
    # Search
    def search(root, dest_node, path):
        if not root:
            return None

        path.append(root)

        if root.node_id == dest_node.node_id:
            return True

        if root.left and search(root.left, dest_node, path):
            return True
        
        if root.right and search(root.right, dest_node, path):
            return True

        path.pop()
        return False

    search(tree, dest_node, path)

    if len(path) == 0:
        return False

    print(f'path:{[node.node_id for node in path]}')

    path = path[1:]

    # Transform
    for transform in path:
        point.location += transform.translation

    return True
Leave a Comment