def apply_pbcs(index: int, boundary: int) -> int:
    """Applies periodic boundary conditions (PBCs).

    Args:
        index (int): Index to apply the PBCs to
        boundary (int): Length of the boundary

    Returns:
        int: Index with PBCs applied to it
    """
    if index < 0:
        index += boundary
    elif index >= boundary:
        index -= boundary

    return index