Browse Source

Fix C# mistakes in Custom drawing in 2D

Fixes #5107
Paul Joannon 4 years ago
parent
commit
d0d8ad1879
1 changed files with 7 additions and 5 deletions
  1. 7 5
      tutorials/2d/custom_drawing_in_2d.rst

+ 7 - 5
tutorials/2d/custom_drawing_in_2d.rst

@@ -183,16 +183,18 @@ In our example, we will simply use a fixed number of points, no matter the radiu
     public void DrawCircleArc(Vector2 center, float radius, float angleFrom, float angleTo, Color color)
     public void DrawCircleArc(Vector2 center, float radius, float angleFrom, float angleTo, Color color)
     {
     {
         int nbPoints = 32;
         int nbPoints = 32;
-        var pointsArc = new Vector2[nbPoints];
+        var pointsArc = new Vector2[nbPoints + 1];
 
 
-        for (int i = 0; i < nbPoints; ++i)
+        for (int i = 0; i <= nbPoints; i++)
         {
         {
             float anglePoint = Mathf.Deg2Rad(angleFrom + i * (angleTo - angleFrom) / nbPoints - 90f);
             float anglePoint = Mathf.Deg2Rad(angleFrom + i * (angleTo - angleFrom) / nbPoints - 90f);
             pointsArc[i] = center + new Vector2(Mathf.Cos(anglePoint), Mathf.Sin(anglePoint)) * radius;
             pointsArc[i] = center + new Vector2(Mathf.Cos(anglePoint), Mathf.Sin(anglePoint)) * radius;
         }
         }
 
 
-        for (int i = 0; i < nbPoints - 1; ++i)
+        for (int i = 0; i < nbPoints - 1; i++)
+        {
             DrawLine(pointsArc[i], pointsArc[i + 1], color);
             DrawLine(pointsArc[i], pointsArc[i + 1], color);
+        }
     }
     }
 
 
 
 
@@ -292,10 +294,10 @@ the same as before, except that we draw a polygon instead of lines:
         pointsArc[0] = center;
         pointsArc[0] = center;
         var colors = new Color[] { color };
         var colors = new Color[] { color };
 
 
-        for (int i = 0; i < nbPoints; ++i)
+        for (int i = 0; i <= nbPoints; i++)
         {
         {
             float anglePoint = Mathf.Deg2Rad(angleFrom + i * (angleTo - angleFrom) / nbPoints - 90);
             float anglePoint = Mathf.Deg2Rad(angleFrom + i * (angleTo - angleFrom) / nbPoints - 90);
-            pointsArc[i + 1] = center + new Vector2(Mathf.Cos(anglePoint), Mathf.Sin(anglePoint)) * radius;
+            pointsArc[i] = center + new Vector2(Mathf.Cos(anglePoint), Mathf.Sin(anglePoint)) * radius;
         }
         }
 
 
         DrawPolygon(pointsArc, colors);
         DrawPolygon(pointsArc, colors);