Skip to content

Commit 29f9cb2

Browse files
author
ynn
committed
feat(--verbose): prints DP and CC in addition to the current index
1 parent 9a3b00f commit 29f9cb2

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/interpreter.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::fmt::{self, Display, Formatter};
12
use std::io::{self, Write};
23

34
use super::cc::CC;
@@ -15,6 +16,19 @@ pub struct Interpreter {
1516
pub output_buf: Vec<u8>,
1617
}
1718

19+
impl Display for Interpreter {
20+
//The implementation is a bit dirty but see https://github.com/rust-lang/rust/issues/55584 .
21+
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
22+
write!(
23+
f,
24+
"{:12} DP:{:5} CC:{:?}",
25+
format!("{:?}", self.cur),
26+
format!("{:?}", self.dp),
27+
self.cc
28+
)
29+
}
30+
}
31+
1832
impl Interpreter {
1933
#[allow(clippy::new_without_default)]
2034
pub fn new() -> Self {

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn run(args: &Args) -> Result<(), Box<dyn Error>> {
4040
let cur_codel = img.get_codel_at(ip.cur);
4141
assert!(!cur_codel.is_black());
4242
if !cur_codel.is_white() {
43-
debug_print(args.verbose, &format!("{:?}", ip.cur));
43+
debug_print(args.verbose, &ip.to_string());
4444

4545
let iter_max = 8; //changes `dp` and `cc` at most 7 times
4646
for i in 0..iter_max {
@@ -99,6 +99,8 @@ pub fn run(args: &Args) -> Result<(), Box<dyn Error>> {
9999
//FIXME: Currently, the average number of iterations needed to find a non-white codel or wall is the size of the current white block.
100100
// Ideally it should be O(1) (like `Block::get_corner_index()`).
101101
loop {
102+
debug_print(args.verbose, &ip.to_string());
103+
102104
if visited.contains(&(ip.cur, ip.dp)) {
103105
return Ok(());
104106
}
@@ -117,8 +119,6 @@ pub fn run(args: &Args) -> Result<(), Box<dyn Error>> {
117119
continue;
118120
}
119121

120-
debug_print(args.verbose, &format!("{:?}", ip.cur));
121-
122122
ip.cur = next_index.unwrap();
123123

124124
if next_codel.is_white() {

0 commit comments

Comments
 (0)