# Untitled

unknown
csharp
a year ago
2.8 kB
4
Indexable
Never
```private void tilePolygon()
{
if(_points.Count < 3){ return; }

// Variable for counting clockwise turns in a row
short clockwiseTurnsCount = 0;

// Store points list with info on turns
List<Vector3> pointsWithTurns = generateTurns(_points);

// We go through each point
for (int pointIndex = 0; pointIndex < _points.Count; pointIndex++)
{
// If this point represents a clockwise turn...
if (pointsWithTurns[pointIndex].z > 0f)
{
// We count it
clockwiseTurnsCount++;

//If it's the third one
if (clockwiseTurnsCount == 3)
{
// Generate 4th point and place a mask tile (this updates points list)

// Call function recursively for updated list
tilePolygon();

break;
}
}
// If this point represents a counterclockwise turn
else
{
// Zero the counter
clockwiseTurnsCount = 0;
}
}

}

{
// Calculate the fourth point to make a rectangle
Vector2 fourthPoint = calculateFourthRectVertex(
_points[pointIndex - 2],
_points[pointIndex - 1],
_points[pointIndex]
);

// Make a list of all rectangle points
List<Vector2> rectangle = new List<Vector2>();

// Calculate points positions
Vector2[] pointsSorted = sortClockwise(rectangle);

// Instantiate and scale a mask tile based on these 4 points
new Vector3(
pointsSorted[0].x + ((pointsSorted[1].x - pointsSorted[0].x) / 2),
pointsSorted[0].y - ((pointsSorted[0].y - pointsSorted[3].y) / 2),
0f
),
transform.rotation
);