direct: update birect.py

This commit is contained in:
Connor Olding 2022-06-18 09:33:26 +02:00
parent 991e72e118
commit 2620721e46

View file

@ -26,7 +26,7 @@ def birect(
max_iters=None, # exit when the optimization procedure iterates this many times
by_longest=False, # measure by rects by longest edge instead of their diagonal
pruning=0,
F=float, # can be float, np.float32, np.float64, decimal, or anything float-like
F=float, # can be float, decimal.Decimal, numpy.float64, or anything float-like
):
assert len(lo) == len(hi), "dimensional mismatch"
@ -48,9 +48,9 @@ def birect(
return res
def ab_to_lu(w_a, w_b): # converts corner points to midpoints, also denominators
# (2 * a + b) / (den * 3) = point halfway between corner "a" and the center
# (2 * a + b) / (den * 3) = point inbetween corner "a" and the center
w_l = [(a[0] + a[0] + b[0], (1 << a[1]) * 3) for a, b in zip(w_a, w_b)]
# (a + 2 * b) / (den * 3) = point halfway between corner "b" and the center
# (a + 2 * b) / (den * 3) = point inbetween corner "b" and the center
w_u = [(a[0] + b[0] + b[0], (1 << b[1]) * 3) for a, b in zip(w_a, w_b)]
return w_l, w_u
@ -202,9 +202,9 @@ def birect(
# ↓b ↓b a↓b a↓
# ┌───────────┐←b ┌─────╥─────┐ ┌─────╥─────┐ ┌─────╥─────┐←a
# │ │ │ ║ │ │ l ║ │ │ l ║ l │
# │ ① u │ ⇒ │ u ② ║ u │ ⇒ │ u ③ ║ u │ ⇒ │ u ║ u │
# │ ① u │ → │ u ② ║ u │ → │ u ③ ║ u │ → │ u ║ u │
# │ │ │ ║ │ b→╞═════╣←a │ b→╞═════╬═════╡←a
# │ l │ ⇒ │ l ║ l │ ⇒ │ l ║ l │ ⇒ │ l ║ l │
# │ l │ → │ l ║ l │ → │ l ║ l │ → │ l ║ l │
# │ │ │ ║ │ │ u ║ │ │ u ║ u │
# a→└───────────┘ └─────╨─────┘ b→└─────╨─────┘ b→└─────╨─────┘
# ↑a ↑a ↑a ↑b
@ -318,7 +318,7 @@ def birect(
v_new = split_rectangles(v_potential)
for j in v_potential:
del v_active[j] # these were just split a moment ago, so remove them
del v_active[j] # these were just subdivided a moment ago, so remove them
for j in v_new:
if v_depth[j] < depth_limit: # TODO: is checking this late wasting evals?
v_active[j] = True # these were just created, so add them