def redirect_edge(edge: Edge, new_node: AbstractNode, old_node: AbstractNode) -> None: """ Redirect `edge` from `old_node` to `new_node`. Routine updates `new_node` and `old_node`. `edge` is added to `new_node`, `old_node` gets a new Edge instead of `edge`. Args: edge: An Edge. new_node: The new `Node` object. old_node: The old `Node` object. Returns: None Raises: ValueError: if `edge` does not point to `old_node`. """ if not edge.is_trace(): if edge.is_dangling(): if edge.node1 is not old_node: raise ValueError(f"edge {edge} is not pointing " f"to old_node {old_node}") edge.node1 = new_node axis = edge.axis1 else: if edge.node1 is old_node: edge.node1 = new_node axis = edge.axis1 elif edge.node2 is old_node: edge.node2 = new_node axis = edge.axis2 else: raise ValueError(f"edge {edge} is not pointing " f"to old_node {old_node}") new_node.add_edge(edge, axis, True) new_edge = Edge(old_node, axis) old_node.add_edge(new_edge, axis, True) else: if edge.node1 is not old_node: raise ValueError(f"edge {edge} is not pointing " f"to old_node {old_node}") edge.node1 = new_node edge.node2 = new_node axis1 = edge.axis1 axis2 = edge.axis2 new_node.add_edge(edge, axis1, True) new_node.add_edge(edge, axis2, True) new_edge = Edge(old_node, axis1, None, old_node, axis2) old_node.add_edge(new_edge, axis1, True) old_node.add_edge(new_edge, axis2, True)
def test_edge_is_trace_true(single_node_edge): node = single_node_edge.node edge = Edge(name="edge", node1=node, axis1=1, node2=node, axis2=2) assert edge.is_trace()