From be6fba93cc905679d696a515365a939ecc52f739 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 27 Sep 2020 17:45:44 +0100 Subject: [PATCH] refactor layout algorithm to allow clash avoidance Signed-off-by: Ian Jackson --- src/bin/otter.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/bin/otter.rs b/src/bin/otter.rs index a90d39fb..32dd3a21 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -768,12 +768,15 @@ mod library_add { fn place(&mut self, bbox: &[Pos;2]) -> Option { let PosC([w,h]) = bbox[1] - bbox[0]; - let (ncbot, tlhs) = loop { + let (ncbot, tlhs) = 'search : loop { let ncbot = max(self.cbot, self.top + h); if ncbot > self.bot { None? } let tlhs = self.clhs; - self.clhs += w; - if self.clhs <= self.rhs { break (ncbot, tlhs) } + 'within_line: loop { + self.clhs += w; + if self.clhs > self.rhs { break 'within_line } + break 'search (ncbot, tlhs); + } // line is full self.top = self.cbot; self.clhs = self.lhs; -- 2.30.2