MegaMan.LevelEditor.JoinTool.NearestJoin C# (CSharp) Метод

NearestJoin() приватный статический Метод

private static NearestJoin ( ScreenDrawingSurface surface, Point location ) : Join
surface ScreenDrawingSurface
location System.Drawing.Point
Результат MegaMan.Common.Join
        private static Join NearestJoin(ScreenDrawingSurface surface, Point location)
        {
            Join nearest = null;

            foreach (var join in surface.Screen.Stage.Joins)
            {
                if (join.screenOne == surface.Screen.Name)
                {
                    int begin = join.offsetOne * surface.Screen.Tileset.TileSize;
                    int end = (join.offsetOne + join.Size) * surface.Screen.Tileset.TileSize;
                    if (join.type == JoinType.Vertical)
                    {
                        if (location.X > surface.Width - surface.Screen.Tileset.TileSize && location.Y >= begin && location.Y <= end)
                        {
                            nearest = join;
                        }
                    }
                    else
                    {
                        if (location.Y > surface.Height - surface.Screen.Tileset.TileSize && location.X >= begin && location.X <= end)
                        {
                            nearest = join;
                        }
                    }
                }
                else if (join.screenTwo == surface.Screen.Name)
                {
                    int begin = join.offsetTwo * surface.Screen.Tileset.TileSize;
                    int end = (join.offsetTwo + join.Size) * surface.Screen.Tileset.TileSize;
                    if (join.type == JoinType.Vertical)
                    {
                        if (location.X < surface.Screen.Tileset.TileSize && location.Y >= begin && location.Y <= end)
                        {
                            nearest = join;
                        }
                    }
                    else
                    {
                        if (location.Y < surface.Screen.Tileset.TileSize && location.X >= begin && location.X <= end)
                        {
                            nearest = join;
                        }
                    }
                }
            }
            return nearest;
        }