# Local Maximum function strange behavior

4.3 C#

### Question

I wrote this function that checks if a given location is a local Minimum or Maximum however it keeps returning images with maximums in clumps which should be impossible by definition there should be at least one pixel separating each one at a minimum. Here is the relevant code.

``````private List<Vector2> GetNeighbors(int x, int y)
{
List<Vector2> neighbors = new();

if (x - 1 >= 0) // WEST
{
}
if (x - 1 >= 0 && y - 1 >= 0) // NORTHWEST
{
}
if (y - 1 >= 0) // NORTH
{
}
if (x + 1 <= worldWidth - 1 && y - 1 >= 0) // NORTHEAST
{
}
if (x + 1 <= worldWidth - 1) // EAST
{
}
if (x + 1 <= worldWidth - 1 && y + 1 <= worldHeight - 1) // SOUTHEAST
{
}
if (y + 1 <= worldHeight - 1) // SOUTH
{
}
if (x - 1 >= 0 && y + 1 <= worldHeight - 1) // SOUTHWEST
{
}

return neighbors;
}
``````
``````private void CheckMaximaMinima(int x,int y,float value)
{
List<Vector2> neighbors = GetNeighbors(x,y);
List<bool> values = new();

for (int i = 0;i<neighbors.Count;i++)
{
float compareValue = noiseImage.GetPixel((int)neighbors[i].X,(int)neighbors[i].Y).Luminance;

if (compareValue < (value + maxminThreshold))
{
}
else
{
}
}

if (values.All(item => item == true))
{
planetImage.SetPixel(x,y,colorMaxima);
}
else if (values.All(item => item == false))
{
planetImage.SetPixel(x,y,colorMinima);
}
}
``````

And here is the output

Is there something wrong with the code or a better solution? Any advice is welcome.