Skip to content

Commit 9c3c52f

Browse files
committed
BUG: correct algorithm in function region_diff
When the radius is zero, it means that none of the remaining polytopes remove anything. We are done at this level, and can save the result. Make the intersection of hyperplanes in `INDICES` empty. In that way the algorithm will pop out of this level and move on.
1 parent ca35514 commit 9c3c52f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

polytope/polytope.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,12 +2093,18 @@ def region_diff(poly, reg, abs_tol=ABS_TOL, intersect_tol=ABS_TOL,
20932093
INDICES = np.hstack([INDICES, beg_mi[level] + M])
20942094
break
20952095
if R < abs_tol:
2096-
level -= 1
2096+
# Since no polytope will remove anything, the current set of
2097+
# hyperplanes must be in the result
20972098
res = union(res, Polytope(A[INDICES, :], B[INDICES]), False)
2098-
INDICES[-1] -= M
2099+
# None of the remaining polytopes removes anything
2100+
# Indicate that we are done at this level
2101+
counter[level] = mi[level]
2102+
# Add the polytope to the indices to get an empty intersection
2103+
# This will force the algorithm to pop out of this level and
2104+
# move on
20992105
INDICES = np.hstack([
21002106
INDICES,
2101-
beg_mi[level] + counter[level] + M
2107+
range(beg_mi[level], beg_mi[level] + mi[level])
21022108
])
21032109
else:
21042110
if save:

0 commit comments

Comments
 (0)