Better handling for avoiding obstacles when layouting text with 0 distance
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
s3lph 2022-10-09 23:50:04 +02:00
parent aa842979e9
commit 7c954242eb
Signed by: s3lph
GPG key ID: 8AC98A811E5BEFF5

View file

@ -348,9 +348,9 @@ class BoundingBox:
else: else:
raise TypeError() raise TypeError()
def compute_weight(self, other, erfas, chaostreffs, ns): def compute_weight(self, other, erfas, chaostreffs, pdist, ns):
w = 0 w = 0
swm = self.with_margin(ns.font_distance) swm = self.with_margin(pdist)
swe = self.with_margin(ns.dotsize_erfa) swe = self.with_margin(ns.dotsize_erfa)
swc = self.with_margin(ns.dotsize_treff) swc = self.with_margin(ns.dotsize_treff)
swme = swm.with_margin(ns.dotsize_erfa) swme = swm.with_margin(ns.dotsize_erfa)
@ -365,7 +365,7 @@ class BoundingBox:
else: else:
w += 50 w += 50
else: else:
w += max(ns.font_distance*2 - swc.chebyshev_distance(o), 0) w += max(pdist*2 - swc.chebyshev_distance(o), 0)
continue continue
if o in swm: if o in swm:
if o.finished: if o.finished:
@ -378,14 +378,14 @@ class BoundingBox:
if location in swe: if location in swe:
w += 1000 w += 1000
else: else:
w += max(ns.font_distance*2 - swe.chebyshev_distance(location), 0) w += max(pdist*2 - swe.chebyshev_distance(location), 0)
for city, location in chaostreffs.items(): for city, location in chaostreffs.items():
if city == self.meta['city']: if city == self.meta['city']:
continue continue
if location in swc: if location in swc:
w += 1000 w += 1000
else: else:
w += max(ns.font_distance*2 - swc.chebyshev_distance(location), 0) w += max(pdist*2 - swc.chebyshev_distance(location), 0)
self._weight = w self._weight = w
@property @property
@ -465,7 +465,7 @@ def optimize_text_layout(ns, erfas, chaostreffs, size, svg):
all_boxes.update(candidates[city]) all_boxes.update(candidates[city])
unfinished_boxes.update(candidates[city]) unfinished_boxes.update(candidates[city])
for box in all_boxes: for box in all_boxes:
box.compute_weight(all_boxes, erfas, chaostreffs, ns) box.compute_weight(all_boxes, erfas, chaostreffs, pdist=max(ns.font_distance, xheight), ns=ns)
# Get candidate with the least number of optimal solutions > 0 # Get candidate with the least number of optimal solutions > 0
optcity = min(unfinished, key=lambda city: len([1 for box in candidates[city] if box.is_optimal]) or float('inf')) optcity = min(unfinished, key=lambda city: len([1 for box in candidates[city] if box.is_optimal]) or float('inf'))
@ -491,7 +491,7 @@ def optimize_text_layout(ns, erfas, chaostreffs, size, svg):
for city in order: for city in order:
all_boxes = set(finished.values()) all_boxes = set(finished.values())
for box in candidates[city]: for box in candidates[city]:
box.compute_weight(all_boxes, erfas, chaostreffs, ns) box.compute_weight(all_boxes, erfas, chaostreffs, pdist=max(ns.font_distance, xheight), ns=ns)
minbox = min(candidates[city], key=lambda box: box.weight) minbox = min(candidates[city], key=lambda box: box.weight)
if minbox is not finished[city]: if minbox is not finished[city]:
changed = True changed = True