Skip to content

compas_cem.elements ¤

The nodes and the trail and deviation edges a topology diagram is built from.

Classes¤

DeviationEdge ¤

DeviationEdge(u, v, force, **kwargs)

An edge that carries a prescribed force between two trails.

Parameters:

  • u

    The key of the first node of the edge.

  • v

    The key of the second node of the edge.

  • force

    The signed force in the edge. A negative value puts the edge in compression, and a positive value in tension.

Notes

A deviation edge is direct when both of its nodes belong to the same sequence, and indirect otherwise. That distinction is drawn from the topology diagram rather than from the edge itself.

Source code in src/compas_cem/elements/deviation.py
def __init__(self, u, v, force, **kwargs):
    attrs = {"force": force, "type": "deviation"}
    super(DeviationEdge, self).__init__(u, v, attrs, **kwargs)

Edge ¤

Edge(u, v, attrs, **kwargs)

The base class shared by trail and deviation edges.

Parameters:

  • u

    The key of the first node of the edge.

  • v

    The key of the second node of the edge.

  • attrs

    The attributes to store on the edge.

Notes

A node key here may also be a set of coordinates. A diagram resolves those to an existing node, or creates one, when the edge is added.

Source code in src/compas_cem/elements/edge.py
def __init__(self, u, v, attrs, **kwargs):
    super(Edge, self).__init__(**kwargs)

    self.u = u
    self.v = v
    self.attributes = attrs

Methods:¤

__iter__ ¤
__iter__()

Iterates over the start and end nodes of an edge.

Yields:

  • key

    The next node key.

Source code in src/compas_cem/elements/edge.py
def __iter__(self):
    """
    Iterates over the start and end nodes of an edge.

    Yields
    ------
    key :
        The next node key.
    """
    for node in (self.u, self.v):
        yield node
from_line classmethod ¤
from_line(line, **kwargs)

Create an edge from a line described by two xyz coordinates.

Parameters:

  • line

    The two end points of the line.

  • **kwargs

    Extra keyword arguments passed to the constructor.

Returns:

  • edge

    An edge whose two nodes are the end points of the line.

Source code in src/compas_cem/elements/edge.py
@classmethod
def from_line(cls, line, **kwargs):
    """
    Create an edge from a line described by two xyz coordinates.

    Parameters
    ----------
    line :
        The two end points of the line.
    **kwargs :
        Extra keyword arguments passed to the constructor.

    Returns
    -------
    edge :
        An edge whose two nodes are the end points of the line.
    """
    edge = cls(line[0], line[1], **kwargs)
    return edge

Node ¤

Node(key=None, xyz=[0.0, 0.0, 0.0], **kwargs)

A point in space that a diagram can be built around.

Parameters:

  • key

    The key to register the node under. If None, the diagram assigns the next available key when the node is added.

  • xyz

    The coordinates of the node.

Source code in src/compas_cem/elements/node.py
def __init__(self, key=None, xyz=[0.0, 0.0, 0.0], **kwargs):
    super(Node, self).__init__(**kwargs)
    self.key = key
    self.xyz = xyz
    self.attributes = {}

Methods:¤

from_point classmethod ¤
from_point(point, *args, **kwargs)

Create a node from a point described by its xyz coordinates.

Parameters:

  • point

    The coordinates of the point.

  • *args

    Additional arguments, ignored.

  • **kwargs

    Extra keyword arguments, ignored.

Returns:

  • node

    A node with no key, sitting at the given point.

Source code in src/compas_cem/elements/node.py
@classmethod
def from_point(cls, point, *args, **kwargs):
    """
    Create a node from a point described by its xyz coordinates.

    Parameters
    ----------
    point :
        The coordinates of the point.
    *args :
        Additional arguments, ignored.
    **kwargs :
        Extra keyword arguments, ignored.

    Returns
    -------
    node :
        A node with no key, sitting at the given point.
    """
    return cls(xyz=point)

TrailEdge ¤

TrailEdge(u, v, length, plane=None, **kwargs)

An edge that advances a trail by a prescribed length.

Parameters:

  • u

    The key of the first node of the edge.

  • v

    The key of the second node of the edge.

  • length

    The signed length of the edge. A negative value puts the edge in compression, and a positive value in tension.

  • plane

    A plane to intersect the trail with instead of advancing it by a fixed length.

Notes

A plane overrides the absolute length of the edge, but the sign of the length is preserved, so the combinatorial state survives the intersection.

TODO: add an explicit combinatorial state to the signature of the constructor.

Source code in src/compas_cem/elements/trail.py
def __init__(self, u, v, length, plane=None, **kwargs):
    attrs = {"length": length, "type": "trail", "plane": plane}
    super(TrailEdge, self).__init__(u, v, attrs, **kwargs)