Source code for sausage_links

#!/usr/bin/env python3

"""
sausage_links
=============

Implementation of the Sausage Links algorithm base Swinging Door in Python.
"""

from typing import TYPE_CHECKING

if TYPE_CHECKING:  # pragma: no cover
    from typing import Generator, Iterator, Tuple, Union

    Source = Union[Generator, Iterator]
    Number = Union[int, float]
    Point = Tuple[Number, Number]
    Stretch = Tuple[Point, Point]
    Slopings = Tuple[float, float]
    Deviation = Union[Number, Tuple[Number, Number]]

__author__: str = "Aleksandr F. Mikhaylov (ChelAxe)"
__version__: str = "1.0.0"
__license__: str = "MIT"


[docs] def _sloping_calc(stretch: "Stretch", deviation: "Deviation") -> "Slopings": """ Calculate slopings upper and lower. :param Stretch stretch: stretch; :param Deviation deviation: compression deflection. :rtype: Slopings :return: Slopings upper and lower. :raises ValueError: if division by 0 occurs during slope calculation. >>> _sloping_calc(((1, 6), (2, 6.5)), 1) (1.5, -0.5) >>> _sloping_calc(((1, 6), (2, 6.5)), (1, 1)) (1.5, -0.5) >>> _sloping_calc(((1, 6), (1, 6.5)), 1) Traceback (most recent call last): ... ValueError: The division by 0 occurs during the calculation of the slope. """ current: "Point" entrance: "Point" current, entrance = stretch dev_up: "Number" dev_down: "Number" if isinstance(deviation, tuple): dev_up, dev_down = deviation else: dev_up = dev_down = deviation dx: "Number" = current[0] - entrance[0] if not dx: raise ValueError( "The division by 0 occurs during the calculation of the slope." ) upper: float = (current[1] - (entrance[1] + dev_up)) / dx lower: float = (current[1] - (entrance[1] - dev_down)) / dx return upper, lower
if __name__ == "__main__": # pragma: no cover import sys from doctest import testmod sys.exit(testmod().failed)