summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-10-17 22:29:10 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-10-17 22:29:10 +0800
commitaa84fa7723d85fca58c6606194405bc557ff1b89 (patch)
tree3613a0a538a62e0021f767a6c7c5aa5500459260
parent06cbbb7f547c6dbaf3461c1787d7943e1d162447 (diff)
fixup! wiprefactor_offset
-rw-r--r--src/image.rs42
1 files changed, 25 insertions, 17 deletions
diff --git a/src/image.rs b/src/image.rs
index 07e8af5..f297d4a 100644
--- a/src/image.rs
+++ b/src/image.rs
@@ -146,12 +146,13 @@ impl<'a> FlowChart<'a> {
}
fn lookahead(&mut self, ast: &[DepthExpr]) {
- let mut largest: u32 = 0;
- let mut copy: Vec<_> = self
+ let mut branches = self
.branches
- .to_vec();
- let cur = copy.first();
- copy.push(1);
+ .clone();
+ branches.push(1);
+ let mut cur = branches
+ .iter_mut()
+ .peekable();
for node in ast {
match node {
@@ -161,22 +162,29 @@ impl<'a> FlowChart<'a> {
then_branch: _,
else_branch: _,
} => {
- largest = largest.max(
- self.text_size(cond)
- .0,
- )
+ // TODO: use a map with unique new so new branches don't conflict
+ if let Some(c) = cur.peek_mut() {
+ **c = (**c).max(
+ self.text_size(cond)
+ .0,
+ );
+ }
}
DepthExpr::IO(s) => {
- largest = largest.max(
- self.text_size(s)
- .0,
- )
+ if let Some(c) = cur.peek_mut() {
+ **c = (**c).max(
+ self.text_size(s)
+ .0,
+ );
+ }
}
DepthExpr::Process(s) => {
- largest = largest.max(
- self.text_size(s)
- .0,
- )
+ if let Some(c) = cur.peek_mut() {
+ **c = (**c).max(
+ self.text_size(s)
+ .0,
+ );
+ }
}
}
}