Skip to content

Commit 3717967

Browse files
committed
Simplify boundary overlap logic
Boundaries overlap when both are inclusive and their values are equal. In all other cases, boundaries overlap when the upper bound of the lower range is larger than the lower bound of the upper range.
1 parent 2b3e6f3 commit 3717967

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/mavedb/view_models/score_range.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import operator
21
from typing import Optional, Literal, Sequence, Union
32
from pydantic import field_validator, model_validator
43

@@ -106,12 +105,6 @@ def test_overlap(range_test: ScoreRangeBase, range_check: ScoreRangeBase) -> boo
106105
range_with_min_value = range_check
107106
range_with_non_min_value = range_test
108107

109-
adjacent_boundary_comparator = (
110-
operator.gt
111-
if range_with_min_value.inclusive_upper_bound or range_with_non_min_value.inclusive_lower_bound
112-
else operator.ge
113-
)
114-
115108
# If both ranges have inclusive bounds and their bounds intersect, we consider them overlapping.
116109
if (
117110
range_with_min_value.inclusive_upper_bound
@@ -125,11 +118,10 @@ def test_overlap(range_test: ScoreRangeBase, range_check: ScoreRangeBase) -> boo
125118

126119
# Since we have ordered the ranges, it's a guarantee that the lower bound of the first range is less
127120
# than or equal to the lower bound of the second range. If the upper bound of the first range is greater
128-
# than or equal to the lower bound of the second range, then the two ranges overlap. Note that if either
129-
# of these ranges has an inclusive upper or lower bound, we should compare them without the equality operator.
130-
if adjacent_boundary_comparator(
131-
inf_or_float(range_with_min_value.range[1], False),
132-
inf_or_float(range_with_non_min_value.range[0], True),
121+
# than the lower bound of the second range, then the two ranges overlap. Inclusive bounds only come into
122+
# play when the boundaries are equal and both bounds are inclusive.
123+
if inf_or_float(range_with_min_value.range[1], False) > inf_or_float(
124+
range_with_non_min_value.range[0], True
133125
):
134126
return True
135127

0 commit comments

Comments
 (0)