Skip to content

Segment

Module: terminaltexteffects.engine.motion

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

Attributes:

Name Type Description
start Waypoint

start waypoint

end Waypoint

end waypoint

distance float

distance between the start and end waypoints

Methods:

Name Description
get_coord_on_segment

float) -> Coord: Returns the coordinate at the given distance along the segment.

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

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

    Methods:
        get_coord_on_segment(distance_factor: float) -> Coord:
            Returns the coordinate at the given distance along the segment.
    """

    start: Waypoint
    end: Waypoint
    distance: float

    def __post_init__(self) -> None:
        self.enter_event_triggered: bool = False
        self.exit_event_triggered: bool = False

    def get_coord_on_segment(self, distance_factor: float) -> Coord:
        """Returns the coordinate at the given distance along the segment.

        Args:
            distance_factor (float): distance factor

        Returns:
            Coord: Coordinate at the given distance.
        """
        if self.start.bezier_control:
            return geometry.find_coord_on_bezier_curve(
                self.start.coord,
                self.start.bezier_control,
                self.end.coord,
                distance_factor,
            )
        else:
            return geometry.find_coord_on_line(self.start.coord, self.end.coord, distance_factor)

    def __eq__(self, other: typing.Any) -> bool:
        if not isinstance(other, Segment):
            return NotImplemented
        return self.start == other.start and self.end == other.end

    def __hash__(self):
        return hash((self.start, self.end))

get_coord_on_segment(distance_factor)

Returns the coordinate at the given distance along the segment.

Parameters:

Name Type Description Default
distance_factor float

distance factor

required

Returns:

Name Type Description
Coord Coord

Coordinate at the given distance.

Source code in terminaltexteffects/engine/motion.py
def get_coord_on_segment(self, distance_factor: float) -> Coord:
    """Returns the coordinate at the given distance along the segment.

    Args:
        distance_factor (float): distance factor

    Returns:
        Coord: Coordinate at the given distance.
    """
    if self.start.bezier_control:
        return geometry.find_coord_on_bezier_curve(
            self.start.coord,
            self.start.bezier_control,
            self.end.coord,
            distance_factor,
        )
    else:
        return geometry.find_coord_on_line(self.start.coord, self.end.coord, distance_factor)