Q:

Get the perimeter of a list of verticies

I am currently developing a level editor, and I've gotten to the point where I have collected a list of vertices that I want to use to create a Polygon collider.
I have obtained these vertices by tagging certain tiles as "colliders" and running them through an algorithm to get a list of tiles that are connected. I then created a list of vertices from the list of connected tiles and removed any duplicates.
Below is an image that will help explain. All of the dots are verticies that are currently in my list, but I want to use the ones colored red to create a polygon.

A:

This is how I ended up solving my problem. Each vertex is a part of four different tiles (Excluding edge of map cases), so I just iterated through every vertex and counted how many neighbors are "of the same type". If the result was 4 then it meant that the vertex was somewhere in the middle of the polygon. If the result was 3 it meant the vertex was on an inner corner. 2 meant it was on an edge. 1 meant it was an outer corner.
private List<Vector2> GetPerimeterOfVerticeList(List<Vector2> vertices, TileType type)
{
    int neighborCount = 0;
    List<Vector2> perimeter = new List<Vector2>();

    //Check the four tiles touching this vertex
    foreach (Vector2 v in vertices)
    {
        //upper left tile
        if (v.x - 1 >= 0 && v.y <= gridHeight - 1 && grid[(int)v.x - 1, (int)v.y].type == type)
        {
            neighborCount++;
        }
        //upper right
        if (v.x <= gridWidth - 1 && v.y <= gridHeight - 1 && grid[(int)v.x, (int)v.y].type == type)
        {
            neighborCount++;
        }
        //bottom right
        if (v.y - 1 >= 0 && v.x <= gridWidth - 1 && grid[(int)v.x, (int)v.y - 1].type == type)
        {
            neighborCount++;
        }
        //bottom left
        if (v.y - 1 >= 0 && v.x - 1 >= 0 && grid[(int)v.x - 1, (int)v.y - 1].type == type)
        {
            neighborCount++;
        }

        //If we have less than 4 neighbors, it means we are on the edge. 3 is an inner corner, 2 is a side piece, 1 is an outer corner
        if (neighborCount < 4)
        {
            perimeter.Add(v);
        }

        //Reset the neighbor count back to 0 for the next vertex check.
        neighborCount = 0;
    }
    return perimeter;
}

