Setting Boundary/Border/Frame for In Game Snapping to Grid

Hey guys,
I'm trying to snap an actor to particular coordinantes during gameplay. There are several great templates that show how to control movement according to the width/height of the grid cells. The problem I am having is that each of these templates uses the entire screen as a grid and I want to have a boundary (or border) around my grid. I'm not sure how to offset the x (or the y) by, for example, 10 pixels to the left before the actor snaps to the grid.
So, imagine a grid that snaps the actor every 40 pixels starting to snap at 50 pixels from the left (allowing for the 10 pixel boundary) instead of at 40 pixels from the left (not compensating for the boundary). Then it would snap again at 90 pixels instead of 80 pixels and so on. Each snap would add 10 pixels to the left to set the boundary, but would then maintain the 40 pixel separation between grid spots.
Using just the x coordinante, I've found two ways to effectively snap an actor to a nearby grid cell. Either way, I can't quite figure out the final offset math.
1) (ceil((floor(( self.Position.X / game.cellWidth )*2))/2))* game.cellWidth
2) ( game.cellWidth /2)+ game.cellWidth *floor( self.Position.X / game.cellWidth )
Thanks.
I'm trying to snap an actor to particular coordinantes during gameplay. There are several great templates that show how to control movement according to the width/height of the grid cells. The problem I am having is that each of these templates uses the entire screen as a grid and I want to have a boundary (or border) around my grid. I'm not sure how to offset the x (or the y) by, for example, 10 pixels to the left before the actor snaps to the grid.
So, imagine a grid that snaps the actor every 40 pixels starting to snap at 50 pixels from the left (allowing for the 10 pixel boundary) instead of at 40 pixels from the left (not compensating for the boundary). Then it would snap again at 90 pixels instead of 80 pixels and so on. Each snap would add 10 pixels to the left to set the boundary, but would then maintain the 40 pixel separation between grid spots.
Using just the x coordinante, I've found two ways to effectively snap an actor to a nearby grid cell. Either way, I can't quite figure out the final offset math.
1) (ceil((floor(( self.Position.X / game.cellWidth )*2))/2))* game.cellWidth
2) ( game.cellWidth /2)+ game.cellWidth *floor( self.Position.X / game.cellWidth )
Thanks.
Comments
Any help or suggestions would be much appreciated. Thanks for your time.
I'm not sure who did the template, but I really appreciate the help. Thanks to...whomever.