Quite a Distance from the Right Solution
by in CodeSOD on 2026-09-30Fritz's team needed to see if one point was within a certain distance from a center point. You or I would likely try and answer this question using a simple distance calculation, since that's the question we're trying to answer. But what if you didn't understand distances at all? Then you could write this little piece of genius.
private bool IsWithin(Point point, int radius)
{
for (int x = -radius; x < radius + 1; x++)
{
for (int y = -radius; y < radius + 1; y++)
{
if ((PositionX == point.X + x) && (PositionY == point.Y + y))
return true;
}
}
return false;
}