@@ -5354,6 +5354,45 @@ impl Cam {
53545354 } ;
53555355 let mut deepest = f64:: INFINITY ;
53565356 let mut cut_z: Option < f64 > = None ;
5357+ // the highest cut at or after each move: a level at depth d is complete (every pass
5358+ // above d cut) only if no later cut is above d. A path that goes back up to cut (a
5359+ // contour's finishing loops after its roughing loop has reached the bottom) gets no
5360+ // stage there: the stock stays as staged before, which holds more material, never less
5361+ let mut from = vec ! [ posted. start; posted. moves. len( ) ] ;
5362+ {
5363+ let mut at = posted. start ;
5364+ for ( i, m) in posted. moves . iter ( ) . enumerate ( ) {
5365+ from[ i] = at;
5366+ at = match * m {
5367+ PMove :: Rapid { to } | PMove :: Line { to, .. } | PMove :: Arc { to, .. } => to,
5368+ PMove :: Cycle { holes, clear, .. } => [ holes[ 0 ] , holes[ 1 ] , clear] ,
5369+ #[ allow( unreachable_patterns) ]
5370+ _ => at,
5371+ } ;
5372+ }
5373+ }
5374+ let mut later_top = vec ! [ f64 :: NEG_INFINITY ; posted. moves. len( ) + 1 ] ;
5375+ for ( i, m) in posted. moves . iter ( ) . enumerate ( ) . rev ( ) {
5376+ let a = from[ i] ;
5377+ // the cutting moves (a pass along a level, a ramp, a helix), at their higher end; a
5378+ // plunge or link goes down a column its level's passes clear around it
5379+ let z = match * m {
5380+ PMove :: Line {
5381+ to,
5382+ phase : Phase :: Cut ,
5383+ ..
5384+ } => {
5385+ if to[ 0 ] == a[ 0 ] && to[ 1 ] == a[ 1 ] {
5386+ f64:: NEG_INFINITY
5387+ } else {
5388+ to[ 2 ] . max ( a[ 2 ] )
5389+ }
5390+ }
5391+ PMove :: Arc { to, .. } => to[ 2 ] . max ( a[ 2 ] ) ,
5392+ _ => f64:: NEG_INFINITY ,
5393+ } ;
5394+ later_top[ i] = later_top[ i + 1 ] . max ( z) ;
5395+ }
53575396 for ( i, m) in posted. moves . iter ( ) . enumerate ( ) {
53585397 match * m {
53595398 // a level's depth: the lowest point it cut (the feed back up is not one)
@@ -5370,6 +5409,7 @@ impl Cam {
53705409 if let Some ( z) = cut_z. take ( )
53715410 && stock_needed
53725411 && z < deepest
5412+ && later_top[ i] <= z
53735413 && !self . ops [ oi] . voids . is_empty ( )
53745414 {
53755415 deepest = z;
0 commit comments