public static CPos ClampToWorld(this World world, CPos xy) { var r = world.Map.Bounds; return(xy.Clamp(new Rectangle(r.X, r.Y, r.Width - 1, r.Height - 1))); }