Skip to content

Segment

Module: terminaltexteffects.engine.motion

A segment of a path consisting of two waypoints and the distance between them.

Segments are created by the Path class. The start waypoint is the end waypoint of the previous segment or the origin waypoint.

Attributes:

Name Type Description
start Waypoint

start waypoint

end Waypoint

end waypoint

distance float

distance between the start and end waypoints

Source code in terminaltexteffects/engine/motion.py
@dataclass
class Segment:
    """A segment of a path consisting of two waypoints and the distance between them.

    Segments are created by the Path class. The start waypoint is the end waypoint of the previous segment
    or the origin waypoint.

    Attributes:
        start (Waypoint): start waypoint
        end (Waypoint): end waypoint
        distance (float): distance between the start and end waypoints

    """

    start: Waypoint
    end: Waypoint
    distance: float

    def __post_init__(self) -> None:
        """Initialize additional attributes for the Segment class."""
        self.enter_event_triggered: bool = False
        self.exit_event_triggered: bool = False

    def __eq__(self, other: object) -> bool:
        """Check if two Segment objects are equal.

        Segments are equal if their start and end waypoints are equal.
        """
        if not isinstance(other, Segment):
            return NotImplemented
        return self.start == other.start and self.end == other.end

    def __hash__(self) -> int:
        """Return the hash value of the Segment.

        Hash is calculated using a tuple of the start and end waypoints.
        """
        return hash((self.start, self.end))

__eq__(other)

Check if two Segment objects are equal.

Segments are equal if their start and end waypoints are equal.

Source code in terminaltexteffects/engine/motion.py
def __eq__(self, other: object) -> bool:
    """Check if two Segment objects are equal.

    Segments are equal if their start and end waypoints are equal.
    """
    if not isinstance(other, Segment):
        return NotImplemented
    return self.start == other.start and self.end == other.end

__hash__()

Return the hash value of the Segment.

Hash is calculated using a tuple of the start and end waypoints.

Source code in terminaltexteffects/engine/motion.py
def __hash__(self) -> int:
    """Return the hash value of the Segment.

    Hash is calculated using a tuple of the start and end waypoints.
    """
    return hash((self.start, self.end))

__post_init__()

Initialize additional attributes for the Segment class.

Source code in terminaltexteffects/engine/motion.py
def __post_init__(self) -> None:
    """Initialize additional attributes for the Segment class."""
    self.enter_event_triggered: bool = False
    self.exit_event_triggered: bool = False