Skip to content

Commit dd88d2a

Browse files
committed
Formatting.
1 parent d87cdd8 commit dd88d2a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/mind_the_gaps/gaps.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,21 @@ def _merge(
8888
if op(inside_a, inside_b) != inside_region:
8989
inside_region = not inside_region
9090

91-
closed = current_endpoint.boundary in "[]"
91+
# Boundary types can swap when differencing depending on
92+
# whether the boundary is inside a region.
93+
is_closed = current_endpoint.boundary in "[]"
9294
b_in_a = inside_a and current_b == current_endpoint
9395
a_in_b = inside_b and current_a == current_endpoint
94-
if op == sub and b_in_a or op == xor and (a_in_b or b_in_a):
95-
closed = not closed
96-
boundary = (")(", "][")[closed][len(endpoints) % 2 == 0]
96+
if op is sub and b_in_a or op is xor and (a_in_b or b_in_a):
97+
is_closed = not is_closed
98+
99+
boundary = (")(", "][")[is_closed][len(endpoints) % 2 == 0]
100+
97101
if (
98102
len(endpoints) > 0
99103
and endpoints[-1].value == current_endpoint.value
100104
and endpoints[-1].boundary + boundary not in {"[]", ")("}
101-
):
105+
): # Remove redundant endpoints such as `0), [0` or `(0, 0]`.
102106
endpoints.pop()
103107
else:
104108
endpoints.append(Endpoint(current_endpoint.value, boundary))

0 commit comments

Comments
 (0)