File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ pub struct Args {
1111 #[ arg( short, long) ]
1212 pub codel_size : Option < usize > ,
1313
14+ /// Terminates the program after this number of iterations
15+ #[ arg( long) ]
16+ pub max_iter : Option < usize > ,
17+
1418 /// Enables debug output (path trace etc.)
1519 #[ arg( short, long) ]
1620 pub verbose : bool ,
Original file line number Diff line number Diff line change @@ -36,10 +36,17 @@ pub fn run(args: &Args) -> Result<(), Box<dyn Error>> {
3636
3737 let mut ip = Interpreter :: new ( ) ;
3838
39+ let mut num_iter = 0 ;
3940 loop {
4041 let cur_codel = img. get_codel_at ( ip. cur ) ;
4142 assert ! ( !cur_codel. is_black( ) ) ;
4243 if !cur_codel. is_white ( ) {
44+ if num_iter == args. max_iter . unwrap_or ( usize:: MAX ) {
45+ println ! ( "Program terminated by `max-iter`." ) ;
46+ return Ok ( ( ) ) ;
47+ }
48+ num_iter += 1 ;
49+
4350 debug_print ( args. verbose , & ip. to_string ( ) ) ;
4451
4552 let iter_max = 8 ; //changes `dp` and `cc` at most 7 times
@@ -99,6 +106,12 @@ pub fn run(args: &Args) -> Result<(), Box<dyn Error>> {
99106 //FIXME: Currently, the average number of iterations needed to find a non-white codel or wall is the size of the current white block.
100107 // Ideally it should be O(1) (like `Block::get_corner_index()`).
101108 loop {
109+ if num_iter == args. max_iter . unwrap_or ( usize:: MAX ) {
110+ println ! ( "Program terminated by `max-iter`." ) ;
111+ return Ok ( ( ) ) ;
112+ }
113+ num_iter += 1 ;
114+
102115 debug_print ( args. verbose , & ip. to_string ( ) ) ;
103116
104117 if visited. contains ( & ( ip. cur , ip. dp ) ) {
You can’t perform that action at this time.
0 commit comments