chiark / gitweb /
refactor layout algorithm to allow clash avoidance
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 27 Sep 2020 16:45:44 +0000 (17:45 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 27 Sep 2020 16:45:44 +0000 (17:45 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/otter.rs

index a90d39fb1850ff32fe6aad2f3c422ee4213e2626..32dd3a21c534b710cfeb8c2fdd90b5e2f2206ad0 100644 (file)
@@ -768,12 +768,15 @@ mod library_add {
       fn place(&mut self, bbox: &[Pos;2]) -> Option<Pos> {
         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;