Skip to content

Instantly share code, notes, and snippets.

@penev92
Last active August 29, 2015 14:17
Show Gist options
  • Save penev92/d47096e0821f078206ec to your computer and use it in GitHub Desktop.
Save penev92/d47096e0821f078206ec to your computer and use it in GitHub Desktop.
public CPos ChooseClosestEdgeCell(CPos pos)
{
var mpos = pos.ToMPos(this);
var x = ((mpos.U - Bounds.Left) < Bounds.Width / 2) ? Bounds.Left : Bounds.Right;
var y = ((mpos.V - Bounds.Top) < Bounds.Height / 2) ? Bounds.Top : Bounds.Bottom;
var distX = Math.Abs(x - mpos.U);
var distY = Math.Abs(y - mpos.V);
return distX < distY ? new MPos(x, mpos.V).ToCPos(this) : new MPos(mpos.U, y).ToCPos(this);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment