File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 1+ use std:: fmt:: { self , Display , Formatter } ;
12use std:: io:: { self , Write } ;
23
34use 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+
1832impl Interpreter {
1933 #[ allow( clippy:: new_without_default) ]
2034 pub fn new ( ) -> Self {
Original file line number Diff line number Diff 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 ( ) {
You can’t perform that action at this time.
0 commit comments