Last active
August 29, 2015 14:17
-
-
Save penev92/d47096e0821f078206ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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