From 7c954242eb4c635bf673196b5532ee71db3e9454 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 9 Oct 2022 23:50:04 +0200 Subject: [PATCH] Better handling for avoiding obstacles when layouting text with 0 distance --- generate_map.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/generate_map.py b/generate_map.py index c9329ef..8bb5a73 100755 --- a/generate_map.py +++ b/generate_map.py @@ -348,9 +348,9 @@ class BoundingBox: else: raise TypeError() - def compute_weight(self, other, erfas, chaostreffs, ns): + def compute_weight(self, other, erfas, chaostreffs, pdist, ns): w = 0 - swm = self.with_margin(ns.font_distance) + swm = self.with_margin(pdist) swe = self.with_margin(ns.dotsize_erfa) swc = self.with_margin(ns.dotsize_treff) swme = swm.with_margin(ns.dotsize_erfa) @@ -365,7 +365,7 @@ class BoundingBox: else: w += 50 else: - w += max(ns.font_distance*2 - swc.chebyshev_distance(o), 0) + w += max(pdist*2 - swc.chebyshev_distance(o), 0) continue if o in swm: if o.finished: @@ -378,14 +378,14 @@ class BoundingBox: if location in swe: w += 1000 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(): if city == self.meta['city']: continue if location in swc: w += 1000 else: - w += max(ns.font_distance*2 - swc.chebyshev_distance(location), 0) + w += max(pdist*2 - swc.chebyshev_distance(location), 0) self._weight = w @property @@ -465,7 +465,7 @@ def optimize_text_layout(ns, erfas, chaostreffs, size, svg): all_boxes.update(candidates[city]) unfinished_boxes.update(candidates[city]) 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 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: all_boxes = set(finished.values()) 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) if minbox is not finished[city]: changed = True