def overlap_length(r_i: int, r_j: int, q_i: int, q_j: int) ->int:
    """
    Returns the number of positions the query (base) alignment overlaps with the reference (projected) alignment

    :param q_i: query start position
    :param q_j: query end position
    :param r_i: reference start position
    :param r_j: reference end position
    :return: Number of positions the two alignments overlap
    """
    if r_j < q_i or q_i > r_j:
        return 0
    else:
        return min(r_j, q_j) - max(r_i, q_i)
