Snap curve to custom grid

hi again

I need to find a concept for the next mission (rhinocommon c#):
I want to have a closed curve snapped to a custom line grid.
if the curve is passing inside a cell of the grid and is covering more than 50% of it (looking from the center of the closed curve), the curve will snap to the cell bounding.
I have added some photo to demonstrate.
what will be the concept for such a task?
thanks a lot…