Ejemplo n.º 1
0
def network_find_crossings(network):
    """Identify all pairs of crossing edges in a network.

    Parameters
    ----------
    network : Network
        A network object.

    Returns
    -------
    list
        A list of edge pairs, with each edge represented by two vertex keys.

    Notes
    -----
    This algorithm assumes that the network lies in the XY plane.

    """
    crossings = set()
    for u1, v1 in network.edges():
        for u2, v2 in network.edges():
            if u1 == u2 or v1 == v2 or u1 == v2 or u2 == v1:
                continue
            else:
                if ((u1, v1), (u2, v2)) in crossings:
                    continue
                if ((u2, v2), (u1, v1)) in crossings:
                    continue
                a = network.vertex_coordinates(u1, 'xy')
                b = network.vertex_coordinates(v1, 'xy')
                c = network.vertex_coordinates(u2, 'xy')
                d = network.vertex_coordinates(v2, 'xy')
                if is_intersection_segment_segment_xy((a, b), (c, d)):
                    crossings.add(((u1, v1), (u2, v2)))
    return list(crossings)
Ejemplo n.º 2
0
def network_is_crossed(network):
    """Verify if a network has crossing edges.

    Parameters
    ----------
    network : Network
        A network object.

    Returns
    -------
    bool
        True if the network has at least one pair of crossing edges.
        False otherwise.

    Notes
    -----
    This algorithm assumes that the network lies in the XY plane.

    """
    for u1, v1 in network.edges():
        for u2, v2 in network.edges():
            if u1 == u2 or v1 == v2 or u1 == v2 or u2 == v1:
                continue
            else:
                a = network.vertex[u1]['x'], network.vertex[u1]['y']
                b = network.vertex[v1]['x'], network.vertex[v1]['y']
                c = network.vertex[u2]['x'], network.vertex[u2]['y']
                d = network.vertex[v2]['x'], network.vertex[v2]['y']
                if is_intersection_segment_segment_xy((a, b), (c, d)):
                    return True
    return False
Ejemplo n.º 3
0
def network_is_crossed(network):
    """Verify if a network has crossing edges.

    Parameters
    ----------
    network : Network
        A network object.

    Returns
    -------
    bool
        True if the network has at least one pair of crossing edges.
        False otherwise.

    Notes
    -----
    This algorithm assumes that the network lies in the XY plane.

    """
    for (u1, v1), (u2, v2) in product(network.edges(), network.edges()):
        if u1 == u2 or v1 == v2 or u1 == v2 or u2 == v1:
            continue
        a = network.node_attributes(u1, 'xy')
        b = network.node_attributes(v1, 'xy')
        c = network.node_attributes(u2, 'xy')
        d = network.node_attributes(v2, 'xy')
        if is_intersection_segment_segment_xy((a, b), (c, d)):
            return True
    return False
Ejemplo n.º 4
0
def network_count_crossings(network):
    """Count the number of crossings (pairs of crossing edges) in the network.

    Parameters
    ----------
    network : Network
        A network object.

    Returns
    -------
    int
        The number of crossings.

    Notes
    -----
    This algorithm assumes that the network lies in the XY plane.

    """
    count = 0
    for u1, v1 in network.edges():
        for u2, v2 in network.edges():
            if u1 == u2 or v1 == v2 or u1 == v2 or u2 == v1:
                continue
            else:
                a = network.vertex[u1]['x'], network.vertex[u1]['y']
                b = network.vertex[v1]['x'], network.vertex[v1]['y']
                c = network.vertex[u2]['x'], network.vertex[u2]['y']
                d = network.vertex[v2]['x'], network.vertex[v2]['y']
                if is_intersection_segment_segment_xy((a, b), (c, d)):
                    count += 1
    return count
Ejemplo n.º 5
0
def network_find_crossings(network):
    """Identify all pairs of crossing edges in a network.

    Parameters
    ----------
    network : :class:`compas.datastructures.Network`
        A network object.

    Returns
    -------
    list[tuple[tuple[hashable, hashable], tuple[hashable, hashable]]]
        A list of edge pairs, with each edge represented by two vertex keys.

    Notes
    -----
    This algorithm assumes that the network lies in the XY plane.

    """
    crossings = set()
    for (u1, v1), (u2, v2) in product(network.edges(), network.edges()):
        if u1 == u2 or v1 == v2 or u1 == v2 or u2 == v1:
            continue
        if ((u1, v1), (u2, v2)) in crossings:
            continue
        if ((u2, v2), (u1, v1)) in crossings:
            continue
        a = network.node_attributes(u1, 'xy')
        b = network.node_attributes(v1, 'xy')
        c = network.node_attributes(u2, 'xy')
        d = network.node_attributes(v2, 'xy')
        if is_intersection_segment_segment_xy((a, b), (c, d)):
            crossings.add(((u1, v1), (u2, v2)))
    return list(crossings)
Ejemplo n.º 6
0
def _are_edges_crossed(edges, vertices):
    for (u1, v1), (u2, v2) in product(edges, edges):
        if u1 == u2 or v1 == v2 or u1 == v2 or u2 == v1:
            continue
        a = vertices[u1]
        b = vertices[v1]
        c = vertices[u2]
        d = vertices[v2]
        if is_intersection_segment_segment_xy((a, b), (c, d)):
            return True
    return False
Ejemplo n.º 7
0
def _network_are_edges_crossed(edges, vertices):
    for u1, v1 in edges:
        for u2, v2 in edges:
            if u1 == u2 or v1 == v2 or u1 == v2 or u2 == v1:
                continue
            else:
                a = vertices[u1]
                b = vertices[v1]
                c = vertices[u2]
                d = vertices[v2]
                if is_intersection_segment_segment_xy((a, b), (c, d)):
                    return True
    return False
Ejemplo n.º 8
0
def network_is_crossed(network):
    for u1, v1 in network.edges():
        for u2, v2 in network.edges():
            if u1 == u2 or v1 == v2 or u1 == v2 or u2 == v1:
                continue
            else:
                a = network.vertex[u1]['x'], network.vertex[u1]['y']
                b = network.vertex[v1]['x'], network.vertex[v1]['y']
                c = network.vertex[u2]['x'], network.vertex[u2]['y']
                d = network.vertex[v2]['x'], network.vertex[v2]['y']
                if is_intersection_segment_segment_xy((a, b), (c, d)):
                    return True
    return False
Ejemplo n.º 9
0
def network_find_crossings(network):
    crossings = []
    for u1, v1 in network.edges():
        for u2, v2 in network.edges():
            if u1 == u2 or v1 == v2 or u1 == v2 or u2 == v1:
                continue
            else:
                a = network.vertex_coordinates(u1, 'xy')
                b = network.vertex_coordinates(v1, 'xy')
                c = network.vertex_coordinates(u2, 'xy')
                d = network.vertex_coordinates(v2, 'xy')
                if is_intersection_segment_segment_xy((a, b), (c, d)):
                    crossings.append(((u1, v1), (u2, v2)))
    return crossings
Ejemplo n.º 10
0
def network_count_crossings(network):
    count = 0
    for u1, v1 in network.edges():
        for u2, v2 in network.edges():
            if u1 == u2 or v1 == v2 or u1 == v2 or u2 == v1:
                continue
            else:
                a = network.vertex[u1]['x'], network.vertex[u1]['y']
                b = network.vertex[v1]['x'], network.vertex[v1]['y']
                c = network.vertex[u2]['x'], network.vertex[u2]['y']
                d = network.vertex[v2]['x'], network.vertex[v2]['y']
                if is_intersection_segment_segment_xy((a, b), (c, d)):
                    count += 1
    return count