Skip to content

Instantly share code, notes, and snippets.

@Metapyziks
Created May 29, 2012 22:08
Show Gist options
  • Select an option

  • Save Metapyziks/2831090 to your computer and use it in GitHub Desktop.

Select an option

Save Metapyziks/2831090 to your computer and use it in GitHub Desktop.
private bool InRange( District district )
{
float xdiff = 0.0f, ydiff = 0.0f;
if ( Center.X < district.Bounds.Left )
xdiff = Math.Min( district.Bounds.Left - Center.X, Center.X - district.Bounds.Right + City.Width );
else if ( Center.X > district.Bounds.Right )
xdiff = Math.Min( Center.X - district.Bounds.Right, district.Bounds.Left - Center.X + City.Width );
if ( Center.Y < district.Bounds.Top )
ydiff = Math.Min( district.Bounds.Top - Center.Y, Center.Y - district.Bounds.Bottom + City.Height );
else if ( Center.Y > district.Bounds.Bottom )
ydiff = Math.Min( Center.Y - district.Bounds.Bottom, district.Bounds.Top - Center.Y + City.Height );
return xdiff * xdiff + ydiff * ydiff <= myRange2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment