From 876d316cda124953f3df5ef2917d71ed7f8807bf Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 5 Apr 2022 17:58:48 -0700 Subject: [PATCH] atlas: use saturating arithmetic --- src/Atlas.zig | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Atlas.zig b/src/Atlas.zig index 018e6b54b..2faf8376c 100644 --- a/src/Atlas.zig +++ b/src/Atlas.zig @@ -151,17 +151,14 @@ fn fit(self: Atlas, idx: usize, width: u32, height: u32) ?u32 { var y = node.y; var i = idx; var width_left = width; - while (true) : (i += 1) { + while (width_left > 0) : (i += 1) { const n = self.nodes.items[i]; if (n.y > y) y = n.y; // If the added height exceeds our texture size, it doesn't fit. if ((y + height) > (self.size - 1)) return null; - // If we have no more width left (width_left - n.width < 0) - // then we are done. - if (n.width >= width_left) break; - width_left -= n.width; + width_left -|= n.width; } return y;